From 92a5efa31be74b8a55c23bf94f92d8a390e67299 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 16 Sep 2020 01:18:46 +0000 Subject: [PATCH] Bug 1662407 - Call nsSHistory::GotoIndex directly when loading from session history in the parent process. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D88976 UltraBlame original commit: a23e9879c8485e6717c9f2519cc5a40031a8b3ec --- docshell/base/BrowsingContext.cpp | 12 ++++++++++++ docshell/base/BrowsingContext.h | 2 ++ docshell/base/CanonicalBrowsingContext.cpp | 17 +++++++++++++++++ docshell/base/CanonicalBrowsingContext.h | 2 ++ docshell/shistory/ChildSHistory.cpp | 15 +++++++-------- dom/ipc/ContentParent.cpp | 11 ++--------- 6 files changed, 42 insertions(+), 17 deletions(-) diff --git a/docshell/base/BrowsingContext.cpp b/docshell/base/BrowsingContext.cpp index fe4a817a96ef..481db5b7e5b3 100644 --- a/docshell/base/BrowsingContext.cpp +++ b/docshell/base/BrowsingContext.cpp @@ -2714,6 +2714,18 @@ void BrowsingContext::RemoveFromSessionHistory() { } } +void BrowsingContext::HistoryGo(int32_t aIndex, + std::function&& aResolver) { + if (XRE_IsContentProcess()) { + ContentChild::GetSingleton()->SendHistoryGo( + this, aIndex, std::move(aResolver), + [](mozilla::ipc:: + ResponseRejectReason) { }); + } else { + Canonical()->HistoryGo(aIndex, std::move(aResolver)); + } +} + } namespace ipc { diff --git a/docshell/base/BrowsingContext.h b/docshell/base/BrowsingContext.h index 0b472f14d761..7f6fad430af6 100644 --- a/docshell/base/BrowsingContext.h +++ b/docshell/base/BrowsingContext.h @@ -672,6 +672,8 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache { Tuple, nsCOMPtr> GetTriggeringAndInheritPrincipalsForCurrentLoad(); + void HistoryGo(int32_t aIndex, std::function&& aResolver); + protected: virtual ~BrowsingContext(); BrowsingContext(WindowContext* aParentWindow, BrowsingContextGroup* aGroup, diff --git a/docshell/base/CanonicalBrowsingContext.cpp b/docshell/base/CanonicalBrowsingContext.cpp index 67067ab9986a..5e44a71f60fa 100644 --- a/docshell/base/CanonicalBrowsingContext.cpp +++ b/docshell/base/CanonicalBrowsingContext.cpp @@ -514,6 +514,23 @@ void CanonicalBrowsingContext::RemoveFromSessionHistory() { } } +void CanonicalBrowsingContext::HistoryGo( + int32_t aIndex, std::function&& aResolver) { + nsSHistory* shistory = static_cast(GetSessionHistory()); + if (!shistory) { + return; + } + + nsTArray loadResults; + nsresult rv = shistory->GotoIndex(aIndex, loadResults); + if (NS_FAILED(rv)) { + return; + } + + aResolver(shistory->GetRequestedIndex()); + nsSHistory::LoadURIs(loadResults); +} + JSObject* CanonicalBrowsingContext::WrapObject( JSContext* aCx, JS::Handle aGivenProto) { return CanonicalBrowsingContext_Binding::Wrap(aCx, this, aGivenProto); diff --git a/docshell/base/CanonicalBrowsingContext.h b/docshell/base/CanonicalBrowsingContext.h index a91696c95ddd..70f830fde99f 100644 --- a/docshell/base/CanonicalBrowsingContext.h +++ b/docshell/base/CanonicalBrowsingContext.h @@ -126,6 +126,8 @@ class CanonicalBrowsingContext final : public BrowsingContext { void RemoveFromSessionHistory(); + void HistoryGo(int32_t aIndex, std::function&& aResolver); + JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; diff --git a/docshell/shistory/ChildSHistory.cpp b/docshell/shistory/ChildSHistory.cpp index 3cc040f63c48..36d7b7c30c17 100644 --- a/docshell/shistory/ChildSHistory.cpp +++ b/docshell/shistory/ChildSHistory.cpp @@ -137,21 +137,20 @@ void ChildSHistory::Go(int32_t aOffset, bool aRequireUserInteraction, index.value() <= 0) { break; } - if (mHistory->HasUserInteractionAtIndex(index.value())) { + if (mHistory && mHistory->HasUserInteractionAtIndex(index.value())) { break; } } if (StaticPrefs::fission_sessionHistoryInParent()) { nsCOMPtr shistory = mHistory; - ContentChild::GetSingleton()->SendHistoryGo( - mBrowsingContext, index.value(), - [shistory](int32_t&& aRequestedIndex) { + mBrowsingContext->HistoryGo( + index.value(), [shistory](int32_t&& aRequestedIndex) { - shistory->InternalSetRequestedIndex(aRequestedIndex); - }, - [](mozilla::ipc:: - ResponseRejectReason) { }); + if (shistory) { + shistory->InternalSetRequestedIndex(aRequestedIndex); + } + }); } else { aRv = mHistory->GotoIndex(index.value()); } diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 2968239b0219..5416b2fe1d21 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -6941,15 +6941,8 @@ mozilla::ipc::IPCResult ContentParent::RecvHistoryGo( const MaybeDiscarded& aContext, int32_t aIndex, HistoryGoResolver&& aResolveRequestedIndex) { if (!aContext.IsDiscarded()) { - nsSHistory* shistory = - static_cast(aContext.get_canonical()->GetSessionHistory()); - nsTArray loadResults; - nsresult rv = shistory->GotoIndex(aIndex, loadResults); - if (NS_FAILED(rv)) { - return IPC_FAIL(this, "GotoIndex failed"); - } - aResolveRequestedIndex(shistory->GetRequestedIndex()); - shistory->LoadURIs(loadResults); + aContext.get_canonical()->HistoryGo(aIndex, + std::move(aResolveRequestedIndex)); } return IPC_OK(); }