Skip to content

Commit 7a9be17

Browse files
Specify serviceworker link type.
1 parent 9e6c421 commit 7a9be17

File tree

2 files changed

+421
-232
lines changed

2 files changed

+421
-232
lines changed

spec/service_worker/index.bs

Lines changed: 113 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ spec: dom
4949
text: Event
5050
text: EventTarget
5151

52+
spec: html; type: element; text: link
5253
spec: html; type: dfn
5354
text: about:blank
5455
text: active document
@@ -59,6 +60,7 @@ spec: html; type: dfn
5960
text: auxiliary browsing context
6061
text: browsing context
6162
text: discard a document
63+
text: document base url
6264
text: effective script origin
6365
text: entry settings object
6466
text: environment settings object
@@ -202,6 +204,8 @@ spec: html; urlPrefix: https://html.spec.whatwg.org/multipage/
202204
text: read only array; url: dfn-read-only-array
203205
urlPrefix: interaction.html
204206
text: has focus steps
207+
urlPrefix: semantics.html
208+
text: external resource link
205209
urlPrefix: webappapis.html
206210
text: classic script
207211
text: creation url
@@ -259,6 +263,12 @@ spec: quota-api; urlPrefix: http://www.w3.org/TR/quota-api/
259263
text: onbeforeevicted; url: widl-ServiceWorkerGlobalScope-onbeforeevicted
260264
text: onevicted; url: widl-ServiceWorkerGlobalScope-onevicted
261265

