diff --git a/spec/service_worker/index.bs b/spec/service_worker/index.bs index a6b14148..42cf6031 100644 --- a/spec/service_worker/index.bs +++ b/spec/service_worker/index.bs @@ -211,22 +211,17 @@ spec: html; urlPrefix: https://html.spec.whatwg.org/multipage/ text: classic script text: creation url text: dom manipulation task source - text: fetch a classic worker script - text: fetch a module script tree text: fire a simple event - text: https state + text: https state; for: environment settings object text: module script text: realm execution context text: report the error text: run a classic script text: run a module script text: script; url: concept-script - text: set up the request; url: fetching-scripts-set-up-request text: task queue; for: event loop - text: process the response; url: fetching-scripts-process-response urlPrefix: workers.html text: get a fetch result - text: https state text: import scripts into worker global scope text: kill a worker text: postprocess the fetch result @@ -328,7 +323,7 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/

A service worker has an associated id (an opaque string), which uniquely identifies itself during the lifetime of its containing service worker registration.

A service worker is dispatched a set of lifecycle events, install and activate, and functional events including fetch.

A service worker has an associated script resource (a script), which represents its own script resource. It is initially set to null. A script resource has an associated has ever been evaluated flag. It is initially unset. A script resource has an associated HTTPS state which is "none", "deprecated", or "modern". Unless stated otherwise, it is "none".

-

A service worker has an associated script resource map which is a List of the Record {\[[key]], \[[value]]} where \[[key]] is a URL and \[[value]] is a script resource.

+

A service worker has an associated script resource map which is a List of the Record {\[[key]], \[[value]]} where \[[key]] is a URL and \[[value]] is a response.

A service worker has an associated skip waiting flag. Unless stated otherwise it is unset.

A service worker has an associated imported scripts updated flag. It is initially unset.

A service worker has an associated set of event types to handle whose element type is an event listener's event type. It is initially set to null.

@@ -2781,43 +2776,29 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/

{{WorkerGlobalScope/importScripts(urls)}}

-

When the importScripts(urls) method is called on a {{ServiceWorkerGlobalScope}} object, the user agent must import scripts into worker global scope, with the following options:

- -

To validate the state, the user agent must do nothing.

- -

To get a fetch result, the user agent must run the following steps:

+

When the importScripts(urls) method is called on a {{ServiceWorkerGlobalScope}} object, the user agent must import scripts into worker global scope, given this {{ServiceWorkerGlobalScope}} object and urls, and with the following steps to perform the fetch given the request request:

    -
  1. Let serviceWorker be the settings object's global object's service worker.
  2. +
  3. Let serviceWorker be request's client's global object's service worker.
  4. If serviceWorker's imported scripts updated flag is unset, then:
      -
    1. Attempt to fetch each resource identified by the resulting absolute URLs, from the origin specified by settings object, using the referrer source specified by settings object, and with the blocking flag set.
    2. +
    3. Let response be the result of fetching request.
    4. +
    5. If response's unsafe response's type is not "error", and response's status is an ok status, then: +
        +
      1. If there exists a corresponding Record record for request's url in serviceWorker's script resource map, set record.\[[value]] to response.
      2. +
      3. Else, set a newly-created Record {\[[key]]: url, \[[value]]: response} to serviceWorker's script resource map.
      4. +
      +
    6. +
    7. Return response.
  5. Else:
      -
    1. If there exists a corresponding Record record for url in serviceWorker's script resource map, set the script resource to record.\[[value]].
    2. -
    3. Else, set the script resource to null.
    4. +
    5. If there exists a corresponding Record record for url in serviceWorker's script resource map, return record.\[[value]].
    6. +
    7. Else, return a network error.
- -

To postprocess the fetch result, the user agent must run the following steps:

- -
    -
  1. If serviceWorker's imported scripts updated flag is unset, then: -
      -
    1. If the fetching attempt failed (e.g. the server returned a 4xx or 5xx status code or equivalent, or there was a DNS error), throw a "{{NetworkError}}" exception and abort all these steps.
    2. -
    3. Else: -
        -
      1. If there exists a corresponding Record record for the resulting absolute URL url in serviceWorker's script resource map, set record.\[[value]] to the fetched script resource.
      2. -
      3. Else, set a newly-created Record {\[[key]]: url, \[[value]]: the fetched script resource} to serviceWorker's script resource map.
      4. -
      -
    4. -
    -
  2. -
  3. Else, if the script resource is null, throw a "{{NetworkError}}" exception and abort all these steps.
  4. -
