Bug 761152 - Copy referrer info to new session history entry on history.pushState r=freddyb

Per spec [1], we should copy over the complete document state [2], which
includes the referrer info. Bug 1773192 has already added this for the
"replace" case when the session history is in parent (almost always the case),
but it is still missing for the "push" case, and the "replace" case when the
session history is not in parent.

[1] https://html.spec.whatwg.org/multipage/browsing-the-web.html#url-and-history-update-steps
[2] https://html.spec.whatwg.org/multipage/browsing-the-web.html#document-state

Differential Revision: https://phabricator.services.mozilla.com/D200684
This commit is contained in:
Malte Juergens
2024-02-22 14:29:06 +00:00
parent f5b4ec3ba0
commit 1bacda615c
4 changed files with 39 additions and 10 deletions

View File

@@ -11376,11 +11376,14 @@ nsresult nsDocShell::UpdateURLAndHistory(Document* aDocument, nsIURI* aNewURI,
if (mozilla::SessionHistoryInParent()) {
MOZ_LOG(gSHLog, LogLevel::Debug,
("nsDocShell %p UpdateActiveEntry (not replacing)", this));
nsString title(mActiveEntry->GetTitle());
nsCOMPtr<nsIReferrerInfo> referrerInfo = mActiveEntry->GetReferrerInfo();
UpdateActiveEntry(false,
/* aPreviousScrollPos = */ Some(scrollPos), aNewURI,
/* aOriginalURI = */ nullptr,
/* aReferrerInfo = */ nullptr,
/* aReferrerInfo = */ referrerInfo,
/* aTriggeringPrincipal = */ aDocument->NodePrincipal(),
csp, title, scrollRestorationIsManual, aData,
uriWasModified);
@@ -11399,12 +11402,14 @@ nsresult nsDocShell::UpdateURLAndHistory(Document* aDocument, nsIURI* aNewURI,
// mode from the current entry.
newSHEntry->SetScrollRestorationIsManual(scrollRestorationIsManual);
// Set the new SHEntry's title (bug 655273).
nsString title;
mOSHE->GetTitle(title);
// Set the new SHEntry's title (bug 655273).
newSHEntry->SetTitle(title);
nsCOMPtr<nsIReferrerInfo> referrerInfo = mOSHE->GetReferrerInfo();
newSHEntry->SetReferrerInfo(referrerInfo);
// Link the new SHEntry to the old SHEntry's BFCache entry, since the
// two entries correspond to the same document.
NS_ENSURE_SUCCESS(newSHEntry->AdoptBFCacheEntry(oldOSHE),
@@ -11453,6 +11458,8 @@ nsresult nsDocShell::UpdateURLAndHistory(Document* aDocument, nsIURI* aNewURI,
mOSHE = newSHEntry;
}
nsCOMPtr<nsIReferrerInfo> referrerInfo = mOSHE->GetReferrerInfo();
newSHEntry->SetURI(aNewURI);
newSHEntry->SetOriginalURI(aNewURI);
// We replaced the URI of the entry, clear the unstripped URI as it
@@ -11463,6 +11470,7 @@ nsresult nsDocShell::UpdateURLAndHistory(Document* aDocument, nsIURI* aNewURI,
// in our case. We could also set it to aNewURI, with the same result.
newSHEntry->SetResultPrincipalURI(nullptr);
newSHEntry->SetLoadReplace(false);
newSHEntry->SetReferrerInfo(referrerInfo);
}
if (!mozilla::SessionHistoryInParent()) {