From 37e45becd760c7d47f30a69cb58b07cd6034da7f Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Tue, 28 Jun 2016 17:03:00 +0200 Subject: [PATCH] Navigate: remove "gone async" and define redirect handling Redirect handling had the following issues that are now fixed: * /a navigating to /b which redirects to /a#test would not unload /a. * Headers set on the initial request were not preserved. * Redirects to javascript URLs would not result in an error. Fixes #314. * Location header was not parsed, and HTTP method was not changed where needed. Fixes #461. Another source of complexity was the "gone async" mechanism, which was used for two steps that could just as easily be factored out and had to be since they were run synchronously, but should not be. Changing that fixes #1446 which discusses the issue around unknown URL schemes in more detail. --- source | 325 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 167 insertions(+), 158 deletions(-) diff --git a/source b/source index 8c14c6b2404..bf33e5b5f7e 100644 --- a/source +++ b/source @@ -2714,8 +2714,9 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d
  • A local scheme -
  • A network scheme
  • An HTTP(S) scheme +
  • A network scheme +
  • A fetch scheme
  • The URL serialiser
  • The host parser
  • The host serialiser @@ -2815,6 +2816,7 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d
  • internal response
  • CSP list
  • HTTPS state +
  • location URL
  • request and its associated: @@ -81759,50 +81761,29 @@ State: <OUTPUT NAME=I>1</OUTPUT> <INPUT VALUE="Increment" TYPE=BUTTON O affecting the prompt to unload a document algorithm.

  • -
  • - -

    Let gone async be false.

    - -

    The handle redirects step later in - this algorithm can in certain cases jump back to the step labeled fragments. Since, between those two steps, this - algorithm goes from operating synchronously in the context of the calling task to operating in parallel independent of the event - loop, some of the intervening steps need to be able to handle both being run as part of a - task and running in parallel. The - gone async flag is thus used to make these steps aware of which mode they are - operating in.

    - -
  • - - - -
  • If gone async is false, cancel any preexisting but not yet mature attempt to navigate browsingContext, - including canceling any instances of the fetch algorithm - started by those attempts. If one of those attempts has already created and initialised a new Document object, - abort that Document also. (Navigation - attempts that have matured already have session - history entries, and are therefore handled during the update the session history with the - new page algorithm, later.)

  • + -
  • If resource is to be handled using a mechanism that does not affect - browsingContext, e.g., ignoring the navigation request altogether because the - specified scheme is not one of the supported protocols, then abort these steps and proceed with that mechanism instead.

  • +
  • Cancel any preexisting but not yet mature + attempt to navigate browsingContext, including canceling any instances of the fetch algorithm started by those attempts. If one of those attempts + has already created and initialised a new + Document object, abort that + Document also. (Navigation attempts that have matured already have session history entries, and are + therefore handled during the update the session history with the new page algorithm, + later.)

  • -

    If gone async is false, prompt - to unload the Document object. If the user refused to allow the - document to be unloaded, then abort these steps.

    +

    Prompt to unload the active + document of browsingContext. If the user refused to allow the document + to be unloaded, then abort these steps.

    If this instance of the navigation algorithm gets canceled while this step is running, the prompt to unload a document algorithm must @@ -81810,21 +81791,8 @@ State: <OUTPUT NAME=I>1</OUTPUT> <INPUT VALUE="Increment" TYPE=BUTTON O

  • -
  • If gone async is false, abort - the active document of browsingContext.

  • - -
  • - -

    If resource is to be handled by displaying some sort of inline content, e.g., an - error message because the specified scheme is not one of the supported protocols, or an inline - prompt to allow the user to select a - registered handler for the given scheme, then display - the inline content and abort these steps.

    - -

    In the case of a registered handler being used, the algorithm will be reinvoked - with a new URL to handle the request.

    - -
  • +
  • Abort the active document of + browsingContext.

  • @@ -81843,6 +81811,9 @@ State: <OUTPUT NAME=I>1</OUTPUT> <INPUT VALUE="Increment" TYPE=BUTTON O
  • +
  • Return to whatever algorithm invoked the navigation steps and continue running these steps + in parallel.

  • +
  • This is the step that attempts to obtain resource, if necessary. Jump to the first @@ -81850,12 +81821,12 @@ State: <OUTPUT NAME=I>1</OUTPUT> <INPUT VALUE="Increment" TYPE=BUTTON O

    -
    If resource has already been obtained (e.g., because it is being used to - populate an object element's new child browsing context)
    +
    If resource is a response
    +

    Run process a navigate response with resource and + browsingContext, and then abort these steps.

    -

    Skip this step. The data is already available.

    - -
    If resource's URL's scheme +
    If resource is a request whose url's scheme is javascript
    @@ -81907,16 +81878,17 @@ State: <OUTPUT NAME=I>1</OUTPUT> <INPUT VALUE="Increment" TYPE=BUTTON O result be undefined instead. (The result will also be undefined if scripting is disabled.)

  • +
  • Let response be null.

  • +
  • Process result: If Type(result) is not - String, then the result of obtaining the resource for the URL is a response to a response whose status is 204.

    -

    Otherwise, the result of obtaining the resource for the URL is a response whose header list consists of `Otherwise, set response a response + whose header list consists of `Content-Type`/`text/html` and `Referrer-Policy`/settings's referrer policy, whose body is result, @@ -81928,12 +81900,12 @@ State: <OUTPUT NAME=I>1</OUTPUT> <INPUT VALUE="Increment" TYPE=BUTTON O not yet specified, pending further investigation into user agent behavior. See issue #1129.

    -

    When it comes time to set the document's address in the navigation algorithm, use address as the - override URL.

    - +

    When it comes time to set the document's address, use address as + the override URL.

  • +
  • Run process a navigate response with response and + browsingContext, and then abort these steps.

  • The task source for this task is the @@ -81984,91 +81956,96 @@ State: <OUTPUT NAME=I>1</OUTPUT> <INPUT VALUE="Increment" TYPE=BUTTON O -

    Otherwise
    - -
    - -
      -
    1. Set resource's client to the - source browsing context'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".

    2. - -
    3. Set resource's omit-Origin-header flag. - -

    4. If resource's method is not - `GET`, or, if the navigation algorithm - was invoked as a result of the form submission - algorithm, then if there is an origin of the active document - of the source browsing context, unset resource's - omit-Origin-header flag.

    5. - -
    6. Otherwise, if browsingContext is a child browsing context, and - the browsing context container of browsingContext has a - browsing context scope origin, set resource's origin to that browsing context scope - origin and unset resource's omit-Origin-header - flag.

    7. - -
    8. Fetch resource.

    9. -
    - -
    +
    If resource is a request whose url's scheme + is a fetch scheme
    +

    Run process a navigate fetch given resource and + browsingContext.

    +
    Otherwise
    +

    Run process a navigate URL scheme given resource and + browsingContext.

    - + -
  • - - - -

    If gone async is false, return to whatever algorithm invoked the - navigation steps and continue running these steps in parallel.

    - -
  • +

    To process a navigate fetch, given a request request and browsing context + browsingContext, run these steps:

    -
  • Let gone async be true.

  • +
      +
    1. Let response be null.

    2. -
    3. Wait for one or more bytes to be available or for the user agent to establish that the - resource in question is empty. During this time, the user agent may allow the user to cancel this - navigation attempt or start other navigation attempts.

    4. +
    5. Set request's client to the + source browsing context'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".

    6. + +
    7. Set request's omit-Origin-header flag. + +

    8. If request's method is not `GET`, or, if the navigation algorithm was invoked + as a result of the form submission algorithm, then if + there is an origin of the active document of the source browsing + context, unset request's omit-Origin-header + flag.

    9. -
    10. Otherwise, if browsingContext is a child browsing context, and the + browsing context container of browsingContext has a browsing + context scope origin, set request's origin to that browsing context scope origin + and unset request's omit-Origin-header flag.

    11. -

      Handle redirects: If fetching the resource results in a redirect, then return to the step labeled fragments with the new resource, except - that if the URL of the target of the redirect does not have a fragment and the URL of the resource that led - to the redirect does, then the fragment of the - resource that led to the redirect must be propagated to the URL of the target of - the redirect.

      +
    12. Fetch request.

    13. -

      So for instance, if the original URL was "http://example.com/#!sample" and "http://example.com/" is - found to redirect to "https://example.com/", the URL of the new resource - will be "https://example.com/#!sample".

      +
    14. Wait for the task on the networking task + source to process response and set response to the + result.

    15. - + + +
    16. Otherwise, if response has a location URL that is a URL whose scheme is "file" or "javascript", then set response to a network error.

    17. + +
    18. Otherwise, if response has a location URL that is a URL whose scheme is a fetch scheme, then run + process a navigate fetch with a new request + whose url is response's location URL. + +

    19. Otherwise, if response has a location URL that is a URL, run the + process a navigate URL scheme given response's location URL and + browsingContext.

    20. -

      Fallback in prefer-online mode: If the resource was not fetched from an - application cache, and was to be fetched using `GET`, and +

      Fallback in prefer-online mode: If response was not fetched from + an application cache, and was to be fetched using `GET`, and there are relevant application caches that are identified by a URL with the same origin as the URL in question, and that have this URL as one of their entries, excluding entries marked as foreign, and whose mode is prefer-online, and the user didn't cancel the - navigation attempt during the earlier step, and the navigation attempt failed (e.g. the server - returned a 4xx or 5xx status, or there was a DNS error), then:

      + data-x="concept-appcache-mode-prefer-online">prefer-online, and the user didn't cancel + the navigation attempt during the earlier step, and response is either a network + error or its status is not an ok + status, then:

      Let candidate be the resource identified by the URL in question from the most appropriate application cache of those that @@ -82078,7 +82055,7 @@ State: <OUTPUT NAME=I>1</OUTPUT> <INPUT VALUE="Increment" TYPE=BUTTON O

      If candidate is not marked as foreign, then the user agent must discard the failed - load and instead continue along these steps using candidate as the resource. + load and instead continue along these steps using candidate as response. The user agent may indicate to the user that the original page load failed, and that the page used was a previously cached resource.

      @@ -82086,19 +82063,20 @@ State: <OUTPUT NAME=I>1</OUTPUT> <INPUT VALUE="Increment" TYPE=BUTTON O
    21. -

      Fallback for fallback entries: If the resource was not fetched from an - application cache, and was to be fetched using `GET`, and +

      Fallback for fallback entries: If response was not fetched from + an application cache, and was to be fetched using `GET`, and its URL matches the fallback namespace of one or more relevant application caches, and the most appropriate application cache of those that match does not have an entry in its online - safelist that has the same origin as the resource's URL and that is a - prefix match for the resource's URL, and the user didn't cancel the navigation - attempt during the earlier step, and the navigation attempt failed (e.g. the server returned a - 4xx or 5xx status, or there was a DNS error), then:

      + safelist that has the same origin as response's URL and that is a + prefix match for response's URL, and the user didn't cancel the + navigation attempt during the earlier step, and response is either a network error or + its status is not an ok status, + then:

      +

      Let candidate be the fallback resource specified for the fallback @@ -82108,16 +82086,24 @@ State: <OUTPUT NAME=I>1</OUTPUT> <INPUT VALUE="Increment" TYPE=BUTTON O

      If candidate is not marked as foreign, then the user agent must discard the failed - load and instead continue along these steps using candidate as the resource. The - document's URL, if appropriate, will still be the + load and instead continue along these steps using candidate as response. + The document's URL, if appropriate, will still be the originally requested URL, not the fallback URL, but the user agent may indicate to the user that the original page load failed, that the page used was a fallback resource, and what the URL of the fallback resource actually is.

      -
    22. +
    23. Run process a navigate response given response and + browsingContext.

    24. +
    + +

    To process a navigate response, given a response response and browsing context + browsingContext, run these steps:

    + +
    1. -

      Resource handling: If the resource is a network error, then If response is a network error, then display the inline content with an appropriate error shown to the user and with the newly created Document object's origin set to a new opaque origin.

      @@ -82126,23 +82112,25 @@ State: <OUTPUT NAME=I>1</OUTPUT> <INPUT VALUE="Increment" TYPE=BUTTON O standard, such as DNS or TLS errors, end up being displayed to users.

    2. -
    3. If the resource's status is +

    4. If response's status is 204 or 205, then abort these steps.

    5. -
    6. If the resource has an `

      If response has an `Content-Disposition` header specifying the attachment disposition type, then handle it as a download.

    7. + data-x="">attachment disposition type, then handle it as a download and abort + these steps.

    8. Let type be the computed type of - the resource.

    9. + response.

      -
    10. If the user agent has been configured to process resources of the given type using some mechanism other than rendering the content in a browsing - context, then skip this step. Otherwise, if the type is one of the - following types, jump to the appropriate entry in the following list, and process the resource as - described there:

      +
    11. +

      If the user agent has been configured to process resources of the given type + using some mechanism other than rendering the content in a browsing context, then + skip this step. Otherwise, if the type is one of the following types, jump to the + appropriate entry in the following list, and process response as described there:

      @@ -82319,6 +82307,27 @@ State: <OUTPUT NAME=I>1</OUTPUT> <INPUT VALUE="Increment" TYPE=BUTTON O
    +

    To process a navigate URL scheme, given a URL url and + browsing context browsingContext, run these steps:

    + +
      +
    1. If url is to be handled using a mechanism that does not affect + browsingContext, e.g., because url's scheme is handled externally, then proceed with that mechanism instead.

    2. + +
    3. +

      Otherwise, url is to be handled by displaying some sort of inline content, e.g., + an error message because the specified scheme is not one of the supported protocols, or an + inline prompt to allow the user to select a + registered handler for the given scheme, then display + the inline content.

      + +

      In the case of a registered handler being used, navigate will be + invoked with a new URL.

      +
    4. +
    +

    When a resource is handled by passing its URL or data to an external software package separate from the user agent (e.g. handing a mailto: URL to a mail client, or a Word document to a word