Skip to content

Commit 2183f5e

Browse files
authored
Clarify determination of active service worker and spec plan (#1455)
This change makes it clear that this behavior needs to be (and will be) specified normatively in HTML Standard, and any future changes for Service Workers will be incorporated into Service Workers Nightly. It also clarifies, non-normatively, the behavior of how a service worker client's active service worker is determined. Issue: #765. This moves the issue to the next milestone.
1 parent b4add25 commit 2183f5e

File tree

2 files changed

+78
-10
lines changed

2 files changed

+78
-10
lines changed

docs/index.bs

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,49 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
260260
</section>
261261

262262
<section>
263-
<h3 id="selection">Selection and Use</h3>
263+
<h3 id="control-and-use">Control and Use</h3>
264264

265-
A [=/service worker client=] independently <a lt="selection">selects</a> and <a>uses</a> a [=/service worker registration=] for its own loading and its subresources. The <dfn id="dfn-service-worker-registration-selection">selection</dfn> of a [=/service worker registration=], upon a <a>non-subresource request</a>, is a process of either <a lt="Match Service Worker Registration">matching</a> a [=/service worker registration=] from <a>scope to registration map</a> or inheriting an existing [=/service worker registration=] from its parent or owner context depending on the request's [=request/url=].
265+
A [=/service worker client=] has an [=active service worker=] that serves its own loading and its subresources. When a [=/service worker client=] has a non-null [=active service worker=], it is said to be <dfn id="dfn-control" lt="controlling|controls|controlled">controlled</dfn> by that [=active service worker=]. When a [=/service worker client=] is [=controlled=] by a [=/service worker=], it is said that the [=/service worker client=] is <dfn id="dfn-use" lt="using|uses|used">using</dfn> the [=/service worker=]’s [=containing service worker registration=].
266+
A [=/service worker client=]'s [=active service worker=] is determined as explained in the following subsections.
266267

267-
When the request's [=request/url=] is not <a lt="is local">local</a>, a [=/service worker client=] <a lt="Match Service Worker Registration">matches</a> a [=/service worker registration=] from <a>scope to registration map</a>. That is, the [=/service worker client=] attempts to consult a [=/service worker registration=] whose [=service worker registration/scope url=] <a lt="Match Service Worker Registration">matches</a> its <a>creation URL</a>.
268+
*The rest of the section is non-normative.*
268269

269-
When the request's [=request/url=] <a>is local</a>, if the [=/service worker client=]'s <a>responsible browsing context</a> is a <a>nested browsing context</a> or the [=/service worker client=] is a <a>worker client</a>, the [=/service worker client=] inherits the [=/service worker registration=] from its <a>parent browsing context</a>'s environment or from the environment of a {{Document}} in the [=/service worker client=]'s [=environment settings object/global object=]'s [=owner set=], respectively, if it exists.
270+
Issue: The behavior in this section is not fully specified yet and will be specified in [HTML Standard](https://html.spec.whatwg.org). The work is tracked by the [issue](https://github.com/w3c/ServiceWorker/issues/765) and the [pull request](https://github.com/whatwg/html/pull/2809).
270271

271-
If the <a>selection</a> was successful, the <a lt="selection">selected</a> [=/service worker registration=]'s <a>active worker</a> starts to <dfn id="dfn-control">control</dfn> the [=/service worker client=]. Otherwise, the flow returns to [=/fetch=] where it falls back to the default behavior. When a [=/service worker client=] is <a>controlled</a> by an <a>active worker</a>, it is considered that the [=/service worker client=] is <dfn id="dfn-use" lt="using|uses|used">using</dfn> the <a>active worker</a>'s <a>containing service worker registration</a>.
272+
<section>
273+
<h4 id="control-and-use-window-client">The window client case</h4>
274+
275+
A [=window client=] is [created](https://html.spec.whatwg.org/#set-up-a-window-environment-settings-object) when a [=/browsing context=] is [created](https://html.spec.whatwg.org/#creating-a-new-browsing-context) and when it [=navigates=].
276+
277+
When a [=window client=] is [created](https://html.spec.whatwg.org/#set-up-a-window-environment-settings-object) in the process of a [=/browsing context=] [creation](https://html.spec.whatwg.org/#creating-a-new-browsing-context):
278+
279+
If the [=/browsing context=]'s initial [=active document=]'s [=/origin=] is an [=opaque origin=], the [=window client=]'s [=active service worker=] is set to null.
280+
Otherwise, it is set to the creator [=document=]'s [=/service worker client=]'s [=active service worker=].
281+
282+
When a [=window client=] is [created](https://html.spec.whatwg.org/#set-up-a-window-environment-settings-object) in the process of the [=/browsing context=]'s [=navigate|navigation=]:
283+
284+
If the [=fetch=] is routed through [=/HTTP fetch=], the [=window client=]'s [=active service worker=] is set to the result of the <a lt="Match Service Worker Registration">service worker registration matching</a>.
285+
Otherwise, if the created [=document=]'s [=/origin=] is an [=opaque origin=] or not the [=same origin|same=] as its creator [=document=]'s [=/origin=], the [=window client=]'s [=active service worker=] is set to null.
286+
Otherwise, it is set to the creator [=document=]'s [=/service worker client=]'s [=active service worker=].
287+
288+
Note: For an initial [=navigate|navigation=] with [=replacement enabled=], the initial [=window client=] that was [created](https://html.spec.whatwg.org/#set-up-a-window-environment-settings-object) when the [=/browsing context=] was [created](https://html.spec.whatwg.org/#creating-a-new-browsing-context) is reused, but the [=active service worker=] is determined by the same behavior as above.
289+
290+
Note: [Sandboxed](https://html.spec.whatwg.org/#attr-iframe-sandbox) [=iframes=] without the sandboxing directives, `allow-same-origin` and `allow-scripts`, result in having the [=active service worker=] value of null as their [=/origin=] is an [=opaque origin=]..
291+
</section>
292+
293+
<section>
294+
<h4 id="control-and-use-worker-client">The worker client case</h4>
295+
296+
A [=worker client=] is <a href="https://html.spec.whatwg.org/#set-up-a-worker-environment-settings-object">created</a> when the user agent [=run a worker|runs a worker=].
297+
298+
When the [=worker client=] is created:
299+
300+
When the [=fetch=] is routed through [=/HTTP fetch=], the [=worker client=]'s [=active service worker=] is set to the result of the <a lt="Match Service Worker Registration">service worker registration matching</a>.
301+
Otherwise, if the [=worker client=]'s [=service worker client/origin=] is an [=opaque origin=], or the [=/request=]'s [=request/URL=] is a [=blob URL=] and the [=worker client=]'s [=service worker client/origin=] is not the [=same origin|same=] as the [=/origin=] of the last item in the [=worker client=]'s [=/global object=]'s [=owner set=], the [=worker client=]'s [=active service worker=] is set to null.
302+
Otherwise, it is set to the [=active service worker=] of the [=environment settings object=] of the last [=item=] in the [=worker client=]'s [=/global object=]'s [=owner set=].
303+
</section>
304+
305+
Note: [=Window clients=] and [=worker clients=] with a [data: URL](https://tools.ietf.org/html/rfc2397#section-2) result in having the [=active service worker=] value of null as their [=/origin=] is an [=opaque origin=]. [=Window clients=] and [=worker clients=] with a [=blob URL=] can inherit the [=active service worker=] of their creator [=document=] or owner, but if the [=/request=]'s [=request/origin=] is not the [=same origin|same=] as the [=/origin=] of their creator [=document=] or owner, the [=active service worker=] is set to null.
272306
</section>
273307

274308
<section>

docs/v1/index.bs

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,49 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
243243
</section>
244244

245245
<section>
246-
<h3 id="selection">Selection and Use</h3>
246+
<h3 id="control-and-use">Control and Use</h3>
247247

248-
A [=/service worker client=] independently <a lt="selection">selects</a> and <a>uses</a> a [=/service worker registration=] for its own loading and its subresources. The <dfn id="dfn-service-worker-registration-selection">selection</dfn> of a [=/service worker registration=], upon a <a>non-subresource request</a>, is a process of either <a lt="Match Service Worker Registration">matching</a> a [=/service worker registration=] from <a>scope to registration map</a> or inheriting an existing [=/service worker registration=] from its parent or owner context depending on the request's [=request/url=].
248+
A [=/service worker client=] has an [=active service worker=] that serves its own loading and its subresources. When a [=/service worker client=] has a non-null [=active service worker=], it is said to be <dfn id="dfn-control" lt="controlling|controls|controlled">controlled</dfn> by that [=active service worker=]. When a [=/service worker client=] is [=controlled=] by a [=/service worker=], it is said that the [=/service worker client=] is <dfn id="dfn-use" lt="using|uses|used">using</dfn> the [=/service worker=]’s [=containing service worker registration=].
249+
A [=/service worker client=]'s [=active service worker=] is determined as explained in the following subsections.
249250

250-
When the request's [=request/url=] is not <a lt="is local">local</a>, a [=/service worker client=] <a lt="Match Service Worker Registration">matches</a> a [=/service worker registration=] from <a>scope to registration map</a>. That is, the [=/service worker client=] attempts to consult a [=/service worker registration=] whose [=service worker registration/scope url=] <a lt="Match Service Worker Registration">matches</a> its <a>creation URL</a>.
251+
*The rest of the section is non-normative.*
251252

252-
When the request's [=request/url=] <a>is local</a>, if the [=/service worker client=]'s <a>responsible browsing context</a> is a <a>nested browsing context</a> or the [=/service worker client=] is a <a>worker client</a>, the [=/service worker client=] inherits the [=/service worker registration=] from its <a>parent browsing context</a>'s environment or from the environment of a {{Document}} in the [=/service worker client=]'s [=environment settings object/global object=]'s [=owner set=], respectively, if it exists.
253+
Note: The behavior in this section is not fully specified yet and will be specified in [HTML Standard](https://html.spec.whatwg.org). The work is tracked by the [issue](https://github.com/w3c/ServiceWorker/issues/765) and the [pull request](https://github.com/whatwg/html/pull/2809). For any Service Workers changes, we will incorporate them into [Service Workers Nightly](https://w3c.github.io/ServiceWorker/).
253254

254-
If the <a>selection</a> was successful, the <a lt="selection">selected</a> [=/service worker registration=]'s <a>active worker</a> starts to <dfn id="dfn-control">control</dfn> the [=/service worker client=]. Otherwise, the flow returns to [=/fetch=] where it falls back to the default behavior. When a [=/service worker client=] is <a>controlled</a> by an <a>active worker</a>, it is considered that the [=/service worker client=] is <dfn id="dfn-use" lt="using|uses|used">using</dfn> the <a>active worker</a>'s <a>containing service worker registration</a>.
255+
<section>
256+
<h4 id="control-and-use-window-client">The window client case</h4>
257+
258+
A [=window client=] is [created](https://html.spec.whatwg.org/#set-up-a-window-environment-settings-object) when a [=/browsing context=] is [created](https://html.spec.whatwg.org/#creating-a-new-browsing-context) and when it [=navigates=].
259+
260+
When a [=window client=] is [created](https://html.spec.whatwg.org/#set-up-a-window-environment-settings-object) in the process of a [=/browsing context=] [creation](https://html.spec.whatwg.org/#creating-a-new-browsing-context):
261+
262+
If the [=/browsing context=]'s initial [=active document=]'s [=/origin=] is an [=opaque origin=], the [=window client=]'s [=active service worker=] is set to null.
263+
Otherwise, it is set to the creator [=document=]'s [=/service worker client=]'s [=active service worker=].
264+
265+
When a [=window client=] is [created](https://html.spec.whatwg.org/#set-up-a-window-environment-settings-object) in the process of the [=/browsing context=]'s [=navigate|navigation=]:
266+
267+
If the [=fetch=] is routed through [=/HTTP fetch=], the [=window client=]'s [=active service worker=] is set to the result of the <a lt="Match Service Worker Registration">service worker registration matching</a>.
268+
Otherwise, if the created [=document=]'s [=/origin=] is an [=opaque origin=] or not the [=same origin|same=] as its creator [=document=]'s [=/origin=], the [=window client=]'s [=active service worker=] is set to null.
269+
Otherwise, it is set to the creator [=document=]'s [=/service worker client=]'s [=active service worker=].
270+
271+
Note: For an initial [=navigate|navigation=] with [=replacement enabled=], the initial [=window client=] that was [created](https://html.spec.whatwg.org/#set-up-a-window-environment-settings-object) when the [=/browsing context=] was [created](https://html.spec.whatwg.org/#creating-a-new-browsing-context) is reused, but the [=active service worker=] is determined by the same behavior as above.
272+
273+
Note: [Sandboxed](https://html.spec.whatwg.org/#attr-iframe-sandbox) [=iframes=] without the sandboxing directives, `allow-same-origin` and `allow-scripts`, result in having the [=active service worker=] value of null as their [=/origin=] is an [=opaque origin=]..
274+
</section>
275+
276+
<section>
277+
<h4 id="control-and-use-worker-client">The worker client case</h4>
278+
279+
A [=worker client=] is <a href="https://html.spec.whatwg.org/#set-up-a-worker-environment-settings-object">created</a> when the user agent [=run a worker|runs a worker=].
280+
281+
When the [=worker client=] is created:
282+
283+
When the [=fetch=] is routed through [=/HTTP fetch=], the [=worker client=]'s [=active service worker=] is set to the result of the <a lt="Match Service Worker Registration">service worker registration matching</a>.
284+
Otherwise, if the [=worker client=]'s [=service worker client/origin=] is an [=opaque origin=], or the [=/request=]'s [=request/URL=] is a [=blob URL=] and the [=worker client=]'s [=service worker client/origin=] is not the [=same origin|same=] as the [=/origin=] of the last item in the [=worker client=]'s [=/global object=]'s [=owner set=], the [=worker client=]'s [=active service worker=] is set to null.
285+
Otherwise, it is set to the [=active service worker=] of the [=environment settings object=] of the last [=item=] in the [=worker client=]'s [=/global object=]'s [=owner set=].
286+
</section>
287+
288+
Note: [=Window clients=] and [=worker clients=] with a [data: URL](https://tools.ietf.org/html/rfc2397#section-2) result in having the [=active service worker=] value of null as their [=/origin=] is an [=opaque origin=]. [=Window clients=] and [=worker clients=] with a [=blob URL=] can inherit the [=active service worker=] of their creator [=document=] or owner, but if the [=/request=]'s [=request/origin=] is not the [=same origin|same=] as the [=/origin=] of their creator [=document=] or owner, the [=active service worker=] is set to null.
255289
</section>
256290

257291
<section>

0 commit comments

Comments
 (0)