Skip to content

Commit 1a185bc

Browse files
committed
finish replacing scope to registration map
1 parent f527031 commit 1a185bc

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=].
@@ -2281,7 +2282,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
22812282
<section>
22822283
<h3 id="privacy">Privacy</h3>
22832284

2284-
[=/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.
2285+
[=/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.
22852286
</section>
22862287
</section>
22872288

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

2355+
A <a>job</a> has a <dfn id="dfn-job-id">id</dfn>
2356+
23542357
A <a>job</a> has a <dfn id="dfn-job-scope-url">scope url</dfn> (a [=/URL=]).
23552358

23562359
A <a>job</a> has a <dfn id="dfn-job-script-url">script url</dfn> (a [=/URL=]).
@@ -2560,7 +2563,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
25602563
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:
25612564
1. Invoke [=Reject Job Promise=] with |job| and "{{SecurityError}}" {{DOMException}}.
25622565
1. Invoke <a>Finish Job</a> with |job| and abort these steps.
2563-
1. Let |registration| be the result of running the <a>Get Registration</a> algorithm passing |job|'s [=job/scope url=] as the argument.
2566+
1. Let |registration| be the result of running the <a>Get Registration</a> algorithm passing |job|'s [=job/id=] as the argument.
25642567
1. If |registration| is not null, then:
25652568
1. Let |newestWorker| be the result of running the <a>Get Newest Worker</a> algorithm passing |registration| as the argument.
25662569
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:
@@ -2579,7 +2582,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
25792582
: Output
25802583
:: none
25812584

2582-
1. Let |registration| be the result of running the <a>Get Registration</a> algorithm passing |job|'s [=job/scope url=] as the argument.
2585+
1. Let |registration| be the result of running the <a>Get Registration</a> algorithm passing |job|'s [=job/id=] as the argument.
25832586
1. If |registration| is null, then:
25842587
1. Invoke [=Reject Job Promise=] with |job| and `TypeError`.
25852588
1. Invoke <a>Finish Job</a> with |job| and abort these steps.
@@ -2630,7 +2633,8 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
26302633
1. Set |embedder policy| to the result of [=obtain an embedder policy|obtaining an embedder policy=] from |response|.
26312634
1. If |serviceWorkerAllowed| is failure, then:
26322635
1. Asynchronously complete these steps with a <a>network error</a>.
2633-
1. Let |scopeURL| be |registration|'s [=service worker registration/scope url=].
2636+
1. Let |id| be |registration|'s [=service worker registration/id=]
2637+
1. TODO: use newest worker scope? Let |scopeURL| be |registration|'s [=service worker registration/scope url=].
26342638
1. Let |maxScopeString| be null.
26352639
1. If |serviceWorkerAllowed| is null, then:
26362640
1. Let |resolvedScope| be the result of [=URL parser|parsing=] "`./`" using |job|'s [=job/script url=] as the [=base URL=].
@@ -2683,7 +2687,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
26832687

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

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

26892693
Else, continue the rest of these steps after the algorithm's asynchronous completion, with |script| being the asynchronous completion value.
@@ -2701,7 +2705,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
27012705
1. Let |runResult| be the result of running the [=Run Service Worker=] algorithm with |worker| and |forceBypassCache|.
27022706
1. If |runResult| is *failure* or an [=abrupt completion=], then:
27032707
1. Invoke [=Reject Job Promise=] with |job| and `TypeError`.
2704-
1. If |newestWorker| is null, then [=map/remove=] [=scope to registration map=][|registration|'s [=service worker registration/scope url=], [[=URL serializer|serialized=]].
2708+
1. If |newestWorker| is null, then [=map/remove=] [=id to registration map=][|registration|'s [=service worker registration/id=]].
27052709
1. Invoke [=Finish Job=] with |job|.
27062710
1. Else, invoke [=Install=] algorithm with |job|, |worker|, and |registration| as its arguments.
27072711
</section>
@@ -2772,7 +2776,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
27722776
1. If |installFailed| is true, then:
27732777
1. Run the <a>Update Worker State</a> algorithm passing |registration|'s [=installing worker=] and "`redundant`" as the arguments.
27742778
1. Run the <a>Update Registration State</a> algorithm passing |registration|, "<code>installing</code>" and null as the arguments.
2775-
1. If |newestWorker| is null, then [=map/remove=] [=scope to registration map=][|registration|'s [=service worker registration/scope url=], [[=URL serializer|serialized=]].
2779+
1. If |newestWorker| is null, then [=map/remove=] [=id to registration map=][|registration|'s [=service worker registration/id=]].
27762780
1. Invoke <a>Finish Job</a> with |job| and abort these steps.
27772781
1. Let |map| be |registration|'s [=installing worker=]'s [=script resource map=].
27782782
1. Let |usedSet| be |registration|'s [=installing worker=]'s [=set of used scripts=].
@@ -3145,7 +3149,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
31453149
: Output
31463150
:: None
31473151

3148-
1. [=map/For each=] <var ignore>scope</var> → |registration| of <a>scope to registration map</a>:
3152+
1. [=map/For each=] <var ignore>id</var> → |registration| of <a>id to registration map</a>:
31493153
1. If |registration|'s <a>installing worker</a> |installingWorker| is not null, then:
31503154
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.
31513155
1. Else, set |installingWorker| to null.
@@ -3179,11 +3183,11 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
31793183
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:
31803184
1. Invoke [=Reject Job Promise=] with |job| and "{{SecurityError}}" {{DOMException}}.
31813185
1. Invoke <a>Finish Job</a> with |job| and abort these steps.
3182-
1. Let |registration| be the result of running <a>Get Registration</a> algorithm passing |job|'s [=job/scope url=] as the argument.
3186+
1. Let |registration| be the result of running <a>Get Registration</a> algorithm passing |job|'s [=job/id=] as the argument.
31833187
1. If |registration| is null, then:
31843188
1. Invoke <a>Resolve Job Promise</a> with |job| and false.
31853189
1. Invoke <a>Finish Job</a> with |job| and abort these steps.
3186-
1. [=map/Remove=] [=scope to registration map=][|job|'s [=job/scope url=]].
3190+
1. [=map/Remove=] [=id to registration map=][|job|'s [=job/id=]].
31873191
1. Invoke <a>Resolve Job Promise</a> with |job| and true.
31883192
1. Invoke [=Try Clear Registration=] with |registration|.
31893193

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

31983202
: Input
3203+
:: |id|, an [=service worker registration/id=]
31993204
:: |scope|, a [=/URL=]
32003205
:: |updateViaCache|, an [=service worker registration/update via cache mode=]
32013206
: Output
32023207
:: |registration|, a [=/service worker registration=]
32033208

32043209
1. Run the following steps atomically.
32053210
1. Let |scopeString| be [=URL serializer|serialized=] |scope| with the *exclude fragment flag* set.
3206-
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|.
3207-
1. [=map/Set=] <a>scope to registration map</a>[|scopeString|] to |registration|.
3211+
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|.
3212+
1. [=map/Set=] <a>id to registration map</a>[|id|] to |registration|.
32083213
1. Return |registration|.
32093214
</section>
32103215

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

33263335
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.
@@ -3329,22 +3338,21 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
33293338
1. If |matchingScopeString| is not the empty string, then:
33303339
1. Set |matchingScope| to the result of <a lt="URL parser">parsing</a> |matchingScopeString|.
33313340
1. Assert: |matchingScope|'s [=url/origin=] and |clientURL|'s [=url/origin=] are [=same origin=].
3332-
1. Return the result of running [=Get Registration=] algorithm passing |matchingScope| as the argument.
3341+
1. Let |matchingId| be |scopeMap|[|matchingScopeString|]'s [=service worker registration/id].
3342+
1. Return the result of running [=Get Registration=] algorithm passing |matchingId| as the argument.
33333343
</section>
33343344

33353345
<section algorithm>
33363346
<h3 id="get-registration-algorithm"><dfn>Get Registration</dfn></h3>
33373347

33383348
: Input
3339-
:: |scope|, a [=/URL=]
3349+
:: |id|, a [=service worker registration/id=]
33403350
: Output
33413351
:: A [=/service worker registration=]
33423352

33433353
1. Run the following steps atomically.
3344-
1. Let |scopeString| be the empty string.
3345-
1. If |scope| is not null, set |scopeString| to [=URL serializer|serialized=] |scope| with the *exclude fragment flag* set.
3346-
1. [=map/For each=] |key| → |value| of <a>scope to registration map</a>:
3347-
1. If |scopeString| matches |key|, then return |value|.
3354+
1. [=map/For each=] |key| → |value| of <a>id to registration map</a>:
3355+
1. If |id| matches |key|, then return |value|.
33483356
1. Return null.
33493357
</section>
33503358

0 commit comments

Comments
 (0)