Changeset 50784 in webkit


Ignore:
Timestamp:
Nov 10, 2009 6:07:18 PM (14 years ago)
Author:
eric@webkit.org
Message:

2009-11-10 Yael Aharon <yael.aharon@nokia.com>

Reviewed by Timothy Hatcher.

Implement URL decomposition IDL attributes for HTMLAnchorElement.
https://bugs.webkit.org/show_bug.cgi?id=29972

Testcases for setting and getting different parts of the URL.

  • fast/dom/HTMLAnchorElement: Added.
  • fast/dom/HTMLAnchorElement/script-tests: Added.
  • fast/dom/HTMLAnchorElement/script-tests/TEMPLATE.html: Added.
  • fast/dom/HTMLAnchorElement/script-tests/set-href-attribute-hash.js: Added.
  • fast/dom/HTMLAnchorElement/script-tests/set-href-attribute-host.js: Added.
  • fast/dom/HTMLAnchorElement/script-tests/set-href-attribute-hostname.js: Added.
  • fast/dom/HTMLAnchorElement/script-tests/set-href-attribute-pathname.js: Added.
  • fast/dom/HTMLAnchorElement/script-tests/set-href-attribute-port.js: Added.
  • fast/dom/HTMLAnchorElement/script-tests/set-href-attribute-protocol.js: Added.
  • fast/dom/HTMLAnchorElement/script-tests/set-href-attribute-search.js: Added.
  • fast/dom/HTMLAnchorElement/set-href-attribute-hash-expected.txt: Added.
  • fast/dom/HTMLAnchorElement/set-href-attribute-hash.html: Added.
  • fast/dom/HTMLAnchorElement/set-href-attribute-host-expected.txt: Added.
  • fast/dom/HTMLAnchorElement/set-href-attribute-host.html: Added.
  • fast/dom/HTMLAnchorElement/set-href-attribute-hostname-expected.txt: Added.
  • fast/dom/HTMLAnchorElement/set-href-attribute-hostname.html: Added.
  • fast/dom/HTMLAnchorElement/set-href-attribute-pathname-expected.txt: Added.
  • fast/dom/HTMLAnchorElement/set-href-attribute-pathname.html: Added.
  • fast/dom/HTMLAnchorElement/set-href-attribute-port-expected.txt: Added.
  • fast/dom/HTMLAnchorElement/set-href-attribute-port.html: Added.
  • fast/dom/HTMLAnchorElement/set-href-attribute-protocol-expected.txt: Added.
  • fast/dom/HTMLAnchorElement/set-href-attribute-protocol.html: Added.
  • fast/dom/HTMLAnchorElement/set-href-attribute-search-expected.txt: Added.
  • fast/dom/HTMLAnchorElement/set-href-attribute-search.html: Added.

2009-11-10 Yael Aharon <yael.aharon@nokia.com>

Reviewed by Timothy Hatcher.

Implement URL decomposition IDL attributes for HTMLAnchorElement.
https://bugs.webkit.org/show_bug.cgi?id=29972.

Add methods for setting different parts of the URL in href attribute.

Tests: fast/dom/HTMLAnchorElement/set-href-attribute-hash.html

fast/dom/HTMLAnchorElement/set-href-attribute-host.html
fast/dom/HTMLAnchorElement/set-href-attribute-hostname.html
fast/dom/HTMLAnchorElement/set-href-attribute-pathname.html
fast/dom/HTMLAnchorElement/set-href-attribute-port.html
fast/dom/HTMLAnchorElement/set-href-attribute-protocol.html
fast/dom/HTMLAnchorElement/set-href-attribute-search.html

  • bindings/js/JSLocationCustom.cpp: (WebCore::JSLocation::setPort):
  • html/HTMLAnchorElement.cpp: (WebCore::parsePortFromStringPosition): (WebCore::HTMLAnchorElement::setHash): (WebCore::HTMLAnchorElement::setHost): (WebCore::HTMLAnchorElement::setHostname): (WebCore::HTMLAnchorElement::setPathname): (WebCore::HTMLAnchorElement::setPort): (WebCore::HTMLAnchorElement::setProtocol): (WebCore::HTMLAnchorElement::setSearch):
  • html/HTMLAnchorElement.h:
  • html/HTMLAnchorElement.idl:
  • loader/FrameLoader.cpp: (WebCore::FrameLoader::iconURL):
  • platform/KURL.cpp: (WebCore::KURL::removePort): (WebCore::KURL::setPort): (WebCore::KURL::prettyURL): (WebCore::protocolIsValid):
  • platform/KURL.h: (WebCore::KURL::canSetHostOrPort): (WebCore::KURL::canSetPathname): (WebCore::KURL::hasPort):
  • platform/network/soup/ResourceHandleSoup.cpp: (WebCore::):