@@ -3195,9 +3176,9 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
"classic"

Fetch a classic worker script given job’s serialized script url, job’s client, and "serviceworker".

"module"
-

Fetch a module script tree given job’s serialized script url, "omit", "serviceworker", and job’s client.

+

Fetch a module worker script tree given job’s serialized script url, job’s client, "serviceworker", "omit", and the to-be-created environment settings object for this service worker.

-

To set up the request given request, run the following steps:

+

To perform the fetch given request, run the following steps if the is top-level flag is set:

  1. Append `Service-Worker`/`script` to request's header list.

    See the definition of the Service-Worker header in Appendix B: Extended HTTP headers.

    @@ -3209,15 +3190,11 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/

Even if the cache mode is not set to "reload", the user agent obeys Cache-Control header's max-age value in the network layer to determine if it should bypass the browser cache.

- -

To process the response given response, run the following steps:

-
    +
  1. Fetch request, and asynchronously wait to run the remaining steps as part of fetch's process response for the response response.
  2. Extract a MIME type from the response's header list. If this MIME type (ignoring parameters) is not one of text/javascript, application/x-javascript, and application/javascript, then:
    1. Invoke Reject Job Promise with job and a "{{SecurityError}}" exception.
    2. -
    3. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument.
    4. -
    5. Invoke Finish Job with job.
    6. -
    7. Return false and abort these steps.
    8. +
    9. Asynchronously complete these steps with a network error.
  3. Let serviceWorkerAllowed be the result of parsing `Service-Worker-Allowed` in response's header list. @@ -3225,10 +3202,7 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
  4. If serviceWorkerAllowed is failure, then:
      -
    1. Invoke Reject Job Promise with job and a TypeError.
    2. -
    3. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument.
    4. -
    5. Invoke Finish Job with job.
    6. -
    7. Return false and abort these steps.
    8. +
    9. Asynchronously complete these steps with a network error.
  5. Let scopeURL be registration's scope url.
  6. @@ -3249,9 +3223,7 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
  7. Else:
    1. Invoke Reject Job Promise with job and a "{{SecurityError}}" exception.
    2. -
    3. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument.
    4. -
    5. Invoke Finish Job with job.
    6. -
    7. Return false and abort these steps.
    8. +
    9. Asynchronously complete these steps with a network error.
  8. If response's cache state is not "local", set registration's last update check time to the current time.
  9. @@ -3259,7 +3231,11 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/

If the algorithm asynchronously completes with null, then:

    -
  1. Invoke Reject Job Promise with job and a TypeError.
  2. +
  3. +

    Invoke Reject Job Promise with job and a TypeError.

    + +

    This will do nothing if Reject Job Promise was previously invoked with a "{{SecurityError}}" exception.

    +
  4. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument.
  5. Invoke Finish Job with job and abort these steps.
@@ -3495,11 +3471,11 @@ spec: webidl; urlPrefix: https://heycam.github.io/webidl/
Return UTF-8.
The API base URL
Return serviceWorker's script url.
-
The origin and effective script origin
+
The origin
Return its registering service worker client's origin.
The creation URL
Return workerGlobalScope's url.
-
The HTTPS state
+
The HTTPS state
Return workerGlobalScope's HTTPS state.
diff --git a/spec/service_worker/index.html b/spec/service_worker/index.html index 6cedb866..9b846ae6 100644 --- a/spec/service_worker/index.html +++ b/spec/service_worker/index.html @@ -1399,7 +1399,7 @@

Service Workers Nightly

-

Editor’s Draft,

+

Editor’s Draft,

This version: @@ -1736,7 +1736,7 @@

A service worker has an associated id (an opaque string), which uniquely identifies itself during the lifetime of its containing service worker registration.

A service worker is dispatched a set of lifecycle events, install and activate, and functional events including fetch.

A service worker has an associated script resource (a script), which represents its own script resource. It is initially set to null. A script resource has an associated has ever been evaluated flag. It is initially unset. A script resource has an associated HTTPS state which is "none", "deprecated", or "modern". Unless stated otherwise, it is "none".

