Changeset 163208 in webkit


Ignore:
Timestamp:
Jan 31, 2014 3:06:25 PM (10 years ago)
Author:
mjs@apple.com
Message:

Implement (most of) URL API
https://bugs.webkit.org/show_bug.cgi?id=127795

Reviewed by Alexey Proskuryakov.

Source/WebCore:

Tests: fast/dom/DOMURL/get-href-attribute-port.html

fast/dom/DOMURL/invalid-url-getters.html
fast/dom/DOMURL/set-href-attribute-hash.html
fast/dom/DOMURL/set-href-attribute-host.html
fast/dom/DOMURL/set-href-attribute-hostname.html
fast/dom/DOMURL/set-href-attribute-pathname.html
fast/dom/DOMURL/set-href-attribute-port.html
fast/dom/DOMURL/set-href-attribute-protocol.html
fast/dom/DOMURL/set-href-attribute-search.html
fast/dom/DOMURL/set-href-attribute-whitespace.html
fast/dom/DOMURL/url-constructor.html
fast/dom/DOMURL/url-origin.html
fast/dom/DOMURL/url-password.html
fast/dom/DOMURL/url-username.html

  • CMakeLists.txt: Update for new IDL file.
  • DerivedSources.make: ditto
  • GNUmakefile.list.am: ditto
  • html/DOMURL.cpp: Implement URL() constructor and instance methods; cribbed from

HTMLAnchorElement mostly
(WebCore::DOMURL::DOMURL):
(WebCore::DOMURL::href):
(WebCore::DOMURL::setHref):
(WebCore::DOMURL::toString):
(WebCore::DOMURL::origin):
(WebCore::DOMURL::protocol):
(WebCore::DOMURL::setProtocol):
(WebCore::DOMURL::username):
(WebCore::DOMURL::setUsername):
(WebCore::DOMURL::password):
(WebCore::DOMURL::setPassword):
(WebCore::DOMURL::host):
(WebCore::parsePortFromStringPosition):
(WebCore::DOMURL::setHost):
(WebCore::DOMURL::hostname):
(WebCore::DOMURL::setHostname):
(WebCore::DOMURL::port):
(WebCore::DOMURL::setPort):
(WebCore::DOMURL::pathname):
(WebCore::DOMURL::setPathname):
(WebCore::DOMURL::search):
(WebCore::DOMURL::setSearch):
(WebCore::DOMURL::hash):
(WebCore::DOMURL::setHash):

  • html/DOMURL.h:

(WebCore::DOMURL::create):

  • html/DOMURL.idl: Update for new methods.
  • html/URLUtils.idl: Added. New IDL file that contains most of the interface.

LayoutTests:

Add a bunch of new tests for URL(), copied from HTMLAnchorElement API tests:

  • fast/dom/DOMURL/get-href-attribute-port-expected.txt: Added.
  • fast/dom/DOMURL/get-href-attribute-port.html: Added.
  • fast/dom/DOMURL/resources: Added.
  • fast/dom/DOMURL/resources/iframe-with-anchor.html: Added.
  • fast/dom/DOMURL/set-href-attribute-hash-expected.txt: Added.
  • fast/dom/DOMURL/set-href-attribute-hash.html: Added.
  • fast/dom/DOMURL/set-href-attribute-host-expected.txt: Added.
  • fast/dom/DOMURL/set-href-attribute-host.html: Added.
  • fast/dom/DOMURL/set-href-attribute-hostname-expected.txt: Added.
  • fast/dom/DOMURL/set-href-attribute-hostname.html: Added.
  • fast/dom/DOMURL/set-href-attribute-pathname-expected.txt: Added.
  • fast/dom/DOMURL/set-href-attribute-pathname.html: Added.
  • fast/dom/DOMURL/set-href-attribute-port-expected.txt: Added.
  • fast/dom/DOMURL/set-href-attribute-port.html: Added.
  • fast/dom/DOMURL/set-href-attribute-protocol-expected.txt: Added.
  • fast/dom/DOMURL/set-href-attribute-protocol.html: Added.
  • fast/dom/DOMURL/set-href-attribute-search-expected.txt: Added.
  • fast/dom/DOMURL/set-href-attribute-search.html: Added.
  • fast/dom/DOMURL/set-href-attribute-whitespace-expected.txt: Added.
  • fast/dom/DOMURL/set-href-attribute-whitespace.html: Added.
  • fast/dom/DOMURL/url-origin-expected.txt: Added.
  • fast/dom/DOMURL/url-origin.html: Added.

