tor-browser

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

commit 4799886d2922026538b1121ed719d9a845d551a2
parent fc022d4a4882b940735c118e8d70d40615513417
Author: Jan-Niklas Jaeschke <jjaschke@mozilla.com>
Date:   Tue, 28 Oct 2025 17:18:25 +0000

Bug 1970123, part 2 - Navigation API: Get `NavigationPrecommitHandler`s from `NavigateEvent::Intercept()`. r=dom-core,webidl,smaug

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

Diffstat:
Mdom/events/NavigateEvent.cpp | 40++++++++++++++++++++++++++--------------
Mdom/events/NavigateEvent.h | 3+++
Mdom/webidl/NavigateEvent.webidl | 1+
3 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/dom/events/NavigateEvent.cpp b/dom/events/NavigateEvent.cpp @@ -27,12 +27,11 @@ extern mozilla::LazyLogModule gNavigationAPILog; namespace mozilla::dom { -NS_IMPL_CYCLE_COLLECTION_INHERITED_WITH_JS_MEMBERS(NavigateEvent, Event, - (mDestination, mSignal, - mFormData, mSourceElement, - mNavigationHandlerList, - mAbortController), - (mInfo)) +NS_IMPL_CYCLE_COLLECTION_INHERITED_WITH_JS_MEMBERS( + NavigateEvent, Event, + (mDestination, mSignal, mFormData, mSourceElement, mNavigationHandlerList, + mAbortController, mNavigationPrecommitHandlerList), + (mInfo)) NS_IMPL_ADDREF_INHERITED(NavigateEvent, Event) NS_IMPL_RELEASE_INHERITED(NavigateEvent, Event) @@ -163,21 +162,34 @@ void NavigateEvent::Intercept(const NavigationInterceptOptions& aOptions, } // Step 4 + if (aOptions.mPrecommitHandler.WasPassed()) { + // Step 4.1 + if (!Cancelable()) { + aRv.ThrowInvalidStateError("Event is not cancelable"); + return; + } + + // Step 4.2 + mNavigationPrecommitHandlerList.AppendElement( + aOptions.mPrecommitHandler.InternalValue().get()); + } + + // Step 5 MOZ_DIAGNOSTIC_ASSERT(mInterceptionState == InterceptionState::None || mInterceptionState == InterceptionState::Intercepted); - // Step 5 + // Step 6 mInterceptionState = InterceptionState::Intercepted; - // Step 6 + // Step 7 if (aOptions.mHandler.WasPassed()) { mNavigationHandlerList.AppendElement( aOptions.mHandler.InternalValue().get()); } - // Step 7 + // Step 8 if (aOptions.mFocusReset.WasPassed()) { - // Step 7.1 + // Step 8.1 if (mFocusResetBehavior && *mFocusResetBehavior != aOptions.mFocusReset.Value()) { RefPtr<Document> document = GetDocument(); @@ -186,20 +198,20 @@ void NavigateEvent::Intercept(const NavigationInterceptOptions& aOptions, aOptions.mFocusReset.Value()); } - // Step 7.2 + // Step 8.2 mFocusResetBehavior = Some(aOptions.mFocusReset.Value()); } - // Step 8 + // Step 9 if (aOptions.mScroll.WasPassed()) { - // Step 8.1 + // Step 9.1 if (mScrollBehavior && *mScrollBehavior != aOptions.mScroll.Value()) { RefPtr<Document> document = GetDocument(); MaybeReportWarningToConsole(document, u"scroll"_ns, *mScrollBehavior, aOptions.mScroll.Value()); } - // Step 8.2 + // Step 9.2 mScrollBehavior.emplace(aOptions.mScroll.Value()); } } diff --git a/dom/events/NavigateEvent.h b/dom/events/NavigateEvent.h @@ -15,6 +15,7 @@ #include "mozilla/dom/BindingDeclarations.h" #include "mozilla/dom/Event.h" #include "mozilla/dom/NavigateEventBinding.h" +#include "mozilla/dom/NavigationPrecommitControllerBinding.h" #include "nsCycleCollectionParticipant.h" namespace mozilla::dom { @@ -135,6 +136,8 @@ class NavigateEvent final : public Event { RefPtr<Element> mSourceElement; uint32_t mLastScrollGeneration; + nsTArray<RefPtr<NavigationPrecommitHandler>> mNavigationPrecommitHandlerList; + // https://html.spec.whatwg.org/multipage/nav-history-apis.html#the-navigateevent-interface:navigateevent-2 enum InterceptionState mInterceptionState = InterceptionState::None; diff --git a/dom/webidl/NavigateEvent.webidl b/dom/webidl/NavigateEvent.webidl @@ -42,6 +42,7 @@ dictionary NavigateEventInit : EventInit { }; dictionary NavigationInterceptOptions { + NavigationPrecommitHandler precommitHandler; NavigationInterceptHandler handler; NavigationFocusReset focusReset; NavigationScrollBehavior scroll;