From 33a7c472fa659564d38b1720b995960e88c5f131 Mon Sep 17 00:00:00 2001 From: Olli Pettay Date: Thu, 13 Aug 2020 23:38:36 +0000 Subject: [PATCH] Bug 1657757 - nsISHEntry.title setter for session-history-in-parent, r=peterv Differential Revision: https://phabricator.services.mozilla.com/D86275 --- docshell/base/nsDocShell.cpp | 46 +++++++++++++++++-------- docshell/base/nsDocShell.h | 2 ++ docshell/shistory/SessionHistoryEntry.h | 2 ++ dom/ipc/ContentParent.cpp | 12 ++++++- dom/ipc/ContentParent.h | 5 ++- dom/ipc/PContent.ipdl | 2 ++ 6 files changed, 53 insertions(+), 16 deletions(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index eb7148d65b0a..90db48b4ce40 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -4739,14 +4739,34 @@ nsDocShell::SetTitle(const nsAString& aTitle) { } // Update SessionHistory with the document's title. - if (mOSHE && mLoadType != LOAD_BYPASS_HISTORY && - mLoadType != LOAD_ERROR_PAGE) { - mOSHE->SetTitle(mTitle); + if (mLoadType != LOAD_BYPASS_HISTORY && mLoadType != LOAD_ERROR_PAGE) { + SetTitleOnHistoryEntry(); } return NS_OK; } +void nsDocShell::SetTitleOnHistoryEntry() { + if (mOSHE) { + mOSHE->SetTitle(mTitle); + } + + if (mActiveEntry) { + mActiveEntry->SetTitle(mTitle); + if (XRE_IsParentProcess()) { + SessionHistoryEntry* entry = + SessionHistoryEntry::GetByInfoId(mActiveEntry->Id()); + if (entry) { + entry->SetTitle(mTitle); + } + } else { + mozilla::Unused + << ContentChild::GetSingleton()->SendSessionHistoryEntryTitle( + mActiveEntry->Id(), mTitle); + } + } +} + nsPoint nsDocShell::GetCurScrollPos() { nsPoint scrollPos; if (nsIScrollableFrame* sf = GetRootScrollFrame()) { @@ -8528,21 +8548,19 @@ nsresult nsDocShell::HandleSameDocumentNavigation( } } + /* Set the title for the SH entry for this target url so that + * SH menus in go/back/forward buttons won't be empty for this. + * Note, this happens on mOSHE (and mActiveEntry in the future) because of + * the code above. + * XXX HandleSameDocumentNavigation needs to be made work with + * session-history-in-parent + */ + SetTitleOnHistoryEntry(); + /* Restore the original LSHE if we were loading something * while same document navigation was initiated. */ SetHistoryEntryAndUpdateBC(Some(oldLSHE), Nothing()); - /* Set the title for the SH entry for this target url. so that - * SH menus in go/back/forward buttons won't be empty for this. - */ - ChildSHistory* shistory = GetSessionHistory(); - if (shistory) { - int32_t index = shistory->Index(); - nsCOMPtr shEntry; - shistory->LegacySHistory()->GetEntryAtIndex(index, getter_AddRefs(shEntry)); - NS_ENSURE_TRUE(shEntry, NS_ERROR_FAILURE); - shEntry->SetTitle(mTitle); - } /* Set the title for the Global History entry for this anchor url. */ diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index d72f40cc8d19..1feb2c734af7 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -1048,6 +1048,8 @@ class nsDocShell final : public nsDocLoader, // LoadGroup. void SetLoadGroupDefaultLoadFlags(nsLoadFlags aLoadFlags); + void SetTitleOnHistoryEntry(); + private: // data members nsID mHistoryID; nsString mTitle; diff --git a/docshell/shistory/SessionHistoryEntry.h b/docshell/shistory/SessionHistoryEntry.h index f59f18662862..f815ef2b4043 100644 --- a/docshell/shistory/SessionHistoryEntry.h +++ b/docshell/shistory/SessionHistoryEntry.h @@ -47,6 +47,8 @@ class SessionHistoryInfo { return mScrollRestorationIsManual; } const nsAString& GetTitle() { return mTitle; } + void SetTitle(const nsAString& aTitle) { mTitle = aTitle; } + nsIURI* GetURI() const { return mURI; } bool GetURIWasModified() const { return mURIWasModified; } diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 5bde85da2921..ef958b019942 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -6962,11 +6962,21 @@ mozilla::ipc::IPCResult ContentParent::RecvSessionHistoryUpdate( } mozilla::ipc::IPCResult ContentParent::RecvSynchronizeLayoutHistoryState( - uint64_t aSessionHistoryEntryID, nsILayoutHistoryState* aState) { + const uint64_t& aSessionHistoryEntryID, nsILayoutHistoryState* aState) { SessionHistoryEntry::UpdateLayoutHistoryState(aSessionHistoryEntryID, aState); return IPC_OK(); } +mozilla::ipc::IPCResult ContentParent::RecvSessionHistoryEntryTitle( + const uint64_t& aSessionHistoryEntryID, const nsString& aTitle) { + SessionHistoryEntry* entry = + SessionHistoryEntry::GetByInfoId(aSessionHistoryEntryID); + if (entry) { + entry->SetTitle(aTitle); + } + return IPC_OK(); +} + mozilla::ipc::IPCResult ContentParent::RecvCommitWindowContextTransaction( const MaybeDiscarded& aContext, WindowContext::BaseTransaction&& aTransaction, uint64_t aEpoch) { diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index 8ca49a475fde..130bbf892895 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -1338,7 +1338,10 @@ class ContentParent final const int32_t& aLength, const nsID& aChangeID); mozilla::ipc::IPCResult RecvSynchronizeLayoutHistoryState( - uint64_t aSessionHistoryEntryID, nsILayoutHistoryState* aState); + const uint64_t& aSessionHistoryEntryID, nsILayoutHistoryState* aState); + + mozilla::ipc::IPCResult RecvSessionHistoryEntryTitle( + const uint64_t& aSessionHistoryEntryID, const nsString& aTitle); // Notify the ContentChild to enable the input event prioritization when // initializing. diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl index 72708034eb6a..5ca2603f2561 100644 --- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -925,6 +925,8 @@ parent: async SynchronizeLayoutHistoryState(uint64_t aSessionHistoryEntryID, nsILayoutHistoryState aState); + async SessionHistoryEntryTitle(uint64_t aSessionHistoryEntryID, + nsString aTitle); async InitBackground(Endpoint aEndpoint);