Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Navigation] Dispatch NavigateEvent on same-document navigations #25640

Merged

Conversation

TingPing
Copy link
Contributor

@TingPing TingPing commented Mar 8, 2024

b3b7f85

[Navigation] Dispatch NavigateEvent on same-document navigations
https://bugs.webkit.org/show_bug.cgi?id=265401

Reviewed by Alex Christensen.

- Partial implementation intercept/finish/scroll/abort in NavigateEvent.
- Implement a large part of the dispatching of Traversal and Push/Reload/Replace events.
- The FrameLoader dispatches the events in the case of same-document loads.
- Gate NavigateEvent.hasUAVisualTransition behind the setting for it.

* LayoutTests/TestExpectations:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/commit-behavior/multiple-intercept-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/cross-window/click-samedocument-crossorigin-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/cross-window/click-samedocument-crossorigin-sameorigindomain.sub-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/cross-window/click-samedocument-sameorigin-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/cross-window/location-samedocument-crossorigin-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/cross-window/location-samedocument-crossorigin-sameorigindomain.sub-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/cross-window/location-samedocument-sameorigin-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/cross-window/open-samedocument-crossorigin-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/cross-window/open-samedocument-crossorigin-sameorigindomain.sub-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/cross-window/open-samedocument-sameorigin-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/cross-window/submit-samedocument-crossorigin-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/cross-window/submit-samedocument-crossorigin-sameorigindomain.sub-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/cross-window/submit-samedocument-sameorigin-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/intercept-after-dispatch-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/intercept-canceled-event-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/intercept-handler-null-or-undefined-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-anchor-fragment-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-anchor-userInitiated-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-form-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-form-get-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-form-userInitiated-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-history-back-after-fragment-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-history-back-noop-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-history-go-0-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-iframe-location-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-location-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-meta-refresh-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-navigation-back-same-document-in-iframe-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-navigation-navigate-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-svg-anchor-fragment-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-window-open-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-window-open-self-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/same-url-replace-cross-document-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/same-url-replace-same-document-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigation-methods/navigate-history-push-not-loaded-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigation-methods/navigate-same-document-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigation-methods/return-value/navigate-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/scroll-behavior/manual-scroll-after-resolve-expected.txt:
* Source/WebCore/loader/FrameLoader.cpp:
(WebCore::determineNavigationType):
(WebCore::FrameLoader::loadInSameDocument):
* Source/WebCore/page/NavigateEvent.cpp:
(WebCore::NavigateEvent::NavigateEvent):
(WebCore::NavigateEvent::create):
(WebCore::NavigateEvent::sharedChecks):
(WebCore::NavigateEvent::intercept):
(WebCore::NavigateEvent::scroll):
(WebCore::NavigateEvent::finish):
* Source/WebCore/page/NavigateEvent.h:
* Source/WebCore/page/Navigation.cpp:
(WebCore::Navigation::currentEntry const):
(WebCore::Navigation::updateCurrentEntry):
(WebCore::Navigation::hasEntriesAndEventsDisabled const):
(WebCore::Navigation::updateForNavigation):
(WebCore::documentCanHaveURLRewritten):
(WebCore::Navigation::innerDispatchNavigateEvent):
(WebCore::Navigation::dispatchTraversalNavigateEvent):
(WebCore::Navigation::dispatchPushReplaceReloadNavigateEvent):
(WebCore::Navigation::dispatchDownloadNavigateEvent):
(WebCore::determineNavigationType): Deleted.
* Source/WebCore/page/Navigation.h:
* Source/WebCore/page/NavigationTransition.h:

Canonical link: https://commits.webkit.org/276522@main

64e8f38

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug   πŸ§ͺ wpe-wk2
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2   πŸ§ͺ api-mac βœ… πŸ§ͺ api-wpe
  πŸ§ͺ ios-wk2-wpt βœ… πŸ§ͺ mac-wk1 βœ… πŸ›  wpe-skia
βœ… πŸ§ͺ api-ios βœ… πŸ§ͺ mac-wk2 βœ… πŸ›  gtk
βœ… πŸ›  tv βœ… πŸ§ͺ mac-AS-debug-wk2   πŸ§ͺ gtk-wk2
  πŸ›  tv-sim   πŸ§ͺ api-gtk
βœ… πŸ›  πŸ§ͺ merge   πŸ›  watch
βœ… πŸ›  watch-sim

