Skip to content

Commit

Permalink
Snapshot fallback base URL for about:-schemed Documents
Browse files Browse the repository at this point in the history
This gives an "about base URL" member to Document, document state, and navigation params. The intention is to capture a Document's creator's base URL when creating a new browsing context, and preserve it to (1) the newly created Document itself, and (2) the newly-created document state. Notably, preserving it in document state means that the same base URL is used when we recreate the Document while traversing the session history.

For the navigation case, we capture the initiator's base URL in the navigate algorithm as initiatorBaseURLSnapshot (alongside initiatorOriginSnapshot). This eventually threads through, via the document state and navigation params, to the point where we initialize a new Document object.

Finally, we remove the concept of a browsing context's creator base URL algorithm, and update the fallback base URL algorithm accordingly to refer to the relevant Document's new "about base URL" member.

This is all rather different from how the previous specification works. Previously, behavior differed between about:srcdoc and about:blank; base URL changes were supposed to be inherited in a live, not snapshotted, fashion; sometimes the navigation initiator was used and sometimes the browsing context creator/embedder; and the spec "crashed" for disconnected srcdoc iframes.

Closes #421. Closes #2883. Closes #3989.
  • Loading branch information
domfarolino authored Jul 13, 2023
1 parent e2d386b commit 787191a
Showing 1 changed file with 90 additions and 27 deletions.
117 changes: 90 additions & 27 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -6944,24 +6944,24 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<span>URL record</span> obtained by running these steps:</p>

<ol>
<li><p>If <var>document</var> is <span>an <code>iframe</code> <code
data-x="attr-iframe-srcdoc">srcdoc</code> document</span>, then return <var>document</var>'s
<span data-x="doc-container-document">container document</span>'s <span>document base
URL</span>.</p></li>

<li>
<!-- https://www.hixie.ch/tests/adhoc/html/navigation/javascript-url/ -->
<p>If <var>document</var> is <span data-x="an iframe srcdoc document">an <code>iframe</code>
<code data-x="attr-iframe-srcdoc">srcdoc</code> document</span>, then:</p>

<!-- this should be tested in the case of a browsing context that was navigated to about:blank
after having been elsewhere, as opposed to the about:blank used at the time of the browsing
context's creation. -->
<ol>
<li><p><span>Assert</span>: <var>document</var>'s <span
data-x="concept-document-about-base-url">about base URL</span> is non-null.</p></li>

<p>If <var>document</var>'s <span data-x="concept-document-url">URL</span> is
<code>about:blank</code>, and <var>document</var>'s <span data-x="concept-document-bc">browsing
context</span>'s <span>creator base URL</span> is non-null, then return that <span>creator base
URL</span>.</p>
<li><p>Return <var>document</var>'s <span data-x="concept-document-about-base-url">about base
URL</span>.</p></li>
</ol>
</li>

<li><p>If <var>document</var>'s <span data-x="concept-document-url">URL</span> is
<code>about:blank</code> and <var>document</var>'s <span
data-x="concept-document-about-base-url">about base URL</span> is non-null, then return
<var>document</var>'s <span data-x="concept-document-about-base-url">about base URL</span>.</p></li>

<!-- https://www.hixie.ch/tests/adhoc/dom/level0/history/pushState/001/ -->

