Bug 1841859 - Part 2: Parse the referrer policy from http header and update the referrer policy. r=jonco,smaug

This implementes the following requirement from the spec:

https://html.spec.whatwg.org/#fetch-a-single-module-script

12. In both cases, let processResponseConsumeBody given response response and null, failure, or a byte sequence bodyBytes be the following algorithm:

  5. Let referrerPolicy be the result of parsing the `Referrer-Policy` header given response.
  6. If referrerPolicy is not the empty string, set options's referrer policy to referrerPolicy.

Differential Revision: https://phabricator.services.mozilla.com/D186944
This commit is contained in:
Yoshi Cheng-Hao Huang
2023-09-20 17:32:15 +00:00
parent 2b03ca80a7
commit 0060499938
2 changed files with 15 additions and 0 deletions

View File

@@ -3730,6 +3730,17 @@ nsresult ScriptLoader::PrepareLoadedRequest(ScriptLoadRequest* aRequest,
return NS_ERROR_NOT_AVAILABLE;
}
if (aRequest->IsModuleRequest()) {
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-single-module-script
// Update script's referrer-policy if there's a Referrer-Policy header in
// the HTTP response.
ReferrerPolicy policy =
nsContentUtils::GetReferrerPolicyFromChannel(httpChannel);
if (policy != ReferrerPolicy::_empty) {
aRequest->UpdateReferrerPolicy(policy);
}
}
nsAutoCString sourceMapURL;
if (nsContentUtils::GetSourceMapURL(httpChannel, sourceMapURL)) {
aRequest->mSourceMapURL = Some(NS_ConvertUTF8toUTF16(sourceMapURL));