Bug 1798986 - Track UnstrippedURI in SessionHistory, r=smaug,timhuang
Previously, we tracked UnstrippedURI on the nsDocShellLoadState and LoadInfo, and manually filled it in to match the previous load when doing a LOAD_CMD_RELOAD in nsDocShell. It is more consistent with other load types to instead store the information in the load state, allowing it to be handled consistently for reloads and other history operations. Unfortunately, this patch has some extra complexity right now, as it needs to support both SHIP and non-SHIP session history. This should disappear in the future when we switch to using exclusively SHIP. Differential Revision: https://phabricator.services.mozilla.com/D161196
This commit is contained in:
@@ -9870,6 +9870,9 @@ nsIPrincipal* nsDocShell::GetInheritedPrincipal(
|
||||
isSrcdoc);
|
||||
}
|
||||
|
||||
// Strip the target query parameters before creating the channel.
|
||||
aLoadState->MaybeStripTrackerQueryStrings(aBrowsingContext);
|
||||
|
||||
OriginAttributes attrs;
|
||||
|
||||
// Inherit origin attributes from PrincipalToInherit if inheritAttrs is
|
||||
@@ -10540,19 +10543,6 @@ nsresult nsDocShell::DoURILoad(nsDocShellLoadState* aLoadState,
|
||||
nsLoadFlags loadFlags = aLoadState->CalculateChannelLoadFlags(
|
||||
mBrowsingContext, Some(uriModified), Some(isXFOError));
|
||||
|
||||
// Get the unstripped URI from the current document channel. The unstripped
|
||||
// URI will be preserved if it's a reload.
|
||||
nsCOMPtr<nsIURI> currentUnstrippedURI;
|
||||
nsCOMPtr<nsIChannel> docChannel = GetCurrentDocChannel();
|
||||
if (docChannel) {
|
||||
nsCOMPtr<nsILoadInfo> docLoadInfo = docChannel->LoadInfo();
|
||||
docLoadInfo->GetUnstrippedURI(getter_AddRefs(currentUnstrippedURI));
|
||||
}
|
||||
|
||||
// Strip the target query parameters before creating the channel.
|
||||
aLoadState->MaybeStripTrackerQueryStrings(mBrowsingContext,
|
||||
currentUnstrippedURI);
|
||||
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
if (DocumentChannel::CanUseDocumentChannel(aLoadState->URI()) &&
|
||||
!isAboutBlankLoadOntoInitialAboutBlank) {
|
||||
@@ -11571,6 +11561,9 @@ nsresult nsDocShell::UpdateURLAndHistory(Document* aDocument, nsIURI* aNewURI,
|
||||
|
||||
newSHEntry->SetURI(aNewURI);
|
||||
newSHEntry->SetOriginalURI(aNewURI);
|
||||
// We replaced the URI of the entry, clear the unstripped URI as it
|
||||
// shouldn't be used for reloads anymore.
|
||||
newSHEntry->SetUnstrippedURI(nullptr);
|
||||
// Setting the resultPrincipalURI to nullptr is fine here: it will cause
|
||||
// NS_GetFinalChannelURI to use the originalURI as the URI, which is aNewURI
|
||||
// in our case. We could also set it to aNewURI, with the same result.
|
||||
@@ -11798,6 +11791,7 @@ nsresult nsDocShell::AddToSessionHistory(
|
||||
nsCOMPtr<nsIInputStream> inputStream;
|
||||
nsCOMPtr<nsIURI> originalURI;
|
||||
nsCOMPtr<nsIURI> resultPrincipalURI;
|
||||
nsCOMPtr<nsIURI> unstrippedURI;
|
||||
bool loadReplace = false;
|
||||
nsCOMPtr<nsIReferrerInfo> referrerInfo;
|
||||
uint32_t cacheKey = 0;
|
||||
@@ -11851,6 +11845,8 @@ nsresult nsDocShell::AddToSessionHistory(
|
||||
|
||||
loadInfo->GetResultPrincipalURI(getter_AddRefs(resultPrincipalURI));
|
||||
|
||||
loadInfo->GetUnstrippedURI(getter_AddRefs(unstrippedURI));
|
||||
|
||||
userActivation = loadInfo->GetHasValidUserGestureActivation();
|
||||
|
||||
// For now keep storing just the principal in the SHEntry.
|
||||
@@ -11920,8 +11916,9 @@ nsresult nsDocShell::AddToSessionHistory(
|
||||
triggeringPrincipal, // Channel or provided principal
|
||||
principalToInherit, partitionedPrincipalToInherit, csp,
|
||||
HistoryID(), GetCreatedDynamically(), originalURI,
|
||||
resultPrincipalURI, loadReplace, referrerInfo, srcdoc,
|
||||
srcdocEntry, baseURI, saveLayoutState, expired, userActivation);
|
||||
resultPrincipalURI, unstrippedURI, loadReplace, referrerInfo,
|
||||
srcdoc, srcdocEntry, baseURI, saveLayoutState, expired,
|
||||
userActivation);
|
||||
|
||||
if (mBrowsingContext->IsTop() && GetSessionHistory()) {
|
||||
bool shouldPersist = ShouldAddToSessionHistory(aURI, aChannel);
|
||||
@@ -12006,6 +12003,7 @@ void nsDocShell::UpdateActiveEntry(
|
||||
aURI, aTriggeringPrincipal, nullptr, nullptr, aCsp, mContentTypeHint);
|
||||
}
|
||||
mActiveEntry->SetOriginalURI(aOriginalURI);
|
||||
mActiveEntry->SetUnstrippedURI(nullptr);
|
||||
mActiveEntry->SetReferrerInfo(aReferrerInfo);
|
||||
mActiveEntry->SetTitle(aTitle);
|
||||
mActiveEntry->SetStateData(static_cast<nsStructuredCloneContainer*>(aData));
|
||||
|
||||
Reference in New Issue
Block a user