Closed Bug 1805259 Opened 2 years ago Closed 2 years ago

[wpt-sync] Sync PR 37460 - Allow the navigate event to cancel same-document main-frame traversals

Categories

(Testing :: web-platform-tests, task, P4)

task

Tracking

(firefox112 fixed)

RESOLVED FIXED
112 Branch
Tracking Status
firefox112 --- fixed

People

(Reporter: wpt-sync, Unassigned)

References

()

Details

(Whiteboard: [wptsync downstream])

Sync web-platform-tests PR 37460 into mozilla-central (this bug is closed when the sync is complete).

PR: https://github.com/web-platform-tests/wpt/pull/37460
Details from upstream follow.

Nate Chapin <japhet@chromium.org> wrote:

Allow the navigate event to cancel same-document main-frame traversals

Currently, the navigate event is allowed to cancel push/replace/reload
navigations, but not traversals. There are two reasons for this:
chromium's architecture made it difficult to support cancelation
without getting out of sync with the authoratative version of the
joint session history in the browser process, and we were
concerned about the possibility of trapping the user if canceling
a traversal was too easy.

The case where we might get out of sync is when multiple frames
navigate as part of a traversal. We want to avoid the case where
some frames cancel the navigation in their frame, but others allow
it to proceed (since giving every frame what it requested would
cause some frames to be out of sync with the browser process). Therefore, only the main frame is allowed to cancel the navigation
via the navigate event. In order to ensure the main frame is able to
cancel the entire traversal, we send the main frame navigation (if any)
to the renderer first and wait for its commit to complete before
proceeding with any subframe navigations.

The main frame is only allowed to cancel a traversal when it is
traversing same-document. We had originally planned on allowing
cross-document traverals to be cancelled, too
(https://chromium-review.googlesource.com/c/chromium/src/+/3868615),
but this proved to have unacceptable performance characteristics,
requiring roundtrips to the renderer whenever a navigate event
handler was present, even if the navigate event handler had no
intention of ever cancelling a traversal.

Therefore the sequence during a traversal is now:

  1. Calculate which frames to navigate
  2. If the main frame needs to do a same-document navigation, then:
    2a. Start the navigation for the main frame only. The navigation
    commit message will be sent to the renderer, and the navigate
    event will fire. If it cancels the navigation, this will be
    reported back to the browser as an Aborted commit.
    2b. If it cancels, abort the entire traversal.
  3. Start navigating all navigating subframes. These navigations will
    all fire a navigate event just before committing, but none of
    those events will be cancealable.

As for preventing trapping the user, we only allow canceling the
navigation in the main frame if the navigating is programmatic, or
if there is a consumable user activation. This ensures that, e.g.,
pressing the back button once mighted be canceled by the navigate
event, but the second back button press is guaranteed to go through.
Traversals via the navigation API or the legacy history API will
always be cancelable because they are programmatic.

Bug: 1371580
Change-Id: I0c8c39bec8e21f3ca86389a4343881ebe2bde43e

Reviewed-on: https://chromium-review.googlesource.com/4092862
WPT-Export-Revision: 49e074df7be4c13221aae2446fdba80d4231802e

Whiteboard: [wptsync downstream] → [wptsync downstream error]

CI Results

Ran 9 Firefox configurations based on mozilla-central, and Firefox, Chrome, and Safari on GitHub CI

Total 12 tests and 1 subtests

Status Summary

Firefox

OK : 12
FAIL: 12

Chrome

OK : 12
PASS: 4
FAIL: 8

Safari

OK : 12
FAIL: 12

Links

Gecko CI (Treeherder)
GitHub PR Head
GitHub PR Base

Details

New Tests That Don't Pass

Pushed by wptsync@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/cfaf33e1a694 [wpt PR 37460] - Allow the navigate event to cancel same-document main-frame traversals, a=testonly https://hg.mozilla.org/integration/autoland/rev/823aa8f2a820 [wpt PR 37460] - Update wpt metadata, a=testonly
Whiteboard: [wptsync downstream error] → [wptsync downstream]
Pushed by wptsync@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/36c7fc464f50 [wpt PR 37460] - Allow the navigate event to cancel same-document main-frame traversals, a=testonly https://hg.mozilla.org/integration/autoland/rev/1f84b5606c0b [wpt PR 37460] - Update wpt metadata, a=testonly
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 112 Branch
You need to log in before you can comment on or make changes to this bug.