From 4fd4ffc574ff51abaa8a5db2cdbdd0bf158a2519 Mon Sep 17 00:00:00 2001 From: Jungkee Song Date: Mon, 24 Oct 2016 20:32:35 +0900 Subject: [PATCH] Improve navigate for service worker hooks Before this patch, there has been no concept that holds reserved client's information referenced from a service worker during a navigation (more precisely before the actual global object and its relevant environment settings object for the resulting resource is created). This patch defines an "environment" concept (a supertype object of an environment settings object) that has an id, a creation URL, a target browsing context, and an active service worker such that service workers' FetchEvent handlers can reference this client information before the corresponding environment settings object is actually created. The changes include: - Create an environment (a reserved client) during a navigation; for worker creation requests, create an environment settings object and set the fields correspondingly - Set request's reserved client to the created environment or environment settings object such that fetch (and Handle Fetch) can use it - Set request's target client id such that fetch (and Handle Fetch) can use it Note: The reserved client's active service worker is set, if available, during the fetch (in service worker's Handle Fetch algorithm). Related issue: https://github.com/w3c/ServiceWorker/issues/870 Related change: https://github.com/whatwg/fetch/pull/383 --- source | 204 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 154 insertions(+), 50 deletions(-) diff --git a/source b/source index 058ba512343..96ae470e5ee 100644 --- a/source +++ b/source @@ -2794,6 +2794,7 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d
  • fetch
  • HTTP-redirect fetch
  • ok status
  • +
  • navigation request
  • network error
  • `Origin` header
  • process response
  • @@ -2827,7 +2828,8 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d
  • header list
  • body
  • client
  • -
  • target browsing context
  • +
  • reserved client
  • +
  • target client id
  • initiator
  • type
  • destination
  • @@ -3867,10 +3869,14 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d

    The following terms are defined in Service Workers:

    @@ -3884,6 +3890,7 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d @@ -77145,8 +77152,9 @@ console.assert(iframeWindow.frameElement === null);

    Script settings for browsing contexts

    When the user agent is required to set up a browsing context environment settings - object, given a JavaScript execution context execution context, it - must run the following steps:

    + object, given a JavaScript execution context execution context and + an optional environment reserved environment, it must run the following + steps:

    1. Let realm be the value of execution context's Realm @@ -77172,7 +77180,6 @@ console.assert(iframeWindow.frameElement === null); -

      The module map
      @@ -77231,13 +77238,6 @@ console.assert(iframeWindow.frameElement === null);
      -
      The creation URL
      -
      - -

      Return url.

      - -
      -
      The HTTPS state
      @@ -77266,6 +77266,42 @@ console.assert(iframeWindow.frameElement === null);
    2. +
    3. +

      If reserved environment is given, then:

      + +
        +
      1. Set settings object's id to + reserved environment's id, + settings object's creation + URL to reserved environment's creation URL, settings object's + target browsing context to + reserved environment's target browsing context, and + settings object's active + service worker to reserved environment's active service worker.

      2. + +
      3. +

        Set reserved environment's id to + the empty string.

        + +

        The identity of the reserved environment is considered to be fully + transferred to the created environment settings object. The reserved environment + is not searchable by the environment’s id from this point on.

        +
      4. +
      +
    4. + +
    5. Otherwise, set settings object's id to a new unique opaque string, settings + object's creation URL to + url, settings object's target browsing context to null, and + settings object's active + service worker to null.

    6. +
    7. Set realm's [[HostDefined]] field to settings object.

    8. Return settings object.

    9. @@ -81265,14 +81301,14 @@ State: <OUTPUT NAME=I>1</OUTPUT> <INPUT VALUE="Increment" TYPE=BUTTON O
    10. Set request's client to sourceBrowsingContext's active document's relevant settings - object, target browsing - context to browsingContext, destination to "document", - mode to "navigate", credentials mode to "include", use-URL-credentials flag, and redirect mode to "manual".

    11. + object, destination to "document", mode to "navigate", credentials + mode to "include", use-URL-credentials flag, redirect mode to "manual", + and target client id to + browsingContext's active document's relevant settings + object's id.

    12. Set request's omit-Origin-header flag. @@ -81288,6 +81324,23 @@ State: <OUTPUT NAME=I>1</OUTPUT> <INPUT VALUE="Increment" TYPE=BUTTON O data-x="concept-request-origin">origin to that browsing context scope origin and unset request's omit-Origin-header flag.

    13. +
    14. +

      Create a new environment reservedEnvironment, and set its id to a new unique opaque string, its creation URL to request's + url, and its target + browsing context to browsingContext.

      + +

      The created environment's active service worker is set in the + handle fetch algorithm during the fetch if its + creation URL matches a service worker + registration.

      +
    15. + +
    16. Set request's reserved + client to reservedEnvironment.

    17. +
    18. If the Should navigation request of type from source in target be blocked by Content Security Policy? algorithm returns "Blocked" when executed upon @@ -81400,15 +81453,15 @@ State: <OUTPUT NAME=I>1</OUTPUT> <INPUT VALUE="Increment" TYPE=BUTTON O

    19. Run process a navigate response given request, - response, navigationType, the source browsing context, and - browsingContext.

    20. + response, navigationType, the source browsing context, + browsingContext, and reservedEnvironment.

    To process a navigate response, given a request request, a response response, a string type, and two - browsing contexts source and browsingContext, run these - steps:

    + data-x="concept-response">response response, a string type, two + browsing contexts source and browsingContext, and an optional + environment reservedEnvironment, run these steps:

    1. @@ -81534,12 +81587,15 @@ State: <OUTPUT NAME=I>1</OUTPUT> <INPUT VALUE="Increment" TYPE=BUTTON O
      1. Let window be null.

      2. +
      3. Let settingsObject be null.

      4. +
      5. If browsingContext's only entry in its session history is the about:blank Document that was added when browsingContext was created, and navigation is occurring with replacement enabled, and that Document has the same origin as the new Document, then set window to the - Window object of that Document.

      6. + Window object of that Document, and set settingsObject to + window's relevant settings object.

      7. Otherwise,

        @@ -81563,7 +81619,8 @@ State: <OUTPUT NAME=I>1</OUTPUT> <INPUT VALUE="Increment" TYPE=BUTTON O
      8. Set up a browsing context environment settings object with realm - execution context.

      9. + execution context and reservedEnvironment, if present, and set + settingsObject to the result.

    2. @@ -81603,6 +81660,27 @@ State: <OUTPUT NAME=I>1</OUTPUT> <INPUT VALUE="Increment" TYPE=BUTTON O
    3. Implement the sandboxing for the Document.

    4. + +
    5. +

      If settingsObject's active service worker is not null, + then:

      + +
        +
      1. If settingsObject is a secure context, + then:

      2. + +
          +
        1. If browsingContext has an opener browsing context and + request's client is a non-secure context, then disown browsingContext's opener.

        2. +
        + +
      3. Otherwise, set settingsObject's active service worker to + null.

      4. +
      +
    @@ -85553,8 +85631,40 @@ interface NavigatorOnLine {
    -

    An environment settings object specifies algorithms for obtaining the - following:

    +

    An environment is an object that identifies the settings of a + current or potential execution environment. An environment has the following + fields:

    + +
    +
    An id
    +

    An opaque string that uniquely identifies the environment.

    + +
    A creation URL
    +
    +

    An absolute URL that represents the location of the resource with which the + environment is associated.

    + +

    In the case of an environment settings object, this URL might be + distinct from the environment settings object's responsible + document's URL, due to mechanisms such as + history.pushState().

    +
    + +
    A target browsing context
    +

    Null or a target browsing context for a navigation request.

    + +
    An active service worker
    +

    Null or a service worker that controls the environment.

    +
    + +

    An environment settings object is an environment that + additionally specifies algorithms for:

    @@ -85651,15 +85761,6 @@ interface NavigatorOnLine { -
    A creation URL
    - -
    -

    An absolute URL representing the location of the resource with which the - environment settings object is associated. Note that this URL might be distinct - from the responsible document's URL, due - to mechanisms such as history.pushState().

    -
    -
    An HTTPS state

    An HTTPS state value representing the security properties of the network @@ -96025,6 +96126,9 @@ interface SharedWorkerGlobalScope : WorkerGlobalScope { data-x="fetching-scripts-is-top-level">is top-level flag is set:

      +
    1. Set request's reserved + client to inside settings.
    2. +
    3. Fetch request, and asynchronously wait to run the remaining steps as part of fetch's process response for the response response.

    4. @@ -96397,14 +96501,6 @@ interface AbstractWorker {
    -
    The creation URL
    -
    - -

    Return worker global scope's url.

    - -
    -
    The HTTPS state
    @@ -96425,6 +96521,14 @@ interface AbstractWorker { +
  • Set settings object's id to a new + unique opaque string, settings object's creation URL to worker global + scope's url, settings object's target browsing context to null, and + settings object's active + service worker to null.

  • +
  • Set realm's [[HostDefined]] field to settings object.

  • Return settings object.

  • @@ -118589,7 +118693,7 @@ INSERT INTERFACES HERE
    (Non-normative) Scalable Vector Graphics (SVG) 2, N. Andronikos, R. Atanassov, T. Bah, A. Bellamy-Royds, B. Birtles, B. Brinza, C. Concolato, E. Dahlström, C. Lilley, C. McCormack, D. Schepers, D. Schulze, R. Schwerdtfeger, S. Takagi, J. Watt. W3C.
    [SW]
    -
    Service Workers, A. Russell, J. Song, J. Archibald. W3C.
    +
    Service Workers, A. Russell, J. Song, J. Archibald. W3C.
    [TOR]
    (Non-normative) Tor.