Skip to content

Commit b18348f

Browse files
committed
Fire navigate events on all windows affected during traversal
Closes #114.
1 parent 3794b90 commit b18348f

File tree

1 file changed

+57
-12
lines changed

1 file changed

+57
-12
lines changed

spec.bs

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ spec: html; urlPrefix: https://html.spec.whatwg.org/multipage/
4747
text: exceptionsEnabled; url: browsing-the-web.html#exceptions-enabled
4848
type: method
4949
for: Document; text: open(unused1, unused2); url: multipage/dynamic-markup-insertion.html#dom-document-open
50+
spec: html; urlPrefix: https://whatpr.org/html/6315/
51+
type: dfn
52+
text: traversable navigable; for: navigable; url: history.html#nav-traversable
53+
text: current session history entry; for: navigable; url: history.html#nav-current-history-entry
54+
text: active session history entry; for: navigable; url: history.html#nav-active-history-entry
55+
text: get the session history entries; for: navigable; url: history.html#getting-session-history-entries
56+
text: session history traversal queue; for: traversable navigable; url: history.html#tn-session-history-traversal-queue
57+
text: current session history step; for: traversable navigable; url: history.html#tn-current-session-history-step
58+
text: get all history steps; for: traversable navigable; url: history.html#getting-all-history-steps
59+
text: step; for: session history entry; url: history.html#she-step
60+
text: apply the history step; url: history.html#apply-the-history-step
61+
text: checkForUserCancelation; for: apply the history step; url: history.html#apply-the-history-step
62+
text: initiatorToCheck; for: apply the history step; url: history.html#apply-the-history-step
63+
text: containing navigable; for: browsing context; url: browsers.html#bc-navigable
64+
text: session; for: browsing context group; url: browsers.html#bcg-session
65+
text: active document; for: navigable; url: history.html#nav-document
66+
text: navigable; url: history.html#navigable
5067
spec: uuid; type: dfn; urlPrefix: https://wicg.github.io/uuid/
5168
text: generate a random UUID; url: #dfn-generate-a-random-uuid
5269
</pre>
@@ -612,10 +629,11 @@ The <dfn attribute for="AppHistoryDestination">sameDocument</dfn> getter steps a
612629
<h3 id="navigate-event-firing">Firing the event</h3>
613630

614631
<div algorithm="fire a traversal navigate event">
615-
To <dfn>fire a traversal `navigate` event</dfn> at an {{AppHistory}} |appHistory| given a [=session history entry=] <dfn for="fire a traversal navigate event">|destinationEntry|</dfn>, a boolean <dfn for="fire a traversal navigate event">|isSameDocument|</dfn>, an optional [=user navigation involvement=] <dfn for="fire a traversal navigate event">|userInvolvement|</dfn> (default "<code>[=user navigation involvement/none=]</code>"), and an optional JavaScript value |info| (default undefined):
632+
To <dfn>fire a traversal `navigate` event</dfn> at an {{AppHistory}} |appHistory| given a [=session history entry=] <dfn for="fire a traversal navigate event">|destinationEntry|</dfn>, an optional [=user navigation involvement=] <dfn for="fire a traversal navigate event">|userInvolvement|</dfn> (default "<code>[=user navigation involvement/none=]</code>"), and an optional JavaScript value |info| (default undefined):
616633

