Bug 266554 - Use document ReferrerInfo for refreshes. r=peterv,ckerschb,dom-core,smaug

When ReferrerInfo is exposed later in the patch set, using the document
referrer info instead of mReferrerInfo will matter, but for now,
behavior should be unchanged.

Optional argument aSendReferrer for the ReferrerInfo constructor is
added. Because the existing behavior of InitWithDocument setting
mSendReferrer to true is acceptable in all other cases, the
aSendReferrer argument is not passed to InitWithDocument and
nsIReferrerInfo.idl is unchanged.

Unused method ReferrerInfo::CloneWithNewSendReferrer is removed.

Differential Revision: https://phabricator.services.mozilla.com/D227449
This commit is contained in:
Zach Hoffman
2024-11-14 02:09:02 +00:00
parent e2150bda1b
commit 8c6dd9f815
3 changed files with 12 additions and 29 deletions

View File

@@ -5057,33 +5057,25 @@ nsDocShell::ForceRefreshURI(nsIURI* aURI, nsIPrincipal* aPrincipal,
bool equalUri = false;
nsresult rv = aURI->Equals(mCurrentURI, &equalUri);
nsCOMPtr<nsIReferrerInfo> referrerInfo;
if (NS_SUCCEEDED(rv) && !equalUri && aDelay <= REFRESH_REDIRECT_TIMER) {
/* It is a META refresh based redirection within the threshold time
* we have in mind (15000 ms as defined by REFRESH_REDIRECT_TIMER).
* Pass a REPLACE flag to LoadURI().
*/
loadState->SetLoadType(LOAD_REFRESH_REPLACE);
/* For redirects we mimic HTTP, which passes the
* original referrer.
* We will pass in referrer but will not send to server
*/
if (mReferrerInfo) {
referrerInfo = static_cast<ReferrerInfo*>(mReferrerInfo.get())
->CloneWithNewSendReferrer(false);
}
} else {
loadState->SetLoadType(LOAD_REFRESH);
/* We do need to pass in a referrer, but we don't want it to
* be sent to the server.
* For most refreshes the current URI is an appropriate
* internal referrer.
*/
referrerInfo = new ReferrerInfo(mCurrentURI, ReferrerPolicy::_empty, false);
}
/* We mimic HTTP, which passes the original referrer.
* TODO(bug 266554): Send the referrer to the server (if allowed by referrer
* policy and tracking protection).
* See step 3 of
* <https://html.spec.whatwg.org/multipage/browsing-the-web.html#create-navigation-params-by-fetching>.
*/
const nsCOMPtr<nsIReferrerInfo> referrerInfo = new ReferrerInfo(*doc, false);
loadState->SetReferrerInfo(referrerInfo);
loadState->SetLoadFlags(
nsIWebNavigation::LOAD_FLAGS_DISALLOW_INHERIT_PRINCIPAL);
loadState->SetFirstParty(true);