Bug 1581859: Part 2a - Add LOCATION_CHANGE_HASHCHANGE onLocationChange flag. r=nika

The naming scheme references the hashchange event. This is required by the
extensions framework to call the appropriate navigation listeners when only
the reference fragment is updated by a navigation.

Differential Revision: https://phabricator.services.mozilla.com/D108725
This commit is contained in:
Kris Maglione
2021-03-25 19:47:00 +00:00
parent 7fd04a3b05
commit 1d47a9d0fb
3 changed files with 35 additions and 4 deletions

View File

@@ -8713,7 +8713,6 @@ nsresult nsDocShell::PerformRetargeting(nsDocShellLoadState* aLoadState) {
targetContext = newBC;
}
}
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(targetContext, rv);
@@ -8735,6 +8734,27 @@ nsresult nsDocShell::PerformRetargeting(nsDocShellLoadState* aLoadState) {
return targetContext->InternalLoad(aLoadState);
}
static nsAutoCString RefMaybeNull(nsIURI* aURI) {
nsAutoCString result;
if (NS_FAILED(aURI->GetRef(result))) {
result.SetIsVoid(true);
}
return result;
}
uint32_t nsDocShell::GetSameDocumentNavigationFlags(nsIURI* aNewURI) {
uint32_t flags = LOCATION_CHANGE_SAME_DOCUMENT;
bool equal = false;
if (mCurrentURI &&
NS_SUCCEEDED(mCurrentURI->EqualsExceptRef(aNewURI, &equal)) && equal &&
RefMaybeNull(mCurrentURI) != RefMaybeNull(aNewURI)) {
flags |= LOCATION_CHANGE_HASHCHANGE;
}
return flags;
}
bool nsDocShell::IsSameDocumentNavigation(nsDocShellLoadState* aLoadState,
SameDocumentNavigationState& aState) {
MOZ_ASSERT(aLoadState);
@@ -8936,6 +8956,10 @@ nsresult nsDocShell::HandleSameDocumentNavigation(
newURIPartitionedPrincipalToInherit = doc->PartitionedPrincipal();
newCsp = doc->GetCsp();
}
uint32_t locationChangeFlags =
GetSameDocumentNavigationFlags(aLoadState->URI());
// Pass true for aCloneSHChildren, since we're not
// changing documents here, so all of our subframes are
// still relevant to the new session history entry.
@@ -9123,8 +9147,7 @@ nsresult nsDocShell::HandleSameDocumentNavigation(
}
if (locationChangeNeeded) {
FireOnLocationChange(this, nullptr, aLoadState->URI(),
LOCATION_CHANGE_SAME_DOCUMENT);
FireOnLocationChange(this, nullptr, aLoadState->URI(), locationChangeFlags);
}
/* Restore the original LSHE if we were loading something
@@ -11518,7 +11541,7 @@ nsresult nsDocShell::UpdateURLAndHistory(Document* aDocument, nsIURI* aNewURI,
aDocument->SetDocumentURI(aNewURI);
SetCurrentURI(aNewURI, nullptr, /* aFireLocationChange */ true,
/* aIsInitialAboutBlank */ false,
LOCATION_CHANGE_SAME_DOCUMENT);
GetSameDocumentNavigationFlags(aNewURI));
AddURIVisit(aNewURI, aCurrentURI, 0);