@TingPing TingPing requested a review from cdumez as a code owner March 8, 2024 19:54
@TingPing TingPing self-assigned this Mar 8, 2024
@TingPing TingPing added the WebCore Misc. For miscellaneous bugs in the WebCore framework (and not JavaScriptCore or WebKit). label Mar 8, 2024
@TingPing TingPing requested a review from rwlbuis March 8, 2024 19:54
@nt1m nt1m requested a review from achristensen07 March 8, 2024 19:58
@webkit-early-warning-system

This comment was marked as outdated.

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 8, 2024
@TingPing TingPing removed the merging-blocked Applied to prevent a change from being merged label Mar 9, 2024
@TingPing TingPing force-pushed the pgriffis/navigation-api-next-4 branch from 22b6e73 to c4d5ced Compare March 9, 2024 16:42
@webkit-early-warning-system

This comment was marked as outdated.

@TingPing TingPing force-pushed the pgriffis/navigation-api-next-4 branch from c4d5ced to 952071f Compare March 9, 2024 16:48
@webkit-early-warning-system

This comment was marked as outdated.

@TingPing TingPing force-pushed the pgriffis/navigation-api-next-4 branch from 952071f to d980baf Compare March 9, 2024 17:11
Source/WebCore/loader/FrameLoader.cpp Outdated Show resolved Hide resolved
Source/WebCore/loader/FrameLoader.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@rwlbuis rwlbuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good, left some comments.

Source/WebCore/loader/FrameLoader.cpp Outdated Show resolved Hide resolved
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 14, 2024
@TingPing TingPing removed the merging-blocked Applied to prevent a change from being merged label Mar 16, 2024
@TingPing TingPing force-pushed the pgriffis/navigation-api-next-4 branch from d072cf9 to a7d3d03 Compare March 16, 2024 01:21
@webkit-early-warning-system

This comment was marked as outdated.

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 16, 2024
@TingPing TingPing removed the merging-blocked Applied to prevent a change from being merged label Mar 16, 2024
@TingPing TingPing force-pushed the pgriffis/navigation-api-next-4 branch from a7d3d03 to fb9529e Compare March 16, 2024 01:31
@webkit-early-warning-system

This comment was marked as outdated.

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 16, 2024
@TingPing TingPing removed the merging-blocked Applied to prevent a change from being merged label Mar 16, 2024
@TingPing TingPing force-pushed the pgriffis/navigation-api-next-4 branch from fb9529e to 46ccbee Compare March 16, 2024 16:16
@webkit-early-warning-system

This comment was marked as outdated.

@TingPing TingPing force-pushed the pgriffis/navigation-api-next-4 branch from 46ccbee to be51663 Compare March 16, 2024 16:45
Copy link
Contributor

@rwlbuis rwlbuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the PR is too big, making review difficult. How about:

  1. refactor PR, with NavigationTransition + NavigationDestination changes + scriptExecutionContext() cleanup.
  2. just a PR with event dispatch algorithms
  3. a PR that calls the event dispatch algorithms

@TingPing TingPing force-pushed the pgriffis/navigation-api-next-4 branch from be51663 to 683a932 Compare March 18, 2024 18:09
@TingPing
Copy link
Contributor Author

TingPing commented Mar 18, 2024

