1fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood/* 2fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 3fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * 4fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * Redistribution and use in source and binary forms, with or without 5fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * modification, are permitted provided that the following conditions 6fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * are met: 7fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * 1. Redistributions of source code must retain the above copyright 8fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * notice, this list of conditions and the following disclaimer. 9fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * 2. Redistributions in binary form must reproduce the above copyright 10fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * notice, this list of conditions and the following disclaimer in the 11fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * documentation and/or other materials provided with the distribution. 12fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * 13fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 187a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19f32ccb142919068f22ac0a0c19459c9153f70ecaMathew Inwood * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 207a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 217a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 227a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 237a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24f32ccb142919068f22ac0a0c19459c9153f70ecaMathew Inwood */ 257a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 267a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood#ifndef KURL_h 277a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood#define KURL_h 28f919c948d7dc585d1ca5fe5f357ec327ea2323c4Mathew Inwood 297a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood#include "PlatformString.h" 30fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood#include "URLString.h" 31fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood#include <wtf/HashMap.h> 32fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 33fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood#if USE(CF) 34fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwoodtypedef const struct __CFURL* CFURLRef; 357a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood#endif 36f32ccb142919068f22ac0a0c19459c9153f70ecaMathew Inwood 377a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood#if PLATFORM(MAC) 38fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood#ifdef __OBJC__ 39fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood@class NSURL; 40fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood#else 41fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwoodclass NSURL; 42fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood#endif 43f919c948d7dc585d1ca5fe5f357ec327ea2323c4Mathew Inwood#endif 44f919c948d7dc585d1ca5fe5f357ec327ea2323c4Mathew Inwood 457a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood#if PLATFORM(QT) 467a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew InwoodQT_BEGIN_NAMESPACE 477a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwoodclass QUrl; 48fd4a4cbc1143a734d357897531daa7105db6459bMathew InwoodQT_END_NAMESPACE 497a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood#endif 507a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 51fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood#if USE(GOOGLEURL) 5277909685887bd6db7454b73cf274afc3aca2f58dBjorn Bringert#include "KURLGooglePrivate.h" 5377909685887bd6db7454b73cf274afc3aca2f58dBjorn Bringert#endif 54fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 557a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood#if USE(JSC) 567a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood#include <runtime/UString.h> 577a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood#endif 587a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 597a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwoodnamespace WebCore { 607a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 617a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwoodclass TextEncoding; 627a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwoodstruct KURLHash; 637a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 647a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwoodtypedef HashMap<String, String> ParsedURLParameters; 65116affd19a834a2df4226a1ae37afcc1113a230eMathew Inwood 66116affd19a834a2df4226a1ae37afcc1113a230eMathew Inwoodenum ParsedURLStringTag { ParsedURLString }; 67116affd19a834a2df4226a1ae37afcc1113a230eMathew Inwood 68116affd19a834a2df4226a1ae37afcc1113a230eMathew Inwoodclass KURL { 69116affd19a834a2df4226a1ae37afcc1113a230eMathew Inwoodpublic: 707a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood // Generates a URL which contains a null string. 717a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood KURL() { invalidate(); } 72fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 73fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood // The argument is an absolute URL string. The string is assumed to be output of KURL::string() called on a valid 74fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood // KURL object, or indiscernible from such. 75fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood // It is usually best to avoid repeatedly parsing a string, unless memory saving outweigh the possible slow-downs. 76fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood KURL(ParsedURLStringTag, const char*); 77fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood KURL(ParsedURLStringTag, const String&); 78fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood KURL(ParsedURLStringTag, const URLString&); 79fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood#if USE(GOOGLEURL) 80fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood KURL(WTF::HashTableDeletedValueType) : m_url(WTF::HashTableDeletedValue) { } 817a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood#else 82fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood KURL(WTF::HashTableDeletedValueType) : m_string(WTF::HashTableDeletedValue) { } 83fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood#endif 84fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood bool isHashTableDeletedValue() const { return string().isHashTableDeletedValue(); } 85fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 86fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood // Resolves the relative URL with the given base URL. If provided, the 877a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood // TextEncoding is used to encode non-ASCII characers. The base URL can be 88fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood // null or empty, in which case the relative URL will be interpreted as 89fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood // absolute. 90fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood // FIXME: If the base URL is invalid, this always creates an invalid 91fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood // URL. Instead I think it would be better to treat all invalid base URLs 92fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood // the same way we treate null and empty base URLs. 93f32ccb142919068f22ac0a0c19459c9153f70ecaMathew Inwood KURL(const KURL& base, const String& relative); 947a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood KURL(const KURL& base, const String& relative, const TextEncoding&); 957a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 967a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 97f32ccb142919068f22ac0a0c19459c9153f70ecaMathew Inwood#if USE(GOOGLEURL) 98f32ccb142919068f22ac0a0c19459c9153f70ecaMathew Inwood // For conversions for other structures that have already parsed and 99f32ccb142919068f22ac0a0c19459c9153f70ecaMathew Inwood // canonicalized the URL. The input must be exactly what KURL would have 100f32ccb142919068f22ac0a0c19459c9153f70ecaMathew Inwood // done with the same input. 101f32ccb142919068f22ac0a0c19459c9153f70ecaMathew Inwood KURL(const CString& canonicalSpec, 102f32ccb142919068f22ac0a0c19459c9153f70ecaMathew Inwood const url_parse::Parsed& parsed, bool isValid); 103f32ccb142919068f22ac0a0c19459c9153f70ecaMathew Inwood#endif 104f32ccb142919068f22ac0a0c19459c9153f70ecaMathew Inwood 1057a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood String strippedForUseAsReferrer() const; 1067a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 1077a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood // FIXME: The above functions should be harmonized so that passing a 1087a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood // base of null or the empty string gives the same result as the 109f32ccb142919068f22ac0a0c19459c9153f70ecaMathew Inwood // standard String constructor. 1107a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 1117a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood // Makes a deep copy. Helpful only if you need to use a KURL on another 1127a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood // thread. Since the underlying StringImpl objects are immutable, there's 1137a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood // no other reason to ever prefer copy() over plain old assignment. 114f32ccb142919068f22ac0a0c19459c9153f70ecaMathew Inwood KURL copy() const; 115f32ccb142919068f22ac0a0c19459c9153f70ecaMathew Inwood 116f32ccb142919068f22ac0a0c19459c9153f70ecaMathew Inwood bool isNull() const; 117f32ccb142919068f22ac0a0c19459c9153f70ecaMathew Inwood bool isEmpty() const; 118f32ccb142919068f22ac0a0c19459c9153f70ecaMathew Inwood bool isValid() const; 119af1ca2cc65a2c2fdf6f396126e235d64e4da0936Mathew Inwood 120f32ccb142919068f22ac0a0c19459c9153f70ecaMathew Inwood // Returns true if this URL has a path. Note that "http://foo.com/" has a 121f32ccb142919068f22ac0a0c19459c9153f70ecaMathew Inwood // path of "/", so this function will return true. Only invalid or 122f32ccb142919068f22ac0a0c19459c9153f70ecaMathew Inwood // non-hierarchical (like "javascript:") URLs will have no path. 123f32ccb142919068f22ac0a0c19459c9153f70ecaMathew Inwood bool hasPath() const; 124f32ccb142919068f22ac0a0c19459c9153f70ecaMathew Inwood 125f32ccb142919068f22ac0a0c19459c9153f70ecaMathew Inwood // Returns true if you can set the host and port for the URL. 126f32ccb142919068f22ac0a0c19459c9153f70ecaMathew Inwood // Non-hierarchical URLs don't have a host and port. 1277a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood bool canSetHostOrPort() const { return isHierarchical(); } 1287a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 1297a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood bool canSetPathname() const { return isHierarchical(); } 1307a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 1317a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood#if USE(GOOGLEURL) 1327a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood const String& string() const { return m_url.string(); } 1337a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood URLString urlString() const { return URLString(m_url.string()); } 13445f42cab0664a8a23975e8913dbe77c1fd8ad86cMathew Inwood#else 13545f42cab0664a8a23975e8913dbe77c1fd8ad86cMathew Inwood const String& string() const { return m_string; } 13645f42cab0664a8a23975e8913dbe77c1fd8ad86cMathew Inwood URLString urlString() const { return URLString(m_string); } 1377a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood#endif 1387a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 139fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood String protocol() const; 1407a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood String host() const; 1417a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood unsigned short port() const; 1427a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood bool hasPort() const; 1437a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood String user() const; 1447a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood String pass() const; 14545f42cab0664a8a23975e8913dbe77c1fd8ad86cMathew Inwood String path() const; 1467a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood String lastPathComponent() const; 1477a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood String query() const; 1487a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood String fragmentIdentifier() const; 1497a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood bool hasFragmentIdentifier() const; 1507a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 1517a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood void copyParsedQueryTo(ParsedURLParameters&) const; 1527a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 1537a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood String baseAsString() const; 1547a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 155f919c948d7dc585d1ca5fe5f357ec327ea2323c4Mathew Inwood String prettyURL() const; 156f919c948d7dc585d1ca5fe5f357ec327ea2323c4Mathew Inwood String fileSystemPath() const; 1577a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 158f919c948d7dc585d1ca5fe5f357ec327ea2323c4Mathew Inwood // Returns true if the current URL's protocol is the same as the null- 159f919c948d7dc585d1ca5fe5f357ec327ea2323c4Mathew Inwood // terminated ASCII argument. The argument must be lower-case. 1607a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood bool protocolIs(const char*) const; 1617a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood bool protocolIsData() const { return protocolIs("data"); } 1627a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood bool protocolInHTTPFamily() const; 163f919c948d7dc585d1ca5fe5f357ec327ea2323c4Mathew Inwood bool isLocalFile() const; 164f919c948d7dc585d1ca5fe5f357ec327ea2323c4Mathew Inwood 165f919c948d7dc585d1ca5fe5f357ec327ea2323c4Mathew Inwood bool setProtocol(const String&); 166f919c948d7dc585d1ca5fe5f357ec327ea2323c4Mathew Inwood void setHost(const String&); 167f919c948d7dc585d1ca5fe5f357ec327ea2323c4Mathew Inwood 168f919c948d7dc585d1ca5fe5f357ec327ea2323c4Mathew Inwood void removePort(); 169f919c948d7dc585d1ca5fe5f357ec327ea2323c4Mathew Inwood void setPort(unsigned short); 170fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 171fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood // Input is like "foo.com" or "foo.com:8000". 172fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood void setHostAndPort(const String&); 173fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 1747a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood void setUser(const String&); 175fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood void setPass(const String&); 176fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 177fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood // If you pass an empty path for HTTP or HTTPS URLs, the resulting path 178fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood // will be "/". 179fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood void setPath(const String&); 1807a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 181f919c948d7dc585d1ca5fe5f357ec327ea2323c4Mathew Inwood // The query may begin with a question mark, or, if not, one will be added 1827a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood // for you. Setting the query to the empty string will leave a "?" in the 1837a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood // URL (with nothing after it). To clear the query, pass a null string. 184fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood void setQuery(const String&); 185fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 186fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood void setFragmentIdentifier(const String&); 187fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood void removeFragmentIdentifier(); 188f919c948d7dc585d1ca5fe5f357ec327ea2323c4Mathew Inwood 189f919c948d7dc585d1ca5fe5f357ec327ea2323c4Mathew Inwood friend bool equalIgnoringFragmentIdentifier(const KURL&, const KURL&); 190fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 191fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood friend bool protocolHostAndPortAreEqual(const KURL&, const KURL&); 192fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 1937a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood unsigned hostStart() const; 1947a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood unsigned hostEnd() const; 1957a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 1967a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood unsigned pathStart() const; 197f919c948d7dc585d1ca5fe5f357ec327ea2323c4Mathew Inwood unsigned pathEnd() const; 198f919c948d7dc585d1ca5fe5f357ec327ea2323c4Mathew Inwood unsigned pathAfterLastSlash() const; 199f919c948d7dc585d1ca5fe5f357ec327ea2323c4Mathew Inwood operator const String&() const { return string(); } 2007a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 2017a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood#if USE(CF) 2027a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood KURL(CFURLRef); 2037a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood CFURLRef createCFURL() const; 2047a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood#endif 2057a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 2067a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood#if PLATFORM(MAC) 2077a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood KURL(NSURL*); 2087a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood operator NSURL*() const; 209af1ca2cc65a2c2fdf6f396126e235d64e4da0936Mathew Inwood#endif 2107a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood#ifdef __OBJC__ 2117a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood operator NSString*() const { return string(); } 2127a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood#endif 2137a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 214fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood#if PLATFORM(QT) 215fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood KURL(const QUrl&); 216fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood operator QUrl() const; 217fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood#endif 2187a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 219fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood#if USE(GOOGLEURL) 220fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood // Getters for the parsed structure and its corresponding 8-bit string. 221fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood const url_parse::Parsed& parsed() const { return m_url.m_parsed; } 222fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood const CString& utf8String() const { return m_url.utf8String(); } 2237a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood#endif 224fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 225fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood#ifndef NDEBUG 226fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood void print() const; 227fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood#endif 228fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 2297a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwoodprivate: 2307a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood void invalidate(); 2317a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood bool isHierarchical() const; 2327a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood static bool protocolIs(const String&, const char*); 2337a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood#if USE(GOOGLEURL) 2347a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood friend class KURLGooglePrivate; 2357a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood void parse(const char* url, const String* originalString); // KURLMac calls this. 2367a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood void copyToBuffer(Vector<char, 512>& buffer) const; // KURLCFNet uses this. 2377a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood KURLGooglePrivate m_url; 2387a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood#else // !USE(GOOGLEURL) 2397a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood void init(const KURL&, const String&, const TextEncoding&); 2407a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood void copyToBuffer(Vector<char, 512>& buffer) const; 2417a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 2427a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood // Parses the given URL. The originalString parameter allows for an 243fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood // optimization: When the source is the same as the fixed-up string, 244fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood // it will use the passed-in string instead of allocating a new one. 245fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood void parse(const String&); 246fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood void parse(const char* url, const String* originalString); 247fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 248fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood String m_string; 249fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood bool m_isValid : 1; 250fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood bool m_protocolInHTTPFamily : 1; 251fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 2527a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood int m_schemeEnd; 2537a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood int m_userStart; 2547a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood int m_userEnd; 2557a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood int m_passwordEnd; 2567a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood int m_hostEnd; 2577a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood int m_portEnd; 258fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood int m_pathAfterLastSlash; 259fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood int m_pathEnd; 2607a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood int m_queryEnd; 2617a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood int m_fragmentEnd; 2627a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood#endif 2637a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood}; 264fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 265fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwoodbool operator==(const KURL&, const KURL&); 266fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwoodbool operator==(const KURL&, const String&); 267bool operator==(const String&, const KURL&); 268bool operator!=(const KURL&, const KURL&); 269bool operator!=(const KURL&, const String&); 270bool operator!=(const String&, const KURL&); 271 272bool equalIgnoringFragmentIdentifier(const KURL&, const KURL&); 273bool protocolHostAndPortAreEqual(const KURL&, const KURL&); 274 275const KURL& blankURL(); 276 277// Functions to do URL operations on strings. 278// These are operations that aren't faster on a parsed URL. 279// These are also different from the KURL functions in that they don't require the string to be a valid and parsable URL. 280// This is especially important because valid javascript URLs are not necessarily considered valid by KURL. 281 282bool protocolIs(const String& url, const char* protocol); 283bool protocolIsJavaScript(const String& url); 284 285bool isDefaultPortForProtocol(unsigned short port, const String& protocol); 286bool portAllowed(const KURL&); // Blacklist ports that should never be used for Web resources. 287 288bool isValidProtocol(const String&); 289 290String mimeTypeFromDataURL(const String& url); 291 292// Unescapes the given string using URL escaping rules, given an optional 293// encoding (defaulting to UTF-8 otherwise). DANGER: If the URL has "%00" 294// in it, the resulting string will have embedded null characters! 295String decodeURLEscapeSequences(const String&); 296String decodeURLEscapeSequences(const String&, const TextEncoding&); 297 298String encodeWithURLEscapeSequences(const String&); 299 300// Inlines. 301 302inline bool operator==(const KURL& a, const KURL& b) 303{ 304 return a.string() == b.string(); 305} 306 307inline bool operator==(const KURL& a, const String& b) 308{ 309 return a.string() == b; 310} 311 312inline bool operator==(const String& a, const KURL& b) 313{ 314 return a == b.string(); 315} 316 317inline bool operator!=(const KURL& a, const KURL& b) 318{ 319 return a.string() != b.string(); 320} 321 322inline bool operator!=(const KURL& a, const String& b) 323{ 324 return a.string() != b; 325} 326 327inline bool operator!=(const String& a, const KURL& b) 328{ 329 return a != b.string(); 330} 331 332#if !USE(GOOGLEURL) 333 334// Inline versions of some non-GoogleURL functions so we can get inlining 335// without having to have a lot of ugly ifdefs in the class definition. 336 337inline bool KURL::isNull() const 338{ 339 return m_string.isNull(); 340} 341 342inline bool KURL::isEmpty() const 343{ 344 return m_string.isEmpty(); 345} 346 347inline bool KURL::isValid() const 348{ 349 return m_isValid; 350} 351 352inline bool KURL::hasPort() const 353{ 354 return m_hostEnd < m_portEnd; 355} 356 357inline bool KURL::protocolInHTTPFamily() const 358{ 359 return m_protocolInHTTPFamily; 360} 361 362inline unsigned KURL::hostStart() const 363{ 364 return (m_passwordEnd == m_userStart) ? m_passwordEnd : m_passwordEnd + 1; 365} 366 367inline unsigned KURL::hostEnd() const 368{ 369 return m_hostEnd; 370} 371 372inline unsigned KURL::pathStart() const 373{ 374 return m_portEnd; 375} 376 377inline unsigned KURL::pathEnd() const 378{ 379 return m_pathEnd; 380} 381 382inline unsigned KURL::pathAfterLastSlash() const 383{ 384 return m_pathAfterLastSlash; 385} 386 387#endif // !USE(GOOGLEURL) 388 389} // namespace WebCore 390 391namespace WTF { 392 393 // KURLHash is the default hash for String 394 template<typename T> struct DefaultHash; 395 template<> struct DefaultHash<WebCore::KURL> { 396 typedef WebCore::KURLHash Hash; 397 }; 398 399} // namespace WTF 400 401#endif // KURL_h 402