Location:
trunk
Files:
24 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r50782 r50784  
     12009-11-10  Yael Aharon  <yael.aharon@nokia.com>
     2
     3        Reviewed by Timothy Hatcher.
     4
     5        Implement URL decomposition IDL attributes for HTMLAnchorElement.
     6        https://bugs.webkit.org/show_bug.cgi?id=29972
     7
     8        Testcases for setting and getting different parts of the URL.
     9
     10        * fast/dom/HTMLAnchorElement: Added.
     11        * fast/dom/HTMLAnchorElement/script-tests: Added.
     12        * fast/dom/HTMLAnchorElement/script-tests/TEMPLATE.html: Added.
     13        * fast/dom/HTMLAnchorElement/script-tests/set-href-attribute-hash.js: Added.
     14        * fast/dom/HTMLAnchorElement/script-tests/set-href-attribute-host.js: Added.
     15        * fast/dom/HTMLAnchorElement/script-tests/set-href-attribute-hostname.js: Added.
     16        * fast/dom/HTMLAnchorElement/script-tests/set-href-attribute-pathname.js: Added.
     17        * fast/dom/HTMLAnchorElement/script-tests/set-href-attribute-port.js: Added.
     18        * fast/dom/HTMLAnchorElement/script-tests/set-href-attribute-protocol.js: Added.
     19        * fast/dom/HTMLAnchorElement/script-tests/set-href-attribute-search.js: Added.
     20        * fast/dom/HTMLAnchorElement/set-href-attribute-hash-expected.txt: Added.
     21        * fast/dom/HTMLAnchorElement/set-href-attribute-hash.html: Added.
     22        * fast/dom/HTMLAnchorElement/set-href-attribute-host-expected.txt: Added.
     23        * fast/dom/HTMLAnchorElement/set-href-attribute-host.html: Added.
     24        * fast/dom/HTMLAnchorElement/set-href-attribute-hostname-expected.txt: Added.
     25        * fast/dom/HTMLAnchorElement/set-href-attribute-hostname.html: Added.
     26        * fast/dom/HTMLAnchorElement/set-href-attribute-pathname-expected.txt: Added.
     27        * fast/dom/HTMLAnchorElement/set-href-attribute-pathname.html: Added.
     28        * fast/dom/HTMLAnchorElement/set-href-attribute-port-expected.txt: Added.
     29        * fast/dom/HTMLAnchorElement/set-href-attribute-port.html: Added.
     30        * fast/dom/HTMLAnchorElement/set-href-attribute-protocol-expected.txt: Added.
     31        * fast/dom/HTMLAnchorElement/set-href-attribute-protocol.html: Added.
     32        * fast/dom/HTMLAnchorElement/set-href-attribute-search-expected.txt: Added.
     33        * fast/dom/HTMLAnchorElement/set-href-attribute-search.html: Added.
     34
    1352009-11-10  Brian Weinstein  <bweinstein@apple.com>
    236
  • trunk/WebCore/ChangeLog

    r50781 r50784  
     12009-11-10  Yael Aharon  <yael.aharon@nokia.com>
     2
     3        Reviewed by Timothy Hatcher.
     4
     5        Implement URL decomposition IDL attributes for HTMLAnchorElement.
     6        https://bugs.webkit.org/show_bug.cgi?id=29972.
     7
     8        Add methods for setting different parts of the URL in href attribute.
     9
     10        Tests: fast/dom/HTMLAnchorElement/set-href-attribute-hash.html
     11               fast/dom/HTMLAnchorElement/set-href-attribute-host.html
     12               fast/dom/HTMLAnchorElement/set-href-attribute-hostname.html
     13               fast/dom/HTMLAnchorElement/set-href-attribute-pathname.html
     14               fast/dom/HTMLAnchorElement/set-href-attribute-port.html
     15               fast/dom/HTMLAnchorElement/set-href-attribute-protocol.html
     16               fast/dom/HTMLAnchorElement/set-href-attribute-search.html
     17
     18        * bindings/js/JSLocationCustom.cpp:
     19        (WebCore::JSLocation::setPort):
     20        * html/HTMLAnchorElement.cpp:
     21        (WebCore::parsePortFromStringPosition):
     22        (WebCore::HTMLAnchorElement::setHash):
     23        (WebCore::HTMLAnchorElement::setHost):
     24        (WebCore::HTMLAnchorElement::setHostname):
     25        (WebCore::HTMLAnchorElement::setPathname):
     26        (WebCore::HTMLAnchorElement::setPort):
     27        (WebCore::HTMLAnchorElement::setProtocol):
     28        (WebCore::HTMLAnchorElement::setSearch):
     29        * html/HTMLAnchorElement.h:
     30        * html/HTMLAnchorElement.idl:
     31        * loader/FrameLoader.cpp:
     32        (WebCore::FrameLoader::iconURL):
     33        * platform/KURL.cpp:
     34        (WebCore::KURL::removePort):
     35        (WebCore::KURL::setPort):
     36        (WebCore::KURL::prettyURL):
     37        (WebCore::protocolIsValid):
     38        * platform/KURL.h:
     39        (WebCore::KURL::canSetHostOrPort):
     40        (WebCore::KURL::canSetPathname):
     41        (WebCore::KURL::hasPort):
     42        * platform/network/soup/ResourceHandleSoup.cpp:
     43        (WebCore::):
     44
    1452009-11-10  Nate Chapin  <japhet@chromium.org>
    246
  • trunk/WebCore/bindings/js/JSLocationCustom.cpp

    r48994 r50784  
    258258    int port = charactersToInt(portString.data(), portString.size());
    259259    if (port < 0 || port > 0xFFFF)
    260         port = 0;
    261     url.setPort(port);
     260        url.removePort();
     261    else
     262        url.setPort(port);
    262263
    263264    navigateIfAllowed(exec, frame, url, !frame->script()->anyPageIsProcessingUserGesture(), false);
  • trunk/WebCore/html/HTMLAnchorElement.cpp

    r50315 r50784  
    5959}
    6060
     61// This function does not allow leading spaces before the port number.
     62static unsigned parsePortFromStringPosition(const String& value, unsigned portStart, unsigned& portEnd)
     63{
     64    portEnd = portStart;
     65    while (isASCIIDigit(value[portEnd]))
     66        ++portEnd;
     67    return value.substring(portStart, portEnd - portStart).toUInt();
     68}
     69
    6170bool HTMLAnchorElement::supportsFocus() const
    6271{
     
    363372}
    364373
     374void HTMLAnchorElement::setHash(const String& value)
     375{
     376    KURL url = href();
     377    if (value[0] == '#')
     378        url.setFragmentIdentifier(value.substring(1));
     379    else
     380        url.setFragmentIdentifier(value);
     381    setHref(url.string());
     382}
     383
    365384String HTMLAnchorElement::host() const
    366385{
     
    373392}
    374393
     394void HTMLAnchorElement::setHost(const String& value)
     395{
     396    if (value.isEmpty())
     397        return;
     398    KURL url = href();
     399    if (!url.canSetHostOrPort())
     400        return;
     401
     402    int separator = value.find(':');
     403    if (!separator)
     404        return;
     405
     406    if (separator == -1)
     407        url.setHostAndPort(value);
     408    else {
     409        unsigned portEnd;
     410        unsigned port = parsePortFromStringPosition(value, separator + 1, portEnd);
     411        if (!port) {
     412            // http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes
     413            // specifically goes against RFC 3986 (p3.2) and
     414            // requires setting the port to "0" if it is set to empty string.
     415            url.setHostAndPort(value.substring(0, separator + 1) + "0");
     416        } else {
     417            if (SecurityOrigin::isDefaultPortForProtocol(port, url.protocol()))
     418                url.setHostAndPort(value.substring(0, separator));
     419            else
     420                url.setHostAndPort(value.substring(0, portEnd));
     421        }
     422    }
     423    setHref(url.string());
     424}
     425
    375426String HTMLAnchorElement::hostname() const
    376427{
     
    378429}
    379430
     431void HTMLAnchorElement::setHostname(const String& value)
     432{
     433    // Before setting new value:
     434    // Remove all leading U+002F SOLIDUS ("/") characters.
     435    unsigned i = 0;
     436    unsigned hostLength = value.length();
     437    while (value[i] == '/')
     438        i++;
     439
     440    if (i == hostLength)
     441        return;
     442
     443    KURL url = href();
     444    if (!url.canSetHostOrPort())
     445        return;
     446
     447    url.setHost(value.substring(i));
     448    setHref(url.string());
     449}
     450
    380451String HTMLAnchorElement::pathname() const
    381452{
     
    383454}
    384455
     456void HTMLAnchorElement::setPathname(const String& value)
     457{
     458    KURL url = href();
     459    if (!url.canSetPathname())
     460        return;
     461
     462    if (value[0] == '/')
     463        url.setPath(value);
     464    else
     465        url.setPath("/" + value);
     466
     467    setHref(url.string());
     468}
     469
    385470String HTMLAnchorElement::port() const
    386471{
     
    388473}
    389474
     475void HTMLAnchorElement::setPort(const String& value)
     476{
     477    KURL url = href();
     478    if (!url.canSetHostOrPort())
     479        return;
     480
     481    // http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes
     482    // specifically goes against RFC 3986 (p3.2) and
     483    // requires setting the port to "0" if it is set to empty string.
     484    unsigned port = value.toUInt();
     485    if (SecurityOrigin::isDefaultPortForProtocol(port, url.protocol()))
     486        url.removePort();
     487    else
     488        url.setPort(port);
     489
     490    setHref(url.string());
     491}
     492
    390493String HTMLAnchorElement::protocol() const
    391494{
    392495    return href().protocol() + ":";
     496}
     497
     498void HTMLAnchorElement::setProtocol(const String& value)
     499{
     500    int separator = value.find(':');
     501
     502    if (!separator)
     503        return;
     504    if (value.isEmpty())
     505        return;
     506
     507    KURL url = href();
     508    // Following Firefox 3.5.2 which removes anything after the first ":"
     509    String newProtocol = value.substring(0, separator);
     510    if (!protocolIsValid(newProtocol))
     511        return;
     512    url.setProtocol(newProtocol);
     513
     514    setHref(url.string());
    393515}
    394516
     
    397519    String query = href().query();
    398520    return query.isEmpty() ? "" : "?" + query;
     521}
     522
     523void HTMLAnchorElement::setSearch(const String& value)
     524{
     525    KURL url = href();
     526    String newSearch = (value[0] == '?') ? value.substring(1) : value;
     527    // Make sure that '#' in the query does not leak to the hash.
     528    url.setQuery(newSearch.replace('#', "%23"));
     529
     530    setHref(url.string());
    399531}
    400532
  • trunk/WebCore/html/HTMLAnchorElement.h

    r49809 r50784  
    6363
    6464    String hash() const;
     65    void setHash(const String&);
     66
    6567    String host() const;
     68    void setHost(const String&);
     69
    6670    String hostname() const;
     71    void setHostname(const String&);
     72
    6773    String pathname() const;
     74    void setPathname(const String&);
     75
    6876    String port() const;
     77    void setPort(const String&);
     78
    6979    String protocol() const;
     80    void setProtocol(const String&);
     81
    7082    String search() const;
     83    void setSearch(const String&);
     84
    7185    String text() const;
    7286
  • trunk/WebCore/html/HTMLAnchorElement.idl

    r45893 r50784  
    3838        attribute [ConvertNullToNullString, Reflect] DOMString type;
    3939
    40         // IE Extensions
     40#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C
    4141        readonly attribute DOMString hash;
    4242        readonly attribute DOMString host;
     
    4646        readonly attribute DOMString protocol;
    4747        readonly attribute DOMString search;
     48#else
     49        attribute [ConvertNullToNullString] DOMString hash;
     50        attribute [ConvertNullToNullString] DOMString host;
     51        attribute [ConvertNullToNullString] DOMString hostname;
     52        attribute [ConvertNullToNullString] DOMString pathname;
     53        attribute [ConvertNullToNullString] DOMString port;
     54        attribute [ConvertNullToNullString] DOMString protocol;
     55        attribute [ConvertNullToNullString] DOMString search;
     56#endif
     57
    4858        readonly attribute DOMString text;
    4959
  • trunk/WebCore/loader/FrameLoader.cpp

    r50698 r50784  
    606606    url.setProtocol(m_URL.protocol());
    607607    url.setHost(m_URL.host());
    608     if (int port = m_URL.port())
    609         url.setPort(port);
     608    if (m_URL.hasPort())
     609        url.setPort(m_URL.port());
    610610    url.setPath("/favicon.ico");
    611611    return url;
  • trunk/WebCore/platform/KURL.cpp

    r50395 r50784  
    686686}
    687687
     688void KURL::removePort()
     689{
     690    if (m_hostEnd == m_portEnd)
     691        return;
     692    parse(m_string.left(m_hostEnd) + m_string.substring(m_portEnd));
     693}
     694
    688695void KURL::setPort(unsigned short i)
    689696{
     
    691698        return;
    692699
    693     if (i) {
    694         bool colonNeeded = m_portEnd == m_hostEnd;
    695         int portStart = (colonNeeded ? m_hostEnd : m_hostEnd + 1);
    696 
    697         parse(m_string.left(portStart) + (colonNeeded ? ":" : "") + String::number(i) + m_string.substring(m_portEnd));
    698     } else
    699         parse(m_string.left(m_hostEnd) + m_string.substring(m_portEnd));
     700    bool colonNeeded = m_portEnd == m_hostEnd;
     701    int portStart = (colonNeeded ? m_hostEnd : m_hostEnd + 1);
     702
     703    parse(m_string.left(portStart) + (colonNeeded ? ":" : "") + String::number(i) + m_string.substring(m_portEnd));
    700704}
    701705
     
    820824        }
    821825        append(authority, host());
    822         if (port() != 0) {
     826        if (hasPort()) {
    823827            authority.append(':');
    824828            append(authority, String::number(port()));
     
    16251629}
    16261630
     1631bool protocolIsValid(const String& protocol)
     1632{
     1633    if (!isSchemeFirstChar(protocol[0]))
     1634        return false;
     1635    unsigned protocolLength = protocol.length();
     1636    for (unsigned i = 1; i < protocolLength; i++) {
     1637        if (!isSchemeChar(protocol[i]))
     1638            return false;
     1639    }
     1640    return true;
     1641}
     1642
    16271643String mimeTypeFromDataURL(const String& url)
    16281644{
  • trunk/WebCore/platform/KURL.h

    r47907 r50784  
    7979    KURL(const KURL& base, const String& relative, const TextEncoding&);
    8080
     81
    8182#if USE(GOOGLEURL)
    8283    // For conversions for other structures that have already parsed and
     
    105106    bool hasPath() const;
    106107
     108    // Returns true if you can set the host and port for the URL.
     109    // Non-hierarchical URLs don't have a host and port.
     110    bool canSetHostOrPort() const { return isHierarchical(); }
     111
     112    bool canSetPathname() const { return isHierarchical(); }
     113   
    107114#if USE(GOOGLEURL)
    108115    const String& string() const { return m_url.string(); }
     
    114121    String host() const;
    115122    unsigned short port() const;
     123    bool hasPort() const;
    116124    String user() const;
    117125    String pass() const;
     
    136144    void setHost(const String&);
    137145
    138     // Setting the port to 0 will clear any port from the URL.
     146    void removePort();
    139147    void setPort(unsigned short);
    140148
     
    255263bool protocolIs(const String& url, const char* protocol);
    256264bool protocolIsJavaScript(const String& url);
     265bool protocolIsValid(const String& protocol);
    257266
    258267String mimeTypeFromDataURL(const String& url);
     
    318327}
    319328
     329inline bool KURL::hasPort() const
     330{
     331    return m_hostEnd < m_portEnd;
     332}
     333
    320334inline bool KURL::protocolInHTTPFamily() const
    321335{
  • trunk/WebCore/platform/network/soup/ResourceHandleSoup.cpp

    r50423 r50784  
    874874    url.removeFragmentIdentifier();
    875875    url.setQuery(String());
    876     url.setPort(0);
     876    url.removePort();
    877877
    878878#if !PLATFORM(WIN_OS)
Note: See TracChangeset for help on using the changeset viewer.