From f280eae95762d20a119d9e136ebc8d6b3be5f25a Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Fri, 29 Apr 2016 15:51:08 -0400 Subject: [PATCH] Use outside settings object to fetch workers As discussed in #1122, #1111, and in https://github.com/slightlyoff/ServiceWorker/pull/889#discussion_r60814606, a number of problems are caused by the current setup of using the settings object of the worker itself as the feth client. Instead, we use the incumbent settings object to do the fetching. (Incumbent, instead of e.g. current, because almost everything else in the (Shared)Worker constructors uses the incumbent settings object.) Notably, for fetching module script trees, this necessitates separating the fetch client settings object from the one used for the module map. This fixes #1111 since now module workers are fetched with the correct client, and thus automatically get the correct referrer. --- source | 176 +++++++++++++++++++++++---------------------------------- 1 file changed, 71 insertions(+), 105 deletions(-) diff --git a/source b/source index c4c87c83b6e..fe2311a4a75 100644 --- a/source +++ b/source @@ -87482,10 +87482,9 @@ interface NavigatorOnLine {
  • Asynchronously complete this algorithm with script.
  • -

    To fetch a classic worker script given a url, a referrer, a - settings object, and a destination, run these steps. The algorithm will - asynchronously complete with either null (on failure) or a new classic script (on - success).

    +

    To fetch a classic worker script given a url, a settings + object, and a destination, run these steps. The algorithm will asynchronously + complete with either null (on failure) or a new classic script (on success).

    1. Let request be a new request whose @@ -87493,7 +87492,6 @@ interface NavigatorOnLine { data-x="concept-request-client">client is settings object, type is "script", destination is destination, referrer is referrer, mode is "same-origin", credentials mode is "same-origin", parser @@ -87531,21 +87529,25 @@ interface NavigatorOnLine {

      To fetch a module script tree given a url, a credentials mode, a cryptographic nonce, a parser state, a destination, a - settings object, and an optional ancestor list, run these steps. The - algorithm will asynchronously complete with either null (on failure) or a module - script (on success).

      + fetch client settings object, and an optional ancestor list and module + map settings object, run these steps. The algorithm will asynchronously complete with either + null (on failure) or a module script (on success).

      1. If ancestor list is not given, let it be an empty list.

      2. -
      3. Fetch a single module script given url, credentials - mode, cryptographic nonce, parser state, destination, and - settings object. If the caller of this algorithm specified custom set up the request or process the response steps, pass those along - while fetching a single module script.

        +
      4. If module map settings object is not given, let it be fetch client + settings object.

      5. -
      6. Return from this algorithm and run the following steps when set up the + request or process the response + steps, pass those along while fetching a single + module script.

        + +
      7. Return from this algorithm, and run the following steps when fetching a single module script asynchronously completes with result:

      8. @@ -87562,12 +87564,6 @@ interface NavigatorOnLine { asynchronously complete this algorithm with descendants result.

      -
      - -

      The following algorithms are used when fetching a - module script tree, and are not meant to be used directly by other specifications (or by - other parts of this specification).

      -

      To fetch the descendants of a module script module script, given a destination and an ancestor list, run these steps. The algorithm will asynchronously complete with either null (on failure) or with module script (on @@ -87633,11 +87629,13 @@ interface NavigatorOnLine {

      To fetch a single module script, given a url, a credentials mode, a cryptographic nonce, a parser state, a destination, - and a settings object, run these steps. The algorithm will asynchronously complete with - either null (on failure) or a module script (on success).

      + a fetch client settings object, and a module map settings object, run these + steps. The algorithm will asynchronously complete with either null (on failure) or a module + script (on success).

        -
      1. Let module map be settings's module map.

      2. +
      3. Let module map be module map settings object's module + map.

      4. If module map contains an entry with key url whose value is "fetching", wait (in parallel) until that entry's value changes, @@ -87658,7 +87656,7 @@ interface NavigatorOnLine { mode, cryptographic nonce metadata is cryptographic nonce, parser metadata is parser stateand client - is settings object.

      5. + is fetch client settings object.

      6. If the caller specified custom steps to set up the request, perform them on request.

      7. @@ -87706,7 +87704,7 @@ interface NavigatorOnLine { decoding response's body.

      8. Let module script be the result of creating a module script given - source text, settings object, response's source text, module map settings object, response's url, credentials mode, and cryptographic nonce.

      9. @@ -97167,10 +97165,9 @@ interface WorkerGlobalScope : EventTarget {

        When a user agent is to run a worker for a script with Worker or SharedWorker object worker, URL - url, URL referrer, MessagePort outside - port, list of relevant Document objects to add docs, - possible WorkerGlobalScope parent worker global scope, and a - WorkerOptions dictionary options, it must run the following steps:

        + url, environment settings object outside settings, + MessagePort outside port, and a WorkerOptions dictionary + options, it must run the following steps:

          @@ -97187,6 +97184,16 @@ interface WorkerGlobalScope : EventTarget {
        1. Let is shared be true if worker is a SharedWorker object, and false otherwise.

        2. +
        3. Let docs be the list of relevant Document objects to + add given outside settings.

        4. + +
        5. Let parent worker global scope be null.

          + +
        6. If outside settings's global + object is a WorkerGlobalScope object (i.e. we are creating a nested worker), + set parent worker global scope to outside settings's global object.

        7. +
        8. Call the JavaScript InitializeHostDefinedRealm() abstract @@ -97204,7 +97211,7 @@ interface WorkerGlobalScope : EventTarget {

        9. Set up a worker environment settings object with realm execution - context, and let settings object be the result.

        10. + context, and let inside settings be the result.

        11. Let destination be "sharedworker" if is shared is true, and "worker" otherwise.

        12. @@ -97215,14 +97222,15 @@ interface WorkerGlobalScope : EventTarget {
          "classic"
          -
          Fetch a classic worker script given url, referrer, - settings object, and destination.
          +
          Fetch a classic worker script given url, outside + settings, and destination.
          "module"
          Fetch a module script tree given url, the value of the credentials member of options, the empty string (as no cryptographic nonce is present for workers), "not - parser-inserted", destination, and settings object.
          + parser-inserted", destination, outside settings, and + inside settings.

          In both cases, to process the @@ -97252,7 +97260,7 @@ interface WorkerGlobalScope : EventTarget {

        13. Associate worker with worker global scope.

        14. Create a new MessagePort object whose owner is settings object. Let inside + data-x="concept-port-owner">owner is inside settings. Let inside port be this new object.

        15. Associate inside port with worker global scope.

        16. @@ -97336,7 +97344,7 @@ interface WorkerGlobalScope : EventTarget {
        17. Event loop: Run the responsible - event loop specified by settings object until it is destroyed.

          + event loop specified by inside settings until it is destroyed.

          The handling of events or the execution of callbacks by tasks run by the event loop might get WorkerType { "classic", "module" }; data-x="blob protocol">blob: URLs.

        18. +
        19. Let outside settings be the incumbent settings object.

          +
        20. Let worker be a new Worker object.

        21. Create a new MessagePort object whose owner is the incumbent settings object. Let this - be the outside port.

        22. + data-x="concept-port-owner">owner is outside settings. Let this be the + outside port.

        23. Associate the outside port with worker.

        24. Let docs be the list of relevant Document objects to - add given the incumbent settings object.

        25. - -
        26. Let parent worker global scope be null.

        27. - -
        28. If the global object specified by the - incumbent settings object is a WorkerGlobalScope object (i.e. we are - creating a nested worker), set parent worker global scope to the - WorkerGlobalScope object that is the global object specified by the incumbent - settings object.

        29. + add given outside settings.

        30. Return worker, and run the following step in parallel.

        31. -
        32. Run a worker given worker, worker URL, the - incumbent settings object's creation URL, outside port, - docs, parent worker global scope, and options.

        33. +
        34. Run a worker given worker, worker URL, outside + settings, outside port, and options.

        @@ -97777,7 +97777,6 @@ interface SharedWorker : EventTarget { the following steps:

          -
        1. The user agent may throw a "SecurityError" DOMException and abort these steps if the request violates a policy decision (e.g. if the user agent is configured to not allow the page to start shared workers).

        2. @@ -97796,12 +97795,7 @@ interface SharedWorker : EventTarget { data-x="blob protocol">blob: URLs.

          -
        3. - -

          Let docs be the list of relevant Document objects to - add given the incumbent settings object.

          - -
        4. +
        5. Let outside settings be the incumbent settings object.

        6. @@ -97812,8 +97806,8 @@ interface SharedWorker : EventTarget {
        7. Let worker be a new SharedWorker object.

        8. Create a new MessagePort object whose owner is the incumbent settings object. Let - this be the outside port.

        9. + data-x="concept-port-owner">owner is outside settings. Let this be the + outside port.

        10. Assign outside port to the port attribute of worker.

        11. @@ -97828,27 +97822,23 @@ interface SharedWorker : EventTarget { SharedWorkerGlobalScope object.

        12. -

          If worker global scope is not null, but the user agent has been - configured to disallow communication between the worker represented by the worker global scope and the scripts whose - settings objects are the incumbent settings - object, then set worker global scope to null.

          + configured to disallow communication between the worker represented by the worker global + scope and the scripts whose settings object is outside settings, then set worker global + scope to null.

          For example, a user agent could have a development mode that isolates a particular top-level browsing context from all other pages, and scripts in that development mode could be blocked from connecting to shared workers running in the normal browser mode.

          -
        13. -

          If worker global scope is not null, then run these steps:

            - -
          1. Associate worker with worker global - scope.

          2. +
          3. Associate worker with worker global scope.

          4. Let settings object be the relevant settings object for worker global scope.

          5. @@ -97857,8 +97847,7 @@ interface SharedWorker : EventTarget { data-x="concept-port-owner">owner is settings object. Let this be the inside port.

            -
          6. Entangle outside port - and inside port.

          7. +
          8. Entangle outside port and inside port.

          9. Create a trusted event that uses the MessageEvent interface, with the name SharedWorker : EventTarget { source, to dispatch the event at worker global scope.

          10. -
          11. - -

            Add to worker global - scope's list of the worker's Documents the - Document objects in docs.

            +
          12. Add to worker global + scope's list of the worker's Documents the + list of relevant Document objects to add given outside + settings.

          13. - - -
          14. - -

            If the global object specified by - the incumbent settings object is a WorkerGlobalScope object, add - worker global scope to the list of the worker's workers of the - WorkerGlobalScope object that is the global object specified by the - incumbent settings object.

            - -
          15. +
          16. If outside settings's global + object is a WorkerGlobalScope object, add worker global scope + to the list of the worker's workers of outside settings's global object.

          17. Return worker and abort all these steps.

          18. -
          -
        14. - - - -
        15. Let parent worker global scope be null.

        16. - -
        17. If the global object specified by - the incumbent settings object is a WorkerGlobalScope object (i.e. we - are creating a nested worker), set parent worker global scope to the - WorkerGlobalScope object that is the global object specified by the incumbent - settings object.

        -
      10. Return worker and perform the remaining steps in parallel.

      11. -
      12. Run a worker given worker, urlRecord, the - incumbent settings object's creation URL, outside port, - docs, parent worker global scope, and options.

      13. +
      14. Run a worker given worker, urlRecord, outside + settings, outside port, and options.

      @@ -120265,6 +120230,7 @@ INSERT INTERFACES HERE Marc Hoyois, Marco Zehe, Marcus Bointon, + Marijn Kruisselbrink, Mark Birbeck, Mark Davis, Mark Miller,