Skip to content

Commit

Permalink
Always replace the initial about:blank Document
Browse files Browse the repository at this point in the history
Previously, the caller of the navigate algorithm would (usually) check for the browsing context still being on the initial about:blank Document, and if so, switch its history handling to "replace". However, a few call sites missed this: e.g., following hyperlinks or window.open() when they were targeted at an existing browsing context.

This change instead centralizes the conversion of "default" navigations into "replace" navigations for the initial about:blank Document.

This also fixes a minor bug where the conversion of "default" into "replace" navigations for same-URL fragment navigations was not taking place correctly, due to the check being located after the fragment navigation step.

Closes #6491.
  • Loading branch information
domenic authored Jan 12, 2022
1 parent 4a73cc6 commit a3df3e9
Showing 1 changed file with 52 additions and 58 deletions.
110 changes: 52 additions & 58 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -23879,9 +23879,9 @@ document.body.appendChild(wbr);</code></pre>
an element's noopener</span> with <var>subject</var> and
<var>targetAttributeValue</var>.</p></li>

<li><p>Let <var>target</var> and <var>windowType</var> be the result of applying <span>the rules
for choosing a browsing context</span> given <var>targetAttributeValue</var>, <var>source</var>,
and <var>noopener</var>.</p></li>
<li><p>Let <var>target</var> be the first return value of applying <span>the rules for choosing a
browsing context</span> given <var>targetAttributeValue</var>, <var>source</var>, and
<var>noopener</var>.</p></li>

<li><p>If <var>target</var> is null, then return.</p></li>

Expand Down Expand Up @@ -23913,22 +23913,17 @@ document.body.appendChild(wbr);</code></pre>
data-x="">no-referrer</code>".</p></li>

<li>
<p>Let <var>historyHandling</var> be "<code data-x="hh-replace">replace</code>" if
<var>windowType</var> is not "<code data-x="">existing or none</code>"; otherwise, "<code
data-x="hh-default">default</code>".</p>
<p><span>Queue an element task</span> on the <span>DOM manipulation task source</span> given
<var>subject</var> to <span>navigate</span><!--DONAV hyperlink--> <var>target</var> to
<var>request</var> with the <span>source browsing context</span> set to
<var>source</var>.</p>

<p class="note">Unlike many other types of navigations, following hyperlinks does not have
special "<code data-x="hh-replace">replace</code>" behavior for when documents are not
<span>completely loaded</span>. This is true for both user-initiated instances of following
hyperlinks, as well as script-triggered ones via, e.g., <code
data-x="">aElement.click()</code>.</p>
</li>

<li><p><span>Queue an element task</span> on the <span>DOM manipulation task source</span> given
<var>subject</var> to <span>navigate</span><!--DONAV hyperlink--> <var>target</var> to
<var>request</var> with <var data-x="navigation-hh">historyHandling</var> set to
<var>historyHandling</var> and the <span>source browsing context</span> set to
<var>source</var>.</p></li>
</ol>

