Skip to content

Commit c92c148

Browse files
jakearchibaldjungkees
authored andcommitted
Changing useCache boolean to updateViaCache enum (#1107)
Changing useCache boolean to updateViaCache enum Issue: #1104. Tests: web-platform-tests/wpt#5515. HTML change: whatwg/html@b5fcec0.
1 parent 6281143 commit c92c148

File tree

4 files changed

+238
-156
lines changed

4 files changed

+238
-156
lines changed

docs/index.bs

+29-23
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
202202

203203
A [=/service worker registration=] has an associated <dfn export id="dfn-last-update-check-time">last update check time</dfn>. It is initially set to null.
204204

205-
A [=/service worker registration=] has an associated <dfn export id="dfn-use-cache">use cache</dfn> (a boolean). It is initially set to false.
205+
A [=/service worker registration=] has an associated <dfn export id="dfn-update-via-cache">update via cache mode</dfn>, which is "`imports`", "`all`", or "`none`". It is initially set to "`imports`".
206206

207207
A [=/service worker registration=] has an associated <dfn export id="dfn-uninstalling-flag">uninstalling flag</dfn>. It is initially unset.
208208

@@ -412,14 +412,20 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
412412
[SameObject] readonly attribute NavigationPreloadManager navigationPreload;
413413

414414
readonly attribute USVString scope;
415-
readonly attribute boolean useCache;
415+
readonly attribute ServiceWorkerUpdateViaCache updateViaCache;
416416

417417
[NewObject] Promise&lt;void&gt; update();
418418
[NewObject] Promise&lt;boolean&gt; unregister();
419419

420420
// event
421421
attribute EventHandler onupdatefound;
422422
};
423+
424+
enum ServiceWorkerUpdateViaCache {
425+
"imports",
426+
"all",
427+
"none"
428+
};
423429
</pre>
424430

425431
A {{ServiceWorkerRegistration}} object represents a [=/service worker registration=]. Each {{ServiceWorkerRegistration}} object is associated with a <dfn for="ServiceWorkerRegistration">service worker registration</dfn> (a [=/service worker registration=]). Multiple separate objects implementing the {{ServiceWorkerRegistration}} interface across documents and workers can all be associated with the same [=/service worker registration=] simultaneously.
@@ -464,10 +470,10 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
464470
</div>
465471
</section>
466472

467-
<section algorithm="service-worker-registration-usecache">
468-
<h4 id="service-worker-registration-usecache">{{ServiceWorkerRegistration/useCache}}</h4>
473+
<section algorithm="service-worker-registration-updateviacache">
474+
<h4 id="service-worker-registration-updateviacache">{{ServiceWorkerRegistration/updateViaCache}}</h4>
469475

470-
The <dfn attribute for="ServiceWorkerRegistration"><code>useCache</code></dfn> attribute *must* return [=ServiceWorkerRegistration/service worker registration=]'s [=service worker registration/use cache=].
476+
The <dfn attribute for="ServiceWorkerRegistration"><code>updateViaCache</code></dfn> attribute *must* return [=ServiceWorkerRegistration/service worker registration=]'s [=service worker registration/update via cache mode=].
471477
</section>
472478

473479
<section algorithm="service-worker-registration-update">
@@ -564,7 +570,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
564570
dictionary RegistrationOptions {
565571
USVString scope;
566572
WorkerType type = "classic";
567-
boolean useCache = false;
573+
ServiceWorkerUpdateViaCache updateViaCache = "imports";
568574
};
569575
</pre>
570576