-

A service worker has an associated script resource map which is a List of the Record {[[key]], [[value]]} where [[key]] is a URL and [[value]] is a script resource.

+

A service worker has an associated script resource map which is a List of the Record {[[key]], [[value]]} where [[key]] is a URL and [[value]] is a response.

A service worker has an associated skip waiting flag. Unless stated otherwise it is unset.

A service worker has an associated imported scripts updated flag. It is initially unset.

A service worker has an associated set of event types to handle whose element type is an event listener’s event type. It is initially set to null.

@@ -1813,7 +1813,7 @@

3. Client Context

Bootstrapping with a ServiceWorker: -
// scope defaults to the path the script sits in
+
// scope defaults to the path the script sits in
 // "/" in this example
 navigator.serviceWorker.register("/serviceworker.js").then(
   function(registration) {
@@ -1856,7 +1856,7 @@ 

For example, consider a document created by a navigation to https://example.com/app.html which matches via the following registration call which has been previously executed:

-
// Script on the page https://example.com/app.html
+
// Script on the page https://example.com/app.html
 navigator.serviceWorker.register("/service_worker.js", { scope: "/" });
 

The value of navigator.serviceWorker.controller.scriptURL will be "https://example.com/service_worker.js".

@@ -2245,7 +2245,7 @@

4. Execution Context

Serving Cached Resources: -
// caching.js
+
// caching.js
 this.addEventListener("install", function(e) {
   e.waitUntil(
     // Open a cache of resources.
@@ -3171,10 +3171,10 @@ 

has more or less the same effect as a document being loaded in a secure context with the following link element:

-
<link rel="serviceworker" href="/js/sw.js" scope="/">
+
<link rel="serviceworker" href="/js/sw.js" scope="/">
 

which is more or less equivalent to the page containing javascript code like:

-
navigator.serviceworker.register("/js/sw.js", { scope: "/" });
+
navigator.serviceworker.register("/js/sw.js", { scope: "/" });
 
@@ -3791,37 +3791,27 @@

7.3.2. importScripts(urls)

-

When the importScripts(urls) method is called on a ServiceWorkerGlobalScope object, the user agent must import scripts into worker global scope, with the following options:

-

To validate the state, the user agent must do nothing.

-

To get a fetch result, the user agent must run the following steps:

+

When the importScripts(urls) method is called on a ServiceWorkerGlobalScope object, the user agent must import scripts into worker global scope, given this ServiceWorkerGlobalScope object and urls, and with the following steps to perform the fetch given the request request:

    -
  1. Let serviceWorker be the settings object’s global object’s service worker. +
  2. Let serviceWorker be request’s client’s global object’s service worker.
  3. If serviceWorker’s imported scripts updated flag is unset, then:
      -
    1. Attempt to fetch each resource identified by the resulting absolute URLs, from the origin specified by settings object, using the referrer source specified by settings object, and with the blocking flag set. +
    2. Let response be the result of fetching request. +
    3. + If response’s unsafe response’s type is not "error", and response’s status is an ok status, then: +
        +
      1. If there exists a corresponding Record record for request’s url in serviceWorker’s script resource map, set record.[[value]] to response. +
      2. Else, set a newly-created Record {[[key]]: url, [[value]]: response} to serviceWorker’s script resource map. +
      +
    4. Return response.
  4. Else:
      -
    1. If there exists a corresponding Record record for url in serviceWorker’s script resource map, set the script resource to record.[[value]]. -
    2. Else, set the script resource to null. -
    -
-

To postprocess the fetch result, the user agent must run the following steps:

-
    -
  1. - If serviceWorker’s imported scripts updated flag is unset, then: -
      -
    1. If the fetching attempt failed (e.g. the server returned a 4xx or 5xx status code or equivalent, or there was a DNS error), throw a "NetworkError" exception and abort all these steps. -
    2. - Else: -
        -
      1. If there exists a corresponding Record record for the resulting absolute URL url in serviceWorker’s script resource map, set record.[[value]] to the fetched script resource. -
      2. Else, set a newly-created Record {[[key]]: url, [[value]]: the fetched script resource} to serviceWorker’s script resource map. -
      +
    3. If there exists a corresponding Record record for url in serviceWorker’s script resource map, return record.[[value]]. +
    4. Else, return a network error.
    -
  2. Else, if the script resource is null, throw a "NetworkError" exception and abort all these steps.
@@ -3875,7 +3865,7 @@

9.3. Define Event Handler

-

Specifications may define an event handler attribute for the corresponding functional event using partial interface definition to the ServiceWorkerGlobalScope interface:

+

Specifications may define an event handler attribute for the corresponding functional event using partial interface definition to the ServiceWorkerGlobalScope interface:

partial interface ServiceWorkerGlobalScope {
   attribute EventHandler onfunctionalevent;
 };
@@ -3884,7 +3874,7 @@ 

9.4. Request Functional Event Dispatch

To request a functional event dispatch to a service worker, specifications may invoke Handle Functional Event algorithm, or its equivalent, with its service worker registration registration and the algorithm callbackSteps as the arguments.

-

Specifications may define an algorithm callbackSteps where the corresponding functional event can be created and fired with specification specific objects. The algorithm is passed globalObject (a ServiceWorkerGlobalScope object) at which it may fire its functional events. This algorithm is called on a task queued by Handle Functional Event algorithm.

+

Specifications may define an algorithm callbackSteps where the corresponding functional event can be created and fired with specification specific objects. The algorithm is passed globalObject (a ServiceWorkerGlobalScope object) at which it may fire its functional events. This algorithm is called on a task queued by Handle Functional Event algorithm.

See an example hook defined in Notifications API.

@@ -4138,12 +4128,12 @@

Update
"classic"
-

Fetch a classic worker script given job’s serialized script url, job’s client, and "serviceworker".

+

Fetch a classic worker script given job’s serialized script url, job’s client, and "serviceworker".

"module"
-

Fetch a module script tree given job’s serialized script url, "omit", "serviceworker", and job’s client.

+

Fetch a module worker script tree given job’s serialized script url, job’s client, "serviceworker", "omit", and the to-be-created environment settings object for this service worker.

-

To set up the request given request, run the following steps:

+

To perform the fetch given request, run the following steps if the is top-level flag is set:

  1. Append `Service-Worker`/`script` to request’s header list. @@ -4155,16 +4145,12 @@

    UpdateIf the time difference in seconds calculated by the current time minus registration’s last update check time is greater than 86400, or force bypass cache flag is set, set request’s cache mode to "reload".

Even if the cache mode is not set to "reload", the user agent obeys Cache-Control header’s max-age value in the network layer to determine if it should bypass the browser cache.

- -

To process the response given response, run the following steps:

-
    +
  1. Fetch request, and asynchronously wait to run the remaining steps as part of fetch’s process response for the response response.
  2. Extract a MIME type from the response’s header list. If this MIME type (ignoring parameters) is not one of text/javascript, application/x-javascript, and application/javascript, then:
    1. Invoke Reject Job Promise with job and a "SecurityError" exception. -
    2. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument. -
    3. Invoke Finish Job with job. -
    4. Return false and abort these steps. +
    5. Asynchronously complete these steps with a network error.
  3. Let serviceWorkerAllowed be the result of parsing `Service-Worker-Allowed` in response’s header list. @@ -4172,10 +4158,7 @@

    Update If serviceWorkerAllowed is failure, then:
      -
    1. Invoke Reject Job Promise with job and a TypeError. -
    2. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument. -
    3. Invoke Finish Job with job. -
    4. Return false and abort these steps. +
    5. Asynchronously complete these steps with a network error.
  4. Let scopeURL be registration’s scope url.
  5. Let maxScopeString be null. @@ -4196,16 +4179,16 @@

    Update
  6. Invoke Reject Job Promise with job and a "SecurityError" exception. -
  7. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument. -
  8. Invoke Finish Job with job. -
  9. Return false and abort these steps. +
  10. Asynchronously complete these steps with a network error.
  • If response’s cache state is not "local", set registration’s last update check time to the current time.
  • Return true.

    If the algorithm asynchronously completes with null, then:

      -
    1. Invoke Reject Job Promise with job and a TypeError. +
    2. +

      Invoke Reject Job Promise with job and a TypeError.

      +

      This will do nothing if Reject Job Promise was previously invoked with a "SecurityError" exception.

    3. If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument.
    4. Invoke Finish Job with job and abort these steps.
    @@ -4315,7 +4298,7 @@

    In
  • If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument.
  • Invoke Finish Job with job and abort these steps. -
  • Set registration’s installing worker’s imported scripts updated flag. +
  • Set registration’s installing worker’s imported scripts updated flag.
  • If registration’s waiting worker is not null, then:
      @@ -4410,7 +4393,7 @@

      InitializeHostDefinedRealm() abstract operation with the following customizations:
    1. Let workerEventLoop be a newly created event loop. @@ -4431,7 +4414,7 @@

      API base URL
      Return serviceWorker’s script url. -
      The origin and effective script origin +
      The origin
      Return its registering service worker client’s origin.
      The creation URL
      Return workerGlobalScope’s url. @@ -5248,7 +5231,7 @@

      Default scope: -
      // Maximum allowed scope defaults to the path the script sits in
      +
      // Maximum allowed scope defaults to the path the script sits in
       // "/js" in this example
       navigator.serviceWorker.register("/js/sw.js").then(function() {
         console.log("Install succeeded with the default scope '/js'.");
      @@ -5257,7 +5240,7 @@ 

      Upper path without Service-Worker-Allowed header: -
      // Set the scope to an upper path of the script location
      +
      // Set the scope to an upper path of the script location
       // Response has no Service-Worker-Allowed header
       navigator.serviceWorker.register("/js/sw.js", { scope: "/" }).catch(function() {
         console.error("Install failed due to the path restriction violation.");
      @@ -5266,7 +5249,7 @@ 

      Upper path with Service-Worker-Allowed header: -
      // Set the scope to an upper path of the script location
      +
      // Set the scope to an upper path of the script location
       // Response included "Service-Worker-Allowed : /"
       navigator.serviceWorker.register("/js/sw.js", { scope: "/" }).then(function() {
         console.log("Install succeeded as the max allowed scope was overriden to '/'.");
      @@ -5275,7 +5258,7 @@ 

      A path restriction voliation even with Service-Worker-Allowed header: -
      // Set the scope to an upper path of the script location
      +
      // Set the scope to an upper path of the script location
       // Response included "Service-Worker-Allowed : /foo"
       navigator.serviceWorker.register("/foo/bar/sw.js", { scope: "/" }).catch(function() {
         console.error("Install failed as the scope is still out of the overriden maximum allowed scope.");
      @@ -5838,7 +5821,7 @@ 

      readablestream
    2. redirect mode
    3. request -
    4. response +
    5. response
    6. skip service worker flag
    7. status
    8. stream @@ -5886,11 +5869,8 @@

      event loops
    9. exceptions enabled flag
    10. external resource link -
    11. fetch a classic worker script -
    12. fetch a module script tree
    13. fire a simple event
    14. focusing steps -
    15. get a fetch result
    16. global object
    17. has focus steps
    18. href @@ -5908,8 +5888,6 @@

      nested browsing contexts
    19. origin
    20. parent browsing context -
    21. postprocess the fetch result -
    22. process the response
    23. queue a task
    24. realm execution context
    25. relevant settings object @@ -5923,7 +5901,6 @@

      runtime script errors handling
    26. same origin
    27. script -
    28. set up the request
    29. shared workers
    30. source browsing context
    31. structuredclonewithtransfer @@ -5941,7 +5918,6 @@

      unload a document
    32. url
    33. user interaction task source -
    34. validate the state
    35. web worker
    36. @@ -6004,7 +5980,6 @@

    37. InvalidAccessError
    38. InvalidStateError -
    39. NetworkError
    40. QuotaExceededError
    41. SecurityError
    42. USVString @@ -6049,7 +6024,7 @@

      N
      [WHATWG-DOM]
      Anne van Kesteren. DOM Standard. Living Standard. URL: https://dom.spec.whatwg.org/
      [WHATWG-URL] -
      Anne van Kesteren; Sam Ruby. URL Standard. Living Standard. URL: https://url.spec.whatwg.org/ +
      Anne van Kesteren. URL Standard. Living Standard. URL: https://url.spec.whatwg.org/

      Informative References

      @@ -6500,8 +6475,8 @@

      #dfn-imported-scripts-updated-flagReferenced in: