tor-browser

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

commit 7f8616af94958811a659a7a2a9fc5d0804e0817e
parent 71b23d56f1a83dbb65d039d3b9d7984ce051e341
Author: Andreas Farre <farre@mozilla.com>
Date:   Thu, 23 Oct 2025 14:44:04 +0000

Bug 1996016 - Copy over previous entries for multipart/x-mixed-replace. r=jjaschke

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

Diffstat:
Mdocshell/base/nsDocShell.cpp | 37+++++++++++++++++++++++++++++++++++++
Mdom/navigation/Navigation.cpp | 6++++++
2 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp @@ -5618,10 +5618,40 @@ static bool IsFollowupPartOfMultipart(nsIRequest* aRequest) { !firstPart; } +static void GetPreviousContiguousEntries( + nsIDocumentViewer* aDocumentViewer, + nsTArray<SessionHistoryInfo>& aContiguousEntries) { + if (!aDocumentViewer || !aDocumentViewer->GetDocument() || + !aDocumentViewer->GetDocument()->GetWindow() || + !aDocumentViewer->GetDocument()->GetWindow()->GetCurrentInnerWindow() || + !aDocumentViewer->GetDocument() + ->GetWindow() + ->GetCurrentInnerWindow() + ->Navigation()) { + return; + } + + nsTArray<RefPtr<NavigationHistoryEntry>> entries; + RefPtr navigation = aDocumentViewer->GetDocument() + ->GetWindow() + ->GetCurrentInnerWindow() + ->Navigation(); + navigation->Entries(entries); + for (const auto& entry : entries) { + aContiguousEntries.AppendElement(*entry->SessionHistoryInfo()); + } +} + nsresult nsDocShell::Embed(nsIDocumentViewer* aDocumentViewer, WindowGlobalChild* aWindowActor, bool aIsTransientAboutBlank, nsIRequest* aRequest, nsIURI* aPreviousURI) { + nsTArray<SessionHistoryInfo> oldContiguousEntries; + if (mozilla::SessionHistoryInParent() && + IsFollowupPartOfMultipart(aRequest)) { + GetPreviousContiguousEntries(mDocumentViewer, oldContiguousEntries); + } + // Save the LayoutHistoryState of the previous document, before // setting up new document PersistLayoutHistoryState(); @@ -5673,6 +5703,13 @@ nsresult nsDocShell::Embed(nsIDocumentViewer* aDocumentViewer, MOZ_LOG(gSHLog, LogLevel::Debug, ("document %p Embed", this)); MoveLoadingToActiveEntry(expired, cacheKey, aPreviousURI); + } else if (mozilla::SessionHistoryInParent() && + IsFollowupPartOfMultipart(aRequest)) { + if (RefPtr navigation = + GetWindow()->GetCurrentInnerWindow()->Navigation()) { + navigation->InitializeHistoryEntries(oldContiguousEntries, + mActiveEntry.get()); + } } bool updateHistory = true; diff --git a/dom/navigation/Navigation.cpp b/dom/navigation/Navigation.cpp @@ -44,6 +44,9 @@ mozilla::LazyLogModule gNavigationAPILog("NavigationAPI"); +#define LOG_FMTE(format, ...) \ + MOZ_LOG_FMT(gNavigationAPILog, LogLevel::Error, format, ##__VA_ARGS__); + #define LOG_FMTW(format, ...) \ MOZ_LOG_FMT(gNavigationAPILog, LogLevel::Warning, format, ##__VA_ARGS__); @@ -356,6 +359,7 @@ void Navigation::UpdateEntriesForSameDocumentNavigation( case NavigationType::Replace: MOZ_LOG(gNavigationAPILog, LogLevel::Debug, ("Replace navigation")); if (!oldCurrentEntry) { + LOG_FMTE("No current entry."); MOZ_ASSERT(false, "FIXME"); return; } @@ -1941,3 +1945,5 @@ void Navigation::CreateNavigationActivationFrom( #undef LOG_FMTV #undef LOG_FMTD #undef LOG_FMTI +#undef LOG_FMTW +#undef LOG_FMTE