@@ -624,7 +630,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
624630
1. Let |scriptURL| be the result of <a lt="URL parser">parsing</a> |scriptURL| with the <a>context object</a>'s <a>relevant settings object</a>'s <a>API base URL</a>.
625631
1. Let |scopeURL| be null.
626632
1. If |options|.{{RegistrationOptions/scope}} is <a>present</a>, set |scopeURL| to the result of <a lt="URL parser">parsing</a> |options|.{{RegistrationOptions/scope}} with the <a>context object</a>'s <a>relevant settings object</a>'s <a>API base URL</a>.
627-
1. Invoke [=Start Register=] with |scopeURL|, |scriptURL|, |p|, |client|, |client|'s <a>creation URL</a>, |options|.{{RegistrationOptions/type}}, and |options|.{{RegistrationOptions/useCache}}.
633+
1. Invoke [=Start Register=] with |scopeURL|, |scriptURL|, |p|, |client|, |client|'s <a>creation URL</a>, |options|.{{RegistrationOptions/type}}, and |options|.{{RegistrationOptions/updateViaCache}}.
628634
1. Return |p|.
629635
</section>
630636

@@ -1782,14 +1788,14 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
17821788
1. If the "<code>scope</code>" <a>target attribute</a> of the <code>Link</code> header is present, set |scopeURL| to the result of <a lt="URL parser">parsing</a> the "<code>scope</code>" <a>target attribute</a> with |scriptURL|.
17831789
1. Let |workerType| be the "<code>workertype</code>" <a>target attribute</a> of the <code>Link</code> header, or "<code>classic</code>" if no such attribute is present.
17841790
1. If |workerType| is not a valid {{WorkerType}} value, abort these steps.
1785-
1. Let |useCache| be true if the <code>Link</code> header has a <a>target attribute</a> named "<code>usecache</code>", otherwise false.
1786-
1. Invoke [=Start Register=] with |scopeURL|, |scriptURL|, a new <a>promise</a>, null, |contextURL|, |workerType|, and |useCache|.
1791+
1. Let |updateViaCache| be the "`updateviacache`" [=target attribute=] of the `Link` header, or "`imports`" if no such attribute is present.
1792+
1. Invoke [=Start Register=] with |scopeURL|, |scriptURL|, a new <a>promise</a>, null, |contextURL|, |workerType|, and |updateViaCache|.
17871793
</section>
17881794

17891795
<section>
17901796
<h3 id="link-element-processing">Processing the <{link}> element</h3>
17911797

1792-
When a <a>serviceworker link</a>'s <{link}> element is <a>inserted into a document</a>, or a <a>serviceworker link</a> is created on a <{link}> element that is already <a>in a document tree</a>, or the <{link/href}> or <{link/scope}> attributes of the <{link}> element of a <a>serviceworker link</a> is changed, the user agent *should* run these steps:
1798+
When a <a>serviceworker link</a>'s <{link}> element is <a>inserted into a document</a>, or a <a>serviceworker link</a> is created on a <{link}> element that is already <a>in a document tree</a>, or the <{link/href}>, <{link/scope}>, or <{link/updateviacache}> attributes of the <{link}> element of a <a>serviceworker link</a> is changed, the user agent *should* run these steps:
17931799

17941800
1. If the <{link/href}> attribute is the empty string, abort these steps.
17951801
1. Let |client| be the document's [=ServiceWorkerContainer/service worker client=].
@@ -1799,9 +1805,9 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
17991805
1. If the <{link/scope}> attribute is present, set |scopeURL| to the result of <a lt="URL parser">parsing</a> the <{link/scope}> attribute with the <{link}> element's <a>node document</a>'s <a>document base URL</a>.
18001806
1. Let |workerType| be the <{link/workertype}> attribute, or "<code>classic</code>" if the <{link/workertype}> attribute is omitted.
18011807
1. If |workerType| is not a valid {{WorkerType}} value, <a>queue a task</a> to <a>fire an event</a> named <code>error</code> at the <{link}> element, and abort these steps.
1802-
1. Let |useCache| be true if the <{link}> element has a <{link/usecache}> attribute, otherwise false.
1808+
1. Let |updateViaCache| be the <{link/updateviacache}> attribute, or "`imports`" if the <{link/updateviacache}> attribute is omitted.
18031809
1. Let |promise| be a new <a>promise</a>.
1804-
1. Invoke [=Start Register=] with |scopeURL|, |scriptURL|, |promise|, |client|, |client|'s <a>creation URL</a>, |workerType|, and |useCache|.
1810+
1. Invoke [=Start Register=] with |scopeURL|, |scriptURL|, |promise|, |client|, |client|'s <a>creation URL</a>, |workerType|, and |updateViaCache|.
18051811
1. Run the following substeps <a>in parallel</a>:
18061812
1. Wait until |promise| settles.
18071813
1. If |promise| rejected, <a>queue a task</a> to <a>fire an event</a> named <code>error</code> at the <{link}> element.
@@ -1838,15 +1844,15 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
18381844
partial interface HTMLLinkElement {
18391845
[CEReactions] attribute USVString scope;
18401846
[CEReactions] attribute WorkerType workerType;
1841-
[CEReactions] attribute boolean useCache;
1847+
[CEReactions] attribute ServiceWorkerUpdateViaCache updateViaCache;
18421848
};
18431849
</pre>
18441850

