181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)/*
281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All rights reserved.
381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) *
481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) * Redistribution and use in source and binary forms, with or without
581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) * modification, are permitted provided that the following conditions
681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) * are met:
781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) * 1. Redistributions of source code must retain the above copyright
881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) *    notice, this list of conditions and the following disclaimer.
981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright
1081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) *    notice, this list of conditions and the following disclaimer in the
1181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) *    documentation and/or other materials provided with the distribution.
1281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) *
1381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
1481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
1781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
1881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
1981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
2181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) */
2581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
2681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)#ifndef KURL_h
2781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)#define KURL_h
2881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
2951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "platform/PlatformExport.h"
3081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)#include "wtf/Forward.h"
310019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch#include "wtf/HashTableDeletedValueType.h"
3293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "wtf/OwnPtr.h"
3381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)#include "wtf/text/WTFString.h"
34e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)#include <url/third_party/mozilla/url_parse.h>
35521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)#include <url/url_canon.h>
3681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
37a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)namespace WTF {
38a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)class TextEncoding;
39a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)}
40a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)
41c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
4281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
4381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)struct KURLHash;
4481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
4581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)enum ParsedURLStringTag { ParsedURLString };
4681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
4751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)class PLATFORM_EXPORT KURL {
4881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)public:
49f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    KURL();
5093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    KURL(const KURL&);
5193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    KURL& operator=(const KURL&);
5293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
53d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)#if COMPILER_SUPPORTS(CXX_RVALUE_REFERENCES)
54d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    KURL(KURL&&);
55d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)    KURL& operator=(KURL&&);
56d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)#endif
57d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)
5893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // The argument is an absolute URL string. The string is assumed to be
5993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // output of KURL::string() called on a valid KURL object, or indiscernible
6093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // from such. It is usually best to avoid repeatedly parsing a string,
6193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // unless memory saving outweigh the possible slow-downs.
6281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    KURL(ParsedURLStringTag, const String&);
6393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    explicit KURL(WTF::HashTableDeletedValueType);
6481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
655267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Creates an isolated URL object suitable for sending to another thread.
665267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    static KURL createIsolated(ParsedURLStringTag, const String&);
675267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
6881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    bool isHashTableDeletedValue() const { return string().isHashTableDeletedValue(); }
6981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
7081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // Resolves the relative URL with the given base URL. If provided, the
7181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // TextEncoding is used to encode non-ASCII characers. The base URL can be
7281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // null or empty, in which case the relative URL will be interpreted as
7381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // absolute.
7481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // FIXME: If the base URL is invalid, this always creates an invalid
7581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // URL. Instead I think it would be better to treat all invalid base URLs
7681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // the same way we treate null and empty base URLs.
7781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    KURL(const KURL& base, const String& relative);
7881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    KURL(const KURL& base, const String& relative, const WTF::TextEncoding&);
7981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
8081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // For conversions from other structures that have already parsed and
8181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // canonicalized the URL. The input must be exactly what KURL would have
8281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // done with the same input.
8310f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    KURL(const AtomicString& canonicalString, const url::Parsed&, bool isValid);
8481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
8581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    String strippedForUseAsReferrer() const;
8681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
8781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // FIXME: The above functions should be harmonized so that passing a
8881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // base of null or the empty string gives the same result as the
8981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // standard String constructor.
9081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
9181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // Makes a deep copy. Helpful only if you need to use a KURL on another
9251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    // thread. Since the underlying StringImpl objects are immutable, there's
9381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // no other reason to ever prefer copy() over plain old assignment.
9481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    KURL copy() const;
9581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
9681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    bool isNull() const;
9781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    bool isEmpty() const;
9881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    bool isValid() const;
9981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
10081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // Returns true if this URL has a path. Note that "http://foo.com/" has a
10181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // path of "/", so this function will return true. Only invalid or
10281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // non-hierarchical (like "javascript:") URLs will have no path.
10381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    bool hasPath() const;
10481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
10581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // Returns true if you can set the host and port for the URL.
10681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // Non-hierarchical URLs don't have a host and port.
10781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    bool canSetHostOrPort() const { return isHierarchical(); }
10881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
10981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    bool canSetPathname() const { return isHierarchical(); }
11081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    bool isHierarchical() const;
11181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
11293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    const String& string() const { return m_string; }
11381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
11481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    String elidedString() const;
11581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
11681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    String protocol() const;
11781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    String host() const;
11881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    unsigned short port() const;
11981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    bool hasPort() const;
12081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    String user() const;
12181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    String pass() const;
12281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    String path() const;
12381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    String lastPathComponent() const;
12481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    String query() const;
12581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    String fragmentIdentifier() const;
12681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    bool hasFragmentIdentifier() const;
12781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
12881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    String baseAsString() const;
12981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
13081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // Returns true if the current URL's protocol is the same as the null-
13181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // terminated ASCII argument. The argument must be lower-case.
13281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    bool protocolIs(const char*) const;
13381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    bool protocolIsData() const { return protocolIs("data"); }
13410f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    // This includes at least about:blank and about:srcdoc.
13510f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    bool protocolIsAbout() const { return protocolIs("about"); }
13681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    bool protocolIsInHTTPFamily() const;
13781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    bool isLocalFile() const;
13810f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    bool isAboutBlankURL() const; // Is exactly about:blank.
13981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
14081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    bool setProtocol(const String&);
14181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    void setHost(const String&);
14281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
14381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    void removePort();
14481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    void setPort(unsigned short);
145bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)    void setPort(const String&);
14681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
14781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // Input is like "foo.com" or "foo.com:8000".
14881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    void setHostAndPort(const String&);
14981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
15081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    void setUser(const String&);
15181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    void setPass(const String&);
15281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
15381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // If you pass an empty path for HTTP or HTTPS URLs, the resulting path
15481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // will be "/".
15581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    void setPath(const String&);
15681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
15781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // The query may begin with a question mark, or, if not, one will be added
15881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // for you. Setting the query to the empty string will leave a "?" in the
15981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    // URL (with nothing after it). To clear the query, pass a null string.
16081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    void setQuery(const String&);
16181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
16281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    void setFragmentIdentifier(const String&);
16381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    void removeFragmentIdentifier();
16481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
16551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)    PLATFORM_EXPORT friend bool equalIgnoringFragmentIdentifier(const KURL&, const KURL&);
16681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
16781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    unsigned hostStart() const;
16881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    unsigned hostEnd() const;
16981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
17081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    unsigned pathStart() const;
17181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    unsigned pathEnd() const;
17281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    unsigned pathAfterLastSlash() const;
17381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
17481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    operator const String&() const { return string(); }
17581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
17610f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    const url::Parsed& parsed() const { return m_parsed; }
17781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
17893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    const KURL* innerURL() const { return m_innerURL.get(); }
17981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
18081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)#ifndef NDEBUG
18181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    void print() const;
18281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)#endif
18381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
18481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    bool isSafeToSendToAnotherThread() const;
18581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
18681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)private:
18793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    void init(const KURL& base, const String& relative, const WTF::TextEncoding* queryEncoding);
18893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
18910f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    String componentString(const url::Component&) const;
190f5e4ad553afbc08dd2e729bb77e937a9a94d5827Torne (Richard Coles)    String stringForInvalidComponent() const;
19181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
19293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    template<typename CHAR>
19310f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    void replaceComponents(const url::Replacements<CHAR>&);
19493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
19593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    template <typename CHAR>
19693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    void init(const KURL& base, const CHAR* relative, int relativeLength, const WTF::TextEncoding* queryEncoding);
19793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    void initInnerURL();
19893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    void initProtocolIsInHTTPFamily();
19993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
20093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    bool m_isValid;
20193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    bool m_protocolIsInHTTPFamily;
20210f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch    url::Parsed m_parsed;
20393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    String m_string;
20493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    OwnPtr<KURL> m_innerURL;
20581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)};
20681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
20751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)PLATFORM_EXPORT bool operator==(const KURL&, const KURL&);
20851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)PLATFORM_EXPORT bool operator==(const KURL&, const String&);
20951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)PLATFORM_EXPORT bool operator==(const String&, const KURL&);
21051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)PLATFORM_EXPORT bool operator!=(const KURL&, const KURL&);
21151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)PLATFORM_EXPORT bool operator!=(const KURL&, const String&);
21251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)PLATFORM_EXPORT bool operator!=(const String&, const KURL&);
21381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
21451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)PLATFORM_EXPORT bool equalIgnoringFragmentIdentifier(const KURL&, const KURL&);
21581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
21651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)PLATFORM_EXPORT const KURL& blankURL();
21781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
21881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)// Functions to do URL operations on strings.
21981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)// These are operations that aren't faster on a parsed URL.
22081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)// These are also different from the KURL functions in that they don't require the string to be a valid and parsable URL.
22181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)// This is especially important because valid javascript URLs are not necessarily considered valid by KURL.
22281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
22351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)PLATFORM_EXPORT bool protocolIs(const String& url, const char* protocol);
22451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)PLATFORM_EXPORT bool protocolIsJavaScript(const String& url);
22581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
22651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)PLATFORM_EXPORT bool isValidProtocol(const String&);
22781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
22881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)// Unescapes the given string using URL escaping rules, given an optional
22981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)// encoding (defaulting to UTF-8 otherwise). DANGER: If the URL has "%00"
23081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)// in it, the resulting string will have embedded null characters!
23151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)PLATFORM_EXPORT String decodeURLEscapeSequences(const String&);
23251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)PLATFORM_EXPORT String decodeURLEscapeSequences(const String&, const WTF::TextEncoding&);
23381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
23451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)PLATFORM_EXPORT String encodeWithURLEscapeSequences(const String&);
23581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
23681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)// Inlines.
23781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
23881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)inline bool operator==(const KURL& a, const KURL& b)
23981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles){
24081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    return a.string() == b.string();
24181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)}
24281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
24381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)inline bool operator==(const KURL& a, const String& b)
24481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles){
24581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    return a.string() == b;
24681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)}
24781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
24881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)inline bool operator==(const String& a, const KURL& b)
24981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles){
25081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    return a == b.string();
25181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)}
25281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
25381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)inline bool operator!=(const KURL& a, const KURL& b)
25481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles){
25581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    return a.string() != b.string();
25681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)}
25781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
25881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)inline bool operator!=(const KURL& a, const String& b)
25981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles){
26081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    return a.string() != b;
26181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)}
26281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
26381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)inline bool operator!=(const String& a, const KURL& b)
26481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles){
26581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)    return a != b.string();
26681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)}
26781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
268c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink
26981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
27081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)namespace WTF {
27181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
27293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)// KURLHash is the default hash for String
273c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)template<> struct DefaultHash<blink::KURL> {
274c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    typedef blink::KURLHash Hash;
27593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)};
27681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
27781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)} // namespace WTF
27881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)
27981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)#endif // KURL_h
280