Skip to content

Commit 5efa1ca

Browse files
Specify serviceworker link type for link element and link header.
1 parent b80ba58 commit 5efa1ca

File tree

1 file changed

+93
-18
lines changed

1 file changed

+93
-18
lines changed

spec/service_worker/index.html

Lines changed: 93 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ <h1>Dependencies</h1>
108108
<li><a href="http://www.w3.org/2001/tag/doc/unsanctioned-tracking/">(Non-normative) Unsanctioned Web Tracking</a></li>
109109
<li><a href="https://w3c.github.io/push-api/">Push API</a></li>
110110
<li><a href="http://tools.ietf.org/html/rfc5234">Augmented BNF for Syntax Specifications: ABNF</a></li>
111+
<li><a href="https://tools.ietf.org/html/rfc5988">Web Linking</a></li>
111112
</ul>
112113
</spec-section>
113114

@@ -620,25 +621,9 @@ <h1><code>register(<var>scriptURL</var>, <var>options</var>)</code></h1>
620621
<ol>
621622
<li>Let <var>p</var> be a <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-promise-objects">promise</a>.</li>
622623
<li>Let <var>client</var> be the <a href="https://dom.spec.whatwg.org/#context-object">context object</a>'s <a href="#dfn-service-worker-container-interface-client">service worker client</a>.</li>
623-
<li>If <var>client</var> is not a <a href="https://w3c.github.io/webappsec-secure-contexts/#secure-context">secure context</a>, reject <var>p</var> with a "<code><a href="http://heycam.github.io/webidl/#securityerror">SecurityError</a></code>" exception and abort these steps.</li>
624+
<li>Let <var>scopeURL</var> be <var>options</var>.</var>scope</var>, or null if <var>options</var>.<var>scope</var> is <a href="http://heycam.github.io/webidl/#dfn-present">not present</a>.</li>
624625
<li>Let <var>scriptURL</var> be the result of <a href="https://url.spec.whatwg.org/#concept-url-parser">parsing</a> <var>scriptURL</var> with <a href="https://html.spec.whatwg.org/multipage/webappapis.html#entry-settings-object">entry settings object</a>'s <a href="https://html.spec.whatwg.org/multipage/webappapis.html#api-base-url">API base URL</a>.</li>
625-
<li>If <var>scriptURL</var> is failure, reject <var>p</var> with a <code>TypeError</code> and abort these steps.</li>
626-
<li>If <var>scriptURL</var>'s <a href="https://url.spec.whatwg.org/#concept-url-scheme">scheme</a> is not one of "<code>http</code>" and "<code>https</code>", reject <var>p</var> with a <code>TypeError</code> and abort these steps.</li>
627-
<li>If any of the strings in <var>scriptURL</var>'s <a href="https://url.spec.whatwg.org/#concept-url-path">path</a> contains either <a href="https://encoding.spec.whatwg.org/#ascii-case-insensitive">ASCII case-insensitive</a> "<code>%2f</code>" or <a href="https://encoding.spec.whatwg.org/#ascii-case-insensitive">ASCII case-insensitive</a> "<code>%5c</code>", reject <var>p</var> with a <code>TypeError</code> and abort these steps.</li>
628-
<li>Let <var>scopeURL</var> be null.</li>
629-
<li>If <var>options</var>.<var>scope</var> is <a href="http://heycam.github.io/webidl/#dfn-present">not present</a>, set <var>scopeURL</var> to the result of <a href="https://url.spec.whatwg.org/#concept-url-parser">parsing</a> a string "<code>./</code>" with <var>scriptURL</var>.
630-
<p class="note">The scope url for the registration is set to the location of the service worker script by default.</p>
631-
</li>
632-
<li>Else, set <var>scopeURL</var> to the result of <a href="https://url.spec.whatwg.org/#concept-url-parser">parsing</a> <var>options</var>.<var>scope</var> with <a href="https://html.spec.whatwg.org/multipage/webappapis.html#entry-settings-object">entry settings object</a>'s <a href="https://html.spec.whatwg.org/multipage/webappapis.html#api-base-url">API base URL</a>.</li>
633-
<li>If <var>scopeURL</var> is failure, reject <var>p</var> with a <code>TypeError</code> and abort these steps.</li>
634-
<li>If <var>scopeURL</var>'s <a href="https://url.spec.whatwg.org/#concept-url-scheme">scheme</a> is not one of "<code>http</code>" and "<code>https</code>", reject <var>p</var> with a <code>TypeError</code> and abort these steps.</li>
635-
<li>If any of the strings in <var>scopeURL</var>'s <a href="https://url.spec.whatwg.org/#concept-url-path">path</a> contains either <a href="https://encoding.spec.whatwg.org/#ascii-case-insensitive">ASCII case-insensitive</a> "<code>%2f</code>" or <a href="https://encoding.spec.whatwg.org/#ascii-case-insensitive">ASCII case-insensitive</a> "<code>%5c</code>", reject <var>p</var> with a <code>TypeError</code> and abort these steps.</li>
636-
<li>Let <var>job</var> be the result of running <a href="#create-job-algorithm">Create Job</a> with <em>register</em>, <var>scopeURL</var>, <var>scriptURL</var>, <var>p</var>, and <var>client</var>.</li>
637-
<li>Run the following substep <a href="https://html.spec.whatwg.org/multipage/infrastructure.html#in-parallel">in parallel</a>:
638-
<ol>
639-
<li>Invoke <a href="#schedule-job-algorithm">Schedule Job</a> with <var>job</var>.</li>
640-
</ol>
641-
</li>
626+
<li>Invoke <a href="#start-register-algorithm">Start Register</a> with <var>scopeURL</var>, <var>scriptURL</var>, <var>p</var>, and <var>client</var>.</li>
642627
<li>Return <var>p</var>.</li>
643628
</ol>
644629
</spec-algorithm>
@@ -1671,6 +1656,59 @@ <h1>Events</h1>
16711656
</spec-section>
16721657
</spec-clause>
16731658