18451851
The <dfn attribute for="HTMLLinkElement" id="link-scope-attribute">scope</dfn> IDL attribute must <a>reflect</a> the element's <dfn element-attr for="link">scope</dfn> content attribute.
18461852

18471853
The <dfn attribute for="HTMLLinkElement" id="link-workertype-attribute">workerType</dfn> IDL attribute must <a>reflect</a> the element's <dfn element-attr for="link">workertype</dfn> content attribute.
18481854

1849-
The <dfn attribute for="HTMLLinkElement" id="link-usecache-attribute">useCache</dfn> IDL attribute must <a>reflect</a> the element's <dfn element-attr for="link">usecache</dfn> content attribute.
1855+
The <dfn attribute for="HTMLLinkElement" id="link-updateviacache-attribute">updateViaCache</dfn> IDL attribute must <a>reflect</a> the element's <dfn element-attr for="link">updateViaCache</dfn> content attribute.
18501856
</section>
18511857
</section>
18521858

@@ -2297,7 +2303,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
22972303
1. Let |registration| be |serviceWorker|'s [=containing service worker registration=].
22982304
1. Set |request|'s [=service-workers mode=] to "`foreign`".
22992305
1. Set |request|'s [=request/cache mode=] to "<code>no-cache</code>" if any of the following are true:
2300-
* |registration|'s [=service worker registration/use cache=] is false.
2306+
* |registration|'s [=service worker registration/update via cache mode=] is "`none`".
23012307
* The [=current global object=]'s [=force bypass cache for importscripts flag=] is set.
23022308
* |registration|'s [=last update check time=] is not null and the time difference in seconds calculated by the current time minus |registration|’s [=last update check time=] is greater than 86400.
23032309
1. Let |response| be the result of <a lt="fetch">fetching</a> |request|.
@@ -2413,7 +2419,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
24132419

24142420
A <a>job</a> has a <dfn id="dfn-job-worker-type">worker type</dfn> ("<code>classic</code>" or "<code>module</code>").
24152421

2416-
A <a>job</a> has a <dfn id="dfn-job-use-cache">use cache</dfn> (a boolean).
2422+
A <a>job</a> has an <dfn id="dfn-job-update-via-cache-mode">update via cache mode</dfn>, which is "`imports`", "`all`", or "`none`".
24172423

24182424
A <a>job</a> has a <dfn id="dfn-job-client">client</dfn> (a [=/service worker client=]). It is initially null.
24192425

@@ -2542,7 +2548,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
25422548
:: |client|, a [=/service worker client=]
25432549
:: |referrer|, a [=/URL=]
25442550
:: |workerType|, a <a>worker type</a>
2545-
:: |useCache|, a boolean
2551+
:: |updateViaCache|, an [=service worker registration/update via cache mode=]
25462552
: Output
25472553
:: none
25482554

