mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
7b4c5ebb95
The code to handle MediaStream URIs is almost the same as for Blobs, so share it. nsHostObjectProtocolHandler is modified a bit to simplify method names. Also we make nsHostObjectProtocolHandler::AddDataEntry take responsibility for generating the URI to avoid duplicating that code later. We need separate subclasses for each kind of host object protocol handler, but we don't need separate subclasses for each kind of host object URI. --HG-- rename : content/base/public/nsBlobProtocolHandler.h => content/base/public/nsHostObjectProtocolHandler.h rename : content/base/src/nsBlobProtocolHandler.cpp => content/base/src/nsHostObjectProtocolHandler.cpp rename : content/base/src/nsBlobURI.cpp => content/base/src/nsHostObjectURI.cpp rename : content/base/src/nsBlobURI.h => content/base/src/nsHostObjectURI.h extra : rebase_source : bfb1d7ea2813100a35f9a2054a67584e38f5f330
91 lines
2.7 KiB
C++
91 lines
2.7 KiB
C++
/* -*- 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"
|
|
#include "nsIDocument.h"
|
|
#include "nsIPrincipal.h"
|
|
#include "nsContentUtils.h"
|
|
#include "nsHostObjectProtocolHandler.h"
|
|
|
|
namespace mozilla {
|
|
namespace dom {
|
|
|
|
void
|
|
URL::CreateObjectURL(nsISupports* aGlobal, nsIDOMBlob* aBlob,
|
|
const objectURLOptions& aOptions,
|
|
nsAString& aResult,
|
|
ErrorResult& aError)
|
|
{
|
|
CreateObjectURLInternal(aGlobal, aBlob, NS_LITERAL_CSTRING(BLOBURI_SCHEME),
|
|
aOptions, aResult, aError);
|
|
}
|
|
|
|
void
|
|
URL::CreateObjectURLInternal(nsISupports* aGlobal, nsISupports* aObject,
|
|
const nsACString& aScheme,
|
|
const mozilla::dom::objectURLOptions& aOptions,
|
|
nsAString& aResult,
|
|
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
|
|
URL::RevokeObjectURL(nsISupports* aGlobal, const nsAString& aURL)
|
|
{
|
|
nsCOMPtr<nsPIDOMWindow> w = do_QueryInterface(aGlobal);
|
|
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);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|