diff options
Diffstat (limited to 'dom/script/ScriptLoader.cpp')
-rw-r--r-- | dom/script/ScriptLoader.cpp | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp index 903822ef5..38649e1dd 100644 --- a/dom/script/ScriptLoader.cpp +++ b/dom/script/ScriptLoader.cpp @@ -1043,7 +1043,7 @@ ScriptLoader::StartLoad(ScriptLoadRequest *aRequest, const nsAString &aType, httpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Accept"), NS_LITERAL_CSTRING("*/*"), false); - httpChannel->SetReferrerWithPolicy(mDocument->GetDocumentURI(), + httpChannel->SetReferrerWithPolicy(aRequest->mReferrer, aRequest->mReferrerPolicy); nsCOMPtr<nsIHttpChannelInternal> internalChannel(do_QueryInterface(httpChannel)); @@ -1175,16 +1175,21 @@ ScriptLoader::CreateLoadRequest(ScriptKind aKind, nsIURI* aURI, nsIScriptElement* aElement, uint32_t aVersion, CORSMode aCORSMode, - const SRIMetadata &aIntegrity) + const SRIMetadata& aIntegrity, + mozilla::net::ReferrerPolicy aReferrerPolicy) { + nsIURI* referrer = mDocument->GetDocumentURI(); + if (aKind == ScriptKind::Classic) { return new ScriptLoadRequest(aKind, aURI, aElement, - aVersion,aCORSMode, - aIntegrity); + aVersion, aCORSMode, + aIntegrity, + referrer, aReferrerPolicy); } MOZ_ASSERT(aKind == ScriptKind::Module); - return new ModuleLoadRequest(aURI, aElement, aVersion, aCORSMode, aIntegrity, this); + return new ModuleLoadRequest(aURI, aElement, aVersion, aCORSMode, + aIntegrity, referrer, aReferrerPolicy, this); } bool @@ -1253,6 +1258,7 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement) // Step 15. and later in the HTML5 spec nsresult rv = NS_OK; RefPtr<ScriptLoadRequest> request; + mozilla::net::ReferrerPolicy ourRefPolicy = mDocument->GetReferrerPolicy(); if (aElement->GetScriptExternal()) { // external script nsCOMPtr<nsIURI> scriptURI = aElement->GetScriptURI(); @@ -1265,7 +1271,6 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement) } // Double-check that the preload matches what we're asked to load now. - mozilla::net::ReferrerPolicy ourRefPolicy = mDocument->GetReferrerPolicy(); CORSMode ourCORSMode = aElement->GetCORSMode(); nsTArray<PreloadInfo>::index_type i = mPreloads.IndexOf(scriptURI.get(), 0, PreloadURIComparator()); @@ -1320,9 +1325,9 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement) } request = CreateLoadRequest(scriptKind, scriptURI, aElement, - version, ourCORSMode, sriMetadata); + version, ourCORSMode, sriMetadata, + ourRefPolicy); request->mIsInline = false; - request->mReferrerPolicy = ourRefPolicy; // set aScriptFromHead to false so we don't treat non preloaded scripts as // blockers for full page load. See bug 792438. @@ -1440,10 +1445,11 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement) return false; } - // Inline scripts ignore ther CORS mode and are always CORS_NONE + // Inline scripts ignore ther CORS mode and are always CORS_NONE. request = CreateLoadRequest(scriptKind, mDocument->GetDocumentURI(), aElement, version, CORS_NONE, - SRIMetadata()); // SRI doesn't apply + SRIMetadata(), // SRI doesn't apply + ourRefPolicy); request->mJSVersion = version; request->mIsInline = true; request->mLineNo = aElement->GetScriptLineNumber(); @@ -2578,9 +2584,9 @@ ScriptLoader::PreloadURI(nsIURI *aURI, const nsAString &aCharset, RefPtr<ScriptLoadRequest> request = CreateLoadRequest(ScriptKind::Classic, aURI, nullptr, 0, - Element::StringToCORSMode(aCrossOrigin), sriMetadata); + Element::StringToCORSMode(aCrossOrigin), sriMetadata, + aReferrerPolicy); request->mIsInline = false; - request->mReferrerPolicy = aReferrerPolicy; nsresult rv = StartLoad(request, aType, aScriptFromHead); if (NS_FAILED(rv)) { |