/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* 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/. */
// If this document is sandboxed without 'allow-scripts', abort. if (GetScriptLoader()->GetDocument()->HasScriptsBlockedBySandbox()) {
*aRvOut = NS_OK; returnfalse;
}
// To prevent dynamic code execution, content scripts can only // load moz-extension URLs.
nsCOMPtr<nsIPrincipal> principal = aRequest->TriggeringPrincipal(); if (BasePrincipal::Cast(principal)->ContentScriptAddonPolicy() &&
!aRequest->mURI->SchemeIs("moz-extension")) {
*aRvOut = NS_ERROR_DOM_WEBEXT_CONTENT_SCRIPT_URI; returnfalse;
}
nsresult ModuleLoader::StartFetch(ModuleLoadRequest* aRequest) { // According to the spec, module scripts have different behaviour to classic // scripts and always use CORS. Only exception: Non linkable about: pages // which load local module scripts. bool isAboutPageLoadingChromeURI = ScriptLoader::IsAboutPageLoadingChromeURI(
aRequest, GetScriptLoader()->GetDocument());
// Delegate Shared Behavior to base ScriptLoader // // aCharsetForPreload is passed as Nothing() because this is not a preload // and `StartLoadInternal` is able to find the charset by using `aRequest` // for this case.
nsresult rv = GetScriptLoader()->StartLoadInternal(
aRequest, securityFlags, Nothing() /* aCharsetForPreload */);
NS_ENSURE_SUCCESS(rv, rv);
if (aRequest->IsTopLevel()) { if (aRequest->GetScriptLoadContext()->mIsInline &&
aRequest->GetScriptLoadContext()->GetParserCreated() ==
NOT_FROM_PARSER) { if (aRequest->mImports.Length() == 0) {
GetScriptLoader()->RunScriptWhenSafe(aRequest);
} else {
AsyncExecuteInlineModule(aRequest); return;
}
} elseif (aRequest->GetScriptLoadContext()->mIsInline &&
aRequest->GetScriptLoadContext()->GetParserCreated() !=
NOT_FROM_PARSER &&
!nsContentUtils::IsSafeToRunScript()) { // Avoid giving inline async module scripts that don't have // external dependencies a guaranteed execution time relative // to the HTML parse. That is, deliberately avoid guaranteeing // that the script would always observe a DOM shape where the // parser has not added further elements to the DOM. // (If `nsContentUtils::IsSafeToRunScript()` returns `true`, // we come here synchronously from the parser. If it returns // `false` we come here from an external dependency completing // its fetch, in which case we already are at an unspecific // point relative to the parse.)
AsyncExecuteInlineModule(aRequest); return;
} else {
GetScriptLoader()->MaybeMoveToLoadedList(aRequest);
GetScriptLoader()->ProcessPendingRequestsAsync();
}
}
if (aMaybeActiveScript) { // https://html.spec.whatwg.org/multipage/webappapis.html#hostloadimportedmodule // Step 6.3. Set fetchOptions to the new descendant script fetch options for // referencingScript's fetch options.
options = aMaybeActiveScript->GetFetchOptions();
referrerPolicy = aMaybeActiveScript->ReferrerPolicy();
baseURL = aMaybeActiveScript->BaseURL();
} else { // We don't have a referencing script so fall back on using // options from the document. This can happen when the user // triggers an inline event handler, as there is no active script // there.
Document* document = GetScriptLoader()->GetDocument();
nsCOMPtr<nsIPrincipal> principal = GetGlobalObject()->PrincipalOrNull();
MOZ_ASSERT_IF(GetKind() == WebExtension,
BasePrincipal::Cast(principal)->ContentScriptAddonPolicy());
MOZ_ASSERT_IF(GetKind() == Normal, principal == document->NodePrincipal());
// https://html.spec.whatwg.org/multipage/webappapis.html#hostloadimportedmodule // Step 4. Let fetchOptions be the default classic script fetch options. // // https://html.spec.whatwg.org/multipage/webappapis.html#default-classic-script-fetch-options // The default classic script fetch options are a script fetch options whose // cryptographic nonce is the empty string, integrity metadata is the empty // string, parser metadata is "not-parser-inserted", credentials mode is // "same-origin", referrer policy is the empty string, and fetch priority is // "auto".
options = new ScriptFetchOptions(
mozilla::CORS_NONE, /* aNonce = */ u""_ns, RequestPriority::Auto,
ParserMetadata::NotParserInserted, principal);
referrerPolicy = document->GetReferrerPolicy();
baseURL = document->GetDocBaseURI();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.