2013-01-28 03:08:21 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "URL.h"
|
|
|
|
|
|
|
|
#include "nsGlobalWindow.h"
|
|
|
|
#include "nsIDOMFile.h"
|
2013-02-15 00:04:11 -08:00
|
|
|
#include "DOMMediaStream.h"
|
2013-06-20 20:15:15 -07:00
|
|
|
#include "mozilla/dom/MediaSource.h"
|
2013-01-28 03:08:21 -08:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsHostObjectProtocolHandler.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
void
|
2012-12-03 08:07:49 -08:00
|
|
|
URL::CreateObjectURL(const GlobalObject& aGlobal, nsIDOMBlob* aBlob,
|
2013-01-28 03:08:21 -08:00
|
|
|
const objectURLOptions& aOptions,
|
2012-12-03 08:07:49 -08:00
|
|
|
nsString& aResult,
|
2013-01-28 03:08:21 -08:00
|
|
|
ErrorResult& aError)
|
|
|
|
{
|
2012-12-03 08:07:49 -08:00
|
|
|
CreateObjectURLInternal(aGlobal.Get(), aBlob,
|
|
|
|
NS_LITERAL_CSTRING(BLOBURI_SCHEME), aOptions, aResult,
|
|
|
|
aError);
|
2013-01-28 03:08:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-02-15 00:04:11 -08:00
|
|
|
URL::CreateObjectURL(const GlobalObject& aGlobal, DOMMediaStream& aStream,
|
2013-01-28 03:08:21 -08:00
|
|
|
const mozilla::dom::objectURLOptions& aOptions,
|
2012-12-03 08:07:49 -08:00
|
|
|
nsString& aResult,
|
2013-01-28 03:08:21 -08:00
|
|
|
ErrorResult& aError)
|
|
|
|
{
|
2013-02-15 00:04:11 -08:00
|
|
|
CreateObjectURLInternal(aGlobal.Get(), &aStream,
|
2012-12-03 08:07:49 -08:00
|
|
|
NS_LITERAL_CSTRING(MEDIASTREAMURI_SCHEME), aOptions,
|
|
|
|
aResult, aError);
|
2013-01-28 03:08:21 -08:00
|
|
|
}
|
|
|
|
|
2013-06-20 20:15:15 -07:00
|
|
|
void
|
|
|
|
URL::CreateObjectURL(const GlobalObject& aGlobal, MediaSource& aSource,
|
|
|
|
const objectURLOptions& aOptions,
|
|
|
|
nsString& aResult,
|
|
|
|
ErrorResult& aError)
|
|
|
|
{
|
|
|
|
CreateObjectURLInternal(aGlobal.Get(), &aSource,
|
|
|
|
NS_LITERAL_CSTRING(MEDIASOURCEURI_SCHEME), aOptions,
|
|
|
|
aResult, aError);
|
|
|
|
}
|
|
|
|
|
2013-01-28 03:08:21 -08:00
|
|
|
void
|
|
|
|
URL::CreateObjectURLInternal(nsISupports* aGlobal, nsISupports* aObject,
|
|
|
|
const nsACString& aScheme,
|
|
|
|
const mozilla::dom::objectURLOptions& aOptions,
|
2012-12-03 08:07:49 -08:00
|
|
|
nsString& aResult,
|
2013-01-28 03:08:21 -08:00
|
|
|
ErrorResult& aError)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> w = do_QueryInterface(aGlobal);
|
|
|
|
nsGlobalWindow* window = static_cast<nsGlobalWindow*>(w.get());
|
|
|
|
NS_PRECONDITION(!window || window->IsInnerWindow(),
|
|
|
|
"Should be inner window");
|
|
|
|
|
|
|
|
if (!window || !window->GetExtantDoc()) {
|
|
|
|
aError.Throw(NS_ERROR_INVALID_POINTER);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocument* doc = window->GetExtantDoc();
|
|
|
|
|
|
|
|
nsCString url;
|
|
|
|
nsresult rv = nsHostObjectProtocolHandler::AddDataEntry(aScheme, aObject,
|
|
|
|
doc->NodePrincipal(), url);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aError.Throw(rv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
doc->RegisterHostObjectUri(url);
|
|
|
|
CopyASCIItoUTF16(url, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-03 08:07:49 -08:00
|
|
|
URL::RevokeObjectURL(const GlobalObject& aGlobal, const nsAString& aURL)
|
2013-01-28 03:08:21 -08:00
|
|
|
{
|
2012-12-03 08:07:49 -08:00
|
|
|
nsCOMPtr<nsPIDOMWindow> w = do_QueryInterface(aGlobal.Get());
|
2013-01-28 03:08:21 -08:00
|
|
|
nsGlobalWindow* window = static_cast<nsGlobalWindow*>(w.get());
|
|
|
|
NS_PRECONDITION(!window || window->IsInnerWindow(),
|
|
|
|
"Should be inner window");
|
|
|
|
if (!window)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NS_LossyConvertUTF16toASCII asciiurl(aURL);
|
|
|
|
|
|
|
|
nsIPrincipal* winPrincipal = window->GetPrincipal();
|
|
|
|
if (!winPrincipal) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPrincipal* principal =
|
|
|
|
nsHostObjectProtocolHandler::GetDataEntryPrincipal(asciiurl);
|
|
|
|
bool subsumes;
|
|
|
|
if (principal && winPrincipal &&
|
|
|
|
NS_SUCCEEDED(winPrincipal->Subsumes(principal, &subsumes)) &&
|
|
|
|
subsumes) {
|
|
|
|
if (window->GetExtantDoc()) {
|
|
|
|
window->GetExtantDoc()->UnregisterHostObjectUri(asciiurl);
|
|
|
|
}
|
|
|
|
nsHostObjectProtocolHandler::RemoveDataEntry(asciiurl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|