1659+
<spec-clause id="link-type-serviceworker">
1660+
<h1>Link type "<code>serviceworker</code>"</h1>
1661+
<p>The <dfn id="dfn-link-type-serviceworker">serviceworker</dfn> keyword may be used with <a href="https://html.spec.whatwg.org/multipage/semantics.html#the-link-element">link</a> elements. This keyword creates an <a href="https://html.spec.whatwg.org/multipage/semantics.html#external-resource-link">external resource link</a> (<dfn id="dfn-serviceworker-link">serviceworker link</dfn>) that is used to declare a <a href="#dfn-service-worker-registration">service worker registration</a> and its <a href="#dfn-scope-url">scope url</a>.</p>
1662+
1663+
<spec-section id="link-element-processing">
1664+
<h1>Processing</h1>
1665+
1666+
<p>When a user agent that supports [<a href="https://tools.ietf.org/html/rfc5988">RFC5988</a>] processes a <code>Link</code> header that contains a <a href="#dfn-serviceworker-link">serviceworker link</a>, the user agent <em class="rfc2119" title="SHOULD">should</em> run these steps or their <a href="#dfn-processing-equivalence">equivalent</a>:</p>
1667+
1668+
<spec-algorithm>
1669+
<ol>
1670+
<li>If the origin of the <a href="https://tools.ietf.org/html/rfc5988#section-5.2">context IRI</a> of the <code>Link</code> header is not <a href="https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy">potentially trustworthy</a>, abort these steps.</li>
1671+
<li>Let <var>scriptURL</var> be the result of <a href="https://url.spec.whatwg.org/#concept-url-parser">parsing</a> the <a href="https://tools.ietf.org/html/rfc5988#section-5.1">target IRI</a> of the <code>Link</code> header.</li>
1672+
<li>Let <var>scopeURL</var> be the <a href="link-scope-attribute">scope</a> <a href="https://tools.ietf.org/html/rfc5988#section-5.4">target attribute</a> of the <code>Link</code> header, or null if no such attribute is present.</li>
1673+
<li>Invoke <a href="#start-register-algorithm">Start Register</a> with <var>scopeURL</var>, <var>scriptURL</var>, a new <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-promise-objects">promise</a>, and null.</li>
1674+
</ol>
1675+
</spec-algorithm>
1676+
1677+
<p>When a <a href="#dfn-serviceworker-link">serviceworker link</a>'s <a href="https://html.spec.whatwg.org/multipage/semantics.html#the-link-element">link</a> element is inserted into a document, the user agent <em class="rfc2119" title="SHOULD">should</em> run these steps or their <a href="#dfn-processing-equivalence">equivalent</a>:</p>
1678+
1679+
<spec-algorithm>
1680+
<ol>
1681+
<li>If the <a href="https://html.spec.whatwg.org/multipage/semantics.html#attr-link-href">href</a> attribute is the empty string, abort these steps.</li>
1682+
<li>Let <var>client</var> be the document's <a href="#dfn-service-worker-container-interface-client">service worker client</a>.</li>
1683+
<li>Let <var>scriptURL</var> be the result of <a href="https://url.spec.whatwg.org/#concept-url-parser">parsing</a> the <a href="https://html.spec.whatwg.org/multipage/semantics.html#attr-link-href">href</a> attribute with document's <a href="https://html.spec.whatwg.org/multipage/infrastructure.html#document-base-url">document base URL</a>.</li>
1684+
<li>Let <var>scopeURL</var> be the <a href="link-scope-attribute">scope</a> attribute, or null if the <a href="link-scope-attribute">scope</a> attribute is omitted.</li>
1685+
<li>Invoke <a href="#start-register-algorithm">Start Register</a> with <var>scopeURL</var>, <var>scriptURL</var>, a new <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-promise-objects">promise</a>, and <var>client</var>.</li>
1686+
</ol>
1687+
</spec-algorithm>
1688+
1689+
<p>The <a href="#dfn-serviceworker-link">serviceworker link</a> element <em class="rfc2119" title="MUST NOT">must not</em> <a href="https://html.spec.whatwg.org/multipage/syntax.html#delay-the-load-event">delay the load event</a> of the element's <a href="https://dom.spec.whatwg.org/#concept-node-document">node document</a>.</p>
1690+
1691+
<p>Example: A resource being loaded with the following response header:</p>
1692+
<spec-code>Link: &lt;/js/sw.js&gt;; rel="serviceworker"; scope="/"</spec-code>
1693+
<p>has more or less the same effect as a document being loaded in a secure context with the following <code>link</code> element:
1694+
<spec-code>&lt;link rel="serviceworker" href="/js/sw.js" scope="/"&gt;</spec-code>
1695+
<p>which is more or less equivalent to the page containing javascript code like:</p>
1696+
<spec-code>navigator.serviceworker.register("/js/sw.js", { scope: "/" });</spec-code>
1697+
1698+
</spec-section>
1699+
1700+
<spec-section id="link-element-interface-section">
1701+
<h1>Link element interface extensions</h1>
1702+
1703+
<spec-idl>partial interface HTMLLinkElement {
1704+
attribute <a href="http://heycam.github.io/webidl/#idl-USVString">USVString</a> <a href="#link-scope-attribute">scope</a>;
1705+
};
1706+
</spec-idl>
1707+
<p>The <dfn id="link-scope-attribute">scope</dfn> attribute returns the value of this element's scope attribute.</p>
1708+
</spec-section>
1709+
1710+
</spec-clause>
1711+
16741712
<spec-clause id="cache-objects">
16751713
<h1>Caches</h1>
16761714
<p>To allow authors to fully manage their content caches for offline use, the <a href="https://html.spec.whatwg.org/multipage/browsers.html#window">Window</a> and the <a href="https://html.spec.whatwg.org/multipage/workers.html#workerglobalscope">WorkerGlobalScope</a> provide the asynchronous caching methods that open and manipulate <code><a href="#cache-interface">Cache</a></code> objects. An <a href="https://html.spec.whatwg.org/multipage/browsers.html#origin-2">origin</a> can have multiple, named <code><a href="#cache-interface">Cache</a></code> objects, whose contents are entirely under the control of scripts. Caches are not shared across <a href="https://html.spec.whatwg.org/multipage/browsers.html#origin-2">origins</a>, and they are completely isolated from the browser's HTTP cache.</p>
@@ -2692,6 +2730,43 @@ <h1>Reject Job Promise</h1>
26922730
</spec-algorithm>
26932731
</spec-section>
26942732

