commit e1bb90b66f88d2f1ff173f5c3247cf691169dcad
parent 2c5f2a0d7a11cc741d35b9ed5be3289d3fd26847
Author: Adam Vandolder <avandolder@mozilla.com>
Date: Tue, 14 Oct 2025 14:21:09 +0000
Bug 1966674 - Part 2: Add NavigationAPIState to DocShellLoadStateInit. r=dom-core,jjaschke
Differential Revision: https://phabricator.services.mozilla.com/D268072
Diffstat:
3 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/docshell/base/nsDocShellLoadState.cpp b/docshell/base/nsDocShellLoadState.cpp
@@ -116,6 +116,11 @@ nsDocShellLoadState::nsDocShellLoadState(
mUnstrippedURI = aLoadState.UnstrippedURI();
mRemoteTypeOverride = aLoadState.RemoteTypeOverride();
+ if (aLoadState.NavigationAPIState()) {
+ mNavigationAPIState = MakeRefPtr<nsStructuredCloneContainer>();
+ mNavigationAPIState->CopyFromClonedMessageData(
+ *aLoadState.NavigationAPIState());
+ }
// We know this was created remotely, as we just received it over IPC.
mWasCreatedRemotely = true;
@@ -213,7 +218,8 @@ nsDocShellLoadState::nsDocShellLoadState(const nsDocShellLoadState& aOther)
mTriggeringRemoteType(aOther.mTriggeringRemoteType),
mSchemelessInput(aOther.mSchemelessInput),
mForceMediaDocument(aOther.mForceMediaDocument),
- mHttpsUpgradeTelemetry(aOther.mHttpsUpgradeTelemetry) {
+ mHttpsUpgradeTelemetry(aOther.mHttpsUpgradeTelemetry),
+ mNavigationAPIState(aOther.mNavigationAPIState) {
MOZ_DIAGNOSTIC_ASSERT(
XRE_IsParentProcess(),
"Cloning a nsDocShellLoadState with the same load identifier is only "
@@ -1442,6 +1448,13 @@ DocShellLoadStateInit nsDocShellLoadState::Serialize(
loadState.UnstrippedURI() = mUnstrippedURI;
loadState.RemoteTypeOverride() = mRemoteTypeOverride;
+ if (mNavigationAPIState) {
+ loadState.NavigationAPIState().emplace();
+ DebugOnly<bool> success = mNavigationAPIState->BuildClonedMessageData(
+ *loadState.NavigationAPIState());
+ MOZ_ASSERT(success);
+ }
+
if (XRE_IsParentProcess()) {
mozilla::ipc::IToplevelProtocol* top = aActor->ToplevelProtocol();
MOZ_RELEASE_ASSERT(top &&
@@ -1477,7 +1490,8 @@ nsIStructuredCloneContainer* nsDocShellLoadState::GetNavigationAPIState()
void nsDocShellLoadState::SetNavigationAPIState(
nsIStructuredCloneContainer* aNavigationAPIState) {
- mNavigationAPIState = aNavigationAPIState;
+ mNavigationAPIState =
+ static_cast<nsStructuredCloneContainer*>(aNavigationAPIState);
}
NavigationType nsDocShellLoadState::GetNavigationType() const {
diff --git a/docshell/base/nsDocShellLoadState.h b/docshell/base/nsDocShellLoadState.h
@@ -438,8 +438,7 @@ class nsDocShellLoadState final {
void SetSourceElement(mozilla::dom::Element* aElement);
already_AddRefed<mozilla::dom::Element> GetSourceElement() const;
- // This is used as the parameter for https://html.spec.whatwg.org/#navigate,
- // but it's currently missing. See bug 1966674
+ // This is used as the parameter for https://html.spec.whatwg.org/#navigate
nsIStructuredCloneContainer* GetNavigationAPIState() const;
void SetNavigationAPIState(nsIStructuredCloneContainer* aNavigationAPIState);
@@ -728,7 +727,7 @@ class nsDocShellLoadState final {
nsWeakPtr mSourceElement;
- nsCOMPtr<nsIStructuredCloneContainer> mNavigationAPIState;
+ RefPtr<nsStructuredCloneContainer> mNavigationAPIState;
RefPtr<mozilla::dom::FormData> mFormDataEntryList;
diff --git a/dom/ipc/DOMTypes.ipdlh b/dom/ipc/DOMTypes.ipdlh
@@ -235,6 +235,9 @@ struct DocShellLoadStateInit
ForceMediaDocument forceMediaDocument;
HTTPSUpgradeTelemetryType HttpsUpgradeTelemetry;
+ // https://html.spec.whatwg.org/#she-navigation-api-state
+ ClonedMessageData? NavigationAPIState;
+
// Fields missing due to lack of need or serialization
// nsCOMPtr<nsIDocShell> mSourceDocShell;
// bool mIsSrcDocLoad; // useless without sourcedocshell