@@ -2558,7 +2564,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
25582564
1. If any of the strings in |scopeURL|'s [=url/path=] contains either <a>ASCII case-insensitive</a> "<code>%2f</code>" or <a>ASCII case-insensitive</a> "<code>%5c</code>", reject |promise| with a <code>TypeError</code> and abort these steps.
25592565
1. Let |job| be the result of running [=Create Job=] with *register*, |scopeURL|, |scriptURL|, |promise|, and |client|.
25602566
1. Set |job|'s [=job/worker type=] to |workerType|.
2561-
1. Set |job|'s [=job/use cache=] to |useCache|.
2567+
1. Set |job|'s [=job/update via cache mode=] to |updateViaCache|.
25622568
1. Set |job|'s [=job/referrer=] to |referrer|.
25632569
1. Invoke [=Schedule Job=] with |job|.
25642570
</section>
@@ -2584,11 +2590,11 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
25842590
1. If |registration| is not null, then:
25852591
1. If |registration|'s <a>uninstalling flag</a> is set, unset it.
25862592
1. Let |newestWorker| be the result of running the <a>Get Newest Worker</a> algorithm passing |registration| as the argument.
2587-
1. If |newestWorker| is not null, |job|'s [=job/script url=] [=url/equals=] |newestWorker|'s [=service worker/script url=] with the *exclude fragments flag* set, and |job|'s [=job/use cache=]'s value equals |registration|'s [=service worker registration/use cache=]'s value, then:
2593+
1. If |newestWorker| is not null, |job|'s [=job/script url=] [=url/equals=] |newestWorker|'s [=service worker/script url=] with the *exclude fragments flag* set, and |job|'s [=job/update via cache mode=]'s value equals |registration|'s [=service worker registration/update via cache mode=], then:
25882594
1. Invoke <a>Resolve Job Promise</a> with |job| and the {{ServiceWorkerRegistration}} object which represents |registration|.
25892595
1. Invoke <a>Finish Job</a> with |job| and abort these steps.
25902596
1. Else:
2591-
1. Invoke <a>Set Registration</a> algorithm with |job|'s [=job/scope url=] and |job|'s [=job/use cache=].
2597+
1. Invoke <a>Set Registration</a> algorithm with |job|'s [=job/scope url=] and |job|'s [=job/update via cache mode=].
25922598
1. Invoke <a>Update</a> algorithm passing |job| as the argument.
25932599
</section>
25942600

@@ -2624,7 +2630,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
26242630
Note: See the definition of the Service-Worker header in Appendix B: Extended HTTP headers.
26252631

26262632
1. Set |request|'s [=request/cache mode=] to "<code>no-cache</code>" if any of the following are true:
2627-
* |registration|'s [=service worker registration/use cache=] is false.
2633+
* |registration|'s [=service worker registration/update via cache mode=] is not "`all`".
26282634
* |job|'s [=force bypass cache flag=] is set.
26292635
* |newestWorker| is not null, and |registration|'s [=last update check time=] is not null and the time difference in seconds calculated by the current time minus |registration|’s [=last update check time=] is greater than 86400.
26302636

@@ -3192,13 +3198,13 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
31923198

31933199
: Input
31943200
:: |scope|, a [=/URL=]
3195-
:: |useCache|, a boolean
3201+
:: |updateViaCache|, an [=service worker registration/update via cache mode=]
31963202
: Output
31973203
:: |registration|, a [=/service worker registration=]
31983204

31993205
1. Run the following steps atomically.
32003206
1. Let |scopeString| be <a lt="URL serializer">serialized</a> |scope| with the *exclude fragment flag* set.
3201-
1. Let |registration| be a new [=/service worker registration=] whose [=service worker registration/scope url=] is set to |scope| and [=service worker registration/use cache=] is set to |useCache|.
3207+
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|.
32023208
1. [=map/Set=] <a>scope to registration map</a>[|scopeString|] to |registration|.
32033209
1. Return |registration|.
32043210
</section>

0 commit comments

Comments
 (0)