2733+
<spec-section id="start-register-algorithm">
2734+
<h1>Start Register</h1>
2735+
2736+
<spec-algorithm>
2737+
<dl>
2738+
<dt>Input</dt>
2739+
<dd><var>scopeURLString</var>, a string</dd>
2740+
<dd><var>scriptURL</var>, a <a href="https://url.spec.whatwg.org/#concept-url">URL</a></dd>
2741+
<dd><var>promise</var>, a <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-promise-objects">promise</a></dd>
2742+
<dd><var>client</var>, a <a href="#dfn-service-worker-client">service worker client</a></dd>
2743+
</dt>
2744+
<dt>Output</dt>
2745+
<dd>none</dd>
2746+
</dl>
2747+
<ol>
2748+
<li>If <var>client</var> is not null and <var>client</var> is not a <a href="https://w3c.github.io/webappsec-secure-contexts/#secure-context">secure context</a>, reject <var>p</var> with a "<code><a href="http://heycam.github.io/webidl/#securityerror">SecurityError</a></code>" exception and abort these steps.</li>
2749+
<li>If <var>scriptURL</var> is failure, reject <var>promise</var> with a <code>TypeError</code> and abort these steps.</li>
2750+
<li>If <var>scriptURL</var>'s <a href="https://url.spec.whatwg.org/#concept-url-scheme">scheme</a> is not one of "<code>http</code>" and "<code>https</code>", reject <var>promise</var> with a <code>TypeError</code> and abort these steps.</li>
2751+
<li>If any of the strings in <var>scriptURL</var>'s <a href="https://url.spec.whatwg.org/#concept-url-path">path</a> contains either <a href="https://encoding.spec.whatwg.org/#ascii-case-insensitive">ASCII case-insensitive</a> "<code>%2f</code>" or <a href="https://encoding.spec.whatwg.org/#ascii-case-insensitive">ASCII case-insensitive</a> "<code>%5c</code>", reject <var>promise</var> with a <code>TypeError</code> and abort these steps.</li>
2752+
<li>Let <var>scopeURL</var> be null.</li>
2753+
<li>If <var>scopeURLString</var> is null, set <var>scopeURL</var> to the result of <a href="https://url.spec.whatwg.org/#concept-url-parser">parsing</a> a string "<code>./</code>" with <var>scriptURL</var>.
2754+
<p class="note">The scope url for the registration is set to the location of the service worker script by default.</p>
2755+
</li>
2756+
<li>Else, set <var>scopeURL</var> to the result of <a href="https://url.spec.whatwg.org/#concept-url-parser">parsing</a> <var></var> with <a href="https://html.spec.whatwg.org/multipage/webappapis.html#entry-settings-object">entry settings object</a>'s <a href="https://html.spec.whatwg.org/multipage/webappapis.html#api-base-url">API base URL</a>.</li>
2757+
<li>If <var>scopeURL</var> is failure, reject <var>promise</var> with a <code>TypeError</code> and abort these steps.</li>
2758+
<li>If <var>scopeURL</var>'s <a href="https://url.spec.whatwg.org/#concept-url-scheme">scheme</a> is not one of "<code>http</code>" and "<code>https</code>", reject <var>promise</var> with a <code>TypeError</code> and abort these steps.</li>
2759+
<li>If any of the strings in <var>scopeURL</var>'s <a href="https://url.spec.whatwg.org/#concept-url-path">path</a> contains either <a href="https://encoding.spec.whatwg.org/#ascii-case-insensitive">ASCII case-insensitive</a> "<code>%2f</code>" or <a href="https://encoding.spec.whatwg.org/#ascii-case-insensitive">ASCII case-insensitive</a> "<code>%5c</code>", reject <var>promise</var> with a <code>TypeError</code> and abort these steps.</li>
2760+
<li>Let <var>job</var> be the result of running <a href="#create-job-algorithm">Create Job</a> with <em>register</em>, <var>scopeURL</var>, <var>scriptURL</var>, <var>promise</var>, and <var>client</var>.</li>
2761+
<li>Run the following substep <a href="https://html.spec.whatwg.org/multipage/infrastructure.html#in-parallel">in parallel</a>:
2762+
<ol>
2763+
<li>Invoke <a href="#schedule-job-algorithm">Schedule Job</a> with <var>job</var>.</li>
2764+
</ol>
2765+
</li>
2766+
</ol>
2767+
</spec-algorithm>
2768+
</spec-section>
2769+
26952770
<spec-section id="register-algorithm">
26962771
<h1>Register</h1>
26972772

0 commit comments

Comments
 (0)