From f0a73659b4046cc35a28855f3544dead66345689 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Thu, 1 Oct 2015 18:49:35 +0200 Subject: [PATCH] Merge URLUtils into Location This fixes the HTML standard side of these issues: * https://github.com/whatwg/url/issues/61 * https://github.com/whatwg/url/issues/62 There is still some cleanup work left on the URL side, e.g., making sure the basic URL parser returns failure for certain conditions when override state is scheme start state. --- source | 516 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 401 insertions(+), 115 deletions(-) diff --git a/source b/source index 3c8e2516787..0f21842fb73 100644 --- a/source +++ b/source @@ -1142,8 +1142,8 @@ ways:

var a = document.links[0]; // obtain the first link in the document
-a.href = 'sample.html'; // change the destination URL of the link
-a.protocol = 'https'; // change just the scheme part of the URL
+a.href = 'sample.html'; // change the destination URL of the link
+a.protocol = 'https'; // change just the scheme part of the URL
 a.setAttribute('href', 'http://example.com/'); // change the content attribute directly

Since DOM trees are used as the way to represent HTML documents when they are processed and @@ -2729,16 +2729,6 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d

  • set the password
  • The domain to ASCII algorithm
  • The domain to Unicode algorithm
  • -
  • URLUtils interface -
  • URLUtilsReadOnly interface -
  • href IDL attribute -
  • protocol IDL attribute -
  • The get the base hook for URLUtils -
  • The update steps hook for URLUtils -
  • The set the input algorithm for URLUtils -
  • The query encoding of an URLUtils object -
  • The input of an URLUtils object -
  • The url of an URLUtils object

    A number of schemes and protocols are referenced by this specification also:

    @@ -8202,7 +8192,7 @@ interface DOMStringMap { [OverrideBuiltins] partial /*sealed*/ interface Document { // resource metadata management - [PutForwards=href, Unforgeable] readonly attribute Location? location; + [PutForwards=href, Unforgeable] readonly attribute Location? location; attribute DOMString domain; readonly attribute DOMString referrer; attribute DOMString cookie; @@ -78995,7 +78985,7 @@ dictionary DragEventInit : MouseEventInit { [Replaceable] readonly attribute WindowProxy self; [Unforgeable] readonly attribute Document document; attribute DOMString name; - [PutForwards=href, Unforgeable] readonly attribute Location location; + [PutForwards=href, Unforgeable] readonly attribute Location location; readonly attribute History history; [Replaceable] readonly attribute BarProp locationbar; [Replaceable] readonly attribute BarProp menubar; @@ -81393,58 +81383,433 @@ State: <OUTPUT NAME=I>1</OUTPUT> <INPUT VALUE="Increment" TYPE=BUTTON O data-x="dom-history">history object.

    [Unforgeable] interface Location {
    -  void assign(DOMString url);
    -  void replace(DOMString url);
    +  stringifier attribute USVString href;
    +           attribute USVString origin;
    +           attribute USVString protocol;
    +           attribute USVString host;
    +           attribute USVString hostname;
    +           attribute USVString port;
    +           attribute USVString pathname;
    +           attribute USVString search;
    +           attribute USVString hash;
    +
    +  void assign(USVString url);
    +  void replace(USVString url);
       void reload();
     
    -  [SameObject] readonly attribute DOMString[] ancestorOrigins;
    -};
    -Location implements URLUtils;
    + [SameObject] readonly attribute USVString[] ancestorOrigins; +};
    +
    location . toString()
    +
    location . href
    +
    +

    Returns the Location object's URL.

    +

    Can be set, to navigate to the given URL.

    +
    -
    location . assign(url)
    +
    location . origin
    +
    +

    Returns the Location object's URL's origin.

    +
    + +
    location . protocol
    +
    +

    Returns the Location object's URL's scheme.

    +

    Can be set, to navigate to the same URL with a changed scheme.

    +
    +
    location . host
    +

    Returns the Location object's URL's host and port (if different from the default + port for the scheme).

    +

    Can be set, to navigate to the same URL with a changed host and port.

    +
    -

    Navigates to the given page.

    +
    location . hostname
    +
    +

    Returns the Location object's URL's host.

    +

    Can be set, to navigate to the same URL with a changed host.

    +
    +
    location . port
    +
    +

    Returns the Location object's URL's port.

    +

    Can be set, to navigate to the same URL with a changed port.

    -
    location . replace(url)
    +
    location . pathname
    +
    +

    Returns the Location object's URL's path.

    +

    Can be set, to navigate to the same URL with a changed path.

    +
    + +
    location . search
    +
    +

    Returns the Location object's URL's query (includes leading "?" if non-empty).

    +

    Can be set, to navigate to the same URL with a changed query (ignores leading "?").

    +
    +
    location . hash
    +

    Returns the Location object's URL's fragment (includes leading "#" if non-empty).

    +

    Can be set, to navigate to the same URL with a changed fragment (ignores leading "#").

    +
    -

    Removes the current page from the session history and navigates to the given page.

    +
    location . assign(url)
    +
    +

    Navigates to the given URL.

    +
    +
    location . replace(url)
    +
    +

    Removes the current page from the session history and navigates to the given URL.

    location . reload()
    -

    Reloads the current page.

    -
    -
    location . ancestorOrigins
    -
    - -

    Returns an array values are the origins of the ancestor browsing contexts, from the parent browsing context to the top-level browsing context.

    -
    -
    -

    The relevant Document is the Location object's associated +

    A Location object has an associated relevant + Document, which is this Location object's associated Document object's browsing context's active document.

    +

    A Location object has an associated url, which is this Location object's + relevant Document's address.

    + +

    A Location object has an associated Location-object-setter + navigate algorithm, which given a url, runs these steps:

    + +
      +
    1. +

      If any of the following conditions are met, let replacement flag be unset; + otherwise, let it be set:

      + +
        +
      • This Location object's relevant Document has + completely loaded, or
      • + +
      • In the task in which the algorithm is running, an + activation behaviour is currently being processed whose click event was trusted, or
      • + +
      • In the task in which the algorithm is running, the event + listener for a trusted click event is being handled.
      • +
      +
    2. + +
    3. Location-object navigate, given url and + replacement flag.

    4. +
    + +

    To Location-object navigate, given a url and + replacement flag, run these steps:

    + +
      +
    1. The source browsing context is the responsible browsing context + specified by the incumbent settings object.

    2. + +
    3. +

      Navigate the browsing context to + url, with exceptions enabled.

      + +

      If the replacement flag is set or the browsing context's + session history contains only one Document, and that was the + about:blank Document created when the browsing context + was created, then the navigation must be done with replacement enabled.

      + +
    4. +
    + +

    The href attribute's getter must return this + Location object's url, serialised.

    + +

    The href attribute's setter must run these steps:

    + +
      +
    1. Let newURL be the resulting parsed URL of resolving the given value relative to the entry settings object's + API base URL.

    2. + +
    3. If that aborted with an error, throw a TypeError exception.

    4. + +
    5. Location-object-setter navigate to newURL.

    6. +
    + +

    The origin attribute's getter must return + the Unicode serialization of this + Location object's url's origin.

    + +

    It returns the Unicode rather than the ASCII serialisation for + compatibility with MessageEvent.

    + +

    The protocol attribute's getter must + return this Location object's url's scheme, followed by ":".

    + +

    The protocol attribute's setter must run these + steps:

    + +
      +
    1. Let copyURL be a copy of this Location object's url.

    2. + +
    3. Let possibleFailure be the result of basic URL + parsing the given value, followed by ":", with copyURL + as url and scheme start state as state override.

    4. + +
    5. If possibleFailure is failure, throw a TypeError + exception.

    6. + +
    7. If copyURL's scheme is not "http" or "https", terminate these steps.

    8. + +
    9. Location-object-setter navigate to copyURL.

    10. +
    + +

    The host attribute's getter must run these + steps:

    + +
      +
    1. Let url be this Location object's url.

    2. + +
    3. If url's host is null, return the empty + string.

    4. + +
    5. If url's port is null, return + url's host, serialised.

    6. + +
    7. Return url's host, serialised, followed by ":" and url's port, serialised.

    8. +
    + +

    The host attribute's setter must run these steps:

    + +
      +
    1. Let copyURL be a copy of this Location object's url.

    2. + +
    3. If copyURL's non-relative flag is set, terminate these + steps.

    4. + +
    5. Basic URL parse the given value, with + copyURL as url and host state as state + override.

    6. + +
    7. Location-object-setter navigate to copyURL.

    8. +
    + +

    The hostname attribute's getter must + run these steps:

    + +
      +
    1. If this Location object's url's + host is null, return the empty string.

    2. + +
    3. Return this Location object's url's host, serialised.

    4. +
    + +

    The hostname attribute's setter must run these + steps:

    + +
      +
    1. Let copyURL be a copy of this Location object's url.

    2. + +
    3. If copyURL's non-relative flag is set, terminate these + steps.

    4. + +
    5. Basic URL parse the given value, with + copyURL as url and hostname state as state + override.

    6. + +
    7. Location-object-setter navigate to copyURL.

    8. +
    + +

    The port attribute's getter must run these + steps:

    + +
      +
    1. If this Location object's url's + port is null, return the empty string.

    2. + +
    3. Return this Location object's url's port, serialised.

    4. +
    + +

    The port attribute's setter must run these steps:

    + +
      +
    1. Let copyURL be a copy of this Location object's url.

    2. + +
    3. If copyURL's host is null, + copyURL's non-relative flag is set, or copyURL's scheme is "file", terminate these + steps.

    4. + +
    5. Basic URL parse the given value, with + copyURL as url and port state as state + override.

    6. + +
    7. Location-object-setter navigate to copyURL.

    8. +
    + +

    The pathname attribute's getter must + run these steps:

    + +
      +
    1. Let url be this Location object's url.

    2. + +
    3. If url's non-relative flag is set, return the first string in + url's path.

    4. + +
    5. Return "/", followed by the strings in url's path (including empty strings), separated from each other by + "/".

    6. +
    + +

    The pathname attribute's setter must run these + steps:

    + +
      +
    1. Let copyURL be a copy of this Location object's url.

    2. + +
    3. If copyURL's non-relative flag is set, terminate these + steps.

    4. + +
    5. Set copyURL's path to the empty + list.

    6. + +
    7. Basic URL parse the given value, with + copyURL as url and path start state as state + override.

    8. + +
    9. Location-object-setter navigate to copyURL.

    10. +
    + +

    The search attribute's getter must run + these steps:

    + +
      +
    1. If this Location object's url's + query is either null or the empty string, return the + empty string.

    2. + +
    3. Return "?", followed by this Location object's url's query.

    4. +
    + +

    The search attribute's setter must run these + steps:

    + +
      +
    1. Let copyURL be a copy of this Location object's url.

    2. + +
    3. If the given value is the empty string, set copyURL's query to null. + +

    4. +

      Otherwise, run these substeps:

      + +
        +
      1. Let input be the given value with a single leading "?" + removed, if any.

      2. + +
      3. Set copyURL's query to the empty + string.

      4. + +
      5. Basic URL parse input, with + copyURL as url and query state as state override, + and the relevant Document's document's character + encoding as encoding override.

      6. +
      +
    5. + +
    6. Location-object-setter navigate to copyURL.

    7. +
    + +

    The hash attribute's getter must run these + steps:

    + +
      +
    1. If this Location object's url's + fragment is either null or the empty string, return + the empty string.

    2. + +
    3. Return "#", followed by this Location object's url's fragment.

    4. +
    + +

    The hash attribute's setter must run these steps:

    + +
      +
    1. Let copyURL be a copy of this Location object's url.

    2. + +
    3. If copyURL's scheme is "javascript", terminate these steps.

    4. + +
    5. If the given value is the empty string, set copyURL's fragment to null. + +

    6. +

      Otherwise, run these substeps:

      + +
        +
      1. Let input be the given value with a single leading "#" + removed, if any.

      2. + +
      3. Set copyURL's fragment to the + empty string.

      4. + +
      5. Basic URL parse input, with + copyURL as url and fragment state as state + override.

      6. +
      +
    7. + +
    8. Location-object-setter navigate to copyURL.

    9. +
    + +
    +

    When the assign(url) method is invoked, the user agent must run the following steps: @@ -81461,20 +81826,7 @@ State: <OUTPUT NAME=I>1</OUTPUT> <INPUT VALUE="Increment" TYPE=BUTTON O

  • -
  • - -

    Navigate the browsing context to - parsedURL, with exceptions enabled.

    - -

    If the browsing context's session history contains only one - Document, and that was the about:blank Document created - when the browsing context was created, then the navigation must be done with - replacement enabled.

    - - -
  • +
  • Location-object navigate to parsedURL.

  • @@ -81494,17 +81846,11 @@ State: <OUTPUT NAME=I>1</OUTPUT> <INPUT VALUE="Increment" TYPE=BUTTON O -
  • Navigate the - browsing context to parsedURL, with replacement enabled - and exceptions enabled.

  • +
  • Location-object navigate to parsedURL with the + replacement flag set.

  • -

    Navigation for the assign() and replace() methods must be done with the responsible - browsing context specified by the incumbent settings object as the - source browsing context.

    -

    When the reload() method is invoked, the user agent must run the appropriate steps from the following list:

    @@ -81558,66 +81904,6 @@ State: <OUTPUT NAME=I>1</OUTPUT> <INPUT VALUE="Increment" TYPE=BUTTON O
    - - - - -

    The Location interface also supports the URLUtils interface.

    - -
    - -

    When the object is created, and whenever the the - address of the relevant Document changes, the user agent must invoke - the object's URLUtils interface's set the - input algorithm with the address of the - relevant Document as the given value.

    - -

    The object's URLUtils interface's get the - base algorithm must return the API base URL specified by the entry - settings object, if there is one, or null otherwise.

    - -

    The object's URLUtils interface's query - encoding is the document's character encoding.

    - -

    When the object's URLUtils interface invokes its update steps with the string value, the - user agent must run the following steps:

    - -
      - -
    1. - -

      If any of the following conditions are met, let mode be normal - navigation; otherwise, let it be replace navigation:

      - -
        - -
      • The Location object's relevant Document has - completely loaded, or
      • - -
      • In the task in which the algorithm is running, an - activation behaviour is currently being processed whose click event was trusted, or
      • - -
      • In the task in which the algorithm is running, the event - listener for a trusted click event is being handled.
      • - -
      - -
    2. - -
    3. If mode is normal navigation, then act as if the assign() method had been called with value as its - argument. Otherwise, act as if the replace() method - had been called with value as its argument.

    4. - -
    - -
    -

    The ancestorOrigins attribute, on getting, must return a read only array whose values are determined as follows. The same object must be returned each time the attribute's value is @@ -81670,7 +81956,7 @@ State: <OUTPUT NAME=I>1</OUTPUT> <INPUT VALUE="Increment" TYPE=BUTTON O