From 4472abffc2c2db34662b0eebd61f2a455501f18c Mon Sep 17 00:00:00 2001 From: Anny Gakhokidze Date: Tue, 7 May 2019 15:23:08 -0400 Subject: [PATCH] Bug 1546761 - Consolidate IPC calls to nsISHistory inside of nsDocShell::OnNewURI, r=peterv, r=nika for adding sync IPC messages Inside of nsDocShell::OnNewURI there are 4 sync IPC calls to nsSHistory that can be replaced with 1 sync IPC call by adding a new method EnsureCorrectEntryAtCurrIndex to nsSHistory. Differential Revision: https://phabricator.services.mozilla.com/D31539 --HG-- extra : rebase_source : 09d7738b2f2dc2334c8f6186e5918b9d0ea3e618 extra : source : 82a41bffcbbca24ad3e84b045d75e4cb01ae1445 extra : histedit_source : 96eb7d2dbed2ad8fe4cc2d37358ec2358f696442 --- docshell/base/nsDocShell.cpp | 12 ++---------- docshell/shistory/PSHistory.ipdl | 1 + docshell/shistory/SHistoryChild.cpp | 5 +++++ docshell/shistory/SHistoryParent.cpp | 6 ++++++ docshell/shistory/SHistoryParent.h | 1 + docshell/shistory/nsISHistory.idl | 2 ++ docshell/shistory/nsSHistory.cpp | 9 +++++++++ ipc/ipdl/sync-messages.ini | 2 ++ 8 files changed, 28 insertions(+), 10 deletions(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index c4dfcf04fdcf..6a5f41499849 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -10855,16 +10855,8 @@ bool nsDocShell::OnNewURI(nsIURI* aURI, nsIChannel* aChannel, } else if (mSessionHistory && mLSHE && mURIResultedInDocument) { // Even if we don't add anything to SHistory, ensure the current index // points to the same SHEntry as our mLSHE. - int32_t index = mSessionHistory->LegacySHistory()->GetRequestedIndex(); - if (index == -1) { - index = mSessionHistory->Index(); - } - nsCOMPtr currentSH; - mSessionHistory->LegacySHistory()->GetEntryAtIndex( - index, getter_AddRefs(currentSH)); - if (currentSH != mLSHE) { - mSessionHistory->LegacySHistory()->ReplaceEntry(index, mLSHE); - } + + mSessionHistory->LegacySHistory()->EnsureCorrectEntryAtCurrIndex(mLSHE); } // If this is a POST request, we do not want to include this in global diff --git a/docshell/shistory/PSHistory.ipdl b/docshell/shistory/PSHistory.ipdl index d91528a78dd7..8a371aecf90b 100644 --- a/docshell/shistory/PSHistory.ipdl +++ b/docshell/shistory/PSHistory.ipdl @@ -56,6 +56,7 @@ parent: sync GetAllEntries() returns (MaybeNewPSHEntry[] entries); sync FindEntryForBFCache(uint64_t sharedID, bool includeCurrentEntry) returns (MaybeNewPSHEntry entries, int32_t startIndex); sync Evict(PSHEntry[] entry); + sync EnsureCorrectEntryAtCurrIndex(PSHEntry entry); async __delete__(); }; diff --git a/docshell/shistory/SHistoryChild.cpp b/docshell/shistory/SHistoryChild.cpp index dd0f27507a0d..6fe21b4132e1 100644 --- a/docshell/shistory/SHistoryChild.cpp +++ b/docshell/shistory/SHistoryChild.cpp @@ -304,6 +304,11 @@ SHistoryChild::RemoveDynEntries(int32_t aIndex, nsISHEntry* aEntry) { SendRemoveDynEntries(aIndex, static_cast(aEntry)); } +NS_IMETHODIMP_(void) +SHistoryChild::EnsureCorrectEntryAtCurrIndex(nsISHEntry* aEntry) { + SendEnsureCorrectEntryAtCurrIndex(static_cast(aEntry)); +} + NS_IMETHODIMP_(void) SHistoryChild::RemoveDynEntriesForBFCacheEntry(nsIBFCacheEntry* aBFEntry) { MaybeNewPSHEntry entry; diff --git a/docshell/shistory/SHistoryParent.cpp b/docshell/shistory/SHistoryParent.cpp index 59a5a75fb2bd..75068e890df0 100644 --- a/docshell/shistory/SHistoryParent.cpp +++ b/docshell/shistory/SHistoryParent.cpp @@ -140,6 +140,12 @@ bool SHistoryParent::RecvRemoveDynEntries(int32_t aIndex, return true; } +bool SHistoryParent::RecvEnsureCorrectEntryAtCurrIndex(PSHEntryParent* aEntry) { + mHistory->EnsureCorrectEntryAtCurrIndex( + static_cast(aEntry)->mEntry); + return true; +} + bool SHistoryParent::RecvRemoveEntries(nsTArray&& aIds, int32_t aIndex, bool* aDidRemove) { mHistory->RemoveEntries(aIds, aIndex, aDidRemove); diff --git a/docshell/shistory/SHistoryParent.h b/docshell/shistory/SHistoryParent.h index 97f87080f559..0b78e1f4f656 100644 --- a/docshell/shistory/SHistoryParent.h +++ b/docshell/shistory/SHistoryParent.h @@ -79,6 +79,7 @@ class SHistoryParent final : public PSHistoryParent { const bool& aIncludeCurrentEntry, MaybeNewPSHEntry* aEntry, int32_t* aIndex); bool RecvEvict(nsTArray&& aEntries); + bool RecvEnsureCorrectEntryAtCurrIndex(PSHEntryParent* aEntry); RefPtr mContext; RefPtr mHistory; diff --git a/docshell/shistory/nsISHistory.idl b/docshell/shistory/nsISHistory.idl index 809f1716d27a..a6015774affa 100644 --- a/docshell/shistory/nsISHistory.idl +++ b/docshell/shistory/nsISHistory.idl @@ -260,4 +260,6 @@ interface nsISHistory: nsISupports [noscript] void Reload(in unsigned long aReloadFlags); + + [notxpcom] void EnsureCorrectEntryAtCurrIndex(in nsISHEntry aEntry); }; diff --git a/docshell/shistory/nsSHistory.cpp b/docshell/shistory/nsSHistory.cpp index cad8a84902a1..435a0f0e70c9 100644 --- a/docshell/shistory/nsSHistory.cpp +++ b/docshell/shistory/nsSHistory.cpp @@ -1358,6 +1358,15 @@ nsSHistory::GotoIndex(int32_t aIndex) { return LoadURI(loadResult); } +NS_IMETHODIMP_(void) +nsSHistory::EnsureCorrectEntryAtCurrIndex(nsISHEntry* aEntry) { + int index = mRequestedIndex == -1 ? mIndex : mRequestedIndex; + MOZ_ASSERT(mIndex > -1); + if (mEntries[index] != aEntry) { + ReplaceEntry(index, aEntry); + } +} + nsresult nsSHistory::GotoIndex(int32_t aIndex, LoadEntryResult& aLoadResult) { return LoadEntry(aIndex, LOAD_HISTORY, HIST_CMD_GOTOINDEX, aLoadResult); } diff --git a/ipc/ipdl/sync-messages.ini b/ipc/ipdl/sync-messages.ini index 3e17383a85e6..3a6d79f4e169 100644 --- a/ipc/ipdl/sync-messages.ini +++ b/ipc/ipdl/sync-messages.ini @@ -852,6 +852,8 @@ description = Standing up Fission description = Standing up Fission [PSHistory::Evict] description = Standing up Fission +[PSHistory::EnsureCorrectEntryAtCurrIndex] +description = Standing up Fission [PContent::PSHEntry] description = Standing up Fission [PSHEntry::GetURI]