Skip to content

Commit

Permalink
Bug 1662407 - Call nsSHistory::GotoIndex directly when loading from s…
Browse files Browse the repository at this point in the history
…ession history in the parent process. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D88976

UltraBlame original commit: a23e9879c8485e6717c9f2519cc5a40031a8b3ec
  • Loading branch information
marco-c committed Sep 16, 2020
1 parent 6b9688f commit 92a5efa
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 17 deletions.
12 changes: 12 additions & 0 deletions docshell/base/BrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2714,6 +2714,18 @@ void BrowsingContext::RemoveFromSessionHistory() {
}
}

void BrowsingContext::HistoryGo(int32_t aIndex,
std::function<void(int32_t&&)>&& aResolver) {
if (XRE_IsContentProcess()) {
ContentChild::GetSingleton()->SendHistoryGo(
this, aIndex, std::move(aResolver),
[](mozilla::ipc::
ResponseRejectReason) { });
} else {
Canonical()->HistoryGo(aIndex, std::move(aResolver));
}
}

}

namespace ipc {
Expand Down
2 changes: 2 additions & 0 deletions docshell/base/BrowsingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,8 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
Tuple<nsCOMPtr<nsIPrincipal>, nsCOMPtr<nsIPrincipal>>
GetTriggeringAndInheritPrincipalsForCurrentLoad();

void HistoryGo(int32_t aIndex, std::function<void(int32_t&&)>&& aResolver);

protected:
virtual ~BrowsingContext();
BrowsingContext(WindowContext* aParentWindow, BrowsingContextGroup* aGroup,
Expand Down
17 changes: 17 additions & 0 deletions docshell/base/CanonicalBrowsingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,23 @@ void CanonicalBrowsingContext::RemoveFromSessionHistory() {
}
}

void CanonicalBrowsingContext::HistoryGo(
int32_t aIndex, std::function<void(int32_t&&)>&& aResolver) {
nsSHistory* shistory = static_cast<nsSHistory*>(GetSessionHistory());
if (!shistory) {
return;
}

nsTArray<nsSHistory::LoadEntryResult> 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<JSObject*> aGivenProto) {
return CanonicalBrowsingContext_Binding::Wrap(aCx, this, aGivenProto);
Expand Down
2 changes: 2 additions & 0 deletions docshell/base/CanonicalBrowsingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ class CanonicalBrowsingContext final : public BrowsingContext {

void RemoveFromSessionHistory();

void HistoryGo(int32_t aIndex, std::function<void(int32_t&&)>&& aResolver);

JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;

Expand Down
15 changes: 7 additions & 8 deletions docshell/shistory/ChildSHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nsISHistory> 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());
}
Expand Down
11 changes: 2 additions & 9 deletions dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6941,15 +6941,8 @@ mozilla::ipc::IPCResult ContentParent::RecvHistoryGo(
const MaybeDiscarded<BrowsingContext>& aContext, int32_t aIndex,
HistoryGoResolver&& aResolveRequestedIndex) {
if (!aContext.IsDiscarded()) {
nsSHistory* shistory =
static_cast<nsSHistory*>(aContext.get_canonical()->GetSessionHistory());
nsTArray<nsSHistory::LoadEntryResult> 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();
}
Expand Down

0 comments on commit 92a5efa

Please sign in to comment.