From a27906065ca5ebf90978e94b546dce5315210e5d Mon Sep 17 00:00:00 2001 From: Jungkee Song Date: Thu, 3 Nov 2016 15:08:08 +0900 Subject: [PATCH] Improve clients.claim() Embrace the recently added environment concept in enumerating service worker clients. Related commit: https://github.com/w3c/ServiceWorker/commit/8b483b091e0f0bae6b698cf05d915c2029748ae0 --- docs/index.bs | 16 +++++++-- docs/index.html | 85 ++++++++++++++++++++++++++-------------------- docs/v1/index.bs | 16 +++++++-- docs/v1/index.html | 81 ++++++++++++++++++++++++------------------- 4 files changed, 120 insertions(+), 78 deletions(-) diff --git a/docs/index.bs b/docs/index.bs index 106040b9..f1c588c8 100644 --- a/docs/index.bs +++ b/docs/index.bs @@ -1447,14 +1447,24 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231
  • Run the following substeps in parallel:
    1. For each service worker client client whose origin is the same as the service worker's origin: +

      For environment type clients, the environment's creation URL's origin should be used for the origin check instead of the client's origin. See the issue to define the environment's origin algorithm.

        -
      1. If client is not a secure context, continue to the next iteration of the loop.
      2. +
      3. If client is a type of environment, then: +
          +
        1. If client’s creation URL is not a potentially trustworthy URL, continue to the next iteration of the loop.
        2. +
        +
      4. +
      5. Else: +
          +
        1. If client is not a secure context, continue to the next iteration of the loop.
        2. +
        +
      6. Let registration be the result of running Match Service Worker Registration algorithm passing client's creation URL as the argument.
      7. If registration is not the service worker's containing service worker registration, continue to the next iteration of the loop.
      8. -
      9. If client's active worker is not the service worker, then: +
      10. If client's active service worker is not the service worker, then:
        1. Invoke Handle Service Worker Client Unload with client as the argument.
        2. -
        3. Set client's active worker to service worker.
        4. +
        5. Set client's active service worker to service worker.
        6. Invoke Notify Controller Change algorithm with client as the argument.
      11. diff --git a/docs/index.html b/docs/index.html index dde500c6..7604ba0b 100644 --- a/docs/index.html +++ b/docs/index.html @@ -2735,15 +2735,25 @@

        service worker client client whose origin is the same as the service worker’s origin: +

        For environment type clients, the environment’s creation URL’s origin should be used for the origin check instead of the client’s origin. See the issue to define the environment’s origin algorithm.

          -
        1. If client is not a secure context, continue to the next iteration of the loop. +
        2. + If client is a type of environment, then: +
            +
          1. If client’s creation URL is not a potentially trustworthy URL, continue to the next iteration of the loop. +
          +
        3. + Else: +
            +
          1. If client is not a secure context, continue to the next iteration of the loop. +
        4. Let registration be the result of running Match Service Worker Registration algorithm passing client’s creation URL as the argument.
        5. If registration is not the service worker’s containing service worker registration, continue to the next iteration of the loop.
        6. - If client’s active worker is not the service worker, then: + If client’s active service worker is not the service worker, then:
          1. Invoke Handle Service Worker Client Unload with client as the argument. -
          2. Set client’s active worker to service worker. +
          3. Set client’s active service worker to service worker.
          4. Invoke Notify Controller Change algorithm with client as the argument.
        @@ -2800,7 +2810,7 @@

        Service workers define the following behaviors for install event and activate event, respectively:

        @@ -3193,7 +3203,7 @@

        activate ExtendableEvent - [Lifecycle event] The service worker’s containing service worker registration’s active worker changes. (See step 12.2 of the Activate algorithm.) + [Lifecycle event] The service worker’s containing service worker registration’s active worker changes. (See step 12.2 of the Activate algorithm.) fetch FetchEvent @@ -4394,16 +4404,16 @@

        Acti
      12. If registration’s waiting worker is null, abort these steps.
      13. Let redundantWorker be null.
      14. - If registration’s active worker is not null, then: + If registration’s active worker is not null, then:
          -
        1. Set redundantWorker to registration’s active worker. +
        2. Set redundantWorker to registration’s active worker.
        3. Wait for redundantWorker to finish handling any in-progress requests.
        4. Terminate redundantWorker.
      15. Run the Update Registration State algorithm passing registration, "active" and registration’s waiting worker as the arguments.
      16. Run the Update Registration State algorithm passing registration, "waiting" and null as the arguments.
      17. - Run the Update Worker State algorithm passing registration’s active worker and activating as the arguments. + Run the Update Worker State algorithm passing registration’s active worker and activating as the arguments.

        Once an active worker is activating, neither a runtime script error nor a force termination of the active worker prevents the active worker from getting activated.

      18. If redundantWorker is not null, run the Update Worker State algorithm passing redundantWorker and redundant as the arguments.
      19. @@ -4416,10 +4426,10 @@

        Acti
      20. For each service worker client client who is using registration:
          -
        1. Set client’s active worker to registration’s active worker. +
        2. Set client’s active worker to registration’s active worker.
        3. Invoke Notify Controller Change algorithm with client as the argument.
        -
      21. Let activeWorker be registration’s active worker. +
      22. Let activeWorker be registration’s active worker.
      23. Invoke Run Service Worker algorithm with activeWorker as the argument.
      24. Queue a task task to run the following substeps: @@ -4430,7 +4440,7 @@

        Acti

    2. Wait for task to have executed or been discarded, or the script to have been aborted by the termination of activeWorker.
    3. Wait for the step labeled WaitForAsynchronousExtensions to complete. -
    4. Run the Update Worker State algorithm passing registration’s active worker and activated as the arguments. +
    5. Run the Update Worker State algorithm passing registration’s active worker and activated as the arguments.
    @@ -4480,7 +4490,7 @@

    referrer policy to serviceWorker’s script resource’s referrer policy.
  • Set workerGlobalScope’s type to serviceWorker’s type.
  • Create a new WorkerLocation object and associate it with workerGlobalScope. -
  • If serviceWorker is an active worker, and there are any tasks queued in serviceWorker’s containing service worker registration’s task queues, queue them to serviceWorker’s event loop’s task queues in the same order using their original task sources. +
  • If serviceWorker is an active worker, and there are any tasks queued in serviceWorker’s containing service worker registration’s task queues, queue them to serviceWorker’s event loop’s task queues in the same order using their original task sources.
  • If script is a classic script, then run the classic script script. Otherwise, it is a module script; run the module script script.

    In addition to the usual possibilities of returning a value or failing due to an exception, this could be prematurely aborted by the kill a worker or terminate a worker algorithms.

    @@ -4556,8 +4566,8 @@
  • @@ -6384,6 +6394,7 @@

    For environment type clients, the environment’s creation URL’s origin should be used for the origin check instead of the client’s origin. See the issue to define the environment’s origin algorithm.
    For environment type clients, the environment’s creation URL’s origin should be used for the origin check instead of the client’s origin. See the issue to define the environment’s origin algorithm.
    +
    For environment type clients, the environment’s creation URL’s origin should be used for the origin check instead of the client’s origin. See the issue to define the environment’s origin algorithm.
    The response’s cache state concept had been removed from fetch. The fetch issue #376 tracks the request to restore the concept or add some similar way to check this state.