266+
spec: rfc5988; urlPrefix: https://tools.ietf.org/html/rfc5988
267+
type: dfn
268+
text: context IRI; url: section-5.2
269+
text: target attribute; url: section-5.4
270+
text: target IRI; url: section-5.1
271+
262272
spec: rfc7230; urlPrefix: https://tools.ietf.org/html/rfc7230
263273
type: dfn
264274
text: field-value; for: http; url: section-3.2
@@ -778,20 +788,7 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
778788
<li>Let <var>client</var> be the <a>context object</a>'s <a href="#dfn-service-worker-container-interface-client">service worker client</a>.</li>
779789
<li>If <var>client</var> is not a <a>secure context</a>, reject <var>p</var> with a "{{SecurityError}}" exception and abort these steps.</li>
780790
<li>Let <var>scriptURL</var> be the result of <a for="url">parsing</a> <var>scriptURL</var> with <a>entry settings object</a>'s <a>API base URL</a>.</li>
781-
<li>If <var>scriptURL</var> is failure, reject <var>p</var> with a <code>TypeError</code> and abort these steps.</li>
782-
<li>If <var>scriptURL</var>'s <a for="url">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>
783-
<li>If any of the strings in <var>scriptURL</var>'s <a for="url">path</a> contains either <a>ASCII case-insensitive</a> "<code>%2f</code>" or <a>ASCII case-insensitive</a> "<code>%5c</code>", reject <var>p</var> with a <code>TypeError</code> and abort these steps.</li>
784-
<li>Let <var>scopeURL</var> be null.</li>
785-
<li>If <var>options</var>.{{RegistrationOptions/scope}} is <a lt="present">not present</a>, set <var>scopeURL</var> to the result of <a for="url">parsing</a> a string "<code>./</code>" with <var>scriptURL</var>.
786-
<p class="note">The scope url for the registration is set to the location of the service worker script by default.</p>
787-
</li>
788-
<li>Else, set <var>scopeURL</var> to the result of <a for="url">parsing</a> <var>options</var>.{{RegistrationOptions/scope}} with <a>entry settings object</a>'s <a>API base URL</a>.</li>
789-
<li>If <var>scopeURL</var> is failure, reject <var>p</var> with a <code>TypeError</code> and abort these steps.</li>
790-
<li>If <var>scopeURL</var>'s <a for="url">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>
791-
<li>If any of the strings in <var>scopeURL</var>'s <a for="url">path</a> contains either <a>ASCII case-insensitive</a> "<code>%2f</code>" or <a>ASCII case-insensitive</a> "<code>%5c</code>", reject <var>p</var> with a <code>TypeError</code> and abort these steps.</li>
792-
<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>'s <a>creation URL</a>.</li>
793-
<li>Set <var>job</var>'s <a>worker type</a> to <var>options</var>.{{RegistrationOptions/type}}.</li>
794-
<li>Invoke <a href="#schedule-job-algorithm">Schedule Job</a> with <var>job</var>.</li>
791+
<li>Invoke [[#start-register-algorithm]] with <var>scopeURL</var>, <var>scriptURL</var>, <var>p</var>, <var>client</var>'s <a>creation URL</a> and <var>options</var>.{{RegistrationOptions/type}}.</li>
795792
<li>Return <var>p</var>.</li>
796793
</ol>
797794
</section>
@@ -2046,6 +2043,77 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
20462043
</section>
20472044
</section>
20482045

2046+
<section>
2047+
<h2 id="link-type-serviceworker">Link type "<code>serviceworker</code>"</h2>
2048+
<p>The <dfn id="dfn-link-type-serviceworker" lt="serviceworker link type"><code>serviceworker</code></dfn> keyword may be used with <{link}> elements. This keyword creates an <a>external resource link</a> (<dfn id="dfn-serviceworker-link">serviceworker link</dfn>) that is used to declare a <a for="service worker registration">service worker registration</a> and its <a for="service worker registration">scope url</a>.</p>
2049+
2050+
<section>
2051+
<h3 id="link-element-processing">Processing</h3>
2052+
2053+
<p>When a user agent that supports [[!RFC5988]] processes a <code>Link</code> header that contains a <a>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>
2054+
2055+
<ol>
2056+
<li>If the <code>Link</code> header has an "<code>anchor</code>" parameter, abort these steps.</li>
2057+
<li>Let <var>contextURL</var> be the result of <a for="url">parsing</a> the <a>context IRI</a> of the <code>Link</code> header.</li>
2058+
<li>If the result of running <a>Is origin potentially trustworthy</a> with the <a for="resource">origin</a> of <var>contextURL</var> is <code>Not Trusted</code>, abort these steps.</li>
2059+
<li>Let <var>request</var> be the <a for="fetch">request</a> for which this header was received in the response.</li>
2060+
<li>If <var>request</var>'s <a for="request">client</a> is not a <a>secure context</a>, abort these steps.</li>
2061+
<li>Let <var>scriptURL</var> be the result of <a for="url">parsing</a> the <a>target IRI</a> of the <code>Link</code> header.</li>
2062+
<li>Let <var>scopeURL</var> be the "<code>scope</code>" <a>target attribute</a> of the <code>Link</code> header, or null if no such attribute is present.</li>
2063+
<li>Invoke [[#start-register-algorithm]] with <var>scopeURL</var>, <var>scriptURL</var>, a new <a>promise</a>, null, and <var>contextURL</var>'s <a for="resource">origin</a>.</li>
2064+
<!-- TODO: worker type -->
2065+
</ol>
2066+
2067+
<p>When a <a>serviceworker link</a>'s <{link}> element is <a lt="in a document">inserted into a document</a>, a <a>serviceworker link</a> is created on a <{link}> element that is already <a>in a Document</a>, or the <{link/href}> or <{link/scope}> attributes of the <{link}> element of a <a>serviceworker link</a> is changed, the user agent <em class="rfc2119" title="SHOULD">should</em> run these steps or their <a href="#dfn-processing-equivalence">equivalent</a>:</p>
2068+
2069+
<ol>
2070+
<li>If the <{link/href}> attribute is the empty string, abort these steps.</li>
2071+
<li>Let <var>client</var> be the document's <a for="ServiceWorkerContainer">service worker client</a>.</li>
2072+
<li>If <var>client</var> is not a <a>secure context</a>, <a>queue a task</a> to <a>fire a simple event</a> named <code>error</code> at the <{link}> element, and abort these steps.</li>
2073+
<li>Let <var>scriptURL</var> be the result of <a for="url">parsing</a> the <{link/href}> attribute with document's <a>document base URL</a>.</li>
2074+
<li>Let <var>scopeURL</var> be the <{link/scope}> attribute, or null if the <{link/scope}> attribute is omitted.</li>
2075+
<li>Let <var>promise</var> be a new <a>promise</a>.</li>
2076+
<li>Invoke [[#start-register-algorithm]] with <var>scopeURL</var>, <var>scriptURL</var>, <var>promise</var>, <var>client</var>, and <var>client</var>'s <a for="resource">origin</a>.</li>
2077+
<!-- TODO: worker type -->
2078+
<li>Run the following substeps <a>in parallel</a>:
2079+
<ol>
2080+
<li>Wait until <var>promise</var> settles.</li>
2081+
<li>If <var>promise</var> rejected, <a>queue a task</a> to <a>fire a simple event</a> named <code>error</code> at the <{link}> element.</li>
2082+
<li>If <var>promise</var> resolved, <a>queue a task</a> to <a>fire a simple event</a> named <code>load</code> at the <{link}> element.</li>
2083+
</ol>
2084+
</li>
2085+
</ol>
2086+
2087+
<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>
2088+
2089+
<div class="example">
2090+
A resource being loaded with the following response header:
2091+
<pre class="highlight">
2092+
Link: &lt;/js/sw.js&gt;; rel="serviceworker"; scope="/"
2093+
</pre>
2094+
has more or less the same effect as a document being loaded in a secure context with the following <code>link</code> element:
2095+
<pre class="lang-html">
2096+
&lt;link rel="serviceworker" href="/js/sw.js" scope="/"&gt;
2097+
</pre>
2098+
which is more or less equivalent to the page containing javascript code like:
2099+
<pre class="lang-js">
2100+
navigator.serviceworker.register("/js/sw.js", { scope: "/" });
2101+
</pre>
2102+
</div>
2103+
</section>
2104+
2105+
<section>
2106+
<h3 id="link-element-interface-section">Link element interface extensions</h3>
2107+
2108+
<pre class="idl">
2109+
partial interface HTMLLinkElement {
2110+
attribute USVString scope;
2111+
};
2112+
</pre>
2113+
2114+
<p>The <dfn id="link-scope-attribute">scope</dfn> attribute returns the value of this element's <dfn element-attr for="link">scope</dfn> attribute.</p>
2115+
</section>
2116+
</section>
20492117

20502118
<section>
20512119
<h2 id="cache-objects">Caches</h2>
@@ -3028,6 +3096,37 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
30283096
</ol>
30293097
</section>
30303098

3099+
<section algorithm="start-register-algorithm">
3100+
<h3 id="start-register-algorithm">Start Register</h3>
3101+
3102+
<dl>
3103+
<dt>Input</dt>
3104+
<dd><var>scopeURLString</var>, a string</dd>
3105+
<dd><var>scriptURL</var>, a <a for="url">URL</a></dd>
3106+
<dd><var>promise</var>, a <a>promise</a></dd>
3107+
<dd><var>referrer</var>, a <a for=url>URL</a></dd>
3108+
<dd><var>workerType</var>, a <a>worker type</a></dd>
3109+
<dt>Output</dt>
3110+
<dd>none</dd>
3111+
</dl>
3112+
<ol>
3113+
<li>If <var>scriptURL</var> is failure, reject <var>promise</var> with a <code>TypeError</code> and abort these steps.</li>
3114+
<li>If <var>scriptURL</var>'s <a for="url">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>
3115+
<li>If any of the strings in <var>scriptURL</var>'s <a for="url">path</a> contains either <a>ASCII case-insensitive</a> "<code>%2f</code>" or <a>ASCII case-insensitive</a> "<code>%5c</code>", reject <var>promise</var> with a <code>TypeError</code> and abort these steps.</li>
3116+
<li>Let <var>scopeURL</var> be null.</li>
3117+
<li>If <var>scopeURLString</var> is null, set <var>scopeURL</var> to the result of <a for="url">parsing</a> a string "<code>./</code>" with <var>scriptURL</var>.
3118+
<p class="note">The scope url for the registration is set to the location of the service worker script by default.</p>
3119+
</li>
3120+
<li>Else, set <var>scopeURL</var> to the result of <a for="url">parsing</a> <var>scopeURLString</var> with <a>entry settings object</a>'s <a>API base URL</a>.</li>
3121+
<li>If <var>scopeURL</var> is failure, reject <var>promise</var> with a <code>TypeError</code> and abort these steps.</li>
3122+
<li>If <var>scopeURL</var>'s <a for="url">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>
3123+
<li>If any of the strings in <var>scopeURL</var>'s <a for="url">path</a> contains either <a>ASCII case-insensitive</a> "<code>%2f</code>" or <a>ASCII case-insensitive</a> "<code>%5c</code>", reject <var>promise</var> with a <code>TypeError</code> and abort these steps.</li>
3124+
<li>Let <var>job</var> be the result of running [[#create-job-algorithm]] with <em>register</em>, <var>scopeURL</var>, <var>scriptURL</var>, <var>promise</var>, and <var>referrer</var>.</li>
3125+
<li>Set <var>job</var>'s <a>worker type</a> to <var>workerType</var>.</li>
3126+
<li>Invoke [[#schedule-job-algorithm]] with <var>job</var>.</li>
3127+
</ol>
3128+
</section>
3129+
30313130
<section algorithm="register-algorithm">
30323131
<h3 id="register-algorithm">Register</h3>
30333132

@@ -3051,11 +3150,6 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
30513150
</ol>
30523151
</li>
30533152
<li>If the <a for="resource">origin</a> of <var>job</var>'s <a href="#dfn-job-scope-url">scope url</a> is not <var>job</var>'s <a for=job>referrer</a>'s <a for="resource">origin</a>, then:
3054-
<ol>
3055-
<li>Invoke <a href="#reject-job-promise-algorithm">Reject Job Promise</a> with <var>job</var> and a "{{SecurityError}}" exception.</li>
3056-
<li>Invoke <a href="#finish-job-algorithm">Finish Job</a> with <var>job</var> and abort these steps.</li>
3057-
</ol>
3058-
</li>
30593153
<li>Let <var>registration</var> be the result of running the <a href="#get-registration-algorithm">Get Registration</a> algorithm passing <var>job</var>'s <a href="#dfn-job-scope-url">scope url</a> as the argument.</li>
30603154
<li>If <var>registration</var> is not null, then:
30613155
<ol>

0 commit comments

Comments
 (0)