Bug 1888756, part 3 - Text Fragments: Add a flag in the DocShell to keep the information if a load was same-document. r=farre,dom-core,edgar

This commit is a prerequisite for part 5 of this patch set.

The idea is to keep the information whether the last
load done by the doc shell was a same-document navigation.
The value is reset for every navigation, therefore it
should always be correct.

There is no changed behavior in this commit.

Differential Revision: https://phabricator.services.mozilla.com/D212818
This commit is contained in:
Jan-Niklas Jaeschke
2024-06-20 10:24:26 +00:00
parent 96b82fad2f
commit ae6c1d60c0
2 changed files with 32 additions and 12 deletions

View File

@@ -366,7 +366,8 @@ nsDocShell::nsDocShell(BrowsingContext* aBrowsingContext,
mIsNavigating(false),
mForcedAutodetection(false),
mCheckingSessionHistory(false),
mNeedToReportActiveAfterLoadingBecomesActive(false) {
mNeedToReportActiveAfterLoadingBecomesActive(false),
mCurrentLoadIsSameDocumentNavigation(false) {
// If no outer window ID was provided, generate a new one.
if (aContentWindowID == 0) {
mContentWindowID = nsContentUtils::GenerateWindowId();
@@ -8628,9 +8629,8 @@ bool nsDocShell::IsSameDocumentNavigation(nsDocShellLoadState* aLoadState,
}
nsresult nsDocShell::HandleSameDocumentNavigation(
nsDocShellLoadState* aLoadState, SameDocumentNavigationState& aState,
bool& aSameDocument) {
aSameDocument = true;
nsDocShellLoadState* aLoadState, SameDocumentNavigationState& aState) {
mCurrentLoadIsSameDocumentNavigation = true;
#ifdef DEBUG
SameDocumentNavigationState state;
MOZ_ASSERT(IsSameDocumentNavigation(aLoadState, state));
@@ -8673,7 +8673,7 @@ nsresult nsDocShell::HandleSameDocumentNavigation(
mCurrentURI) ||
nsScriptSecurityManager::IsHttpOrHttpsAndCrossOrigin(mCurrentURI,
newURI)) {
aSameDocument = false;
mCurrentLoadIsSameDocumentNavigation = false;
MOZ_LOG(gSHLog, LogLevel::Debug,
("nsDocShell[%p]: possible violation of the same origin policy "
"during same document navigation",
@@ -9136,6 +9136,10 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState,
MOZ_ASSERT(aLoadState->TriggeringPrincipal(),
"need a valid TriggeringPrincipal");
// Set this to false to take early returns into account.
// This flag is set to true in `HandleSameDocumentNavigation()`.
mCurrentLoadIsSameDocumentNavigation = false;
if (!aLoadState->TriggeringPrincipal()) {
MOZ_ASSERT(false, "InternalLoad needs a valid triggeringPrincipal");
return NS_ERROR_FAILURE;
@@ -9184,7 +9188,7 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState,
// If we don't have a target, we're loading into ourselves, and our load
// delegate may want to intercept that load.
SameDocumentNavigationState sameDocumentNavigationState;
bool sameDocument =
const bool maybeSameDocumentNavigation =
IsSameDocumentNavigation(aLoadState, sameDocumentNavigationState) &&
!aLoadState->GetPendingRedirectedChannel();
@@ -9291,14 +9295,15 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState,
// See if this is actually a load between two history entries for the same
// document. If the process fails, or if we successfully navigate within the
// same document, return.
if (sameDocument) {
nsresult rv = HandleSameDocumentNavigation(
aLoadState, sameDocumentNavigationState, sameDocument);
if (maybeSameDocumentNavigation) {
nsresult rv =
HandleSameDocumentNavigation(aLoadState, sameDocumentNavigationState);
NS_ENSURE_SUCCESS(rv, rv);
if (shouldTakeFocus) {
mBrowsingContext->Focus(CallerType::System, IgnoreErrors());
}
if (sameDocument) {
// This flag is set in `HandleSameDocumentNavigation()`.
if (mCurrentLoadIsSameDocumentNavigation) {
return rv;
}
}