tor-browser

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

commit 9f16b9309e3e47eb188ff296b6190b262425e1d3
parent 7e71f6b15e4cfde2fe850c44dc223ffabbb2354c
Author: Cristina Horotan <chorotan@mozilla.com>
Date:   Tue, 21 Oct 2025 12:28:51 +0300

Revert "Bug 1992939 - Pre-compute current entry index for intercepted traverse navigations. r=jjaschke" for causing wpt failures on /navigation-api/scroll-behavior/after-transition-basic.html

This reverts commit 2efb9540ff0bd24830cb58cf8527ad5ae2b9ee8b.

Diffstat:
Mdom/events/NavigateEvent.cpp | 8--------
Mdom/navigation/Navigation.cpp | 71+++++++++++++++++++++++++----------------------------------------------
Mdom/navigation/Navigation.h | 2--
Atesting/web-platform/meta/navigation-api/navigate-event/intercept-same-document-history-back.html.ini | 3+++
4 files changed, 28 insertions(+), 56 deletions(-)

diff --git a/dom/events/NavigateEvent.cpp b/dom/events/NavigateEvent.cpp @@ -19,9 +19,6 @@ extern mozilla::LazyLogModule gNavigationAPILog; -#define LOG_FMTI(format, ...) \ - MOZ_LOG_FMT(gNavigationAPILog, LogLevel::Info, format, ##__VA_ARGS__); - #define LOG_FMT(format, ...) \ MOZ_LOG_FMT(gNavigationAPILog, LogLevel::Debug, format, ##__VA_ARGS__); @@ -139,8 +136,6 @@ static void MaybeReportWarningToConsole(Document* aDocument, // https://html.spec.whatwg.org/#dom-navigateevent-intercept void NavigateEvent::Intercept(const NavigationInterceptOptions& aOptions, ErrorResult& aRv) { - LOG_FMTI("Called NavigateEvent.intercept()"); - // Step 1 if (PerformSharedChecks(aRv); aRv.Failed()) { return; @@ -202,8 +197,6 @@ void NavigateEvent::Intercept(const NavigationInterceptOptions& aOptions, // https://html.spec.whatwg.org/#dom-navigateevent-scroll void NavigateEvent::Scroll(ErrorResult& aRv) { - LOG_FMTI("Called NavigateEvent.scroll()"); - // Step 1 if (PerformSharedChecks(aRv); aRv.Failed()) { return; @@ -481,5 +474,4 @@ void NavigateEvent::ProcessScrollBehavior() { } } // namespace mozilla::dom -#undef LOG_FMTI #undef LOG_FMT diff --git a/dom/navigation/Navigation.cpp b/dom/navigation/Navigation.cpp @@ -44,18 +44,9 @@ mozilla::LazyLogModule gNavigationAPILog("NavigationAPI"); -#define LOG_FMTW(format, ...) \ - MOZ_LOG_FMT(gNavigationAPILog, LogLevel::Warning, format, ##__VA_ARGS__); - -#define LOG_FMTI(format, ...) \ - MOZ_LOG_FMT(gNavigationAPILog, LogLevel::Info, format, ##__VA_ARGS__); - -#define LOG_FMTD(format, ...) \ +#define LOG_FMT(format, ...) \ MOZ_LOG_FMT(gNavigationAPILog, LogLevel::Debug, format, ##__VA_ARGS__); -#define LOG_FMTV(format, ...) \ - MOZ_LOG_FMT(gNavigationAPILog, LogLevel::Verbose, format, ##__VA_ARGS__); - namespace mozilla::dom { static void InitNavigationResult(NavigationResult& aResult, @@ -236,7 +227,6 @@ already_AddRefed<NavigationHistoryEntry> Navigation::GetCurrentEntry() const { void Navigation::UpdateCurrentEntry( JSContext* aCx, const NavigationUpdateCurrentEntryOptions& aOptions, ErrorResult& aRv) { - LOG_FMTI("Called navigation.updateCurrentEntry()"); RefPtr currentEntry(GetCurrentEntry()); if (!currentEntry) { aRv.ThrowInvalidStateError( @@ -297,10 +287,10 @@ bool Navigation::HasEntriesAndEventsDisabled() const { void Navigation::InitializeHistoryEntries( mozilla::Span<const SessionHistoryInfo> aNewSHInfos, const SessionHistoryInfo* aInitialSHInfo) { - LOG_FMTD("Attempting to initialize history entries for {}.", - aInitialSHInfo->GetURI() - ? aInitialSHInfo->GetURI()->GetSpecOrDefault() - : "<no uri>"_ns) + LOG_FMT("Attempting to initialize history entries for {}.", + aInitialSHInfo->GetURI() + ? aInitialSHInfo->GetURI()->GetSpecOrDefault() + : "<no uri>"_ns) mEntries.Clear(); mCurrentEntryIndex.reset(); @@ -342,7 +332,13 @@ void Navigation::UpdateEntriesForSameDocumentNavigation( switch (aNavigationType) { case NavigationType::Traverse: MOZ_LOG(gNavigationAPILog, LogLevel::Debug, ("Traverse navigation")); - SetCurrentEntryIndex(aDestinationSHE); + mCurrentEntryIndex.reset(); + for (auto i = 0ul; i < mEntries.Length(); i++) { + if (mEntries[i]->IsSameEntry(aDestinationSHE)) { + mCurrentEntryIndex = Some(i); + break; + } + } MOZ_ASSERT(mCurrentEntryIndex); break; @@ -497,8 +493,9 @@ Navigation::CreateSerializedStateAndMaybeSetEarlyErrorResult( void Navigation::Navigate(JSContext* aCx, const nsAString& aUrl, const NavigationNavigateOptions& aOptions, NavigationResult& aResult) { - LOG_FMTI("Called navigation.navigate() with url = {}", - NS_ConvertUTF16toUTF8(aUrl)); + MOZ_LOG_FMT(gNavigationAPILog, LogLevel::Debug, + "Called navigation.navigate() with url = {}", + NS_ConvertUTF16toUTF8(aUrl)); // 4. Let document be this's relevant global object's associated Document. const RefPtr<Document> document = GetAssociatedDocument(); if (!document) { @@ -610,7 +607,7 @@ void Navigation::Navigate(JSContext* aCx, const nsAString& aUrl, void Navigation::PerformNavigationTraversal(JSContext* aCx, const nsID& aKey, const NavigationOptions& aOptions, NavigationResult& aResult) { - LOG_FMTV("traverse navigation to {}", aKey.ToString().get()); + LOG_FMT("traverse navigation to {}", aKey.ToString().get()); // 1. Let document be navigation's relevant global object's associated // Document. const Document* document = GetAssociatedDocument(); @@ -733,7 +730,7 @@ void Navigation::PerformNavigationTraversal(JSContext* aCx, const nsID& aKey, // https://html.spec.whatwg.org/#dom-navigation-reload void Navigation::Reload(JSContext* aCx, const NavigationReloadOptions& aOptions, NavigationResult& aResult) { - LOG_FMTI("Called navigation.reload()"); + MOZ_LOG(gNavigationAPILog, LogLevel::Debug, ("Called navigation.reload()")); // 1. Let document be this's relevant global object's associated Document. const RefPtr<Document> document = GetAssociatedDocument(); if (!document) { @@ -812,8 +809,9 @@ void Navigation::Reload(JSContext* aCx, const NavigationReloadOptions& aOptions, void Navigation::TraverseTo(JSContext* aCx, const nsAString& aKey, const NavigationOptions& aOptions, NavigationResult& aResult) { - LOG_FMTI("Called navigation.traverseTo() with key = {}", - NS_ConvertUTF16toUTF8(aKey).get()); + MOZ_LOG_FMT(gNavigationAPILog, LogLevel::Debug, + "Called navigation.traverseTo() with key = {}", + NS_ConvertUTF16toUTF8(aKey).get()); // 1. If this's current entry index is −1, then return an early error result // for an "InvalidStateError" DOMException. @@ -848,7 +846,7 @@ void Navigation::TraverseTo(JSContext* aCx, const nsAString& aKey, // https://html.spec.whatwg.org/#dom-navigation-back void Navigation::Back(JSContext* aCx, const NavigationOptions& aOptions, NavigationResult& aResult) { - LOG_FMTI("Called navigation.back()"); + MOZ_LOG(gNavigationAPILog, LogLevel::Debug, ("Called navigation.back()")); // 1. If this's current entry index is −1 or 0, then return an early error // result for an "InvalidStateError" DOMException. if (mCurrentEntryIndex.isNothing() || *mCurrentEntryIndex == 0 || @@ -871,7 +869,7 @@ void Navigation::Back(JSContext* aCx, const NavigationOptions& aOptions, // https://html.spec.whatwg.org/#dom-navigation-forward void Navigation::Forward(JSContext* aCx, const NavigationOptions& aOptions, NavigationResult& aResult) { - LOG_FMTI("Called navigation.forward()"); + MOZ_LOG(gNavigationAPILog, LogLevel::Debug, ("Called navigation.forward()")); // 1. If this's current entry index is −1 or is equal to this's entry list's // size − 1, then return an early error result for an "InvalidStateError" @@ -1113,7 +1111,7 @@ static void LogEvent(Event* aEvent, NavigateEvent* aOngoingEvent, } } - LOG_FMTD("{}", fmt::join(log.begin(), log.end(), std::string_view{" "})); + LOG_FMT("{}", fmt::join(log.begin(), log.end(), std::string_view{" "})); } nsresult Navigation::FireEvent(const nsAString& aName) { @@ -1386,11 +1384,6 @@ bool Navigation::InnerFireNavigateEvent( // 32.7.1.4 ResumeApplyTheHistoryStep(entry->SessionHistoryInfo(), navigable->Top(), userInvolvement); - - // This is not in the spec, but both Chrome and Safari does this or - // something similar. - MOZ_ASSERT(entry->Index() >= 0); - mCurrentEntryIndex = Some(entry->Index()); } break; @@ -1562,7 +1555,7 @@ bool Navigation::InnerFireNavigateEvent( // performs these steps, since spec can perform more of // #apply-the-history-steps in a synchronous way. if (apiMethodTracker) { - LOG_FMTD("Waiting for committed"); + LOG_FMT("Waiting for committed"); apiMethodTracker->CommittedPromise()->AddCallbacksWithCycleCollectedArgs( [successSteps, failureSteps]( JSContext*, JS::Handle<JS::Value>, ErrorResult&, @@ -1579,7 +1572,7 @@ bool Navigation::InnerFireNavigateEvent( nsCOMPtr(globalObject), nsTArray<RefPtr<Promise>>(std::move(promiseList)), scope); } else { - LOG_FMTD("No API method tracker, not waiting for committed"); + LOG_FMT("No API method tracker, not waiting for committed"); // If we don't have an apiMethodTracker we can immediately start waiting // for the promise list. Promise::WaitForAll(globalObject, promiseList, successSteps, failureSteps, @@ -1661,16 +1654,6 @@ void Navigation::PromoteUpcomingAPIMethodTrackerToOngoing( navigation->mUpcomingTraverseAPIMethodTrackers.Remove(*key); } -void Navigation::SetCurrentEntryIndex(const SessionHistoryInfo* aTargetInfo) { - mCurrentEntryIndex.reset(); - if (auto* entry = FindNavigationHistoryEntry(*aTargetInfo)) { - MOZ_ASSERT(entry->Index() > 0); - mCurrentEntryIndex = Some(entry->Index()); - } - - LOG_FMTW("Session history entry did not exist"); -} - // https://html.spec.whatwg.org/#inform-the-navigation-api-about-aborting-navigation void Navigation::InnerInformAboutAbortingNavigation(JSContext* aCx) { // As per https://github.com/whatwg/html/issues/11579, we should abort all @@ -1974,7 +1957,3 @@ void Navigation::CreateNavigationActivationFrom( } } // namespace mozilla::dom - -#undef LOG_FMTV -#undef LOG_FMTD -#undef LOG_FMTI diff --git a/dom/navigation/Navigation.h b/dom/navigation/Navigation.h @@ -205,8 +205,6 @@ class Navigation final : public DOMEventTargetHelper { static void CleanUp(NavigationAPIMethodTracker* aNavigationAPIMethodTracker); - void SetCurrentEntryIndex(const SessionHistoryInfo* aTargetInfo); - Document* GetAssociatedDocument() const; // Update the state managing if we need to dispatch the traverse event or not. diff --git a/testing/web-platform/meta/navigation-api/navigate-event/intercept-same-document-history-back.html.ini b/testing/web-platform/meta/navigation-api/navigate-event/intercept-same-document-history-back.html.ini @@ -0,0 +1,3 @@ +[intercept-same-document-history-back.html] + [event.intercept() can intercept same-document history.back()] + expected: FAIL