Bug 1567940 Apply ReferrerInfo to Download and fix Go to Download Page button r=Gijs,dimi

In the old way, if referrer is ommited we will not be able to go to
download page. In that case, we should use originalReferrer in
ReferrerInfo object

Differential Revision: https://phabricator.services.mozilla.com/D39875
This commit is contained in:
Thomas Nguyen
2019-08-20 16:22:44 +00:00
parent 4652004508
commit 1b050362ee
22 changed files with 302 additions and 171 deletions

View File

@@ -1348,25 +1348,18 @@ FetchDriver::AsyncOnChannelRedirect(nsIChannel* aOldChannel,
// In redirect, httpChannel already took referrer-policy into account, so
// updates requests associated referrer policy from channel.
if (httpChannel) {
nsCOMPtr<nsIURI> computedReferrer;
nsAutoString computedReferrerSpec;
nsCOMPtr<nsIReferrerInfo> referrerInfo = httpChannel->GetReferrerInfo();
if (referrerInfo) {
mRequest->SetReferrerPolicy(
static_cast<net::ReferrerPolicy>(referrerInfo->GetReferrerPolicy()));
computedReferrer = referrerInfo->GetComputedReferrer();
Unused << referrerInfo->GetComputedReferrerSpec(computedReferrerSpec);
}
// Step 8 https://fetch.spec.whatwg.org/#main-fetch
// If requests referrer is not "no-referrer" (empty), set requests
// referrer to the result of invoking determine requests referrer.
if (computedReferrer) {
nsAutoCString spec;
rv = computedReferrer->GetSpec(spec);
NS_ENSURE_SUCCESS(rv, rv);
mRequest->SetReferrer(NS_ConvertUTF8toUTF16(spec));
} else {
mRequest->SetReferrer(EmptyString());
}
mRequest->SetReferrer(computedReferrerSpec);
}
aCallback->OnRedirectVerifyCallback(NS_OK);