Skip to content

Commit 1f28504

Browse files
committed
finish replacing scope to registration map
1 parent be1d8f1 commit 1f28504

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

docs/index.bs

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,12 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
236236

237237
A [=/service worker registration=] has an associated <dfn export>navigation preload header value</dfn>, which is a [=byte sequence=]. It is initially set to \`<code>true</code>\`.
238238

239-
A [=/service worker registration=] is said to be <dfn export id="dfn-service-worker-registration-unregistered">unregistered</dfn> if [=scope to registration map=][this [=/service worker registration=]'s [=service worker registration/scope url=]] is not this [=/service worker registration=].
239+
A [=/service worker registration=] is said to be <dfn export id="dfn-service-worker-registration-unregistered">unregistered</dfn> if [=id to registration map=][this [=/service worker registration=]'s [=service worker registration/id=]] is not this [=/service worker registration=].
240240

241241
<section>
242242
<h4 id="service-worker-registration-lifetime">Lifetime</h4>
243243

244-
A user agent *must* persistently keep a list of <a>registered</a> [=/service worker registrations=] unless otherwise they are explicitly <a>unregistered</a>. A user agent has a <a>scope to registration map</a> that stores the entries of the tuple of [=/service worker registration=]'s [=service worker registration/scope url=], [=URL serializer|serialized=], and the corresponding [=/service worker registration=]. The lifetime of [=/service worker registrations=] is beyond that of the {{ServiceWorkerRegistration}} objects which represent them within the lifetime of their corresponding [=/service worker clients=].
244+
A user agent *must* persistently keep a list of <a>registered</a> [=/service worker registrations=] unless otherwise they are explicitly <a>unregistered</a>. A user agent has an <a>id to registration map</a> that stores the entries of the tuple of [=/service worker registration=]'s [=service worker registration/id=] and the corresponding [=/service worker registration=]. The lifetime of [=/service worker registrations=] is beyond that of the {{ServiceWorkerRegistration}} objects which represent them within the lifetime of their corresponding [=/service worker clients=].
245245
</section>
246246
</section>
247247

@@ -773,7 +773,8 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
773773
1. Let |promise| be [=a new promise=].
774774
1. Run the following steps [=in parallel=]:
775775
1. Let |registrations| be a new [=list=].
776-
1. [=map/For each=] |scope| → |registration| of [=scope to registration map=]:
776+
1. [=map/For each=] |id| → |registration| of [=id to registration map=]:
777+
1. Let |scope| be |registration|'s [=service worker registration/scope url=], [=URL serializer|serialized=].
777778
1. If the [=url/origin=] of the result of [=URL parser|parsing=] |scope| is the [=same origin|same=] as |client|'s [=environment settings object/origin=], then [=append=] |registration| to |registrations|.
778779
1. [=Queue a task=] on |promise|'s [=relevant settings object=]'s [=responsible event loop=], using the [=DOM manipulation task source=], to run the following steps:
779780
1. Let |registrationObjects| be a new [=list=].
@@ -2272,7 +2273,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
22722273
<section>
22732274
<h3 id="privacy">Privacy</h3>
22742275

2275-
[=/Service workers=] introduce new persistent storage features including <a>scope to registration map</a> (for [=/service worker registrations=] and their [=/service workers=]), [=request response list=] and <a>name to cache map</a> (for caches), and [=script resource map=] (for script resources). In order to protect users from any potential <a biblio data-biblio-type="informative" lt="unsanctioned-tracking">unsanctioned tracking</a> threat, these persistent storages *should* be cleared when users intend to clear them and *should* maintain and interoperate with existing user controls e.g. purging all existing persistent storages.
2276+
[=/Service workers=] introduce new persistent storage features including <a>id to registration map</a> (for [=/service worker registrations=] and their [=/service workers=]), [=request response list=] and <a>name to cache map</a> (for caches), and [=script resource map=] (for script resources). In order to protect users from any potential <a biblio data-biblio-type="informative" lt="unsanctioned-tracking">unsanctioned tracking</a> threat, these persistent storages *should* be cleared when users intend to clear them and *should* maintain and interoperate with existing user controls e.g. purging all existing persistent storages.
22762277
</section>
22772278
</section>
22782279

@@ -2342,6 +2343,8 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
23422343
<div dfn-for="job">
23432344
A <a>job</a> has a <dfn id="dfn-job-type">job type</dfn>, which is one of *register*, *update*, and *unregister*.
23442345

2346+
A <a>job</a> has a <dfn id="dfn-job-id">id</dfn>
2347+
23452348
A <a>job</a> has a <dfn id="dfn-job-scope-url">scope url</dfn> (a [=/URL=]).
23462349

23472350
A <a>job</a> has a <dfn id="dfn-job-script-url">script url</dfn> (a [=/URL=]).
@@ -2551,7 +2554,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
25512554
1. If the [=environment settings object/origin=] of |job|'s [=job/scope url=] is not |job|'s [=job/referrer=]'s [=environment settings object/origin=], then:
25522555
1. Invoke [=Reject Job Promise=] with |job| and "{{SecurityError}}" {{DOMException}}.
25532556
1. Invoke <a>Finish Job</a> with |job| and abort these steps.
2554-
1. Let |registration| be the result of running the <a>Get Registration</a> algorithm passing |job|'s [=job/scope url=] as the argument.
2557+
1. Let |registration| be the result of running the <a>Get Registration</a> algorithm passing |job|'s [=job/id=] as the argument.
25552558
1. If |registration| is not null, then:
25562559
1. Let |newestWorker| be the result of running the <a>Get Newest Worker</a> algorithm passing |registration| as the argument.
25572560
1. If |newestWorker| is not null, |job|'s [=job/script url=] [=url/equals=] |newestWorker|'s [=service worker/script url=], |job|'s [=job/worker type=] equals |newestWorker|'s [=service worker/type=], and |job|'s [=job/update via cache mode=]'s value equals |registration|'s [=service worker registration/update via cache mode=], then:
@@ -2570,7 +2573,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
25702573
: Output
25712574
:: none
25722575

2573-
1. Let |registration| be the result of running the <a>Get Registration</a> algorithm passing |job|'s [=job/scope url=] as the argument.
2576+
1. Let |registration| be the result of running the <a>Get Registration</a> algorithm passing |job|'s [=job/id=] as the argument.
25742577
1. If |registration| is null, then:
25752578
1. Invoke [=Reject Job Promise=] with |job| and `TypeError`.
25762579
1. Invoke <a>Finish Job</a> with |job| and abort these steps.
@@ -2623,7 +2626,8 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
26232626
1. Set |embedder policy| to the result of [=obtain an embedder policy|obtaining an embedder policy=] from |response|.
26242627
1. If |serviceWorkerAllowed| is failure, then:
26252628
1. Asynchronously complete these steps with a <a>network error</a>.
2626-
1. Let |scopeURL| be |registration|'s [=service worker registration/scope url=].
2629+
1. Let |id| be |registration|'s [=service worker registration/id=]
2630+
1. TODO: use newest worker scope? Let |scopeURL| be |registration|'s [=service worker registration/scope url=].
26272631
1. Let |maxScopeString| be null.
26282632
1. If |serviceWorkerAllowed| is null, then:
26292633
1. Let |resolvedScope| be the result of [=URL parser|parsing=] "`./`" using |job|'s [=job/script url=] as the [=base URL=].
@@ -2676,7 +2680,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
26762680

26772681
Note: This will do nothing if [=Reject Job Promise=] was previously invoked with "{{SecurityError}}" {{DOMException}}.
26782682

2679-
1. If |newestWorker| is null, then [=map/remove=] [=scope to registration map=][|scopeURL|, [=URL serializer|serialized=]].
2683+
1. If |newestWorker| is null, then [=map/remove=] [=id to registration map=][|id|].
26802684
1. Invoke <a>Finish Job</a> with |job| and abort these steps.
26812685

26822686
Else, continue the rest of these steps after the algorithm's asynchronous completion, with |script| being the asynchronous completion value.
@@ -2695,7 +2699,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
26952699
1. Let |runResult| be the result of running the [=Run Service Worker=] algorithm with |worker| and |forceBypassCache|.
26962700
1. If |runResult| is *failure* or an [=abrupt completion=], then:
26972701
1. Invoke [=Reject Job Promise=] with |job| and `TypeError`.
2698-
1. If |newestWorker| is null, then [=map/remove=] [=scope to registration map=][|registration|'s [=service worker registration/scope url=], [[=URL serializer|serialized=]].
2702+
1. If |newestWorker| is null, then [=map/remove=] [=id to registration map=][|registration|'s [=service worker registration/id=]].
26992703
1. Invoke [=Finish Job=] with |job|.
27002704
1. Else, invoke [=Install=] algorithm with |job|, |worker|, and |registration| as its arguments.
27012705
</section>
@@ -2766,7 +2770,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
27662770
1. If |installFailed| is true, then:
27672771
1. Run the <a>Update Worker State</a> algorithm passing |registration|'s [=installing worker=] and "`redundant`" as the arguments.
27682772
1. Run the <a>Update Registration State</a> algorithm passing |registration|, "<code>installing</code>" and null as the arguments.
2769-
1. If |newestWorker| is null, then [=map/remove=] [=scope to registration map=][|registration|'s [=service worker registration/scope url=], [[=URL serializer|serialized=]].
2773+
1. If |newestWorker| is null, then [=map/remove=] [=id to registration map=][|registration|'s [=service worker registration/id=]].
27702774
1. Invoke <a>Finish Job</a> with |job| and abort these steps.
27712775
1. Let |map| be |registration|'s [=installing worker=]'s [=script resource map=].
27722776
1. Let |usedSet| be |registration|'s [=installing worker=]'s [=set of used scripts=].
@@ -3142,7 +3146,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
31423146
: Output
31433147
:: None
31443148

3145-
1. [=map/For each=] <var ignore>scope</var> → |registration| of <a>scope to registration map</a>:
3149+
1. [=map/For each=] <var ignore>id</var> → |registration| of <a>id to registration map</a>:
31463150
1. If |registration|'s <a>installing worker</a> |installingWorker| is not null, then:
31473151
1. If |registration|'s [=waiting worker=] is null and |registration|'s [=active worker=] is null, invoke <a>Clear Registration</a> with |registration| and continue to the next iteration of the loop.
31483152
1. Else, set |installingWorker| to null.
@@ -3176,11 +3180,11 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
31763180
1. If the [=environment settings object/origin=] of |job|'s [=job/scope url=] is not |job|'s [=job/client=]'s [=environment settings object/origin=], then:
31773181
1. Invoke [=Reject Job Promise=] with |job| and "{{SecurityError}}" {{DOMException}}.
31783182
1. Invoke <a>Finish Job</a> with |job| and abort these steps.
3179-
1. Let |registration| be the result of running <a>Get Registration</a> algorithm passing |job|'s [=job/scope url=] as the argument.
3183+
1. Let |registration| be the result of running <a>Get Registration</a> algorithm passing |job|'s [=job/id=] as the argument.
31803184
1. If |registration| is null, then:
31813185
1. Invoke <a>Resolve Job Promise</a> with |job| and false.
31823186
1. Invoke <a>Finish Job</a> with |job| and abort these steps.
3183-
1. [=map/Remove=] [=scope to registration map=][|job|'s [=job/scope url=]].
3187+
1. [=map/Remove=] [=id to registration map=][|job|'s [=job/id=]].
31843188
1. Invoke <a>Resolve Job Promise</a> with |job| and true.
31853189
1. Invoke [=Try Clear Registration=] with |registration|.
31863190

@@ -3193,15 +3197,16 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
31933197
<h3 id="set-registration-algorithm"><dfn>Set Registration</dfn></h3>
31943198

31953199
: Input
3200+
:: |id|, an [=service worker registration/id=]
31963201
:: |scope|, a [=/URL=]
31973202
:: |updateViaCache|, an [=service worker registration/update via cache mode=]
31983203
: Output
31993204
:: |registration|, a [=/service worker registration=]
32003205

32013206
1. Run the following steps atomically.
32023207
1. Let |scopeString| be [=URL serializer|serialized=] |scope| with the *exclude fragment flag* set.
3203-
1. Let |registration| be a new [=/service worker registration=] whose [=service worker registration/scope url=] is set to |scope| and [=service worker registration/update via cache mode=] is set to |updateViaCache|.
3204-
1. [=map/Set=] <a>scope to registration map</a>[|scopeString|] to |registration|.
3208+
1. Let |registration| be a new [=/service worker registration=] whose [=service worker registration/id=] is set to |id|, [=service worker registration/scope url=] is set to |scope|, and [=service worker registration/update via cache mode=] is set to |updateViaCache|.
3209+
1. [=map/Set=] <a>id to registration map</a>[|id|] to |registration|.
32053210
1. Return |registration|.
32063211
</section>
32073212

@@ -3317,7 +3322,11 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
33173322
1. Run the following steps atomically.
33183323
1. Let |clientURLString| be <a lt="URL serializer">serialized</a> |clientURL|.
33193324
1. Let |matchingScopeString| be the empty string.
3320-
1. Let |scopeStringSet| be the result of [=map/get the keys|getting the keys=] from <a>scope to registration map</a>.
3325+
1. Let |scopeMap| be the empty map.
3326+
1. [=map/For each=] |key| → |value| of <a>id to registration map</a>:
3327+
1. If |value|'s [=service worker registration/active worker=/ is null, then [=continue=].
3328+
1. [=map/Set=] |scopeMap|[|value|'s [=service worker registration/scope url] to |value|.
3329+
1. Let |scopeStringSet| be the result of [=map/get the keys|getting the keys=] from |scopeMap|.
33213330
1. Set |matchingScopeString| to the longest value in |scopeStringSet| which the value of |clientURLString| starts with, if it exists.
33223331

33233332
Note: The URL string matching in this step is prefix-based rather than path-structural. E.g. a client URL string with "https://example.com/prefix-of/resource.html" will match a registration for a scope with "https://example.com/prefix". The URL string comparison is safe for the same-origin security as HTTP(S) URLs are always [=URL serializer|serialized=] with a trailing slash at the end of the origin part of the URLs.
@@ -3326,22 +3335,21 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
33263335
1. If |matchingScopeString| is not the empty string, then:
33273336
1. Set |matchingScope| to the result of <a lt="URL parser">parsing</a> |matchingScopeString|.
33283337
1. Assert: |matchingScope|'s [=url/origin=] and |clientURL|'s [=url/origin=] are [=same origin=].
3329-
1. Return the result of running [=Get Registration=] algorithm passing |matchingScope| as the argument.
3338+
1. Let |matchingId| be |scopeMap|[|matchingScopeString|]'s [=service worker registration/id].
3339+
1. Return the result of running [=Get Registration=] algorithm passing |matchingId| as the argument.
33303340
</section>
33313341

33323342
<section algorithm>
33333343
<h3 id="get-registration-algorithm"><dfn>Get Registration</dfn></h3>
33343344

33353345
: Input
3336-
:: |scope|, a [=/URL=]
3346+
:: |id|, a [=service worker registration/id=]
33373347
: Output
33383348
:: A [=/service worker registration=]
33393349

33403350
1. Run the following steps atomically.
3341-
1. Let |scopeString| be the empty string.
3342-
1. If |scope| is not null, set |scopeString| to [=URL serializer|serialized=] |scope| with the *exclude fragment flag* set.
3343-
1. [=map/For each=] |key| → |value| of <a>scope to registration map</a>:
3344-
1. If |scopeString| matches |key|, then return |value|.
3351+
1. [=map/For each=] |key| → |value| of <a>id to registration map</a>:
3352+
1. If |id| matches |key|, then return |value|.
33453353
1. Return null.
33463354
</section>
33473355

0 commit comments

Comments
 (0)