tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 35b02b2cfa2c7d07e687316d2291507a02a349b4
parent 84ed31a3cf16f54bcda8d7474ec6e04c826eba1b
Author: Adam Vandolder <avandolder@mozilla.com>
Date:   Fri, 31 Oct 2025 09:17:10 +0000

Bug 1996573 - Part 2: Reconstruct the active entry list only during a session restore. r=farre,dom-core,smaug

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

Diffstat:
Mdocshell/base/CanonicalBrowsingContext.cpp | 27+++++----------------------
Mdocshell/shistory/nsSHistory.cpp | 15+++++++++++++++
Mdocshell/shistory/nsSHistory.h | 2++
3 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/docshell/base/CanonicalBrowsingContext.cpp b/docshell/base/CanonicalBrowsingContext.cpp @@ -646,6 +646,11 @@ CanonicalBrowsingContext::CreateLoadingSessionHistoryEntryForLoad( bool sessionHistoryLoad = existingLoadingInfo && existingLoadingInfo->mLoadIsFromSessionHistory; + if (sessionHistoryLoad && !mActiveEntry && mActiveEntryList.isEmpty()) { + nsSHistory* shistory = static_cast<nsSHistory*>(GetSessionHistory()); + mActiveEntryList = shistory->ConstructContiguousEntryListFrom(entry); + } + MOZ_LOG_FMT(gNavigationAPILog, LogLevel::Debug, "Determining navigation type from loadType={}", aLoadState->LoadType()); @@ -657,28 +662,6 @@ CanonicalBrowsingContext::CreateLoadingSessionHistoryEntryForLoad( return loadingInfo; } - if (*navigationType == NavigationType::Traverse && !mActiveEntry) { - // We must have just been recreated from a session restore, so we need - // to reconstruct the list of contiguous entries. - auto* shistory = static_cast<nsSHistory*>(GetSessionHistory()); - MOZ_ASSERT(mActiveEntryList.isEmpty()); - mActiveEntryList.insertFront(entry); - - SessionHistoryEntry* currEntry = entry; - while (auto* prevEntry = - shistory->FindAdjacentContiguousEntryFor(currEntry, -1)) { - currEntry->setPrevious(prevEntry); - currEntry = prevEntry; - } - - currEntry = entry; - while (auto* nextEntry = - shistory->FindAdjacentContiguousEntryFor(currEntry, 1)) { - currEntry->setNext(nextEntry); - currEntry = nextEntry; - } - } - loadingInfo->mTriggeringEntry = mActiveEntry ? Some(mActiveEntry->Info()) : Nothing(); MOZ_LOG_FMT(gNavigationAPILog, LogLevel::Verbose, diff --git a/docshell/shistory/nsSHistory.cpp b/docshell/shistory/nsSHistory.cpp @@ -2500,6 +2500,21 @@ mozilla::dom::SessionHistoryEntry* nsSHistory::FindAdjacentContiguousEntryFor( return nullptr; } +LinkedList<SessionHistoryEntry> nsSHistory::ConstructContiguousEntryListFrom( + SessionHistoryEntry* aEntry) { + LinkedList<SessionHistoryEntry> entryList; + entryList.insertBack(aEntry); + for (auto* entry = aEntry; + (entry = FindAdjacentContiguousEntryFor(entry, -1));) { + entryList.insertFront(entry); + } + for (auto* entry = aEntry; + (entry = FindAdjacentContiguousEntryFor(entry, 1));) { + entryList.insertBack(entry); + } + return entryList; +} + bool nsSHistory::ForEachDifferingEntry( nsISHEntry* aPrevEntry, nsISHEntry* aNextEntry, BrowsingContext* aParent, const std::function<void(nsISHEntry*, BrowsingContext*)>& aCallback) { diff --git a/docshell/shistory/nsSHistory.h b/docshell/shistory/nsSHistory.h @@ -219,6 +219,8 @@ class nsSHistory : public mozilla::LinkedListElement<nsSHistory>, mozilla::dom::SessionHistoryEntry* FindAdjacentContiguousEntryFor( mozilla::dom::SessionHistoryEntry* aEntry, int32_t aSearchDirection); + mozilla::LinkedList<mozilla::dom::SessionHistoryEntry> + ConstructContiguousEntryListFrom(mozilla::dom::SessionHistoryEntry* aEntry); protected: virtual ~nsSHistory();