To fire an "`amazingthing`" event (which is of type `AmazingThingEvent`) on a particular |serviceWorkerRegistration|, and initialize the event object's properties, the prose would be:
diff --git a/docs/v1/index.bs b/docs/v1/index.bs
index 1062a359..acfe6bc5 100644
--- a/docs/v1/index.bs
+++ b/docs/v1/index.bs
@@ -197,6 +197,8 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
A [=/service worker registration=] has an associated
last update check time. It is initially set to null.
+ A [=/service worker registration=] is said to be
stale if the registration's [=last update check time=] is non-null and the time difference in seconds calculated by the current time minus the registration's [=last update check time=] is greater than 86400.
+
A [=/service worker registration=] has an associated
update via cache mode, which is "`imports`", "`all`", or "`none`". It is initially set to "`imports`".
A [=/service worker registration=] has an associated
uninstalling flag. It is initially unset.
@@ -347,6 +349,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
1. If the {{ServiceWorker/state}} attribute value of the
context object is {{"redundant"}}, [=throw=] an "{{InvalidStateError}}" {{DOMException}}.
1. Let |serviceWorker| be the [=/service worker=] represented by the
context object.
+ 1. If the result of running the [=Should Skip Event=] algorithm with "message" and |serviceWorker|, is true, then return.
1. Invoke
Run Service Worker algorithm with |serviceWorker| as the argument.
1. Let |incumbentSettings| be the
incumbent settings object, and |incumbentGlobal| its [=environment settings object/global object=].
1. Let |serializeWithTransferResult| be
StructuredSerializeWithTransfer(|message|, |transfer|). Rethrow any exceptions.
@@ -1983,7 +1986,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
1. Set |request|'s [=request/cache mode=] to "`no-cache`" if any of the following are true:
* |registration|'s [=service worker registration/update via cache mode=] is "`none`".
* The [=current global object=]'s [=force bypass cache for importscripts flag=] is set.
- * |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.
+ * |registration| is [=stale=].
1. Let |response| be the result of [=fetch|fetching=] |request|.
1. Set |response| to |response|'s [=unsafe response=].
1. If |response|’s [=response/cache state=] is not "`local`", set |registration|’s [=service worker registration/last update check time=] to the current time.
@@ -2312,7 +2315,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
1. Set |request|'s [=request/cache mode=] to "
no-cache
" if any of the following are true:
* |registration|'s [=service worker registration/update via cache mode=] is not "`all`".
* |job|'s [=force bypass cache flag=] is set.
- * |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.
+ * |newestWorker| is not null and |registration| is [=stale=].
Note: Even if the cache mode is not set to "
no-cache
", the user agent obeys Cache-Control header's max-age value in the network layer to determine if it should bypass the browser cache.
@@ -2352,7 +2355,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
1. Set |request|'s [=request/cache mode=] to "`no-cache`" if any of the following are true:
* |registration|'s [=service worker registration/update via cache mode=] is "`none`".
* |job|'s [=force bypass cache flag=] is set.
- * |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.
+ * |registration| is [=stale=].
1. Let |fetchedResponse| be the result of [=fetch|fetching=] |request|.
1. Set |fetchedResponse| to |fetchedResponse|'s [=unsafe response=].
1. Set |updatedResourceMap|[|request|'s [=request/url=]] to |fetchedResponse|.
@@ -2431,19 +2434,20 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
1. Invoke [=Resolve Job Promise=] with |job| and |registration|.
1.
Queue a task to
fire an event named
updatefound
at all the {{ServiceWorkerRegistration}} objects for all the [=/service worker clients=] whose
creation URL matches |registration|'s [=service worker registration/scope url=] and all the [=/service workers=] whose
containing service worker registration is |registration|.
1. Let |installingWorker| be |registration|'s
installing worker.
- 1. Invoke
Run Service Worker algorithm given |installingWorker|, and with the *force bypass cache for importscripts flag* set if |job|'s [=job/force bypass cache flag=] is set.
- 1.
Queue a task |task| to run the following substeps:
- 1. Let |e| be the result of
creating an event with {{ExtendableEvent}}.
- 1. Initialize |e|’s {{Event/type}} attribute to {{install!!event}}.
- 1.
Dispatch |e| at |installingWorker|'s [=service worker/global object=].
- 1. *WaitForAsynchronousExtensions*: Run the following substeps
in parallel:
- 1.
Wait until |e| is not [=ExtendableEvent/active=].
- 1. If |e|'s [=ExtendableEvent/timed out flag=] is set, or the result of [=waiting for all=] of |e|'s [=extend lifetime promises=] rejected, set |installFailed| to true.
-
- If |task| is discarded or the script has been aborted by the
termination of |installingWorker|, set |installFailed| to true.
-
- 1. Wait for |task| to have executed or been discarded.
- 1. Wait for the step labeled *WaitForAsynchronousExtensions* to complete.
+ 1. If the result of running the [=Should Skip Event=] algorithm with |installingWorker| and "install" is false, then:
+ 1. Invoke
Run Service Worker algorithm given |installingWorker|, and with the *force bypass cache for importscripts flag* set if |job|'s [=job/force bypass cache flag=] is set.
+ 1.
Queue a task |task| to run the following substeps:
+ 1. Let |e| be the result of
creating an event with {{ExtendableEvent}}.
+ 1. Initialize |e|’s {{Event/type}} attribute to {{install!!event}}.
+ 1.
Dispatch |e| at |installingWorker|'s [=service worker/global object=].
+ 1. *WaitForAsynchronousExtensions*: Run the following substeps
in parallel:
+ 1.
Wait until |e| is not [=ExtendableEvent/active=].
+ 1. If |e|'s [=ExtendableEvent/timed out flag=] is set, or the result of [=waiting for all=] of |e|'s [=extend lifetime promises=] rejected, set |installFailed| to true.
+
+ If |task| is discarded or the script has been aborted by the
termination of |installingWorker|, set |installFailed| to true.
+
+ 1. Wait for |task| to have executed or been discarded.
+ 1. Wait for the step labeled *WaitForAsynchronousExtensions* to complete.
1. If |installFailed| is true, then:
1. Run the
Update Worker State algorithm passing |registration|'s [=installing worker=] and *redundant* as the arguments.
1. Run the
Update Registration State algorithm passing |registration|, "
installing
" and null as the arguments.
@@ -2494,14 +2498,15 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
1. Set |client|'s
active worker to |registration|'s
active worker.
1. Invoke
Notify Controller Change algorithm with |client| as the argument.
1. Let |activeWorker| be |registration|'s
active worker.
- 1. Invoke
Run Service Worker algorithm with |activeWorker| as the argument.
- 1.
Queue a task |task| to run the following substeps:
- 1. Let |e| be the result of
creating an event with {{ExtendableEvent}}.
- 1. Initialize |e|’s {{Event/type}} attribute to {{activate!!event}}.
- 1.
Dispatch |e| at |activeWorker|'s [=service worker/global object=].
- 1.
*WaitForAsynchronousExtensions*: Wait, [=in parallel=], until |e| is not [=ExtendableEvent/active=].
- 1. Wait for |task| to have executed or been discarded, or the script to have been aborted by the
termination of |activeWorker|.
- 1. Wait for the step labeled *WaitForAsynchronousExtensions* to complete.
+ 1. If the result of running the [=Should Skip Event=] algorithm with |activeWorker| and "activate" is false, then:
+ 1. Invoke
Run Service Worker algorithm with |activeWorker| as the argument.
+ 1.
Queue a task |task| to run the following substeps:
+ 1. Let |e| be the result of
creating an event with {{ExtendableEvent}}.
+ 1. Initialize |e|’s {{Event/type}} attribute to {{activate!!event}}.
+ 1.
Dispatch |e| at |activeWorker|'s [=service worker/global object=].
+ 1.
*WaitForAsynchronousExtensions*: Wait, [=in parallel=], until |e| is not [=ExtendableEvent/active=].
+ 1. Wait for |task| to have executed or been discarded, or the script to have been aborted by the
termination of |activeWorker|.
+ 1. Wait for the step labeled *WaitForAsynchronousExtensions* to complete.
1. Run the
Update Worker State algorithm passing |registration|'s
active worker and *activated* as the arguments.
@@ -2606,7 +2611,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
Handle Fetch
- The Handle Fetch algorithm is the entry point for the [=/fetch=] handling handed to the [=/service worker=] context.
+ The [=Handle Fetch=] algorithm is the entry point for the [=/fetch=] handling handed to the [=/service worker=] context.
: Input
:: |request|, a [=/request=]
@@ -2642,13 +2647,12 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
1. If |client|'s active service worker is non-null, set |registration| to |client|'s active service worker's containing service worker registration.
1. Else, return null.
1. Let |activeWorker| be |registration|'s active worker.
- 1. If |activeWorker|'s set of event types to handle does not [=set/contain=] fetch
, then:
- 1. Return null and continue running these steps in parallel.
- 1. If |request| is a non-subresource request, or |request| is a subresource request and the time difference in seconds calculated by the current time minus |registration|'s last update check time is greater than 86400, invoke Soft Update algorithm with |registration|.
- 1. Abort these steps.
-
- Note: To avoid unnecessary delays, the Handle Fetch enforces early return when no event listeners have been deterministically added in the service worker's global during the very first script execution.
-
+ 1. Let |shouldSoftUpdate| be true if any of the following are true, and false otherwise:
+ * |request| is a [=non-subresource request=].
+ * |request| is a [=subresource request=] and |registration| is [=stale=].
+ 1. If the result of running the [=Should Skip Event=] algorithm with "fetch" and |activeWorker| is true, then:
+ 1. If |shouldSoftUpdate| is true, then [=in parallel=] run the [=Soft Update=] algorithm with |registration|.
+ 1. Return.
1. If |activeWorker|'s state is *activating*, wait for |activeWorker|'s state to become *activated*.
1. Invoke Run Service Worker algorithm with |activeWorker| as the argument.
1. Queue a task |task| to run the following substeps:
@@ -2671,17 +2675,24 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
The |task| *must* use |activeWorker|'s event loop and the handle fetch task source.
1. Wait for |task| to have executed or been discarded.
- 1. If |respondWithEntered| is false, then:
- 1. If |eventCanceled| is true, return a network error and continue running these steps in parallel.
- 1. Else, return null and continue running these steps in parallel.
- 1. If |request| is a non-subresource request, or |request| is a subresource request and the time difference in seconds calculated by the current time minus |registration|'s last update check time is greater than 86400, invoke Soft Update algorithm with |registration|.
- 1. Abort these steps.
- 1. If |handleFetchFailed| is true, then:
- 1. Return a network error and continue running these steps in parallel.
- 1. If |request| is a non-subresource request, or |request| is a subresource request and the time difference in seconds calculated by the current time minus |registration|'s last update check time is greater than 86400, invoke Soft Update algorithm with |registration|.
- 1. Else:
- 1. Return |response| and continue running these steps in parallel.
- 1. If |request| is a non-subresource request, or |request| is a subresource request and the time difference in seconds calculated by the current time minus |registration|'s last update check time is greater than 86400, invoke Soft Update algorithm with |registration|.
+ 1. If |shouldSoftUpdate| is true, then [=in parallel=] run the [=Soft Update=] algorithm with |registration|.
+ 1. If |respondWithEntered| is false, then return a [=network error=] if |eventCanceled| is true and null otherwise.
+ 1. If |handleFetchFailed| is true, then return a [=network error=].
+ 1. Return |response|.
+
+
+
+ Should Skip Event
+ : Input
+ :: |eventName|, a string
+ :: |serviceWorker|, a [=/service worker=]
+ : Output
+ :: a boolean
+
+ Note: To avoid unnecessary delays, this specification permits skipping event dispatch when no event listeners for the event have been deterministically added in the service worker's global during the very first script execution.
+
+ 1. If |serviceWorker|'s [=set of event types to handle=] does not [=set/contain=] |eventName|, then the user agent *may* return true.
+ 1. Return false.
@@ -2699,12 +2710,9 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
1. Assert: [=scope to registration map=] contains a value equal to |registration|.
1. Assert: |registration|'s [=active worker=] is not null.
1. Let |activeWorker| be |registration|'s [=active worker=].
- 1. If |activeWorker|'s [=set of event types to handle=] does not [=set/contain=] |eventName|, then return and run the following steps [=in parallel=]:
- 1. If the time difference in seconds calculated by the current time minus |registration|'s [=last update check time=] is greater than 86400, invoke [=Soft Update=] algorithm with |registration|.
- 1. Abort these steps.
-
- Note: To avoid unnecessary delays, the Handle Functional Event enforces early return when no event listeners have been deterministically added in the service worker's global during the very first script execution.
-
+ 1. If the result of running [=Should Skip Event=] with |eventName| and |activeWorker| is true, then:
+ 1. If |registration| is [=stale=], then [=in parallel=] run the [=Soft Update=] algorithm with |registration|.
+ 2. Return.
1. If |activeWorker|'s [=state=] is *activating*, wait for |activeWorker|'s [=state=] to become *activated*.
1. Invoke [=Run Service Worker=] algorithm with |activeWorker| as the argument.
1. [=Queue a task=] |task| to run these substeps:
@@ -2717,7 +2725,7 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
The |task| *must* use |activeWorker|'s [=event loop=] and the [=handle functional event task source=].
1. Wait for |task| to have executed or been discarded.
- 1. If the time difference in seconds calculated by the current time minus |registration|'s [=last update check time=] is greater than 86400, invoke [=Soft Update=] algorithm with |registration|.
+ 1. If |registration| is [=stale=], then [=in parallel=] run the [=Soft Update=] algorithm with |registration|.
To fire an "`amazingthing`" event (which is of type `AmazingThingEvent`) on a particular |serviceWorkerRegistration|, and initialize the event object's properties, the prose would be: