summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/KURL.h
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/platform/KURL.h')
-rw-r--r--WebCore/platform/KURL.h282
1 files changed, 200 insertions, 82 deletions
diff --git a/WebCore/platform/KURL.h b/WebCore/platform/KURL.h
index 5c340d4..f31c641 100644
--- a/WebCore/platform/KURL.h
+++ b/WebCore/platform/KURL.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -26,12 +26,10 @@
#ifndef KURL_h
#define KURL_h
-#include "DeprecatedString.h"
#include "PlatformString.h"
-#include <wtf/Platform.h>
#if PLATFORM(CF)
-typedef const struct __CFURL * CFURLRef;
+typedef const struct __CFURL* CFURLRef;
#endif
#if PLATFORM(MAC)
@@ -41,125 +39,245 @@ typedef const struct __CFURL * CFURLRef;
class NSURL;
#endif
#endif
+
#if PLATFORM(QT)
+QT_BEGIN_NAMESPACE
class QUrl;
+QT_END_NAMESPACE
#endif
namespace WebCore {
- class KURL;
- class TextEncoding;
-
- bool operator==(const KURL&, const KURL&);
- inline bool operator!=(const KURL &a, const KURL &b) { return !(a == b); }
+class TextEncoding;
+struct KURLHash;
- bool equalIgnoringRef(const KURL&, const KURL&);
+// FIXME: Our terminology here is a bit inconsistent. We refer to the part
+// after the "#" as the "fragment" in some places and the "ref" in others.
+// We should fix the terminology to match the URL and URI RFCs as closely
+// as possible to resolve this.
class KURL {
public:
- KURL();
- KURL(const char*);
- KURL(const KURL&, const DeprecatedString&);
- KURL(const KURL&, const DeprecatedString&, const TextEncoding&);
- KURL(const DeprecatedString&);
-#if PLATFORM(MAC)
- KURL(NSURL*);
-#endif
-#if PLATFORM(CF)
- KURL(CFURLRef);
-#endif
-#if PLATFORM(QT)
- KURL(const QUrl&);
-#endif
+ // Generates a URL which contains a null string.
+ KURL() { invalidate(); }
+
+ // The argument is an absolute URL string. The string is assumed to be
+ // already encoded.
+ // FIXME: This constructor has a special case for strings that start with
+ // "/", prepending "file://" to such strings; it would be good to get
+ // rid of that special case.
+ explicit KURL(const char*);
+
+ // The argument is an absolute URL string. The string is assumed to be
+ // already encoded.
+ // FIXME: For characters with codes other than 0000-00FF will be chopped
+ // off, so this call is currently not safe to use with arbitrary strings.
+ // FIXME: This constructor has a special case for strings that start with
+ // "/", prepending "file://" to such strings; it would be good to get
+ // rid of that special case.
+ explicit KURL(const String&);
+
+ // Resolves the relative URL with the given base URL. If provided, the
+ // TextEncoding is used to encode non-ASCII characers. The base URL can be
+ // null or empty, in which case the relative URL will be interpreted as
+ // absolute.
+ // FIXME: If the base URL is invalid, this always creates an invalid
+ // URL. Instead I think it would be better to treat all invalid base URLs
+ // the same way we treate null and empty base URLs.
+ KURL(const KURL& base, const String& relative);
+ KURL(const KURL& base, const String& relative, const TextEncoding&);
+
+ // FIXME: The above functions should be harmonized so that passing a
+ // base of null or the empty string gives the same result as the
+ // standard String constructor.
- bool isNull() const { return urlString.isNull(); }
- bool isEmpty() const { return urlString.isEmpty(); }
+ bool isNull() const { return m_string.isNull(); }
+ bool isEmpty() const { return m_string.isEmpty(); }
+ bool isValid() const { return m_isValid; }
+
+ // Returns true if this URL has a path. Note that "http://foo.com/" has a
+ // path of "/", so this function will return true. Only invalid or
+ // non-hierarchical (like "javascript:") URLs will have no path.
bool hasPath() const;
- String string() const { return urlString; }
- const DeprecatedString& deprecatedString() const { return urlString; }
-
- DeprecatedString protocol() const;
- DeprecatedString host() const;
- unsigned short int port() const;
- DeprecatedString user() const;
- DeprecatedString pass() const;
- DeprecatedString path() const;
- DeprecatedString lastPathComponent() const;
- DeprecatedString query() const;
- DeprecatedString ref() const;
+ const String& string() const { return m_string; }
+
+ String protocol() const;
+ String host() const;
+ unsigned short port() const;
+ String user() const;
+ String pass() const;
+ String path() const;
+ String lastPathComponent() const;
+ String query() const; // Includes the "?".
+ String ref() const; // Does *not* include the "#".
bool hasRef() const;
- DeprecatedString encodedHtmlRef() const { return ref(); }
+ String prettyURL() const;
+ String fileSystemPath() const;
+
+ // Returns true if the current URL's protocol is the same as the null-
+ // terminated ASCII argument. The argument must be lower-case.
+ bool protocolIs(const char*) const;
+ bool isLocalFile() const;
+
+ void setProtocol(const String&);
+ void setHost(const String&);
- void setProtocol(const DeprecatedString &);
- void setHost(const DeprecatedString &);
- void setPort(unsigned short int);
- void setHostAndPort(const DeprecatedString&);
- void setUser(const DeprecatedString &);
- void setPass(const DeprecatedString &);
- void setPath(const DeprecatedString &);
- void setQuery(const DeprecatedString &);
- void setRef(const DeprecatedString &);
+ // Setting the port to 0 will clear any port from the URL.
+ void setPort(unsigned short);
- DeprecatedString prettyURL() const;
+ // Input is like "foo.com" or "foo.com:8000".
+ void setHostAndPort(const String&);
+
+ void setUser(const String&);
+ void setPass(const String&);
+
+ // If you pass an empty path for HTTP or HTTPS URLs, the resulting path
+ // will be "/".
+ void setPath(const String&);
+
+ // The query may begin with a question mark, or, if not, one will be added
+ // for you. Setting the query to the empty string will leave a "?" in the
+ // URL (with nothing after it). To clear the query, pass a null string.
+ void setQuery(const String&);
+
+ void setRef(const String&);
+ void removeRef();
+
+ friend bool equalIgnoringRef(const KURL&, const KURL&);
+
+ friend bool protocolHostAndPortAreEqual(const KURL&, const KURL&);
+
+ operator const String&() const { return m_string; }
+ operator JSC::UString() const { return m_string; }
+
+ unsigned hostStart() const { return (m_passwordEnd == m_userStart) ? m_passwordEnd : m_passwordEnd + 1; }
+ unsigned hostEnd() const { return m_hostEnd; }
+
+ unsigned pathStart() const { return m_portEnd; }
+ unsigned pathEnd() const { return m_pathEnd; }
+ unsigned pathAfterLastSlash() const { return m_pathAfterLastSlash; }
#if PLATFORM(CF)
+ KURL(CFURLRef);
CFURLRef createCFURL() const;
#endif
+
#if PLATFORM(MAC)
- NSURL *getNSURL() const;
+ KURL(NSURL*);
+ operator NSURL*() const;
#endif
-#if PLATFORM(QT)
- operator QUrl() const;
+#ifdef __OBJC__
+ operator NSString*() const { return m_string; }
#endif
-#ifdef ANDROID_JAVASCRIPT_SECURITY
- // Returns true if the current URL's protocol is the same as the null-
- // terminated ASCII argument. The argument must be lower-case.
- bool protocolIs(const char*) const;
+#if PLATFORM(QT)
+ KURL(const QUrl&);
+ operator QUrl() const;
#endif
- bool isLocalFile() const;
- String fileSystemPath() const;
-
- static DeprecatedString decode_string(const DeprecatedString&);
- static DeprecatedString decode_string(const DeprecatedString&, const TextEncoding&);
- static DeprecatedString encode_string(const DeprecatedString&);
-
- friend bool operator==(const KURL &, const KURL &);
#ifndef NDEBUG
void print() const;
#endif
private:
+ void invalidate();
bool isHierarchical() const;
- void init(const KURL&, const DeprecatedString&, const TextEncoding&);
-#ifdef ANDROID_JAVASCRIPT_SECURITY
+ void init(const KURL&, const String&, const TextEncoding&);
static bool protocolIs(const String&, const char*);
-#endif
- void parse(const char *url, const DeprecatedString *originalString);
+ void copyToBuffer(Vector<char, 512>& buffer) const;
+
+ // Parses the given URL. The originalString parameter allows for an
+ // optimization: When the source is the same as the fixed-up string,
+ // it will use the passed-in string instead of allocating a new one.
+ void parse(const String&);
+ void parse(const char* url, const String* originalString);
- DeprecatedString urlString;
+ String m_string;
bool m_isValid;
- int schemeEndPos;
- int userStartPos;
- int userEndPos;
- int passwordEndPos;
- int hostEndPos;
- int portEndPos;
- int pathEndPos;
- int queryEndPos;
- int fragmentEndPos;
-
- friend bool equalIgnoringRef(const KURL& a, const KURL& b);
+ int m_schemeEnd;
+ int m_userStart;
+ int m_userEnd;
+ int m_passwordEnd;
+ int m_hostEnd;
+ int m_portEnd;
+ int m_pathAfterLastSlash;
+ int m_pathEnd;
+ int m_queryEnd;
+ int m_fragmentEnd;
};
-#ifdef ANDROID_JAVASCRIPT_SECURITY
+bool operator==(const KURL&, const KURL&);
+bool operator==(const KURL&, const String&);
+bool operator==(const String&, const KURL&);
+bool operator!=(const KURL&, const KURL&);
+bool operator!=(const KURL&, const String&);
+bool operator!=(const String&, const KURL&);
+
+bool equalIgnoringRef(const KURL&, const KURL&);
+bool protocolHostAndPortAreEqual(const KURL&, const KURL&);
+
+const KURL& blankURL();
+
+// Functions to do URL operations on strings.
+// These are operations that aren't faster on a parsed URL.
+
bool protocolIs(const String& url, const char* protocol);
-#endif
+String mimeTypeFromDataURL(const String& url);
+
+// Unescapes the given string using URL escaping rules, given an optional
+// encoding (defaulting to UTF-8 otherwise). DANGER: If the URL has "%00"
+// in it, the resulting string will have embedded null characters!
+String decodeURLEscapeSequences(const String&);
+String decodeURLEscapeSequences(const String&, const TextEncoding&);
+
+String encodeWithURLEscapeSequences(const String&);
+
+// Inlines.
+
+inline bool operator==(const KURL& a, const KURL& b)
+{
+ return a.string() == b.string();
+}
+
+inline bool operator==(const KURL& a, const String& b)
+{
+ return a.string() == b;
+}
+
+inline bool operator==(const String& a, const KURL& b)
+{
+ return a == b.string();
+}
+
+inline bool operator!=(const KURL& a, const KURL& b)
+{
+ return a.string() != b.string();
+}
+
+inline bool operator!=(const KURL& a, const String& b)
+{
+ return a.string() != b;
+}
+
+inline bool operator!=(const String& a, const KURL& b)
+{
+ return a != b.string();
}
+} // namespace WebCore
+
+namespace WTF {
+
+ // KURLHash is the default hash for String
+ template<typename T> struct DefaultHash;
+ template<> struct DefaultHash<WebCore::KURL> {
+ typedef WebCore::KURLHash Hash;
+ };
+
+} // namespace WTF
+
#endif // KURL_h