</div>
Expand Down Expand Up @@ -30970,10 +30965,6 @@ interface <dfn interface>HTMLIFrameElement</dfn> : <span>HTMLElement</span> {
<ol>
<li><p>Let <var>historyHandling</var> be "<code data-x="hh-default">default</code>".</p>

<li><p>If <var>element</var>'s <span>nested browsing context</span> is <span>still on its initial
<code>about:blank</code> <code>Document</code></span>, then set <var>historyHandling</var> to
"<code data-x="hh-replace">replace</code>".</p></li>

<li><p>If <var>element</var>'s <span>nested browsing context</span>'s <span>active
document</span> is not <span>completely loaded</span>, then set <var>historyHandling</var> to
"<code data-x="hh-replace">replace</code>".</p></li>
Expand Down Expand Up @@ -56985,17 +56976,14 @@ fur
<li><p>Let <var>noopener</var> be the result of <span data-x="get an element's noopener">getting
an element's noopener</span> with <var>form</var> and <var>target</var>.</p></li>

<li><p>Let <var>target browsing context</var> and <var>windowType</var> be the result of
applying <span>the rules for choosing a browsing context</span> using <var>target</var>,
<var>form browsing context</var>, and <var>noopener</var>.</p></li>

<li><p>Let <var>historyHandling</var> be "<code data-x="hh-replace">replace</code>" if
<var>windowType</var> is either "<code data-x="">new and unrestricted</code>" or "<code
data-x="">new with no opener</code>"; otherwise "<code
data-x="hh-default">default</code>".</p></li>
<li><p>Let <var>target browsing context</var> be the first return value of applying <span>the
rules for choosing a browsing context</span> using <var>target</var>, <var>form browsing
context</var>, and <var>noopener</var>.</p></li>

<li><p>If <var>target browsing context</var> is null, then return.</p></li>

<li><p>Let <var>historyHandling</var> be "<code data-x="hh-default">default</code>".</p></li>

<li><p>If <var>form document</var> has not yet <span>completely loaded</span>, then set
<var>historyHandling</var> to "<code data-x="hh-replace">replace</code>".</p></li>

Expand Down Expand Up @@ -81087,9 +81075,8 @@ console.assert(iframeWindow.frameElement === null);
</ol>

<p class="note">If the newly created <span>browsing context</span> is immediately <span
data-x="navigate">navigated</span>, then the navigation will be done with <var
data-x="navigation-hh">historyHandling</var> set to "<code
data-x="hh-replace">replace</code>".</p>
data-x="navigate">navigated</span>, then the navigation will be done with a "<code
data-x="hh-replace">replace</code>" <span>history handling behavior</span>.</p>
</dd>

<dt>If the user agent has been configured such that in this instance it will reuse
Expand Down Expand Up @@ -81693,10 +81680,8 @@ dictionary <dfn dictionary>WindowPostMessageOptions</dfn> : <span>StructuredSeri
data-x="">no-referrer</code>".</p></li>

<li><p><span>Navigate</span><!--DONAV window.open()--> <var>target browsing context</var> to
<var>request</var>, with <var><span>exceptionsEnabled</span></var> set to true, <var
data-x="navigation-hh">historyHandling</var> set to "<code
data-x="hh-replace">replace</code>", and the <span>source browsing context</span> set to
<var>source browsing context</var>.</p></li>
<var>request</var>, with <var><span>exceptionsEnabled</span></var> set to true and the
<span>source browsing context</span> set to <var>source browsing context</var>.</p></li>
</ol>
</li>
</ol>
Expand Down Expand Up @@ -85955,6 +85940,16 @@ interface <dfn interface>History</dfn> {
<li><p>Let <var>browsingContext</var> be <var>document</var>'s <span
data-x="concept-document-bc">browsing context</span>.</p></li>

<li>
<p>If <var>browsingContext</var> is <span>still on its initial <code>about:blank</code>
<code>Document</code></span>, then set <var>isPush</var> to false.</p>

<p class="note">This means that <code data-x="dom-history-pushState">pushState()</code> on an
<span data-x="is initial about:blank">initial <code>about:blank</code></span>
<code>Document</code> behaves as a <code data-x="dom-history-replaceState">replaceState()</code>
call.</p>
</li>

<li>
<p>If <var>isPush</var> is true, then:</p>

Expand Down Expand Up @@ -86588,10 +86583,6 @@ interface <dfn interface>Location</dfn> { // but see also <a href="#the-location
data-x="concept-incumbent-global">incumbent global object</span>'s <span data-x="window
bc">browsing context</span>.</p></li>

<li><p>If <var>browsingContext</var> is <span>still on its initial <code>about:blank</code>
<code>Document</code></span>, then set <var>historyHandling</var> to "<code
data-x="hh-replace">replace</code>".</p></li>

<li><p>If this <code>Location</code> object's <span>relevant <code>Document</code></span> is not
yet <span>completely loaded</span>, and the <span data-x="concept-incumbent-global">incumbent
global object</span> does not have <span>transient activation</span>, then set
Expand Down Expand Up @@ -87410,6 +87401,27 @@ interface <dfn interface>Location</dfn> { // but see also <a href="#the-location
https://github.com/whatwg/html/issues/1213
https://software.hixie.ch/utilities/js/live-dom-viewer/?saved=1946 to 1955 -->

<li id="navigate-convert-to-replace">
<p>If <var>historyHandling</var> is "<code data-x="hh-default">default</code>", and any of the
following are true:</p>

<ul>
<li><p><var>browsingContext</var> is <span>still on its initial <code>about:blank</code>
<code>Document</code></span></p></li>

<li><p><var>resource</var> is a <span data-x="concept-request">request</span> whose <span
data-x="concept-request-url">URL</span> <span data-x="concept-url-equals">equals</span>
<var>browsingContext</var>'s <span>active document</span>'s <span
data-x="concept-document-url">URL</span></p></li>

<li><p><var>resource</var> is a <span data-x="concept-request">request</span> whose <span
data-x="concept-request-url">URL</span>'s <span data-x="concept-url-scheme">scheme</span> is
"<code data-x="javascript protocol">javascript</code>"</p></li>
</ul>

<p>then set <var>historyHandling</var> to "<code data-x="hh-replace">replace</code>".</p>
</li>

<li id="navigate-fragid-step">
<p>If <var>historyHandling</var> is not "<code data-x="hh-reload">reload</code>",
<var>resource</var> is a <span data-x="concept-request">request</span>, <var>resource</var>'s
Expand All @@ -87429,15 +87441,6 @@ interface <dfn interface>Location</dfn> { // but see also <a href="#the-location
</ol>
</li>

<li><p>If <var>historyHandling</var> is "<code data-x="hh-default">default</code>",
<var>resource</var> is a <span data-x="concept-request">request</span>, and either
<var>resource</var>'s <span data-x="concept-request-url">URL</span> <span
data-x="concept-url-equals">equals</span> <var>browsingContext</var>'s <span>active
document</span>'s <span data-x="concept-document-url">URL</span> or <var>resource</var>'s <span
data-x="concept-request-url">URL</span>'s <span data-x="concept-url-scheme">scheme</span> is
"<code data-x="javascript protocol">javascript</code>", then set <var>historyHandling</var> to
"<code data-x="hh-replace">replace</code>".</li>

<li><p>Let <var>incumbentNavigationOrigin</var> be the <span>origin</span> of the <span>incumbent
settings object</span>, or if no <span>script</span> was involved, the <span
data-x="concept-document-origin">origin</span> of the <span>node document</span> of the element
Expand Down Expand Up @@ -89331,6 +89334,11 @@ new PaymentRequest(&hellip;); // Allowed to use
<li><p>Let <var>newDocument</var> be <var>entry</var>'s <span
data-x="she-document">document</span>.</p></li>

<li><p>Assert: <var>newDocument</var>'s <span>is initial <code>about:blank</code></span> is
false, i.e., we never traverse back to the <span data-x="is initial about:blank">initial
<code>about:blank</code></span> <code>Document</code> because it always gets <a
href="#navigate-convert-to-replace">replaced</a> when we navigate away from it.</p></li>

<li><p>If <var>newDocument</var> is different than the <span>current entry</span>'s <span
data-x="she-document">document</span>, or <var>historyHandling</var> is "<code
data-x="hh-entry-update">entry update</code>" or "<code data-x="hh-reload">reload</code>",
Expand Down Expand Up @@ -89448,20 +89456,6 @@ new PaymentRequest(&hellip;); // Allowed to use
<li><p>Set <var>newDocument</var>'s <span data-x="concept-document-url">URL</span> to
<var>entry</var>'s <span data-x="she-url">URL</span>.</p></li>

<li>
<p>Set <var>newDocument</var>'s <span>is initial <code>about:blank</code></span> to false.</p>

<p class="XXX">The spec currently allows keeping the <span
data-x="is initial about:blank">initial <code>about:blank</code></span> <code>Document</code>
in session history, but this is probably a bug: see <a
href="https://github.com/whatwg/html/issues/6491">issue #6491</a> (and especially <a
href="https://github.com/whatwg/html/issues/6491#issuecomment-799866620">this comment</a>). If
we fix that then we can convert this step into an assert that <var>newDocument</var>'s <span>is
initial <code>about:blank</code></span> is false, i.e., an assert that we never traverse back to
the <span data-x="is initial about:blank">initial <code>about:blank</code></span>
<code>Document</code>.</p>
</li>

<li><p>Let <var>hashChanged</var> be false, and let <var>oldURL</var> and <var>newURL</var> be
null.</p></li>

Expand Down

0 comments on commit a3df3e9

Please sign in to comment.