mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 15:25:52 +00:00
Bug 1706615
- Part 8: Preserve the unstripped URI when doing a reload. r=smaug
To restore the stripped query parameters when ETP toggle has been set to off, we preserve the current unstripped URI to the new loadState when doing a reload. By doing this, it will redirect the channel back to the unstripped URI because the loading channel is in the content blocking allow list and it has a unstripped URI in its loadInfo. Differential Revision: https://phabricator.services.mozilla.com/D116116
This commit is contained in:
parent
521d7a9cd7
commit
55a6f082b6
@ -10451,8 +10451,18 @@ 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);
|
||||
aLoadState->MaybeStripTrackerQueryStrings(mBrowsingContext,
|
||||
currentUnstrippedURI);
|
||||
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
if (DocumentChannel::CanUseDocumentChannel(aLoadState->URI())) {
|
||||
|
@ -573,7 +573,7 @@ bool nsDocShellLoadState::LoadIsFromSessionHistory() const {
|
||||
}
|
||||
|
||||
void nsDocShellLoadState::MaybeStripTrackerQueryStrings(
|
||||
BrowsingContext* aContext) {
|
||||
BrowsingContext* aContext, nsIURI* aCurrentUnstrippedURI) {
|
||||
MOZ_ASSERT(aContext);
|
||||
|
||||
// We don't need to strip for sub frames because the query string has been
|
||||
@ -605,7 +605,24 @@ void nsDocShellLoadState::MaybeStripTrackerQueryStrings(
|
||||
if (URLQueryStringStripper::Strip(URI(), strippedURI)) {
|
||||
mUnstrippedURI = URI();
|
||||
SetURI(strippedURI);
|
||||
} else if (LoadType() & nsIDocShell::LOAD_CMD_RELOAD) {
|
||||
// Preserve the Unstripped URI if it's a reload. By doing this, we can
|
||||
// restore the stripped query parameters once the ETP has been toggled to
|
||||
// off.
|
||||
mUnstrippedURI = aCurrentUnstrippedURI;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
// Make sure that unstripped URI is the same as URI() but only the query
|
||||
// string could be different.
|
||||
if (mUnstrippedURI) {
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
URLQueryStringStripper::Strip(mUnstrippedURI, uri);
|
||||
bool equals = false;
|
||||
Unused << URI()->Equals(uri, &equals);
|
||||
MOZ_ASSERT(equals);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
const nsString& nsDocShellLoadState::Target() const { return mTarget; }
|
||||
|
@ -323,7 +323,8 @@ class nsDocShellLoadState final {
|
||||
bool aLoadingFromActiveEntry);
|
||||
void ClearLoadIsFromSessionHistory();
|
||||
|
||||
void MaybeStripTrackerQueryStrings(mozilla::dom::BrowsingContext* aContext);
|
||||
void MaybeStripTrackerQueryStrings(mozilla::dom::BrowsingContext* aContext,
|
||||
nsIURI* aCurrentUnstrippedURI = nullptr);
|
||||
|
||||
protected:
|
||||
// Destructor can't be defaulted or inlined, as header doesn't have all type
|
||||
|
Loading…
Reference in New Issue
Block a user