Skip to content

Commit 49f5cd3

Browse files
authored
Revamp base URL change processing
This removes the dependency on two concepts supposedly defined in DOM, that have not existed for many years. Instead, we have HTML directly call into the new "respond to base URL changes" steps, when mutations happen to a Document that would cause the base URL to change. Also reorganizes some of the base URL stuff to stick together, instead of being mixed between "Dynamic changes to base URLs" and "Terminology". Closes whatwg/dom#61.
1 parent 172cccf commit 49f5cd3

File tree

1 file changed

+69
-83
lines changed

1 file changed

+69
-83
lines changed

source

Lines changed: 69 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -3312,7 +3312,6 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
33123312
<dfn data-x="concept-node-clone-parent" data-x-href="https://dom.spec.whatwg.org/#clone-a-node-parent"><var>parent</var></dfn>, and
33133313
<dfn data-x="concept-node-clone-fallbackRegistry" data-x-href="https://dom.spec.whatwg.org/#clone-a-node-fallbackregistry"><var>fallbackRegistry</var></dfn>, and the concept of
33143314
<dfn data-x="concept-node-clone-ext" data-x-href="https://dom.spec.whatwg.org/#concept-node-clone-ext">cloning steps</dfn></li>
3315-
<li>The concept of <dfn>base URL change steps</dfn> and the definition of what happens when an element is <dfn>affected by a base URL change</dfn></li>
33163315
<li>The concept of an element's <dfn data-x="concept-id" data-x-href="https://dom.spec.whatwg.org/#concept-id">unique identifier (ID)</dfn></li>
33173316
<li>The concept of an element's <dfn data-x="concept-class" data-x-href="https://dom.spec.whatwg.org/#concept-class">classes</dfn></li>
33183317
<li>The term <dfn data-x="concept-supported-tokens" data-x-href="https://dom.spec.whatwg.org/#concept-supported-tokens">supported tokens</dfn></li>
@@ -7212,6 +7211,8 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
72127211
data-x="strip leading and trailing ASCII whitespace">stripping leading and trailing ASCII
72137212
whitespace</span> from it, it is a <span>valid non-empty URL</span>.</p>
72147213

7214+
<hr>
7215+
72157216
<p>This specification defines the URL <dfn><code>about:legacy-compat</code></dfn> as a reserved,
72167217
though unresolvable, <code data-x="about protocol">about:</code> URL, for use in <span
72177218
data-x="syntax-doctype">DOCTYPE</span>s in <span>HTML documents</span> when needed for
@@ -7227,46 +7228,6 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
72277228
document"><code>iframe</code> <code data-x="attr-iframe-srcdoc">srcdoc</code> documents</span>.
72287229
<ref>ABOUT</ref></p>
72297230

7230-
<p>The <dfn>fallback base URL</dfn> of a <code>Document</code> object <var>document</var> is the
7231-
<span>URL record</span> obtained by running these steps:</p>
7232-
7233-
<ol>
7234-
<li>
7235-
<p>If <var>document</var> is <span data-x="an iframe srcdoc document">an <code>iframe</code>
7236-
<code data-x="attr-iframe-srcdoc">srcdoc</code> document</span>, then:</p>
7237-
7238-
<ol>
7239-
<li><p><span>Assert</span>: <var>document</var>'s <span
7240-
data-x="concept-document-about-base-url">about base URL</span> is non-null.</p></li>
7241-
7242-
<li><p>Return <var>document</var>'s <span data-x="concept-document-about-base-url">about base
7243-
URL</span>.</p></li>
7244-
</ol>
7245-
</li>
7246-
7247-
<li><p>If <var>document</var>'s <span data-x="concept-document-url">URL</span> <span>matches
7248-
<code>about:blank</code></span> and <var>document</var>'s <span
7249-
data-x="concept-document-about-base-url">about base URL</span> is non-null, then return
7250-
<var>document</var>'s <span data-x="concept-document-about-base-url">about base URL</span>.</p></li>
7251-
7252-
<!-- https://www.hixie.ch/tests/adhoc/dom/level0/history/pushState/001/ -->
7253-
7254-
<li><p>Return <var>document</var>'s <span data-x="concept-document-url">URL</span>.</p></li>
7255-
</ol>
7256-
7257-
<p>The <dfn export>document base URL</dfn> of a <code>Document</code> object is the
7258-
<span>URL record</span> obtained by running these steps:</p>
7259-
7260-
<ol>
7261-
<li><p>If there is no <code>base</code> element that has an <code
7262-
data-x="attr-base-href">href</code> attribute in the <code>Document</code>, then return the
7263-
<code>Document</code>'s <span>fallback base URL</span>.</p></li>
7264-
7265-
<li><p>Otherwise, return the <span>frozen base URL</span> of the first <code>base</code> element
7266-
in the <code>Document</code> that has an <code data-x="attr-base-href">href</code> attribute, in
7267-
<span>tree order</span>.</p></li>
7268-
</ol>
7269-
72707231
<hr>
72717232

