tor-browser

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

commit 09765611e405401698de875a631704b37b1ae06d
parent 0d3090d41a690fbd519f7f13b06da54352d98600
Author: Andreas Farre <farre@mozilla.com>
Date:   Thu,  6 Nov 2025 10:24:25 +0000

Bug 1998632 - Get associated document from global window. r=smaug

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

Diffstat:
Mdom/events/NavigateEvent.cpp | 21+++++++++++++++------
Mdom/events/NavigateEvent.h | 4+++-
Dtesting/web-platform/meta/navigation-api/navigate-event/intercept-on-synthetic-event.html.ini | 3---
Dtesting/web-platform/meta/navigation-api/scroll-behavior/scroll-on-synthetic-event.html.ini | 3---
4 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/dom/events/NavigateEvent.cpp b/dom/events/NavigateEvent.cpp @@ -193,7 +193,7 @@ void NavigateEvent::Intercept(const NavigationInterceptOptions& aOptions, // Step 8.1 if (mFocusResetBehavior && *mFocusResetBehavior != aOptions.mFocusReset.Value()) { - RefPtr<Document> document = GetDocument(); + RefPtr<Document> document = GetAssociatedDocument(); MaybeReportWarningToConsole(document, u"focusReset"_ns, *mFocusResetBehavior, aOptions.mFocusReset.Value()); @@ -207,7 +207,7 @@ void NavigateEvent::Intercept(const NavigationInterceptOptions& aOptions, if (aOptions.mScroll.WasPassed()) { // Step 9.1 if (mScrollBehavior && *mScrollBehavior != aOptions.mScroll.Value()) { - RefPtr<Document> document = GetDocument(); + RefPtr<Document> document = GetAssociatedDocument(); MaybeReportWarningToConsole(document, u"scroll"_ns, *mScrollBehavior, aOptions.mScroll.Value()); } @@ -255,7 +255,7 @@ void NavigateEvent::InitNavigateEvent(const NavigateEventInit& aEventInitDict) { mInfo = aEventInitDict.mInfo; mHasUAVisualTransition = aEventInitDict.mHasUAVisualTransition; mSourceElement = aEventInitDict.mSourceElement; - if (RefPtr document = GetDocument()) { + if (RefPtr document = GetAssociatedDocument()) { mLastScrollGeneration = document->LastScrollGeneration(); } } @@ -330,7 +330,7 @@ void NavigateEvent::Finish(bool aDidFulfill) { // https://html.spec.whatwg.org/#navigateevent-perform-shared-checks void NavigateEvent::PerformSharedChecks(ErrorResult& aRv) { // Step 1 - if (RefPtr document = GetDocument(); + if (RefPtr document = GetAssociatedDocument(); !document || !document->IsFullyActive()) { aRv.ThrowInvalidStateError("Document isn't fully active"); return; @@ -499,13 +499,13 @@ void NavigateEvent::ProcessScrollBehavior() { // Step 3 if (mNavigationType == NavigationType::Traverse || mNavigationType == NavigationType::Reload) { - RefPtr<Document> document = GetDocument(); + RefPtr<Document> document = GetAssociatedDocument(); RestoreScrollPositionData(document, mLastScrollGeneration); return; } // Step 4.1 - RefPtr<Document> document = GetDocument(); + RefPtr<Document> document = GetAssociatedDocument(); // If there is no document there's not much to do. if (!document) { return; @@ -523,6 +523,15 @@ void NavigateEvent::ProcessScrollBehavior() { // Step 4.3 document->ScrollToRef(); } + +Document* NavigateEvent::GetAssociatedDocument() const { + if (nsCOMPtr<nsPIDOMWindowInner> globalWindow = + do_QueryInterface(GetParentObject())) { + return globalWindow->GetExtantDoc(); + } + return nullptr; +} + } // namespace mozilla::dom #undef LOG_FMTI diff --git a/dom/events/NavigateEvent.h b/dom/events/NavigateEvent.h @@ -126,6 +126,8 @@ class NavigateEvent final : public Event { MOZ_CAN_RUN_SCRIPT void ProcessScrollBehavior(); + Document* GetAssociatedDocument() const; + explicit NavigateEvent(EventTarget* aOwner); ~NavigateEvent(); @@ -140,7 +142,7 @@ class NavigateEvent final : public Event { JS::Heap<JS::Value> mInfo; bool mHasUAVisualTransition = false; RefPtr<Element> mSourceElement; - uint32_t mLastScrollGeneration; + uint32_t mLastScrollGeneration = 0; nsTArray<RefPtr<NavigationPrecommitHandler>> mNavigationPrecommitHandlerList; diff --git a/testing/web-platform/meta/navigation-api/navigate-event/intercept-on-synthetic-event.html.ini b/testing/web-platform/meta/navigation-api/navigate-event/intercept-on-synthetic-event.html.ini @@ -1,3 +0,0 @@ -[intercept-on-synthetic-event.html] - [event.intercept() throws if invoked on a synthetic event] - expected: FAIL diff --git a/testing/web-platform/meta/navigation-api/scroll-behavior/scroll-on-synthetic-event.html.ini b/testing/web-platform/meta/navigation-api/scroll-behavior/scroll-on-synthetic-event.html.ini @@ -1,3 +0,0 @@ -[scroll-on-synthetic-event.html] - [scroll: scroll() should throw if invoked on a synthetic event.] - expected: FAIL