I split this into a few commits. The first two have their own PRs so this will just land the third commit. I can move out the FrameLoader bits too if that makes sense, though then this patch will do very little.

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 18, 2024
@TingPing TingPing removed the merging-blocked Applied to prevent a change from being merged label Mar 19, 2024
@TingPing TingPing force-pushed the pgriffis/navigation-api-next-4 branch from 683a932 to 11e2e89 Compare March 19, 2024 11:19
Source/WebCore/page/Navigation.cpp Show resolved Hide resolved
Source/WebCore/page/NavigateEvent.h Outdated Show resolved Hide resolved
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#fire-a-download-request-navigate-event
bool Navigation::dispatchDownloadNavigateEvent(const URL&, const String& downloadFilename)
{
// FIXME
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When to call this is tricky, since it seems to be handled mostly in FrameLoaderClient. Maybe an option is to send the event in PolicyChecker::checkNavigationPolicy before calling startDownload.

Copy link
Contributor Author

@TingPing TingPing Mar 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the policychecker was one place I was looking.

All of these dispatches seem tricky to find the ideal spot, the general web navigation specs don't seem super aligned with WebKit's structure to me.

Copy link
Contributor

@rwlbuis rwlbuis Mar 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the policychecker was one place I was looking.

All of these dispatches seem tricky to find the ideal spot, the general navigation specs don't seem super aligned with WebKit's structure to me.

Correct, for example the download handling has a quite seperate algorithm, but I would bet that spec was done after the implementation. I would like to work on refactoring that, but it is not crucial for Navigation API.

@TingPing TingPing force-pushed the pgriffis/navigation-api-next-4 branch from 11e2e89 to c5e46c1 Compare March 22, 2024 01:33
@webkit-early-warning-system

This comment was marked as outdated.

@TingPing TingPing force-pushed the pgriffis/navigation-api-next-4 branch from c5e46c1 to 64e8f38 Compare March 22, 2024 01:39
@TingPing TingPing added the merge-queue Applied to send a pull request to merge-queue label Mar 22, 2024
https://bugs.webkit.org/show_bug.cgi?id=265401

Reviewed by Alex Christensen.

- Partial implementation intercept/finish/scroll/abort in NavigateEvent.
- Implement a large part of the dispatching of Traversal and Push/Reload/Replace events.
- The FrameLoader dispatches the events in the case of same-document loads.
- Gate NavigateEvent.hasUAVisualTransition behind the setting for it.

* LayoutTests/TestExpectations:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/commit-behavior/multiple-intercept-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/cross-window/click-samedocument-crossorigin-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/cross-window/click-samedocument-crossorigin-sameorigindomain.sub-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/cross-window/click-samedocument-sameorigin-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/cross-window/location-samedocument-crossorigin-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/cross-window/location-samedocument-crossorigin-sameorigindomain.sub-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/cross-window/location-samedocument-sameorigin-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/cross-window/open-samedocument-crossorigin-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/cross-window/open-samedocument-crossorigin-sameorigindomain.sub-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/cross-window/open-samedocument-sameorigin-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/cross-window/submit-samedocument-crossorigin-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/cross-window/submit-samedocument-crossorigin-sameorigindomain.sub-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/cross-window/submit-samedocument-sameorigin-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/intercept-after-dispatch-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/intercept-canceled-event-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/intercept-handler-null-or-undefined-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-anchor-fragment-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-anchor-userInitiated-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-form-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-form-get-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-form-userInitiated-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-history-back-after-fragment-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-history-back-noop-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-history-go-0-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-iframe-location-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-location-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-meta-refresh-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-navigation-back-same-document-in-iframe-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-navigation-navigate-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-svg-anchor-fragment-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-window-open-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/navigate-window-open-self-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/same-url-replace-cross-document-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigate-event/same-url-replace-same-document-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigation-methods/navigate-history-push-not-loaded-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigation-methods/navigate-same-document-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/navigation-methods/return-value/navigate-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/navigation-api/scroll-behavior/manual-scroll-after-resolve-expected.txt:
* Source/WebCore/loader/FrameLoader.cpp:
(WebCore::determineNavigationType):
(WebCore::FrameLoader::loadInSameDocument):
* Source/WebCore/page/NavigateEvent.cpp:
(WebCore::NavigateEvent::NavigateEvent):
(WebCore::NavigateEvent::create):
(WebCore::NavigateEvent::sharedChecks):
(WebCore::NavigateEvent::intercept):
(WebCore::NavigateEvent::scroll):
(WebCore::NavigateEvent::finish):
* Source/WebCore/page/NavigateEvent.h:
* Source/WebCore/page/Navigation.cpp:
(WebCore::Navigation::currentEntry const):
(WebCore::Navigation::updateCurrentEntry):
(WebCore::Navigation::hasEntriesAndEventsDisabled const):
(WebCore::Navigation::updateForNavigation):
(WebCore::documentCanHaveURLRewritten):
(WebCore::Navigation::innerDispatchNavigateEvent):
(WebCore::Navigation::dispatchTraversalNavigateEvent):
(WebCore::Navigation::dispatchPushReplaceReloadNavigateEvent):
(WebCore::Navigation::dispatchDownloadNavigateEvent):
(WebCore::determineNavigationType): Deleted.
* Source/WebCore/page/Navigation.h:
* Source/WebCore/page/NavigationTransition.h:

Canonical link: https://commits.webkit.org/276522@main
@webkit-commit-queue
Copy link
Collaborator

Committed 276522@main (b3b7f85): https://commits.webkit.org/276522@main

Reviewed commits have been landed. Closing PR #25640 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit b3b7f85 into WebKit:main Mar 22, 2024
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebCore Misc. For miscellaneous bugs in the WebCore framework (and not JavaScriptCore or WebKit).
Projects
None yet
6 participants