72727233
<p>A <span>URL</span> <dfn>matches <code>about:blank</code></dfn> if its <span
@@ -7374,58 +7335,82 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
73747335

73757336
<div w-nodev>
73767337

7377-
<h4>Dynamic changes to base URLs</h4>
7338+
<h4>Document base URLs</h4>
73787339

7379-
<p>When a document's <span>document base URL</span> changes, all elements in that document are
7380-
<span>affected by a base URL change</span>.</p>
7340+
<p>The <dfn export>document base URL</dfn> of a <code>Document</code> <var>document</var> is the
7341+
<span>URL record</span> obtained by running these steps:</p>
73817342

7382-
<p>The following are <span>base URL change steps</span>, which run when an element is
7383-
<span>affected by a base URL change</span> (as defined by <cite>DOM</cite>):</p>
7343+
<ol>
7344+
<li><p>If <var>document</var> has no <span>descendant</span> <code>base</code> element that has
7345+
an <code data-x="attr-base-href">href</code> attribute, then return <var>document</var>'s
7346+
<span>fallback base URL</span>.</p></li>
73847347

7385-
<dl class="switch">
7348+
<li><p>Otherwise, return the <span>frozen base URL</span> of the first <code>base</code> element
7349+
in <var>document</var> that has an <code data-x="attr-base-href">href</code> attribute, in
7350+
<span>tree order</span>.</p></li>
7351+
</ol>
73867352

7387-
<dt>If the element creates a <span>hyperlink</span></dt>
7353+
<p>The <dfn>fallback base URL</dfn> of a <code>Document</code> object <var>document</var> is the
7354+
<span>URL record</span> obtained by running these steps:</p>
73887355

7389-
<dd>
7390-
<p>If the <span>URL</span> identified by the hyperlink is being shown to the user, or if any
7391-
data derived from that <span>URL</span> is affecting the display, then the <code
7392-
data-x="attr-hyperlink-href">href</code> attribute's value should be <span
7393-
data-x="encoding-parsing a URL">reparsed</span>, relative to the element's <span>node
7394-
document</span> and the UI updated appropriately.</p>
7356+
<ol>
7357+
<li>
7358+
<p>If <var>document</var> is <span data-x="an iframe srcdoc document">an <code>iframe</code>
7359+
<code data-x="attr-iframe-srcdoc">srcdoc</code> document</span>:</p>
73957360

7396-
<p class="example">For example, the CSS <code data-x="selector-link">:link</code>/<code
7397-
data-x="selector-visited">:visited</code> <span data-x="pseudo-class">pseudo-classes</span>
7398-
might have been affected.</p>
7361+
<ol>
7362+
<li><p><span>Assert</span>: <var>document</var>'s <span
7363+
data-x="concept-document-about-base-url">about base URL</span> is non-null.</p></li>
73997364

7400-
<p>If the hyperlink has a <code data-x="attr-hyperlink-ping">ping</code> attribute and its
7401-
<span data-x="URL">URL(s)</span> are being shown to the user, then the <code
7402-
data-x="attr-hyperlink-ping">ping</code> attribute's tokens should be <span
7403-
data-x="encoding-parsing a URL">reparsed</span>, relative to the element's <span>node
7404-
document</span> and the UI updated appropriately.</p>
7405-
</dd>
7365+
<li><p>Return <var>document</var>'s <span data-x="concept-document-about-base-url">about base
7366+
URL</span>.</p></li>
7367+
</ol>
7368+
</li>
74067369

7407-
<dt>If the element is a <code>q</code>, <code>blockquote</code>, <code>ins</code>, or
7408-
<code>del</code> element with a <code data-x="">cite</code> attribute</dt>
7370+
<li><p>If <var>document</var>'s <span data-x="concept-document-url">URL</span> <span>matches
7371+
<code>about:blank</code></span> and <var>document</var>'s <span
7372+
data-x="concept-document-about-base-url">about base URL</span> is non-null, then return
7373+
<var>document</var>'s <span data-x="concept-document-about-base-url">about base
7374+
URL</span>.</p></li>
74097375

