diff --git a/docshell/base/BrowsingContext.cpp b/docshell/base/BrowsingContext.cpp index 38cfc52ddd10..5bdb5c84aa99 100644 --- a/docshell/base/BrowsingContext.cpp +++ b/docshell/base/BrowsingContext.cpp @@ -409,8 +409,12 @@ void BrowsingContext::CreateFromIPC(BrowsingContext::IPCInitializer&& aInit, } context->mWindowless = aInit.mWindowless; - if (aInit.mHasSessionHistory) { - context->InitSessionHistory(); + if (context->GetHasSessionHistory()) { + context->CreateChildSHistory(); + if (StaticPrefs::fission_sessionHistoryInParent()) { + context->GetChildSessionHistory()->SetIndexAndLength( + aInit.mSessionHistoryIndex, aInit.mSessionHistoryCount, nsID()); + } } // NOTE: Call through the `Set` methods for these values to ensure that any @@ -607,7 +611,7 @@ void BrowsingContext::Attach(bool aFromIPC, ContentParent* aOriginProcess) { PopupBlocker::RegisterOpenPopupSpam(); } - if (IsTop() && GetHasSessionHistory()) { + if (IsTop() && GetHasSessionHistory() && !mChildSessionHistory) { CreateChildSHistory(); } @@ -2069,7 +2073,10 @@ BrowsingContext::IPCInitializer BrowsingContext::GetIPCInitializer() { init.mUseRemoteTabs = mUseRemoteTabs; init.mUseRemoteSubframes = mUseRemoteSubframes; init.mOriginAttributes = mOriginAttributes; - init.mHasSessionHistory = mChildSessionHistory != nullptr; + if (mChildSessionHistory && StaticPrefs::fission_sessionHistoryInParent()) { + init.mSessionHistoryIndex = mChildSessionHistory->Index(); + init.mSessionHistoryCount = mChildSessionHistory->Count(); + } init.mRequestContextId = mRequestContextId; init.mFields = mFields.RawValues(); return init; @@ -2726,6 +2733,12 @@ void BrowsingContext::HistoryGo(int32_t aIndex, } } +void BrowsingContext::SetChildSHistory(ChildSHistory* aChildSHistory) { + mChildSessionHistory = aChildSHistory; + mChildSessionHistory->SetBrowsingContext(this); + mFields.SetWithoutSyncing(true); +} + } // namespace dom namespace ipc { @@ -2768,6 +2781,8 @@ void IPDLParamTraits::Write( WriteIPDLParam(aMessage, aActor, aInit.mUseRemoteSubframes); WriteIPDLParam(aMessage, aActor, aInit.mOriginAttributes); WriteIPDLParam(aMessage, aActor, aInit.mRequestContextId); + WriteIPDLParam(aMessage, aActor, aInit.mSessionHistoryIndex); + WriteIPDLParam(aMessage, aActor, aInit.mSessionHistoryCount); WriteIPDLParam(aMessage, aActor, aInit.mFields); } @@ -2783,6 +2798,10 @@ bool IPDLParamTraits::Read( &aInit->mUseRemoteSubframes) || !ReadIPDLParam(aMessage, aIterator, aActor, &aInit->mOriginAttributes) || !ReadIPDLParam(aMessage, aIterator, aActor, &aInit->mRequestContextId) || + !ReadIPDLParam(aMessage, aIterator, aActor, + &aInit->mSessionHistoryIndex) || + !ReadIPDLParam(aMessage, aIterator, aActor, + &aInit->mSessionHistoryCount) || !ReadIPDLParam(aMessage, aIterator, aActor, &aInit->mFields)) { return false; } diff --git a/docshell/base/BrowsingContext.h b/docshell/base/BrowsingContext.h index 73e15d90b451..7a8a186250fa 100644 --- a/docshell/base/BrowsingContext.h +++ b/docshell/base/BrowsingContext.h @@ -591,7 +591,8 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache { bool mWindowless = false; bool mUseRemoteTabs = false; bool mUseRemoteSubframes = false; - bool mHasSessionHistory = false; + int32_t mSessionHistoryIndex = -1; + int32_t mSessionHistoryCount = 0; OriginAttributes mOriginAttributes; uint64_t mRequestContextId = 0; @@ -679,6 +680,12 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache { BrowsingContext(WindowContext* aParentWindow, BrowsingContextGroup* aGroup, uint64_t aBrowsingContextId, Type aType, FieldValues&& aInit); + void SetChildSHistory(ChildSHistory* aChildSHistory); + already_AddRefed ForgetChildSHistory() { + // FIXME Do we need to unset mHasSessionHistory? + return mChildSessionHistory.forget(); + } + private: void Attach(bool aFromIPC, ContentParent* aOriginProcess); diff --git a/docshell/base/CanonicalBrowsingContext.cpp b/docshell/base/CanonicalBrowsingContext.cpp index 6ac8e7494a8a..0b93dba56b93 100644 --- a/docshell/base/CanonicalBrowsingContext.cpp +++ b/docshell/base/CanonicalBrowsingContext.cpp @@ -164,6 +164,8 @@ void CanonicalBrowsingContext::ReplacedBy( if (mSessionHistory) { mSessionHistory->SetBrowsingContext(aNewContext); mSessionHistory.swap(aNewContext->mSessionHistory); + RefPtr childSHistory = ForgetChildSHistory(); + aNewContext->SetChildSHistory(childSHistory); } MOZ_ASSERT(aNewContext->mLoadingEntries.IsEmpty()); diff --git a/docshell/shistory/ChildSHistory.cpp b/docshell/shistory/ChildSHistory.cpp index 92dcfca161f3..dbc7a0e09cca 100644 --- a/docshell/shistory/ChildSHistory.cpp +++ b/docshell/shistory/ChildSHistory.cpp @@ -21,6 +21,10 @@ namespace dom { ChildSHistory::ChildSHistory(BrowsingContext* aBrowsingContext) : mBrowsingContext(aBrowsingContext) {} +void ChildSHistory::SetBrowsingContext(BrowsingContext* aBrowsingContext) { + mBrowsingContext = aBrowsingContext; +} + void ChildSHistory::SetIsInProcess(bool aIsInProcess) { if (!aIsInProcess) { mHistory = nullptr; diff --git a/docshell/shistory/ChildSHistory.h b/docshell/shistory/ChildSHistory.h index 4a4e864615b9..703fbefd5fc7 100644 --- a/docshell/shistory/ChildSHistory.h +++ b/docshell/shistory/ChildSHistory.h @@ -44,6 +44,8 @@ class ChildSHistory : public nsISupports, public nsWrapperCache { explicit ChildSHistory(BrowsingContext* aBrowsingContext); + void SetBrowsingContext(BrowsingContext* aBrowsingContext); + // Create or destroy the session history implementation in the child process. // This can be removed once session history is stored exclusively in the // parent process.