617634
1. Let |destinationURL| be |destinationEntry|'s [=session history entry/URL=].
618635
1. Let |destinationState| be |destinationEntry|'s [=session history entry/app history state=].
636+
1. Let |isSameDocument| be true if |destinationEntry|'s [=session history entry/document=] is equal to |appHistory|'s [=relevant global object=]'s [=associated Document=]; otherwise false.
619637
1. Let |event| be the result of [=creating an event=] given {{AppHistoryNavigateEvent}}, in |appHistory|'s [=relevant Realm=].
620638
1. Set |event|'s [=AppHistoryNavigateEvent/destination entry=] to |destinationEntry|.
621639
1. Return the result of performing the [=inner navigate event firing algorithm=] given |appHistory|, |event|, "{{AppHistoryNavigationType/traverse}}", |isSameDocument|, |destinationURL|, |destinationState|, |userInvolvement|, |info|, and null.
@@ -650,6 +668,7 @@ The <dfn attribute for="AppHistoryDestination">sameDocument</dfn> getter steps a
650668
then initialize |event|'s {{AppHistoryNavigateEvent/hashChange}} to true. Otherwise, initialize it to false.
651669
1. If |destinationURL| is [=rewritable=] relative to |currentURL|, and either |isSameDocument| is true or |navigationType| is not "{{AppHistoryNavigationType/traverse}}", then initialize |event|'s {{AppHistoryNavigateEvent/canRespond}} to true. Otherwise, initialize it to false.
652670
1. If either |userInvolvement| is not "<code>[=user navigation involvement/browser UI=]</code>" or |navigationType| is not "{{AppHistoryNavigationType/traverse}}", then initialize |event|'s {{Event/cancelable}} to true.
671+
1. If both |event|'s {{AppHistoryNavigateEvent/canRespond}} and |event|'s {{Event/cancelable}} are false, then return true. (No event is actually fired.)
653672
1. If |userInvolvement| is "<code>[=user navigation involvement/none=]</code>", then initialize |event|'s {{AppHistoryNavigateEvent/userInitiated}} to false. Otherwise, initialize it to true.
654673
1. If |formDataEntryList| is not null, then initialize |event|'s {{AppHistoryNavigateEvent/formData}} to a [=new=] {{FormData}} created in |realm|, associated to |formDataEntryList|. Otherwise, initialize it to null.
655674
1. [=Assert=]: |appHistory|'s [=AppHistory/ongoing navigate event=] is null.
@@ -963,17 +982,6 @@ With the above infrastructure in place, we can actually fire and handle the {{Ap
963982
<p class="note">"<code>[=user navigation involvement/browser UI=]</code>" or [=same origin-domain|cross origin-domain=] navigations that cause <a spec="HTML" lt="navigate to a fragment">fragment navigations</a> <em>do</em> fire the {{AppHistory/navigate}} event; those are handled as part of the <a spec="HTML">navigate to a fragment</a> algorithm called earlier in <a spec="HTML">navigate</a>, which is not guarded by this condition.
964983
</div>
965984

966-
<div algorithm="traverse the history by a delta">
967-
Modify the <a spec="HTML">traverse the history by a delta</a> algorithm by inserting the following steps inside the queued task, before the call to <a spec="HTML">traverse the history</a>. Recall that per [[#user-initiated-patches]] we have introduced a |userInvolvement| argument.
968-
969-
1. Let |appHistory| be <var ignore>specified browsing context</var>'s [=browsing context/active window=]'s [=Window/app history=].
970-
1. [=Cancel any ongoing navigate event=] for |appHistory|.
971-
1. Let |isSameDocument| be true if <var ignore>specified browsing context</var>'s [=active document=] equals <var ignore>specified entry</var>'s [=session history entry/document=]; otherwise, false.
972-
1. If either |isSameDocument| is true or |userInvolvement| is not "<code>[=user navigation involvement/browser UI=]</code>", then:
973-
1. Let |continue| be the result of [=firing a traversal navigate event=] at |appHistory| with <i>[=fire a traversal navigate event/destinationEntry=]</i> set to <var ignore>specified entry</var>, <i>[=fire a traversal navigate event/isSameDocument=]</i> set to |isSameDocument|, and <i>[=fire a traversal navigate event/userInvolvement=]</i> set to |userInvolvement|.
974-
1. If |continue| is false, abort these steps.
975-
</div>
976-
977985
<div algorithm>
978986
To <dfn>convert a history handling behavior to a navigation type</dfn> given a <a spec="HTML">history handling behavior</a> |historyHandling|:
979987

@@ -989,6 +997,43 @@ With the above infrastructure in place, we can actually fire and handle the {{Ap
989997
:: "{{AppHistoryNavigationType/push}}"
990998
</div>
991999

1000+
<h3 id="navigate-event-traversal-patches">History traversal updates</h3>
1001+
1002+
<div algorithm="traverse the history by a delta">
1003+
The <a spec="HTML">traverse the history by a delta</a> algorithm will be totally re-written as part of <a href="https://github.com/whatwg/html/pull/6315">the session history rewrite</a>. Here we reproduce the final version of the algorithm, after both that rewrite and with appropriate app history updates. Recall that per [[#user-initiated-patches]] we have introduced a |userInvolvement| argument, so the arguments are now |delta|, |source browsing context|, and |userInvolvement|.
1004+
1005+
1. Let |traversable| be |source browsing context|'s [=browsing context/containing navigable=]'s [=navigable/traversable navigable=].
1006+
1. Let |initiatorOrigin| be |source browsing context|'s [=active document=]'s [=Document/origin=].
1007+
1. [=parallel queue/enqueue steps|Enqueue the following steps=] to |traversable|'s [=traversable navigable/session history traversal queue=]:
1008+
1. Let |allSteps| be the result of [=traversable navigable/getting all history steps=] for |traversable|.
1009+
1. Let |targetStep| be TODO compute using [=traversable navigable/current session history step=], |allSteps|, and |delta|. Will be failure if there is no step |delta| away from the current one.
1010+
1. If |targetStep| is failure, then return.
1011+
1. [=Apply the history step=] |targetStep| to |traversable| with true, <var ignore>step</var>, |initiatorOrigin|, and |userInvolvement|.
1012+
</div>
1013+
1014+
<div algorithm="apply the history step">
1015+
Modify the <a spec="HTML">apply the history step</a> algorithm as follows. Change <var ignore>checkForUserCancellation</var> to |fireBeforeunloadAndNavigate|. Add the |userInvolvement| parameter. Then, insert the following step after step 12 (which assembles |toTraverse| and other lists) but before step 13 (which checks if unloading is user-cancelled):
1016+
1017+
1. If |fireBeforeunloadAndNavigate| is true and the result of <a>firing traversal `navigate` events</a> given |toTraverse|, <var ignore>step</var>, <var ignore>initiatorToCheck</var>, and |userInvolvement| is false, then return.
1018+
</div>
1019+
1020+
<div algorithm>
1021+
To <dfn>fire traversal `navigate` events</dfn> for a [=list=] of [=navigables=] |toTraverse|, an integer |step|, an [=origin=] |initiatorOrigin|, and a [=user navigation involvement=] |userInvolvement|:
1022+
1023+
1. Let |overallResult| be true.
1024+
1. Let |totalTasks| be the [=list/size=] of |toTraverse|.
1025+
1. Let |completedTasks| be 0.
1026+
1. [=list/For each=] |navigable| of |toTraverse|, [=queue a global task=] on the [=history traversal task source=] given |navigable|'s [=navigable/active document=]'s [=relevant global object=] to run these steps:
1027+
1. Let |destinationEntry| be the item in the result of [=navigable/getting the session history entries=] for |navigable| that has the greatest [=session history entry/step=] less than or equal to |step|.
1028+
1. If |destinationEntry|'s [=session history entry/document=] is not equal to |navigable|'s [=navigable/active document=], and |initiatorOrigin| is not [=same origin-domain=] with |navigable|'s [=navigable/active document=]'s [=Document/origin=], then abort these steps.
1029+
1. Let |appHistory| be |navigable|'s [=navigable/active document=]'s [=relevant global object=]'s [=Window/app history=].
1030+
1. Let |result| be the result of [=firing a traversal navigate event=] at |appHistory| with <i>[=fire a traversal navigate event/destinationEntry=]</i> set to |destinationEntry| and <i>[=fire a traversal navigate event/userInvolvement=]</i> set to |userInvolvement|.
1031+
1. If |result| is false, then set |overallResult| to false.
1032+
1. Increment |completedTasks|.
1033+
1. Wait for |completedTasks| to be |totalTasks|.
1034+
1. Return |overallResult|.
1035+
</div>
1036+
9921037
<h2 id="session-history-patches">Patches to session history</h2>
9931038

9941039
This section details monkeypatches to [[!HTML]] to track appropriate data for associating an {{AppHistory}} with a [=session history entry=].

0 commit comments

Comments
 (0)