From 712d15974a085109a13ff6218d8a959f9d63be76 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.) This fixes #1111 since now module workers are fetched with the correct client, and thus automatically get the correct referrer. --- source | 126 +++++++++++++++++++++------------------------------------ 1 file changed, 45 insertions(+), 81 deletions(-) diff --git a/source b/source index 4dce93f0ba2..4a856ff7608 100644 --- a/source +++ b/source @@ -87027,10 +87027,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 @@ -87038,7 +87037,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 @@ -96469,10 +96467,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:

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

        @@ -96489,6 +96486,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 @@ -96517,14 +96524,14 @@ 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, and outside settings.

        In both cases, to process the @@ -97012,31 +97019,23 @@ enum WorkerType { "classic", "module" }; data-x="blob protocol">blob: URLs.

      9. +
      10. Let outside settings be the incumbent settings object.

        +
      11. Let worker be a new Worker object.

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

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

      14. Associate the outside port with worker.

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

      16. - -
      17. Let parent worker global scope be null.

      18. - -
      19. 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.

      20. + add given outside settings.

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

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

      24. +
      25. Run a worker given worker, worker URL, outside + settings, outside port, and options.

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

        -
      1. The user agent may throw a SecurityError exception 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. @@ -97096,12 +97094,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. @@ -97112,8 +97105,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. @@ -97128,27 +97121,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. @@ -97157,8 +97146,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. - -
        13. - -

          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.

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

        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.

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

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

    5. +
    6. Run a worker given worker, urlRecord, outside + settings, outside port, and options.