<li><p>Return <var>document</var>'s <span data-x="concept-document-url">URL</span>.</p></li>
Expand Down Expand Up @@ -10585,6 +10585,12 @@ partial interface <dfn id="document" data-lt="">Document</dfn> {
<p>Each <code>Document</code> has a <dfn data-x="concept-document-navigation-id">navigation
id</dfn>, which is a <span>navigation ID</span> or null, initially null.</p>

<p>Each <code>Document</code> has an <dfn data-x="concept-document-about-base-url">about base
URL</dfn>, which is a <span>URL</span> or null, initially null.</p>

<p class="note">This is only populated for "<code data-x="">about:</code>"-schemed
<code>Document</code>s.</p>

<h4>The <code>DocumentOrShadowRoot</code> interface</h4>

<p><cite>DOM</cite> defines the <code data-x="DOM
Expand Down Expand Up @@ -93222,6 +93228,10 @@ interface <dfn interface>BeforeUnloadEvent</dfn> : <span>Event</span> {

<dt><span data-x="document-state-nav-target-name">navigable target name</span></dt>
<dd><var>targetName</var></dd>

<dt><span data-x="document-state-about-base-url">about base URL</span></dt>
<dd><var>document</var>'s <span data-x="concept-document-about-base-url">about base
URL</span></dd>
</dl>
</li>

Expand Down Expand Up @@ -93384,6 +93394,10 @@ interface <dfn interface>BeforeUnloadEvent</dfn> : <span>Event</span> {

<dt><span data-x="document-state-nav-target-name">navigable target name</span></dt>
<dd><var>targetName</var></dd>

<dt><span data-x="document-state-about-base-url">about base URL</span></dt>
<dd><var>document</var>'s <span data-x="concept-document-about-base-url">about base
URL</span></dd>
</dl>
</li>

Expand Down Expand Up @@ -94045,9 +94059,6 @@ interface <dfn interface>BeforeUnloadEvent</dfn> : <span>Event</span> {
<li><p>An <dfn data-x="browsing-context-initial-url">initial URL</dfn>, a <span>URL</span> or
null, initially null.</p></li>

<li><p>A <dfn>creator base URL</dfn>, null or an algorithm that returns a <span>URL</span>,
initially null.</p></li>

<li><p>A <dfn data-x="virtual-browsing-context-group-id">virtual browsing context group ID</dfn>
integer, initially 0. This is used by <span data-x="coop-struct-report-only-value">cross-origin
opener policy reporting</span>, to keep track of the browsing context group switches that would
Expand Down Expand Up @@ -94121,15 +94132,17 @@ interface <dfn interface>BeforeUnloadEvent</dfn> : <span>Event</span> {

<li><p>Let <var>creatorOrigin</var> be null.</p>

<li><p>Let <var>creatorBaseURL</var> be null.</p></li>

<li id="creator-browsing-context">
<p>If <var>creator</var> is non-null, then:</p>

<ol>
<li><p>Set <var>creatorOrigin</var> to <var>creator</var>'s <span
data-x="concept-document-origin">origin</span>.</p></li>

<li><p>Set <var>browsingContext</var>'s <span>creator base URL</span> to an algorithm which
returns <var>creator</var>'s <span data-x="document base URL">base URL</span>.</p></li>
<li><p>Set <var>creatorBaseURL</var> to <var>creator</var>'s <span>document base
URL</span>.</p></li>

<li><p>Set <var>browsingContext</var>'s <span
data-x="virtual-browsing-context-group-id">virtual browsing context group ID</span> to
Expand Down Expand Up @@ -94215,6 +94228,9 @@ interface <dfn interface>BeforeUnloadEvent</dfn> : <span>Event</span> {

<dt><span>is initial <code>about:blank</code></span></dt>
<dd>true</dd>

<dt><span data-x="concept-document-about-base-URL">about base URL</span></dt>
<dd><var>creatorBaseURL</var></dd>
</dl>
</li>

Expand Down Expand Up @@ -94893,6 +94909,16 @@ interface <dfn interface>BeforeUnloadEvent</dfn> : <span>Event</span> {
data-x="document-state-nav-target-name">navigable target name</span> is cleared.</p>
</li>

<li>
<p>An <dfn data-x="document-state-about-base-url">about base URL</dfn>, which is a
<span>URL</span> or null, initially null.</p>

<p class="note">This will be populated only for "<code data-x="">about:</code>"-schemed
<code>Document</code>s and will be the <span>fallback base URL</span> for those
<code>Document</code>s. It is a snapshot of the initiator <code>Document</code>'s <span>document
base URL</span>.</p>
</li>

<li><p><dfn data-x="document-state-nested-histories">Nested histories</dfn>, a <span>list</span>
of <span data-x="nested history">nested histories</span>, initially an empty
<span>list</span>.</p></li>
Expand Down Expand Up @@ -95615,6 +95641,10 @@ location.href = '#foo';</code></pre>
<dt><dfn data-x="navigation-params-nav-timing-type">navigation timing type</dfn></dt>
<dd>a <code>NavigationTimingType</code> used for <span data-x="create the navigation timing
entry">creating the navigation timing entry</span> for the new <code>Document</code></dd>

<dt><dfn data-x="navigation-params-about-base-url">about base URL</dfn></dt>
<dd>a <span>URL</span> or null used to populate the new <code>Document</code>'s <span
data-x="concept-document-about-base-url">about base URL</span></dd>
</dl>

<p class="note">Once a <span>navigation params</span> struct is created, this standard does not
Expand Down Expand Up @@ -95749,6 +95779,9 @@ location.href = '#foo';</code></pre>
<li><p>Let <var>initiatorOriginSnapshot</var> be <var>sourceDocument</var>'s <span
data-x="concept-document-origin">origin</span>.</p></li>

<li><p>Let <var>initiatorBaseURLSnapshot</var> be <var>sourceDocument</var>'s <span>document base
URL</span>.</p></li>

<li id="sandboxLinks">
<p>If <var>sourceDocument</var>'s <span>node navigable</span> is not <span>allowed by
sandboxing to navigate</span> <var>navigable</var> given and <var>sourceSnapshotParams</var>,
Expand Down Expand Up @@ -96016,16 +96049,17 @@ location.href = '#foo';</code></pre>
the document state is finalized.</p>
</li>

<li><p>If <var>url</var> is <code>about:blank</code>, then set <var>documentState</var>'s <span
data-x="document-state-origin">origin</span> to <var>documentState</var>'s <span
data-x="document-state-initiator-origin">initiator origin</span>.</p></li>
<li>
<p>If <var>url</var> is <code>about:blank</code> or <code>about:srcdoc</code>, then:</p>

<li><p>Otherwise, if <var>url</var> is <code>about:srcdoc</code>, then set
<var>documentState</var>'s <span
data-x="document-state-origin">origin</span> to
<var>navigable</var>'s <span data-x="nav-parent">parent</span>'s <span
data-x="nav-document">active document</span>'s <span
data-x="concept-document-origin">origin</span>.</p></li>
<ol>
<li><p>Set <var>documentState</var>'s <span data-x="document-state-origin">origin</span> to
<var>initiatorOriginSnapshot</var>.</p></li>

<li><p>Set <var>documentState</var>'s <span data-x="document-state-about-base-url">about base
URL</span> to <var>initiatorBaseURLSnapshot</var>.</p></li>
</ol>
</li>

<li><p>Let <var>historyEntry</var> be a new <span>session history entry</span>, with its <span
data-x="she-url">URL</span> set to <var>url</var> and its <span
Expand Down Expand Up @@ -96124,6 +96158,10 @@ location.href = '#foo';</code></pre>

<dt><span data-x="navigation-params-nav-timing-type">navigation timing type</span></dt>
<dd>"<code data-x="dom-navigationtimingtype-navigate">navigate</code>"</dd>

<dt><span data-x="navigation-params-about-base-url">about base URL</span></dt>
<dd><var>documentState</var>'s <span data-x="document-state-about-base-url">about base
URL</span></dd>
</dl>
</li>
</ol>
Expand Down Expand Up @@ -96334,6 +96372,10 @@ location.href = '#foo';</code></pre>
<dt><span data-x="document-state-initiator-origin">origin</span></dt>
<dd><var>initiatorOriginSnapshot</var></dd>

<dt><span data-x="document-state-about-base-url">about base URL</span></dt>
<dd><var>oldDocState</var>'s <span data-x="document-state-about-base-url">about base
URL</span></dd>

<dt><span data-x="document-state-resource">resource</span></dt>
<dd>null</dd>

Expand Down Expand Up @@ -96504,6 +96546,10 @@ location.href = '#foo';</code></pre>

<dt><span data-x="navigation-params-nav-timing-type">navigation timing type</span></dt>
<dd>"<code data-x="dom-navigationtimingtype-navigate">navigate</code>"</dd>

<dt><span data-x="navigation-params-about-base-url">about base URL</span></dt>
<dd><var>targetNavigable</var>'s <span data-x="nav-document">active document</span>'s <span
data-x="concept-document-about-base-url">about base URL</span></dd>
</dl>
</li>

Expand Down Expand Up @@ -97806,6 +97852,10 @@ location.href = '#foo';</code></pre>

<dt><span data-x="navigation-params-nav-timing-type">navigation timing type</span></dt>
<dd><var>navTimingType</var></dd>

<dt><span data-x="navigation-params-about-base-url">about base URL</span></dt>
<dd><var>entry</var>'s <span data-x="she-document-state">document state</span>'s <span
data-x="document-state-about-base-url">about base URL</span></dd>
</dl>
</li>
</ol>
Expand Down Expand Up @@ -98205,6 +98255,9 @@ location.href = '#foo';</code></pre>
<dt><span data-x="document-state-origin">origin</span></dt>
<dd><var>oldDocState</var>'s <span data-x="document-state-origin">origin</span></dd>

<dt><span data-x="document-state-about-base-url">about base URL</span></dt>
<dd><var>oldDocState</var>'s <span data-x="document-state-about-base-url">about base URL</span></dd>

<dt><span data-x="document-state-resource">resource</span></dt>
<dd><var>oldDocState</var>'s <span data-x="document-state-resource">resource</span></dd>

Expand Down Expand Up @@ -98426,6 +98479,10 @@ location.href = '#foo';</code></pre>

<dt><span data-x="navigation-params-nav-timing-type">navigation timing type</span></dt>
<dd><var>navTimingType</var></dd>

<dt><span data-x="navigation-params-about-base-url">about base URL</span></dt>
<dd><var>entry</var>'s <span data-x="she-document-state">document state</span>'s <span
data-x="document-state-about-base-url">about base URL</span></dd>
</dl>
</li>
</ol>
Expand Down Expand Up @@ -100058,6 +100115,9 @@ location.href = '#foo';</code></pre>

<dt><span>current document readiness</span></dt>
<dd>"<code data-x="">loading</code>"</dd>

<dt><span data-x="concept-document-about-base-url">about base URL</span></dt>
<dd><var>navigationParams</var>'s <span data-x="navigation-params-about-base-URL">about base URL</span></dd>
</dl>
</li>

Expand Down Expand Up @@ -100566,6 +100626,9 @@ new PaymentRequest(&hellip;); // Allowed to use

<dt><span data-x="navigation-params-nav-timing-type">navigation timing type</span></dt>
<dd><var>navTimingType</var></dd>

<dt><span data-x="navigation-params-about-base-url">about base URL</span></dt>
<dd>null</dd>
</dl>
</li>

Expand Down

0 comments on commit 787191a

Please sign in to comment.