Bug 1916559 - Only store pending uninvoked directives for same document navigation. r=peterv

Differential Revision: https://phabricator.services.mozilla.com/D221637
This commit is contained in:
Andreas Farre
2024-09-12 06:02:24 +00:00
parent 2f09bc4d4e
commit fdd79b0fba
2 changed files with 22 additions and 19 deletions

View File

@@ -8431,6 +8431,17 @@ uint32_t nsDocShell::GetSameDocumentNavigationFlags(nsIURI* aNewURI) {
return flags;
}
struct SameDocumentNavigationState {
nsAutoCString mCurrentHash;
nsAutoCString mNewHash;
nsTArray<TextDirective> mTextDirectives;
bool mCurrentURIHasRef = false;
bool mNewURIHasRef = false;
bool mSameExceptHashes = false;
bool mSecureUpgradeURI = false;
bool mHistoryNavBetweenSameDoc = false;
};
bool nsDocShell::IsSameDocumentNavigation(nsDocShellLoadState* aLoadState,
SameDocumentNavigationState& aState) {
MOZ_ASSERT(aLoadState);
@@ -8451,15 +8462,9 @@ bool nsDocShell::IsSameDocumentNavigation(nsDocShellLoadState* aLoadState,
}
// A Fragment Directive must be removed from the new hash in order to allow
// fallback element id scroll. Additionally, the extracted parsed text
// directives need to be stored for further use.
nsTArray<TextDirective> textDirectives;
if (FragmentDirective::ParseAndRemoveFragmentDirectiveFromFragmentString(
aState.mNewHash, &textDirectives, aLoadState->URI())) {
if (Document* doc = GetDocument()) {
doc->FragmentDirective()->SetTextDirectives(std::move(textDirectives));
}
}
// fallback element id scroll.
FragmentDirective::ParseAndRemoveFragmentDirectiveFromFragmentString(
aState.mNewHash, &aState.mTextDirectives, aLoadState->URI());
if (currentURI && NS_SUCCEEDED(rvURINew)) {
nsresult rvURIOld = currentURI->GetRef(aState.mCurrentHash);
@@ -8596,6 +8601,12 @@ nsresult nsDocShell::HandleSameDocumentNavigation(
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
doc->DoNotifyPossibleTitleChange();
// Store the pending uninvoked directives if it is a same document navigation.
// We need to set it here, in case the navigation happens before the document
// has actually finished loading.
doc->FragmentDirective()->SetTextDirectives(
std::move(aState.mTextDirectives));
nsCOMPtr<nsIURI> currentURI = mCurrentURI;
// We need to upgrade the new URI from http: to https: