tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 7217e527a5570ecd09cb447a3dd653a2e01b484e
parent c19da6e773a19e75b100f3819ce034eac43a10de
Author: Simon Farre <sfarre@mozilla.com>
Date:   Tue,  2 Dec 2025 08:05:49 +0000

Bug 2003131 - Get request referrer policy for doc r=smaug

This adds the RequestReferrerPolicy getter for Document. Making it
possible to read the referrer policy value by which "this" document was
loaded with.

https://html.spec.whatwg.org/#document-state-request-referrer-policy

Differential Revision: https://phabricator.services.mozilla.com/D274480

Diffstat:
Mdom/base/Document.cpp | 6++++++
Mdom/base/Document.h | 14++++++++++++++
Mdom/navigation/NavigationHistoryEntry.cpp | 3++-
Dtesting/web-platform/meta/navigation-api/navigation-history-entry/no-referrer-from-meta-url-censored.html.ini | 3---
Dtesting/web-platform/meta/navigation-api/navigation-history-entry/no-referrer-url-censored.html.ini | 3---
5 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp @@ -4318,6 +4318,11 @@ void Document::EnsureNotEnteringAndExitFullscreen() { } } +// https://html.spec.whatwg.org/#document-state-request-referrer-policy +ReferrerPolicy Document::ReferrerPolicyUsedToFetchThisDocument() const { + return mRequestReferrerPolicy; +} + void Document::SetReferrerInfo(nsIReferrerInfo* aReferrerInfo) { mReferrerInfo = aReferrerInfo; mCachedReferrerInfoForInternalCSSAndSVGResources = nullptr; @@ -4362,6 +4367,7 @@ nsresult Document::InitReferrerInfo(nsIChannel* aChannel) { if (nsCOMPtr<nsIReferrerInfo> referrerInfo = httpChannel->GetReferrerInfo()) { SetReferrerInfo(referrerInfo); + mRequestReferrerPolicy = referrerInfo->ReferrerPolicy(); } // Override policy if we get one from Referrerr-Policy header diff --git a/dom/base/Document.h b/dom/base/Document.h @@ -835,6 +835,16 @@ class Document : public nsINode, ReferrerPolicyEnum ReferrerPolicy() const { return GetReferrerPolicy(); } /** + * The referrer policy that was used for the fetch of this document, what the + * spec calls "request referrer policy". Not to be confused with the history + * policy container's referrer policy, which dictates the policy for fetches + * made by this document (see ReferrerPolicy()). + * + * See: https://html.spec.whatwg.org/#document-state-request-referrer-policy + */ + ReferrerPolicyEnum ReferrerPolicyUsedToFetchThisDocument() const; + + /** * If true, this flag indicates that all mixed content subresource * loads for this document (and also embeded browsing contexts) will * be blocked. @@ -4765,6 +4775,10 @@ class Document : public nsINode, nsCOMPtr<nsIReferrerInfo> mPreloadReferrerInfo; nsCOMPtr<nsIReferrerInfo> mReferrerInfo; + // A request referrer policy, which is a referrer policy, initially the + // default referrer policy. + ReferrerPolicyEnum mRequestReferrerPolicy = + ReferrerPolicyEnum::Strict_origin_when_cross_origin; nsString mLastModified; diff --git a/dom/navigation/NavigationHistoryEntry.cpp b/dom/navigation/NavigationHistoryEntry.cpp @@ -43,7 +43,8 @@ void NavigationHistoryEntry::GetUrl(nsAString& aResult) const { MOZ_DIAGNOSTIC_ASSERT(GetAssociatedDocument()); if (!SameDocument()) { - auto referrerPolicy = GetAssociatedDocument()->ReferrerPolicy(); + const auto referrerPolicy = + GetAssociatedDocument()->ReferrerPolicyUsedToFetchThisDocument(); if (referrerPolicy == ReferrerPolicy::No_referrer || referrerPolicy == ReferrerPolicy::Origin) { aResult.SetIsVoid(true); diff --git a/testing/web-platform/meta/navigation-api/navigation-history-entry/no-referrer-from-meta-url-censored.html.ini b/testing/web-platform/meta/navigation-api/navigation-history-entry/no-referrer-from-meta-url-censored.html.ini @@ -1,3 +0,0 @@ -[no-referrer-from-meta-url-censored.html] - [The url of a document with no-referrer referrer meta tag is censored in NavigationHistoryEntry] - expected: FAIL diff --git a/testing/web-platform/meta/navigation-api/navigation-history-entry/no-referrer-url-censored.html.ini b/testing/web-platform/meta/navigation-api/navigation-history-entry/no-referrer-url-censored.html.ini @@ -1,3 +0,0 @@ -[no-referrer-url-censored.html] - [The url of a document with no-referrer referrer policy is censored in NavigationHistoryEntry] - expected: FAIL