mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-16 05:45:33 +00:00
Bug 1402784 - Use nsIContentPolicy::TYPE_INTERNAL_AUDIOWORKLET and nsIContentPolicy::TYPE_INTERNAL_PAINTWORKLET in Worklet code, r=smaug
Depends on D67105 Differential Revision: https://phabricator.services.mozilla.com/D67106 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
96d0e4f828
commit
6e5bd2d254
@ -1499,6 +1499,7 @@ DOMInterfaces = {
|
||||
'Worklet': {
|
||||
# Paint worklets just use the Worklet interface.
|
||||
'concrete': True,
|
||||
'implicitJSContext': [ 'addModule' ],
|
||||
},
|
||||
|
||||
'XMLHttpRequest': {
|
||||
|
@ -183,7 +183,7 @@ void GetRequestURLFromChrome(const nsAString& aInput, nsAString& aRequestURL,
|
||||
return;
|
||||
}
|
||||
}
|
||||
already_AddRefed<URL> ParseURLFromWorker(const GlobalObject& aGlobal,
|
||||
already_AddRefed<URL> ParseURLFromWorker(nsIGlobalObject* aGlobal,
|
||||
const nsAString& aInput,
|
||||
ErrorResult& aRv) {
|
||||
WorkerPrivate* worker = GetCurrentThreadWorkerPrivate();
|
||||
@ -191,16 +191,15 @@ already_AddRefed<URL> ParseURLFromWorker(const GlobalObject& aGlobal,
|
||||
worker->AssertIsOnWorkerThread();
|
||||
|
||||
NS_ConvertUTF8toUTF16 baseURL(worker->GetLocationInfo().mHref);
|
||||
RefPtr<URL> url =
|
||||
URL::Constructor(aGlobal.GetAsSupports(), aInput, baseURL, aRv);
|
||||
RefPtr<URL> url = URL::Constructor(aGlobal, aInput, baseURL, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
aRv.ThrowTypeError<MSG_INVALID_URL>(NS_ConvertUTF16toUTF8(aInput));
|
||||
}
|
||||
return url.forget();
|
||||
}
|
||||
void GetRequestURLFromWorker(const GlobalObject& aGlobal,
|
||||
const nsAString& aInput, nsAString& aRequestURL,
|
||||
nsACString& aURLfragment, ErrorResult& aRv) {
|
||||
void GetRequestURLFromWorker(nsIGlobalObject* aGlobal, const nsAString& aInput,
|
||||
nsAString& aRequestURL, nsACString& aURLfragment,
|
||||
ErrorResult& aRv) {
|
||||
RefPtr<URL> url = ParseURLFromWorker(aGlobal, aInput, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return;
|
||||
@ -266,11 +265,19 @@ already_AddRefed<Request> Request::Constructor(const GlobalObject& aGlobal,
|
||||
const RequestOrUSVString& aInput,
|
||||
const RequestInit& aInit,
|
||||
ErrorResult& aRv) {
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
|
||||
return Constructor(global, aGlobal.Context(), aInput, aInit, aRv);
|
||||
}
|
||||
|
||||
/*static*/
|
||||
already_AddRefed<Request> Request::Constructor(nsIGlobalObject* aGlobal,
|
||||
JSContext* aCx,
|
||||
const RequestOrUSVString& aInput,
|
||||
const RequestInit& aInit,
|
||||
ErrorResult& aRv) {
|
||||
bool hasCopiedBody = false;
|
||||
RefPtr<InternalRequest> request;
|
||||
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
|
||||
|
||||
RefPtr<AbortSignal> signal;
|
||||
|
||||
if (aInput.IsRequest()) {
|
||||
@ -301,7 +308,7 @@ already_AddRefed<Request> Request::Constructor(const GlobalObject& aGlobal,
|
||||
nsAutoString requestURL;
|
||||
nsCString fragment;
|
||||
if (NS_IsMainThread()) {
|
||||
nsCOMPtr<nsPIDOMWindowInner> inner(do_QueryInterface(global));
|
||||
nsCOMPtr<nsPIDOMWindowInner> inner(do_QueryInterface(aGlobal));
|
||||
Document* doc = inner ? inner->GetExtantDoc() : nullptr;
|
||||
if (doc) {
|
||||
GetRequestURLFromDocument(doc, input, requestURL, fragment, aRv);
|
||||
@ -317,7 +324,7 @@ already_AddRefed<Request> Request::Constructor(const GlobalObject& aGlobal,
|
||||
}
|
||||
request = new InternalRequest(NS_ConvertUTF16toUTF8(requestURL), fragment);
|
||||
}
|
||||
request = request->GetRequestConstructorCopy(global, aRv);
|
||||
request = request->GetRequestConstructorCopy(aGlobal, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -355,7 +362,7 @@ already_AddRefed<Request> Request::Constructor(const GlobalObject& aGlobal,
|
||||
} else {
|
||||
nsAutoString referrerURL;
|
||||
if (NS_IsMainThread()) {
|
||||
nsCOMPtr<nsPIDOMWindowInner> inner(do_QueryInterface(global));
|
||||
nsCOMPtr<nsPIDOMWindowInner> inner(do_QueryInterface(aGlobal));
|
||||
Document* doc = inner ? inner->GetExtantDoc() : nullptr;
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
if (doc) {
|
||||
@ -374,7 +381,7 @@ already_AddRefed<Request> Request::Constructor(const GlobalObject& aGlobal,
|
||||
uri->GetSpec(spec);
|
||||
CopyUTF8toUTF16(spec, referrerURL);
|
||||
if (!referrerURL.EqualsLiteral(kFETCH_CLIENT_REFERRER_STR)) {
|
||||
nsCOMPtr<nsIPrincipal> principal = global->PrincipalOrNull();
|
||||
nsCOMPtr<nsIPrincipal> principal = aGlobal->PrincipalOrNull();
|
||||
if (principal) {
|
||||
nsresult rv =
|
||||
principal->CheckMayLoad(uri,
|
||||
@ -424,7 +431,7 @@ already_AddRefed<Request> Request::Constructor(const GlobalObject& aGlobal,
|
||||
UniquePtr<mozilla::ipc::PrincipalInfo> principalInfo;
|
||||
|
||||
if (NS_IsMainThread()) {
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(global);
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal);
|
||||
if (window) {
|
||||
nsCOMPtr<Document> doc;
|
||||
doc = window->GetExtantDoc();
|
||||
@ -506,8 +513,7 @@ already_AddRefed<Request> Request::Constructor(const GlobalObject& aGlobal,
|
||||
|
||||
RefPtr<InternalHeaders> headers;
|
||||
if (aInit.mHeaders.WasPassed()) {
|
||||
RefPtr<Headers> h =
|
||||
Headers::Constructor(aGlobal, aInit.mHeaders.Value(), aRv);
|
||||
RefPtr<Headers> h = Headers::Create(aGlobal, aInit.mHeaders.Value(), aRv);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -587,7 +593,7 @@ already_AddRefed<Request> Request::Constructor(const GlobalObject& aGlobal,
|
||||
}
|
||||
}
|
||||
|
||||
RefPtr<Request> domRequest = new Request(global, request, signal);
|
||||
RefPtr<Request> domRequest = new Request(aGlobal, request, signal);
|
||||
domRequest->SetMimeType();
|
||||
|
||||
if (aInput.IsRequest()) {
|
||||
@ -596,7 +602,7 @@ already_AddRefed<Request> Request::Constructor(const GlobalObject& aGlobal,
|
||||
inputReq->GetBody(getter_AddRefs(body));
|
||||
if (body) {
|
||||
inputReq->SetBody(nullptr, 0);
|
||||
inputReq->SetBodyUsed(aGlobal.Context(), aRv);
|
||||
inputReq->SetBodyUsed(aCx, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -104,6 +104,12 @@ class Request final : public FetchBody<Request>, public nsWrapperCache {
|
||||
const RequestInit& aInit,
|
||||
ErrorResult& rv);
|
||||
|
||||
static already_AddRefed<Request> Constructor(nsIGlobalObject* aGlobal,
|
||||
JSContext* aCx,
|
||||
const RequestOrUSVString& aInput,
|
||||
const RequestInit& aInit,
|
||||
ErrorResult& rv);
|
||||
|
||||
nsIGlobalObject* GetParentObject() const { return mOwner; }
|
||||
|
||||
already_AddRefed<Request> Clone(ErrorResult& aRv);
|
||||
|
@ -30,6 +30,10 @@ class AudioWorkletImpl final : public WorkletImpl {
|
||||
|
||||
nsresult SendControlMessage(already_AddRefed<nsIRunnable> aRunnable) override;
|
||||
|
||||
nsContentPolicyType ContentPolicyType() const override {
|
||||
return nsIContentPolicy::TYPE_INTERNAL_AUDIOWORKLET;
|
||||
}
|
||||
|
||||
// Execution thread only.
|
||||
dom::AudioWorkletGlobalScope* GetGlobalScope() {
|
||||
return static_cast<dom::AudioWorkletGlobalScope*>(
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "mozilla/dom/BlobBinding.h"
|
||||
#include "mozilla/dom/Fetch.h"
|
||||
#include "mozilla/dom/PromiseNativeHandler.h"
|
||||
#include "mozilla/dom/Request.h"
|
||||
#include "mozilla/dom/Response.h"
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
#include "mozilla/dom/ScriptLoader.h"
|
||||
@ -70,10 +71,9 @@ class WorkletFetchHandler final : public PromiseNativeHandler,
|
||||
public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
|
||||
static already_AddRefed<Promise> Fetch(Worklet* aWorklet,
|
||||
static already_AddRefed<Promise> Fetch(Worklet* aWorklet, JSContext* aCx,
|
||||
const nsAString& aModuleURL,
|
||||
const WorkletOptions& aOptions,
|
||||
CallerType aCallerType,
|
||||
ErrorResult& aRv) {
|
||||
MOZ_ASSERT(aWorklet);
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
@ -121,14 +121,25 @@ class WorkletFetchHandler final : public PromiseNativeHandler,
|
||||
}
|
||||
}
|
||||
|
||||
RequestOrUSVString request;
|
||||
request.SetAsUSVString().ShareOrDependUpon(aModuleURL);
|
||||
RequestOrUSVString requestInput;
|
||||
requestInput.SetAsUSVString().ShareOrDependUpon(aModuleURL);
|
||||
|
||||
RequestInit init;
|
||||
init.mCredentials.Construct(aOptions.mCredentials);
|
||||
RequestInit requestInit;
|
||||
requestInit.mCredentials.Construct(aOptions.mCredentials);
|
||||
|
||||
RefPtr<Promise> fetchPromise =
|
||||
FetchRequest(global, request, init, aCallerType, aRv);
|
||||
RefPtr<Request> request =
|
||||
Request::Constructor(global, aCx, requestInput, requestInit, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
request->OverrideContentPolicyType(aWorklet->Impl()->ContentPolicyType());
|
||||
|
||||
RequestOrUSVString finalRequestInput;
|
||||
finalRequestInput.SetAsRequest() = request;
|
||||
|
||||
RefPtr<Promise> fetchPromise = FetchRequest(
|
||||
global, finalRequestInput, requestInit, CallerType::System, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
// OK to just return null, since caller will ignore return value
|
||||
// anyway if aRv is a failure.
|
||||
@ -453,13 +464,13 @@ JSObject* Worklet::WrapObject(JSContext* aCx,
|
||||
return mImpl->WrapWorklet(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
already_AddRefed<Promise> Worklet::AddModule(const nsAString& aModuleURL,
|
||||
already_AddRefed<Promise> Worklet::AddModule(JSContext* aCx,
|
||||
const nsAString& aModuleURL,
|
||||
const WorkletOptions& aOptions,
|
||||
CallerType aCallerType,
|
||||
ErrorResult& aRv) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
return WorkletFetchHandler::Fetch(this, aModuleURL, aOptions, aCallerType,
|
||||
aRv);
|
||||
return WorkletFetchHandler::Fetch(this, aCx, aModuleURL, aOptions, aRv);
|
||||
}
|
||||
|
||||
WorkletFetchHandler* Worklet::GetImportFetchHandler(const nsACString& aURI) {
|
||||
|
@ -42,7 +42,8 @@ class Worklet final : public nsISupports, public nsWrapperCache {
|
||||
virtual JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
already_AddRefed<Promise> AddModule(const nsAString& aModuleURL,
|
||||
already_AddRefed<Promise> AddModule(JSContext* aCx,
|
||||
const nsAString& aModuleURL,
|
||||
const WorkletOptions& aOptions,
|
||||
CallerType aCallerType, ErrorResult& aRv);
|
||||
|
||||
|
@ -64,6 +64,8 @@ class WorkletImpl {
|
||||
|
||||
void NotifyWorkletFinished();
|
||||
|
||||
virtual nsContentPolicyType ContentPolicyType() const = 0;
|
||||
|
||||
// Execution thread only.
|
||||
dom::WorkletGlobalScope* GetGlobalScope();
|
||||
|
||||
|
@ -18,6 +18,10 @@ class PaintWorkletImpl final : public WorkletImpl {
|
||||
static already_AddRefed<dom::Worklet> CreateWorklet(
|
||||
nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal);
|
||||
|
||||
nsContentPolicyType ContentPolicyType() const override {
|
||||
return nsIContentPolicy::TYPE_INTERNAL_PAINTWORKLET;
|
||||
}
|
||||
|
||||
protected:
|
||||
// Execution thread only.
|
||||
already_AddRefed<dom::WorkletGlobalScope> ConstructGlobalScope() override;
|
||||
|
Loading…
x
Reference in New Issue
Block a user