7410-
<dd>
7411-
<p>If the <span>URL</span> identified by the <code data-x="">cite</code> attribute is being
7412-
shown to the user, or if any data derived from that <span>URL</span> is affecting the display,
7413-
then the <code data-x="">cite</code> attribute's value should be <span data-x="encoding-parsing
7414-
a URL">reparsed</span>, relative to the element's <span>node document</span> and the UI updated
7415-
appropriately.</p>
7416-
</dd>
7376+
<!-- https://www.hixie.ch/tests/adhoc/dom/level0/history/pushState/001/ -->
74177377

7418-
<dt>Otherwise</dt>
7378+
<li><p>Return <var>document</var>'s <span data-x="concept-document-url">URL</span>.</p></li>
7379+
</ol>
74197380

7420-
<dd>
7421-
<p>The element is not directly affected.</p>
7381+
<hr>
74227382

7423-
<p class="example">For instance, changing the base URL doesn't affect the image displayed by
7424-
<code>img</code> elements, although subsequent accesses of the <code
7425-
data-x="dom-img-src">src</code> IDL attribute from script will return a new <span>absolute
7426-
URL</span> that might no longer correspond to the image being shown.</p>
7427-
</dd>
7428-
</dl>
7383+
<p>To <dfn>set the URL</dfn> for a <code>Document</code> <var>document</var> to a <span>URL
7384+
record</span> <var>url</var>:</p>
7385+
7386+
<ol>
7387+
<li><p>Set <var>document</var>'s <span data-x="concept-document-url">URL</span> to
7388+
<var>url</var>.</p></li>
7389+
7390+
<li><p><span>Respond to base URL changes</span> given <var>document</var>.</p></li>
7391+
</ol>
7392+
7393+
<p id="dynamic-changes-to-base-urls">To <dfn>respond to base URL changes</dfn> for a
7394+
<code>Document</code> <var>document</var>:</p>
7395+
7396+
<ol>
7397+
<li><p>The user agent should update any user interface elements which are displaying affected
7398+
URLs, or data derived from such URLs, to the user. Examples of such user interface elements would
7399+
be a status bar that displays a <span>hyperlink</span>'s <span
7400+
data-x="concept-hyperlink-url">url</span>, or some user interface which displays the URL
7401+
specified by a <code>q</code>, <code>blockquote</code>, <code>ins</code>, or <code>del</code>
7402+
element's <code data-x="">cite</code> attribute.</p></li>
7403+
7404+
<li><p>Ensure that the CSS <code data-x="selector-link">:link</code>/<code
7405+
data-x="selector-visited">:visited</code>/etc. <span data-x="pseudo-class">pseudo-classes</span>
7406+
are updated appropriately.</p></li>
7407+
</ol>
7408+
7409+
<p class="example" id="example-base-url-change-img-unaffected">This means that changing the base
7410+
URL doesn't affect, for example, the image displayed by <code>img</code> elements. Thus,
7411+
subsequent accesses of the <code data-x="dom-img-src">src</code> IDL attribute from script will
7412+
return a new <span>absolute URL</span> that might no longer correspond to the image being
7413+
shown.</p>
74297414

74307415
</div>
74317416

@@ -15345,6 +15330,8 @@ interface <dfn interface>HTMLBaseElement</dfn> : <span>HTMLElement</span> {
1534515330
</li>
1534615331

1534715332
<li><p>Set <var>element</var>'s <span>frozen base URL</span> to <var>urlRecord</var>.</p></li>
15333+
15334+
<li><p><span>Respond to base URL changes</span> given <var>document</var>.</p></li>
1534815335
</ol>
1534915336

1535015337
<p>The <dfn attribute for="HTMLBaseElement"><code data-x="dom-base-href">href</code></dfn> IDL
@@ -103684,8 +103671,7 @@ location.href = '#foo';</code></pre>
103684103671
state</span> given <var>document</var> and <var>newEntry</var>.</p></li>
103685103672

103686103673
<li>
103687-
<p>Set <var>document</var>'s <span data-x="concept-document-url">URL</span> to
103688-
<var>newURL</var>.</p>
103674+
<p><span>Set the URL</span> given <var>document</var> to <var>newURL</var>.</p>
103689103675

103690103676
<p class="note">Since this is neither a <span data-x="navigate">navigation</span> nor a <span
103691103677
data-x="traverse the history by a delta">history traversal</span>, it does not cause a <code

0 commit comments

Comments
 (0)