tor-browser

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

commit 123cb4730ee3f404dedf349d424721c2bd1a1d90
parent 7bb587f4b39688097858b02e90223f1cde0f25c9
Author: Andreas Farre <farre@mozilla.com>
Date:   Tue,  2 Dec 2025 15:54:51 +0000

Bug 2002946 - Pass source browsing context to GotoIndex. r=smaug

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

Diffstat:
Mdocshell/base/CanonicalBrowsingContext.cpp | 2+-
Mdocshell/shistory/nsSHistory.cpp | 65++++++++++++++++++++++++++++++++++++++++-------------------------
Mdocshell/shistory/nsSHistory.h | 21++++++++++++++-------
3 files changed, 55 insertions(+), 33 deletions(-)

diff --git a/docshell/base/CanonicalBrowsingContext.cpp b/docshell/base/CanonicalBrowsingContext.cpp @@ -1613,7 +1613,7 @@ Maybe<int32_t> CanonicalBrowsingContext::HistoryGo( // GoToIndex checks that index is >= 0 and < length. nsTArray<nsSHistory::LoadEntryResult> loadResults; - nsresult rv = shistory->GotoIndex(index.value(), loadResults, sameEpoch, + nsresult rv = shistory->GotoIndex(this, index.value(), loadResults, sameEpoch, aOffset == 0, aUserActivation); if (NS_FAILED(rv)) { MOZ_LOG(gSHLog, LogLevel::Debug, diff --git a/docshell/shistory/nsSHistory.cpp b/docshell/shistory/nsSHistory.cpp @@ -1682,10 +1682,11 @@ nsresult nsSHistory::Reload(uint32_t aReloadFlags, return NS_OK; } - nsresult rv = LoadEntry( - mIndex, loadType, HIST_CMD_RELOAD, aLoadResults, /* aSameEpoch */ false, - /* aLoadCurrentEntry */ true, - aReloadFlags & nsIWebNavigation::LOAD_FLAGS_USER_ACTIVATION); + nsresult rv = + LoadEntry(/* aSourceBrowsingContext */ nullptr, mIndex, loadType, + HIST_CMD_RELOAD, aLoadResults, /* aSameEpoch */ false, + /* aLoadCurrentEntry */ true, + aReloadFlags & nsIWebNavigation::LOAD_FLAGS_USER_ACTIVATION); if (NS_FAILED(rv)) { aLoadResults.Clear(); return rv; @@ -1709,7 +1710,8 @@ nsresult nsSHistory::ReloadCurrentEntry( // Notify listeners NotifyListeners(mListeners, [](auto l) { l->OnHistoryGotoIndex(); }); - return LoadEntry(mIndex, LOAD_HISTORY, HIST_CMD_RELOAD, aLoadResults, + return LoadEntry(/* aSourceBrowsingContext */ nullptr, mIndex, LOAD_HISTORY, + HIST_CMD_RELOAD, aLoadResults, /* aSameEpoch */ false, /* aLoadCurrentEntry */ true, /* aUserActivation */ false); } @@ -2247,8 +2249,9 @@ nsSHistory::UpdateIndex() { NS_IMETHODIMP nsSHistory::GotoIndex(int32_t aIndex, bool aUserActivation) { nsTArray<LoadEntryResult> loadResults; - nsresult rv = GotoIndex(aIndex, loadResults, /*aSameEpoch*/ false, - aIndex == mIndex, aUserActivation); + nsresult rv = + GotoIndex(/* aSourceBrowsingContext */ nullptr, aIndex, loadResults, + /*aSameEpoch*/ false, aIndex == mIndex, aUserActivation); NS_ENSURE_SUCCESS(rv, rv); LoadURIs(loadResults, /* aCheckForCancelation */ true); @@ -2263,12 +2266,14 @@ nsSHistory::EnsureCorrectEntryAtCurrIndex(nsISHEntry* aEntry) { } } -nsresult nsSHistory::GotoIndex(int32_t aIndex, +nsresult nsSHistory::GotoIndex(BrowsingContext* aSourceBrowsingContext, + int32_t aIndex, nsTArray<LoadEntryResult>& aLoadResults, bool aSameEpoch, bool aLoadCurrentEntry, bool aUserActivation) { - return LoadEntry(aIndex, LOAD_HISTORY, HIST_CMD_GOTOINDEX, aLoadResults, - aSameEpoch, aLoadCurrentEntry, aUserActivation); + return LoadEntry(aSourceBrowsingContext, aIndex, LOAD_HISTORY, + HIST_CMD_GOTOINDEX, aLoadResults, aSameEpoch, + aLoadCurrentEntry, aUserActivation); } NS_IMETHODIMP_(bool) @@ -2300,22 +2305,25 @@ nsSHistory::CanGoBackFromEntryAtIndex(int32_t aIndex, bool* aCanGoBack) { } nsresult nsSHistory::LoadNextPossibleEntry( - int32_t aNewIndex, long aLoadType, uint32_t aHistCmd, - nsTArray<LoadEntryResult>& aLoadResults, bool aLoadCurrentEntry, - bool aUserActivation) { + BrowsingContext* aSourceBrowsingContext, int32_t aNewIndex, long aLoadType, + uint32_t aHistCmd, nsTArray<LoadEntryResult>& aLoadResults, + bool aLoadCurrentEntry, bool aUserActivation) { mRequestedIndex = -1; if (aNewIndex < mIndex) { - return LoadEntry(aNewIndex - 1, aLoadType, aHistCmd, aLoadResults, + return LoadEntry(aSourceBrowsingContext, aNewIndex - 1, aLoadType, aHistCmd, + aLoadResults, /*aSameEpoch*/ false, aLoadCurrentEntry, aUserActivation); } if (aNewIndex > mIndex) { - return LoadEntry(aNewIndex + 1, aLoadType, aHistCmd, aLoadResults, + return LoadEntry(aSourceBrowsingContext, aNewIndex + 1, aLoadType, aHistCmd, + aLoadResults, /*aSameEpoch*/ false, aLoadCurrentEntry, aUserActivation); } return NS_ERROR_FAILURE; } -nsresult nsSHistory::LoadEntry(int32_t aIndex, long aLoadType, +nsresult nsSHistory::LoadEntry(BrowsingContext* aSourceBrowsingContext, + int32_t aIndex, long aLoadType, uint32_t aHistCmd, nsTArray<LoadEntryResult>& aLoadResults, bool aSameEpoch, bool aLoadCurrentEntry, @@ -2398,21 +2406,24 @@ nsresult nsSHistory::LoadEntry(int32_t aIndex, long aLoadType, if (mRequestedIndex == mIndex) { // Possibly a reload case - InitiateLoad(nextEntry, rootBC, aLoadType, aLoadResults, aLoadCurrentEntry, - aUserActivation, requestedOffset); + InitiateLoad(aSourceBrowsingContext, nextEntry, rootBC, aLoadType, + aLoadResults, aLoadCurrentEntry, aUserActivation, + requestedOffset); return NS_OK; } // Going back or forward. bool differenceFound = ForEachDifferingEntry( prevEntry, nextEntry, rootBC, - [self = RefPtr{this}, aLoadType, &aLoadResults, aLoadCurrentEntry, - aUserActivation, + [self = RefPtr{this}, + sourceBrowsingContext = RefPtr{aSourceBrowsingContext}, aLoadType, + &aLoadResults, aLoadCurrentEntry, aUserActivation, requestedOffset](nsISHEntry* aEntry, BrowsingContext* aParent) { // Set the Subframe flag if not navigating the root docshell. aEntry->SetIsSubFrame(aParent->Id() != self->mRootBC); - self->InitiateLoad(aEntry, aParent, aLoadType, aLoadResults, - aLoadCurrentEntry, aUserActivation, requestedOffset); + self->InitiateLoad(sourceBrowsingContext, aEntry, aParent, aLoadType, + aLoadResults, aLoadCurrentEntry, aUserActivation, + requestedOffset); }); if (!differenceFound) { // LoadNextPossibleEntry will change the offset by one, and in order @@ -2420,8 +2431,9 @@ nsresult nsSHistory::LoadEntry(int32_t aIndex, long aLoadType, // the value it had initially. mRequestedIndex = originalRequestedIndex; // We did not find any differences. Go further in the history. - return LoadNextPossibleEntry(aIndex, aLoadType, aHistCmd, aLoadResults, - aLoadCurrentEntry, aUserActivation); + return LoadNextPossibleEntry(aSourceBrowsingContext, aIndex, aLoadType, + aHistCmd, aLoadResults, aLoadCurrentEntry, + aUserActivation); } return NS_OK; @@ -2608,7 +2620,8 @@ bool nsSHistory::ForEachDifferingEntry( return differenceFound; } -void nsSHistory::InitiateLoad(nsISHEntry* aFrameEntry, +void nsSHistory::InitiateLoad(BrowsingContext* aSourceBrowsingContext, + nsISHEntry* aFrameEntry, BrowsingContext* aFrameBC, long aLoadType, nsTArray<LoadEntryResult>& aLoadResults, bool aLoadCurrentEntry, bool aUserActivation, @@ -2621,6 +2634,8 @@ void nsSHistory::InitiateLoad(nsISHEntry* aFrameEntry, nsCOMPtr<nsIURI> newURI = aFrameEntry->GetURI(); RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState(newURI); + loadState->SetSourceBrowsingContext(aSourceBrowsingContext); + loadState->SetHasValidUserGestureActivation(aUserActivation); // At the time we initiate a history entry load we already know if https-first diff --git a/docshell/shistory/nsSHistory.h b/docshell/shistory/nsSHistory.h @@ -175,7 +175,11 @@ class nsSHistory : public mozilla::LinkedListElement<nsSHistory>, nsresult Reload(uint32_t aReloadFlags, nsTArray<LoadEntryResult>& aLoadResults); nsresult ReloadCurrentEntry(nsTArray<LoadEntryResult>& aLoadResults); - nsresult GotoIndex(int32_t aIndex, nsTArray<LoadEntryResult>& aLoadResults, + // Passing aSourceBrowsingContext should only be done by + // CanonicalBrowsingContext::HistoryGo, since that corresponds to a call to + // #apply-the-traverse-history-step + nsresult GotoIndex(mozilla::dom::BrowsingContext* aSourceBrowsingContext, + int32_t aIndex, nsTArray<LoadEntryResult>& aLoadResults, bool aSameEpoch, bool aLoadCurrentEntry, bool aUserActivation); @@ -241,13 +245,15 @@ class nsSHistory : public mozilla::LinkedListElement<nsSHistory>, mozilla::dom::BrowsingContext* aParent, const std::function<void(nsISHEntry*, mozilla::dom::BrowsingContext*)>& aCallback); - void InitiateLoad(nsISHEntry* aFrameEntry, + void InitiateLoad(mozilla::dom::BrowsingContext* aSourceBrowsingContext, + nsISHEntry* aFrameEntry, mozilla::dom::BrowsingContext* aFrameBC, long aLoadType, nsTArray<LoadEntryResult>& aLoadResult, bool aLoadCurrentEntry, bool aUserActivation, int32_t aOffset); - nsresult LoadEntry(int32_t aIndex, long aLoadType, uint32_t aHistCmd, + nsresult LoadEntry(mozilla::dom::BrowsingContext* aSourceBrowsingContext, + int32_t aIndex, long aLoadType, uint32_t aHistCmd, nsTArray<LoadEntryResult>& aLoadResults, bool aSameEpoch, bool aLoadCurrentEntry, bool aUserActivation); @@ -271,10 +277,11 @@ class nsSHistory : public mozilla::LinkedListElement<nsSHistory>, // content viewers to cache, based on amount of total memory static uint32_t CalcMaxTotalViewers(); - nsresult LoadNextPossibleEntry(int32_t aNewIndex, long aLoadType, - uint32_t aHistCmd, - nsTArray<LoadEntryResult>& aLoadResults, - bool aLoadCurrentEntry, bool aUserActivation); + nsresult LoadNextPossibleEntry( + mozilla::dom::BrowsingContext* aSourceBrowsingContext, int32_t aNewIndex, + long aLoadType, uint32_t aHistCmd, + nsTArray<LoadEntryResult>& aLoadResults, bool aLoadCurrentEntry, + bool aUserActivation); // aIndex is the index of the entry which may be removed. // If aKeepNext is true, aIndex is compared to aIndex + 1,