Brand new tests for username and password properties, accessors on invalid URLS,
and different constructor modes:

  • fast/dom/DOMURL/invalid-url-getters-expected.txt: Added.
  • fast/dom/DOMURL/invalid-url-getters.html: Added.
  • fast/dom/DOMURL/url-constructor-expected.txt: Added.
  • fast/dom/DOMURL/url-constructor.html: Added.
  • fast/dom/DOMURL/url-password-expected.txt: Added.
  • fast/dom/DOMURL/url-password.html: Added.
  • fast/dom/DOMURL/url-username-expected.txt: Added.
  • fast/dom/DOMURL/url-username.html: Added.

Update tests and results for the fact that URL constructor takes arguments.

  • fast/dom/DOMURL/check-instanceof-domurl-functions.html:
  • fast/dom/constructed-objects-prototypes-expected.txt:
  • fast/dom/script-tests/constructed-objects-prototypes.js:
  • js/dom/constructor-length.html:
  • platform/efl/js/dom/constructor-length-expected.txt:
  • platform/gtk-wk2/js/dom/constructor-length-expected.txt:
  • platform/gtk/js/dom/constructor-length-expected.txt:
  • platform/mac/js/dom/constructor-length-expected.txt:
Location:
trunk
Files:
29 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r163205 r163208  
     12014-01-31  Maciej Stachowiak  <mjs@apple.com>
     2
     3        Implement (most of) URL API
     4        https://bugs.webkit.org/show_bug.cgi?id=127795
     5
     6        Reviewed by Alexey Proskuryakov.
     7
     8        Add a bunch of new tests for URL(), copied from HTMLAnchorElement API tests:
     9
     10        * fast/dom/DOMURL/get-href-attribute-port-expected.txt: Added.
     11        * fast/dom/DOMURL/get-href-attribute-port.html: Added.
     12        * fast/dom/DOMURL/resources: Added.
     13        * fast/dom/DOMURL/resources/iframe-with-anchor.html: Added.
     14        * fast/dom/DOMURL/set-href-attribute-hash-expected.txt: Added.
     15        * fast/dom/DOMURL/set-href-attribute-hash.html: Added.
     16        * fast/dom/DOMURL/set-href-attribute-host-expected.txt: Added.
     17        * fast/dom/DOMURL/set-href-attribute-host.html: Added.
     18        * fast/dom/DOMURL/set-href-attribute-hostname-expected.txt: Added.
     19        * fast/dom/DOMURL/set-href-attribute-hostname.html: Added.
     20        * fast/dom/DOMURL/set-href-attribute-pathname-expected.txt: Added.
     21        * fast/dom/DOMURL/set-href-attribute-pathname.html: Added.
     22        * fast/dom/DOMURL/set-href-attribute-port-expected.txt: Added.
     23        * fast/dom/DOMURL/set-href-attribute-port.html: Added.
     24        * fast/dom/DOMURL/set-href-attribute-protocol-expected.txt: Added.
     25        * fast/dom/DOMURL/set-href-attribute-protocol.html: Added.
     26        * fast/dom/DOMURL/set-href-attribute-search-expected.txt: Added.
     27        * fast/dom/DOMURL/set-href-attribute-search.html: Added.
     28        * fast/dom/DOMURL/set-href-attribute-whitespace-expected.txt: Added.
     29        * fast/dom/DOMURL/set-href-attribute-whitespace.html: Added.
     30        * fast/dom/DOMURL/url-origin-expected.txt: Added.
     31        * fast/dom/DOMURL/url-origin.html: Added.
     32
     33        Brand new tests for username and password properties, accessors on invalid URLS,
     34        and different constructor modes:
     35        * fast/dom/DOMURL/invalid-url-getters-expected.txt: Added.
     36        * fast/dom/DOMURL/invalid-url-getters.html: Added.
     37        * fast/dom/DOMURL/url-constructor-expected.txt: Added.
     38        * fast/dom/DOMURL/url-constructor.html: Added.
     39        * fast/dom/DOMURL/url-password-expected.txt: Added.
     40        * fast/dom/DOMURL/url-password.html: Added.
     41        * fast/dom/DOMURL/url-username-expected.txt: Added.
     42        * fast/dom/DOMURL/url-username.html: Added.
     43
     44        Update tests and results for the fact that URL constructor takes arguments.
     45        * fast/dom/DOMURL/check-instanceof-domurl-functions.html:
     46        * fast/dom/constructed-objects-prototypes-expected.txt:
     47        * fast/dom/script-tests/constructed-objects-prototypes.js:
     48        * js/dom/constructor-length.html:
     49        * platform/efl/js/dom/constructor-length-expected.txt:
     50        * platform/gtk-wk2/js/dom/constructor-length-expected.txt:
     51        * platform/gtk/js/dom/constructor-length-expected.txt:
     52        * platform/mac/js/dom/constructor-length-expected.txt:
     53
    1542014-01-31  Bem Jones-Bey  <bjonesbe@adobe.com>
    255
  • trunk/LayoutTests/fast/dom/DOMURL/check-instanceof-domurl-functions.html

    r155265 r163208  
    88description("Test instanceof functions and properties of URL and webkitURL.");
    99
    10 var url = new URL;
     10var url = new URL("about:blank");
    1111
    1212shouldBeTrue("'createObjectURL' in URL");
  • trunk/LayoutTests/fast/dom/constructed-objects-prototypes-expected.txt

    r149001 r163208  
    1414PASS (new inner.ProgressEvent()).isInner is true
    1515PASS (new inner.ProgressEvent()).constructor.isInner is true
    16 PASS (new inner.URL()).isInner is true
    17 PASS (new inner.URL()).constructor.isInner is true
     16PASS (new inner.URL('about:blank')).isInner is true
     17PASS (new inner.URL('about:blank')).constructor.isInner is true
    1818PASS (new inner.XMLHttpRequest()).isInner is true
    1919PASS (new inner.XMLHttpRequest()).constructor.isInner is true
  • trunk/LayoutTests/fast/dom/script-tests/constructed-objects-prototypes.js

    r149001 r163208  
    1212
    1313var argumentsForConstructor = {
     14    'URL' : "'about:blank'",
    1415    'Worker' : "'foo'",
    1516}
  • trunk/LayoutTests/js/dom/constructor-length.html

    r156066 r163208  
    5555shouldBe('WebSocket.length', '1');
    5656shouldBe('Worker.length', '1');
    57 shouldBe('URL.length', '0');
     57shouldBe('URL.length', '1');
    5858shouldBe('XMLHttpRequest.length', '0');
    5959shouldBe('XMLSerializer.length', '0');
  • trunk/LayoutTests/platform/efl/js/dom/constructor-length-expected.txt

    r158660 r163208  
    5151PASS WebSocket.length is 1
    5252PASS Worker.length is 1
    53 PASS URL.length is 0
     53PASS URL.length is 1
    5454PASS XMLHttpRequest.length is 0
    5555PASS XMLSerializer.length is 0
  • trunk/LayoutTests/platform/gtk-wk2/js/dom/constructor-length-expected.txt

    r156412 r163208  
    5151PASS WebSocket.length is 1
    5252PASS Worker.length is 1
    53 PASS URL.length is 0
     53PASS URL.length is 1
    5454PASS XMLHttpRequest.length is 0
    5555PASS XMLSerializer.length is 0
  • trunk/LayoutTests/platform/gtk/js/dom/constructor-length-expected.txt

    r156704 r163208  
    5151PASS WebSocket.length is 1
    5252PASS Worker.length is 1
    53 PASS URL.length is 0
     53PASS URL.length is 1
    5454PASS XMLHttpRequest.length is 0
    5555PASS XMLSerializer.length is 0
  • trunk/LayoutTests/platform/mac/js/dom/constructor-length-expected.txt

    r156066 r163208  
    5151PASS WebSocket.length is 1
    5252PASS Worker.length is 1
    53 PASS URL.length is 0
     53PASS URL.length is 1
    5454PASS XMLHttpRequest.length is 0
    5555PASS XMLSerializer.length is 0
  • trunk/Source/WebCore/CMakeLists.txt

    r163195 r163208  
    493493    html/TextMetrics.idl
    494494    html/TimeRanges.idl
     495    html/URLUtils.idl
    495496    html/ValidityState.idl
    496497    html/VoidCallback.idl
  • trunk/Source/WebCore/ChangeLog

    r163205 r163208  
     12014-01-30  Maciej Stachowiak  <mjs@apple.com>
     2
     3        Implement (most of) URL API
     4        https://bugs.webkit.org/show_bug.cgi?id=127795
     5
     6        Reviewed by Alexey Proskuryakov.
     7
     8        Tests: fast/dom/DOMURL/get-href-attribute-port.html
     9               fast/dom/DOMURL/invalid-url-getters.html
     10               fast/dom/DOMURL/set-href-attribute-hash.html
     11               fast/dom/DOMURL/set-href-attribute-host.html
     12               fast/dom/DOMURL/set-href-attribute-hostname.html
     13               fast/dom/DOMURL/set-href-attribute-pathname.html
     14               fast/dom/DOMURL/set-href-attribute-port.html
     15               fast/dom/DOMURL/set-href-attribute-protocol.html
     16               fast/dom/DOMURL/set-href-attribute-search.html
     17               fast/dom/DOMURL/set-href-attribute-whitespace.html
     18               fast/dom/DOMURL/url-constructor.html
     19               fast/dom/DOMURL/url-origin.html
     20               fast/dom/DOMURL/url-password.html
     21               fast/dom/DOMURL/url-username.html
     22
     23        * CMakeLists.txt: Update for new IDL file.
     24        * DerivedSources.make: ditto
     25        * GNUmakefile.list.am: ditto
     26        * html/DOMURL.cpp: Implement URL() constructor and instance methods; cribbed from
     27        HTMLAnchorElement mostly
     28        (WebCore::DOMURL::DOMURL):
     29        (WebCore::DOMURL::href):
     30        (WebCore::DOMURL::setHref):
     31        (WebCore::DOMURL::toString):
     32        (WebCore::DOMURL::origin):
     33        (WebCore::DOMURL::protocol):
     34        (WebCore::DOMURL::setProtocol):
     35        (WebCore::DOMURL::username):
     36        (WebCore::DOMURL::setUsername):
     37        (WebCore::DOMURL::password):
     38        (WebCore::DOMURL::setPassword):
     39        (WebCore::DOMURL::host):
     40        (WebCore::parsePortFromStringPosition):
     41        (WebCore::DOMURL::setHost):
     42        (WebCore::DOMURL::hostname):
     43        (WebCore::DOMURL::setHostname):
     44        (WebCore::DOMURL::port):
     45        (WebCore::DOMURL::setPort):
     46        (WebCore::DOMURL::pathname):
     47        (WebCore::DOMURL::setPathname):
     48        (WebCore::DOMURL::search):
     49        (WebCore::DOMURL::setSearch):
     50        (WebCore::DOMURL::hash):
     51        (WebCore::DOMURL::setHash):
     52        * html/DOMURL.h:
     53        (WebCore::DOMURL::create):
     54        * html/DOMURL.idl: Update for new methods.
     55        * html/URLUtils.idl: Added. New IDL file that contains most of the interface.
     56
    1572014-01-31  Bem Jones-Bey  <bjonesbe@adobe.com>
    258
  • trunk/Source/WebCore/DerivedSources.make

    r162795 r163208  
    405405    $(WebCore)/html/TextMetrics.idl \
    406406    $(WebCore)/html/TimeRanges.idl \
     407    $(WebCore)/html/URLUtils.idl \
    407408    $(WebCore)/html/ValidityState.idl \
    408409    $(WebCore)/html/VoidCallback.idl \
  • trunk/Source/WebCore/GNUmakefile.list.am

    r163180 r163208  
    14991499        $(WebCore)/html/TextMetrics.idl \
    15001500        $(WebCore)/html/TimeRanges.idl \
     1501        $(WebCore)/html/URLUtils.idl \
    15011502        $(WebCore)/html/ValidityState.idl \
    15021503        $(WebCore)/html/VoidCallback.idl \
  • trunk/Source/WebCore/html/DOMURL.cpp

    r158650 r163208  
    11/*
     2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
     3 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
     4 *           (C) 2000 Simon Hausmann <hausmann@kde.org>
     5 * Copyright (C) 2003, 2006, 2007, 2008, 2009, 2010, 2014 Apple Inc. All rights reserved.
     6 *           (C) 2006 Graham Dennis (graham.dennis@gmail.com)
    27 * Copyright (C) 2011 Google Inc. All rights reserved.
    38 * Copyright (C) 2012 Motorola Mobility Inc.
    49 *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
     10 * This library is free software; you can redistribute it and/or
     11 * modify it under the terms of the GNU Library General Public
     12 * License as published by the Free Software Foundation; either
     13 * version 2 of the License, or (at your option) any later version.
    814 *
    9  * 1.  Redistributions of source code must retain the above copyright
    10  *     notice, this list of conditions and the following disclaimer.
    11  * 2.  Redistributions in binary form must reproduce the above copyright
    12  *     notice, this list of conditions and the following disclaimer in the
    13  *     documentation and/or other materials provided with the distribution.
     15 * This library is distributed in the hope that it will be useful,
     16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     18 * Library General Public License for more details.
    1419 *
    15  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
    16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    18  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
    19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     20 * You should have received a copy of the GNU Library General Public License
     21 * along with this library; see the file COPYING.LIB.  If not, write to
     22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     23 * Boston, MA 02110-1301, USA.
    2524 */
    2625
    2726#include "config.h"
     27#include "DOMURL.h"
     28
     29#include "SecurityOrigin.h"
    2830
    2931#if ENABLE(BLOB)
    30 
    31 #include "DOMURL.h"
    32 
    3332#include "ActiveDOMObject.h"
    3433#include "Blob.h"
     
    3837#include "ResourceRequest.h"
    3938#include "ScriptExecutionContext.h"
    40 #include "SecurityOrigin.h"
    4139#include <wtf/MainThread.h>
     40#endif // ENABLE(BLOB)
    4241
    4342namespace WebCore {
     43
     44PassRefPtr<DOMURL> DOMURL::create(const String& url, const String& base, ExceptionCode& ec)
     45{
     46    return adoptRef(new DOMURL(url, base, ec));
     47}
     48
     49PassRefPtr<DOMURL> DOMURL::create(const String& url, const DOMURL* base, ExceptionCode& ec)
     50{
     51    ASSERT(base);
     52    return adoptRef(new DOMURL(url, *base, ec));
     53}
     54
     55PassRefPtr<DOMURL> DOMURL::create(const String& url, ExceptionCode& ec)
     56{
     57    return adoptRef(new DOMURL(url, ec));
     58}
     59
     60inline DOMURL::DOMURL(const String& url, const String& base, ExceptionCode& ec)
     61    : m_baseURL(URL(), base)
     62    , m_url(m_baseURL, url)
     63{
     64    if (!m_baseURL.isValid() || !m_url.isValid())
     65        ec = TypeError;
     66}
     67
     68inline DOMURL::DOMURL(const String& url, const DOMURL& base, ExceptionCode& ec)
     69    : m_baseURL(base.href())
     70    , m_url(m_baseURL, url)
     71{
     72    if (!m_baseURL.isValid() || !m_url.isValid())
     73        ec = TypeError;
     74}
     75
     76inline DOMURL::DOMURL(const String& url, ExceptionCode& ec)
     77    : m_baseURL(blankURL())
     78    , m_url(m_baseURL, url)
     79{
     80    if (!m_url.isValid())
     81        ec = TypeError;
     82}
     83
     84const URL& DOMURL::href() const
     85{
     86    return m_url;
     87}
     88
     89void DOMURL::setHref(const String& url)
     90{
     91    m_url = URL(m_baseURL, url);
     92}
     93
     94void DOMURL::setHref(const String& url, ExceptionCode& ec)
     95{
     96    setHref(url);
     97    if (!m_url.isValid())
     98        ec = TypeError;
     99}
     100
     101const String& DOMURL::toString() const
     102{
     103    return href().string();
     104}
     105
     106String DOMURL::origin() const
     107{
     108    RefPtr<SecurityOrigin> origin = SecurityOrigin::create(href());
     109    return origin->toString();
     110}
     111
     112String DOMURL::protocol() const
     113{
     114    return href().protocol() + ':';
     115}
     116
     117void DOMURL::setProtocol(const String& value)
     118{
     119    URL url = href();
     120    url.setProtocol(value);
     121    setHref(url.string());
     122}
     123
     124String DOMURL::username() const
     125{
     126    return href().user();
     127}
     128
     129void DOMURL::setUsername(const String& user)
     130{
     131    URL url = href();
     132    url.setUser(user);
     133    setHref(url);
     134}
     135
     136String DOMURL::password() const
     137{
     138    return href().pass();
     139}
     140
     141void DOMURL::setPassword(const String& pass)
     142{
     143    URL url = href();
     144    url.setPass(pass);
     145    setHref(url);
     146}
     147
     148String DOMURL::host() const
     149{
     150    const URL& url = href();
     151    if (url.hostEnd() == url.pathStart())
     152        return url.host();
     153    if (isDefaultPortForProtocol(url.port(), url.protocol()))
     154        return url.host();
     155    return url.host() + ':' + String::number(url.port());
     156}
     157
     158// This function does not allow leading spaces before the port number.
     159static unsigned parsePortFromStringPosition(const String& value, unsigned portStart, unsigned& portEnd)
     160{
     161    portEnd = portStart;
     162    while (isASCIIDigit(value[portEnd]))
     163        ++portEnd;
     164    return value.substring(portStart, portEnd - portStart).toUInt();
     165}
     166
     167void DOMURL::setHost(const String& value)
     168{
     169    if (value.isEmpty())
     170        return;
     171    URL url = href();
     172    if (!url.canSetHostOrPort())
     173        return;
     174
     175    size_t separator = value.find(':');
     176    if (!separator)
     177        return;
     178
     179    if (separator == notFound)
     180        url.setHostAndPort(value);
     181    else {
     182        unsigned portEnd;
     183        unsigned port = parsePortFromStringPosition(value, separator + 1, portEnd);
     184        if (!port) {
     185            // http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes
     186            // specifically goes against RFC 3986 (p3.2) and
     187            // requires setting the port to "0" if it is set to empty string.
     188            url.setHostAndPort(value.substring(0, separator + 1) + '0');
     189        } else {
     190            if (isDefaultPortForProtocol(port, url.protocol()))
     191                url.setHostAndPort(value.substring(0, separator));
     192            else
     193                url.setHostAndPort(value.substring(0, portEnd));
     194        }
     195    }
     196    setHref(url.string());
     197}
     198
     199String DOMURL::hostname() const
     200{
     201    return href().host();
     202}
     203
     204void DOMURL::setHostname(const String& value)
     205{
     206    // Before setting new value:
     207    // Remove all leading U+002F SOLIDUS ("/") characters.
     208    unsigned i = 0;
     209    unsigned hostLength = value.length();
     210    while (value[i] == '/')
     211        i++;
     212
     213    if (i == hostLength)
     214        return;
     215
     216    URL url = href();
     217    if (!url.canSetHostOrPort())
     218        return;
     219
     220    url.setHost(value.substring(i));
     221    setHref(url.string());
     222}
     223
     224String DOMURL::port() const
     225{
     226    if (href().hasPort())
     227        return String::number(href().port());
     228
     229    return emptyString();
     230}
     231
     232void DOMURL::setPort(const String& value)
     233{
     234    URL url = href();
     235    if (!url.canSetHostOrPort())
     236        return;
     237
     238    // http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes
     239    // specifically goes against RFC 3986 (p3.2) and
     240    // requires setting the port to "0" if it is set to empty string.
     241    // FIXME: http://url.spec.whatwg.org/ doesn't appear to require this; test what browsers do
     242    unsigned port = value.toUInt();
     243    if (isDefaultPortForProtocol(port, url.protocol()))
     244        url.removePort();
     245    else
     246        url.setPort(port);
     247
     248    setHref(url.string());
     249}
     250
     251String DOMURL::pathname() const
     252{
     253    return href().path();
     254}
     255
     256void DOMURL::setPathname(const String& value)
     257{
     258    URL url = href();
     259    if (!url.canSetPathname())
     260        return;
     261
     262    if (value[0] == '/')
     263        url.setPath(value);
     264    else
     265        url.setPath("/" + value);
     266
     267    setHref(url.string());
     268}
     269
     270String DOMURL::search() const
     271{
     272    String query = href().query();
     273    return query.isEmpty() ? emptyString() : "?" + query;
     274}
     275
     276void DOMURL::setSearch(const String& value)
     277{
     278    URL url = href();
     279    String newSearch = (value[0] == '?') ? value.substring(1) : value;
     280    // Make sure that '#' in the query does not leak to the hash.
     281    url.setQuery(newSearch.replaceWithLiteral('#', "%23"));
     282
     283    setHref(url.string());
     284}
     285
     286String DOMURL::hash() const
     287{
     288    String fragmentIdentifier = href().fragmentIdentifier();
     289    if (fragmentIdentifier.isEmpty())
     290        return emptyString();
     291    return AtomicString(String("#" + fragmentIdentifier));
     292}
     293
     294void DOMURL::setHash(const String& value)
     295{
     296    URL url = href();
     297    if (value[0] == '#')
     298        url.setFragmentIdentifier(value.substring(1));
     299    else
     300        url.setFragmentIdentifier(value);
     301    setHref(url.string());
     302}
     303
     304#if ENABLE(BLOB)
    44305
    45306String DOMURL::createObjectURL(ScriptExecutionContext* scriptExecutionContext, Blob* blob)
     
    76337}
    77338
     339#endif // ENABLE(BLOB)
     340
    78341} // namespace WebCore
    79 
    80 #endif // ENABLE(BLOB)
  • trunk/Source/WebCore/html/DOMURL.h

    r156550 r163208  
    2828#define DOMURL_h
    2929
     30#include "ExceptionCode.h"
    3031#include "URL.h"
    3132#include <wtf/HashSet.h>
     
    4344
    4445public:
    45     static PassRefPtr<DOMURL> create() { return adoptRef(new DOMURL); }
     46    static PassRefPtr<DOMURL> create(const String& url, const String& base, ExceptionCode&);
     47    static PassRefPtr<DOMURL> create(const String& url, const DOMURL* base, ExceptionCode&);
     48    static PassRefPtr<DOMURL> create(const String& url, ExceptionCode&);
     49
     50    const URL& href() const;
     51    void setHref(const String& url);
     52    void setHref(const String&, ExceptionCode&);
     53    const String& toString() const;
     54
     55    String origin() const;
     56
     57    String protocol() const;
     58    void setProtocol(const String&);
     59
     60    String username() const;
     61    void setUsername(const String&);
     62
     63    String password() const;
     64    void setPassword(const String&);
     65
     66    String host() const;
     67    void setHost(const String&);
     68
     69    String hostname() const;
     70    void setHostname(const String&);
     71
     72    String port() const;
     73    void setPort(const String&);
     74
     75    String pathname() const;
     76    void setPathname(const String&);
     77
     78    String search() const;
     79    void setSearch(const String&);
     80
     81    String hash() const;
     82    void setHash(const String&);
     83
    4684
    4785#if ENABLE(BLOB)
     
    5391    static String createPublicURL(ScriptExecutionContext*, URLRegistrable*);
    5492#endif
     93private:
     94    DOMURL(const String& url, const String& base, ExceptionCode&);
     95    DOMURL(const String& url, const DOMURL& base, ExceptionCode&);
     96    DOMURL(const String& url, ExceptionCode&);
     97
     98    URL m_baseURL;
     99    URL m_url;
    55100};
    56101
  • trunk/Source/WebCore/html/DOMURL.idl

    r162878 r163208  
    2727[
    2828    GlobalContext=DOMWindow&WorkerGlobalScope,
    29     Constructor,
     29    Constructor(DOMString url),
     30    Constructor(DOMString url, DOMString base),
     31    Constructor(DOMString url, DOMURL base),
     32    ConstructorRaisesException,
    3033    JSGenerateToNativeObject,
    3134    JSGenerateToJSObject,
     
    3740    [CallWith=ScriptExecutionContext,Conditional=BLOB] static void revokeObjectURL(DOMString url);
    3841};
     42
     43DOMURL implements URLUtils;
Note: See TracChangeset for help on using the changeset viewer.