ported from mozilla: Bug 1264792 - Update request'referrer policy when redirect.r=bkelly,dragana. (763507de3e)

This commit is contained in:
roytam1 2024-10-03 07:35:53 +08:00
commit 97fb5d7f9b
16 changed files with 244 additions and 91 deletions

View file

@ -1345,12 +1345,19 @@ public:
httpChannel->GetRequestHeader(NS_LITERAL_CSTRING("Referer"), referrer);
if (!referrer.IsEmpty()) {
mReferrer = referrer;
} else {
// If there's no referrer Header, means the header was omitted for
// security/privacy reason.
mReferrer = EmptyCString();
}
uint32_t referrerPolicy = 0;
rv = httpChannel->GetReferrerPolicy(&referrerPolicy);
NS_ENSURE_SUCCESS(rv, rv);
switch (referrerPolicy) {
case nsIHttpChannel::REFERRER_POLICY_UNSET:
mReferrerPolicy = ReferrerPolicy::_empty;
break;
case nsIHttpChannel::REFERRER_POLICY_NO_REFERRER:
mReferrerPolicy = ReferrerPolicy::No_referrer;
break;
@ -1366,6 +1373,15 @@ public:
case nsIHttpChannel::REFERRER_POLICY_UNSAFE_URL:
mReferrerPolicy = ReferrerPolicy::Unsafe_url;
break;
case nsIHttpChannel::REFERRER_POLICY_SAME_ORIGIN:
mReferrerPolicy = ReferrerPolicy::Same_origin;
break;
case nsIHttpChannel::REFERRER_POLICY_STRICT_ORIGIN_WHEN_XORIGIN:
mReferrerPolicy = ReferrerPolicy::Strict_origin_when_cross_origin;
break;
case nsIHttpChannel::REFERRER_POLICY_STRICT_ORIGIN:
mReferrerPolicy = ReferrerPolicy::Strict_origin;
break;
default:
MOZ_ASSERT_UNREACHABLE("Invalid Referrer Policy enum value?");
break;