Skip to content

Commit 8fe87a5

Browse files
committed
[Navigation API] NavigateEvent.sourceElement can be cross-window.
https://bugs.webkit.org/show_bug.cgi?id=301885 rdar://163962362 Reviewed by NOBODY (OOPS!). NavigateEvent.sourceElement should be allowed to reference elements from different browsing contexts (e.g., when an anchor in a parent window targets an iframe). Since navigate events only fire for same-origin navigations, there is no security risk in exposing the source element across windows. This aligns WebKit's behavior with the HTML specification and matches Chromium's implementation after their fix. Spec: https://html.spec.whatwg.org/multipage/nav-history-apis.html#fire-a-push/replace/reload-navigate-event * LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-anchor-with-target.html: imported from web-platform-tests/wpt#55760 * Source/WebCore/loader/FrameLoader.cpp: (WebCore::FrameLoader::dispatchNavigateEvent):
1 parent 9f30772 commit 8fe87a5

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-anchor-with-target.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
assert_equals(new URL(e.destination.url).pathname,
2121
"/navigation-api/navigate-event/foo.html");
2222
assert_false(e.destination.sameDocument);
23-
assert_equals(e.destination.key, "");
24-
assert_equals(e.destination.id, "");
23+
assert_equals(e.destination.key, "");
24+
assert_equals(e.destination.id, "");
2525
assert_equals(e.destination.index, -1);
26-
assert_equals(e.sourceElement, null);
26+
assert_equals(e.sourceElement, a);
2727
e.preventDefault();
2828
});
2929
a.click();

Source/WebCore/loader/FrameLoader.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4426,11 +4426,6 @@ bool FrameLoader::dispatchNavigateEvent(FrameLoadType loadType, const FrameLoadR
44264426

44274427
RefPtr sourceElement = event ? dynamicDowncast<Element>(event->target()) : nullptr;
44284428

4429-
// For non-form navigations, if sourceElement is from a different frame, it should be null.
4430-
// For form submissions, sourceElement can be from a different frame (when form has target attribute).
4431-
if (!formState && sourceElement && sourceElement->document().frame() != m_frame.ptr())
4432-
sourceElement = nullptr;
4433-
44344429
return window->protectedNavigation()->dispatchPushReplaceReloadNavigateEvent(newURL, navigationType, isSameDocument, formState, classicHistoryAPIState, sourceElement.get());
44354430
}
44364431

0 commit comments

Comments
 (0)