commit 0f1dde9516698dad14e761f300c4f01f5330c07f
parent 3e33759f74a1082455053884035c9449ae289288
Author: Adam Vandolder <avandolder@mozilla.com>
Date: Tue, 14 Oct 2025 14:21:11 +0000
Bug 1966674 - Part 9: Make Navigation API State-related naming and types more consistent. r=jjaschke
Differential Revision: https://phabricator.services.mozilla.com/D268182
Diffstat:
6 files changed, 35 insertions(+), 33 deletions(-)
diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp
@@ -3958,7 +3958,7 @@ nsresult nsDocShell::ReloadNavigable(
aNavigationAPIState;
if (!destinationNavigationAPIState) {
destinationNavigationAPIState =
- mActiveEntry ? mActiveEntry->GetNavigationState() : nullptr;
+ mActiveEntry ? mActiveEntry->GetNavigationAPIState() : nullptr;
}
// 1.4 Let continue be the result of firing a push/replace/reload navigate
@@ -8960,7 +8960,7 @@ nsresult nsDocShell::HandleSameDocumentNavigation(
// https://html.spec.whatwg.org/#navigate-fragid
// Step 2
RefPtr<nsIStructuredCloneContainer> destinationNavigationAPIState =
- mActiveEntry ? mActiveEntry->GetNavigationState() : nullptr;
+ mActiveEntry ? mActiveEntry->GetNavigationAPIState() : nullptr;
// Step 3
if (auto* navigationAPIState = aLoadState->GetNavigationAPIState()) {
destinationNavigationAPIState = navigationAPIState;
@@ -9320,7 +9320,7 @@ nsresult nsDocShell::HandleSameDocumentNavigation(
}
if (destinationNavigationAPIState) {
- mActiveEntry->SetNavigationState(destinationNavigationAPIState);
+ mActiveEntry->SetNavigationAPIState(destinationNavigationAPIState);
}
if (LOAD_TYPE_HAS_FLAGS(mLoadType, LOAD_FLAGS_REPLACE_HISTORY)) {
diff --git a/docshell/shistory/SessionHistoryEntry.cpp b/docshell/shistory/SessionHistoryEntry.cpp
@@ -55,7 +55,7 @@ SessionHistoryInfo::SessionHistoryInfo(nsDocShellLoadState* aLoadState,
? Nothing()
: Some(aLoadState->SrcdocData())),
mBaseURI(aLoadState->BaseURI()),
- mNavigationState(static_cast<nsStructuredCloneContainer*>(
+ mNavigationAPIState(static_cast<nsStructuredCloneContainer*>(
aLoadState->GetNavigationAPIState())),
mLoadReplace(aLoadState->LoadReplace()),
mHasUserActivation(aLoadState->HasValidUserGestureActivation()),
@@ -167,7 +167,7 @@ void SessionHistoryInfo::Reset(nsIURI* aURI, const nsID& aDocShellID,
mTransient = false;
mHasUserInteraction = false;
mHasUserActivation = false;
- mNavigationState = nullptr;
+ mNavigationAPIState = nullptr;
mSharedState.Get()->mTriggeringPrincipal = aTriggeringPrincipal;
mSharedState.Get()->mPrincipalToInherit = aPrincipalToInherit;
@@ -255,13 +255,13 @@ bool SessionHistoryInfo::IsSubFrame() const {
return mSharedState.Get()->mIsFrameNavigation;
}
-nsStructuredCloneContainer* SessionHistoryInfo::GetNavigationState() const {
- return mNavigationState.get();
+nsIStructuredCloneContainer* SessionHistoryInfo::GetNavigationAPIState() const {
+ return mNavigationAPIState.get();
}
-void SessionHistoryInfo::SetNavigationState(
- nsStructuredCloneContainer* aState) {
- mNavigationState = aState;
+void SessionHistoryInfo::SetNavigationAPIState(
+ nsIStructuredCloneContainer* aState) {
+ mNavigationAPIState = static_cast<nsStructuredCloneContainer*>(aState);
}
void SessionHistoryInfo::SetSaveLayoutStateFlag(bool aSaveLayoutStateFlag) {
@@ -1586,11 +1586,11 @@ void IPDLParamTraits<dom::SessionHistoryInfo>::Write(
}
Maybe<std::tuple<uint32_t, dom::ClonedMessageData>> navigationState;
- if (aParam.mNavigationState) {
+ if (aParam.mNavigationAPIState) {
navigationState.emplace();
- NS_ENSURE_SUCCESS_VOID(aParam.mNavigationState->GetFormatVersion(
+ NS_ENSURE_SUCCESS_VOID(aParam.mNavigationAPIState->GetFormatVersion(
&std::get<0>(*navigationState)));
- NS_ENSURE_TRUE_VOID(aParam.mNavigationState->BuildClonedMessageData(
+ NS_ENSURE_TRUE_VOID(aParam.mNavigationAPIState->BuildClonedMessageData(
std::get<1>(*navigationState)));
}
@@ -1760,11 +1760,11 @@ bool IPDLParamTraits<dom::SessionHistoryInfo>::Read(
if (navigationState.isSome()) {
uint32_t version = std::get<0>(*navigationState);
- aResult->mNavigationState = new nsStructuredCloneContainer(version);
- aResult->mNavigationState->StealFromClonedMessageData(
+ aResult->mNavigationAPIState = new nsStructuredCloneContainer(version);
+ aResult->mNavigationAPIState->StealFromClonedMessageData(
std::get<1>(*navigationState));
}
- MOZ_ASSERT_IF(navigationState.isNothing(), !aResult->mNavigationState);
+ MOZ_ASSERT_IF(navigationState.isNothing(), !aResult->mNavigationAPIState);
return true;
}
diff --git a/docshell/shistory/SessionHistoryEntry.h b/docshell/shistory/SessionHistoryEntry.h
@@ -169,8 +169,8 @@ class SessionHistoryInfo {
const nsID& NavigationKey() const { return mNavigationKey; }
const nsID& NavigationId() const { return mNavigationId; }
- nsStructuredCloneContainer* GetNavigationState() const;
- void SetNavigationState(nsStructuredCloneContainer* aState);
+ nsIStructuredCloneContainer* GetNavigationAPIState() const;
+ void SetNavigationAPIState(nsIStructuredCloneContainer* aState);
already_AddRefed<nsIURI> GetURIOrInheritedForAboutBlank() const;
@@ -198,7 +198,8 @@ class SessionHistoryInfo {
// Fields needed for NavigationHistoryEntry.
nsID mNavigationKey = nsID::GenerateUUID();
nsID mNavigationId = nsID::GenerateUUID();
- RefPtr<nsStructuredCloneContainer> mNavigationState;
+ // https://html.spec.whatwg.org/#she-navigation-api-state
+ RefPtr<nsStructuredCloneContainer> mNavigationAPIState;
bool mLoadReplace = false;
bool mURIWasModified = false;
diff --git a/dom/navigation/Navigation.cpp b/dom/navigation/Navigation.cpp
@@ -93,8 +93,7 @@ struct NavigationAPIMethodTracker final : public nsISupports {
mCommittedToEntry = aNHE;
if (mSerializedState) {
// Step 2
- aNHE->SetState(
- static_cast<nsStructuredCloneContainer*>(mSerializedState.get()));
+ aNHE->SetNavigationAPIState(mSerializedState);
// At this point, apiMethodTracker's serialized state is no longer needed.
// We drop it do now for efficiency.
mSerializedState = nullptr;
@@ -244,7 +243,7 @@ void Navigation::UpdateCurrentEntry(
return;
}
- currentEntry->SetState(serializedState);
+ currentEntry->SetNavigationAPIState(serializedState);
NavigationCurrentEntryChangeEventInit init;
init.mFrom = currentEntry;
@@ -741,7 +740,7 @@ void Navigation::Reload(JSContext* aCx, const NavigationReloadOptions& aOptions,
// 4.2 If current is not null, then set serializedState to current's
// session history entry's navigation API state.
if (RefPtr<NavigationHistoryEntry> current = GetCurrentEntry()) {
- serializedState = current->GetNavigationState();
+ serializedState = current->GetNavigationAPIState();
}
}
// 5. If document is not fully active, then return an early error result for
@@ -921,8 +920,8 @@ bool Navigation::FireTraverseNavigateEvent(
FindNavigationHistoryEntry(aDestinationSessionHistoryInfo);
// Step 6.2 and step 7.2
- RefPtr<nsStructuredCloneContainer> state =
- destinationNHE ? destinationNHE->GetNavigationState() : nullptr;
+ RefPtr<nsIStructuredCloneContainer> state =
+ destinationNHE ? destinationNHE->GetNavigationAPIState() : nullptr;
// Step 8
bool isSameDocument =
diff --git a/dom/navigation/NavigationHistoryEntry.cpp b/dom/navigation/NavigationHistoryEntry.cpp
@@ -110,7 +110,7 @@ void NavigationHistoryEntry::GetState(JSContext* aCx,
if (!mSHInfo) {
return;
}
- RefPtr<nsStructuredCloneContainer> state = mSHInfo->GetNavigationState();
+ RefPtr<nsIStructuredCloneContainer> state = mSHInfo->GetNavigationAPIState();
if (!state) {
aResult.setUndefined();
return;
@@ -123,8 +123,9 @@ void NavigationHistoryEntry::GetState(JSContext* aCx,
}
}
-void NavigationHistoryEntry::SetState(nsStructuredCloneContainer* aState) {
- mSHInfo->SetNavigationState(aState);
+void NavigationHistoryEntry::SetNavigationAPIState(
+ nsIStructuredCloneContainer* aState) {
+ mSHInfo->SetNavigationAPIState(aState);
}
bool NavigationHistoryEntry::IsSameEntry(
@@ -159,12 +160,13 @@ const nsID& NavigationHistoryEntry::Key() const {
return mSHInfo->NavigationKey();
}
-nsStructuredCloneContainer* NavigationHistoryEntry::GetNavigationState() const {
+nsIStructuredCloneContainer* NavigationHistoryEntry::GetNavigationAPIState()
+ const {
if (!mSHInfo) {
return nullptr;
}
- return mSHInfo->GetNavigationState();
+ return mSHInfo->GetNavigationAPIState();
}
void NavigationHistoryEntry::ResetIndexForDisposal() { mIndex = -1; }
diff --git a/dom/navigation/NavigationHistoryEntry.h b/dom/navigation/NavigationHistoryEntry.h
@@ -10,7 +10,7 @@
#include "mozilla/DOMEventTargetHelper.h"
class nsIGlobalObject;
-class nsStructuredCloneContainer;
+class nsIStructuredCloneContainer;
namespace mozilla::dom {
@@ -34,7 +34,6 @@ class NavigationHistoryEntry final : public DOMEventTargetHelper {
void GetState(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
ErrorResult& aRv) const;
- void SetState(nsStructuredCloneContainer* aState);
IMPL_EVENT_HANDLER(dispose);
@@ -47,7 +46,8 @@ class NavigationHistoryEntry final : public DOMEventTargetHelper {
const nsID& Key() const;
- nsStructuredCloneContainer* GetNavigationState() const;
+ nsIStructuredCloneContainer* GetNavigationAPIState() const;
+ void SetNavigationAPIState(nsIStructuredCloneContainer* aState);
class SessionHistoryInfo* SessionHistoryInfo() { return mSHInfo.get(); }