#ifndef KURL_h
#define KURL_h
#include "PlatformString.h"
#include "URLString.h"
#include <wtf/HashMap.h>
#if USE(CF)
typedef const struct __CFURL* CFURLRef;
#endif
#if PLATFORM(MAC)
#ifdef __OBJC__
@class NSURL;
#else
class NSURL;
#endif
#endif
#if PLATFORM(QT)
QT_BEGIN_NAMESPACE
class QUrl;
QT_END_NAMESPACE
#endif
#if USE(GOOGLEURL)
#include "KURLGooglePrivate.h"
#endif
#if USE(JSC)
#include <runtime/UString.h>
#endif
namespace WebCore {
class TextEncoding;
struct KURLHash;
typedef HashMap<String, String> ParsedURLParameters;
enum ParsedURLStringTag { ParsedURLString };
class KURL {
public:
KURL() { invalidate(); }
KURL(ParsedURLStringTag, const char*);
KURL(ParsedURLStringTag, const String&);
KURL(ParsedURLStringTag, const URLString&);
#if USE(GOOGLEURL)
KURL(WTF::HashTableDeletedValueType) : m_url(WTF::HashTableDeletedValue) { }
#else
KURL(WTF::HashTableDeletedValueType) : m_string(WTF::HashTableDeletedValue) { }
#endif
bool isHashTableDeletedValue() const { return string().isHashTableDeletedValue(); }
KURL(const KURL& base, const String& relative);
KURL(const KURL& base, const String& relative, const TextEncoding&);
#if USE(GOOGLEURL)
KURL(const CString& canonicalSpec, const url_parse::Parsed&, bool isValid);
#endif
String strippedForUseAsReferrer() const;
KURL copy() const;
bool isNull() const;
bool isEmpty() const;
bool isValid() const;
bool hasPath() const;
bool canSetHostOrPort() const { return isHierarchical(); }
bool canSetPathname() const { return isHierarchical(); }
#if USE(GOOGLEURL)
const String& string() const { return m_url.string(); }
URLString urlString() const { return URLString(m_url.string()); }
#else
const String& string() const { return m_string; }
URLString urlString() const { return URLString(m_string); }
#endif
String protocol() const;
String host() const;
unsigned short port() const;
bool hasPort() const;
String user() const;
String pass() const;
String path() const;
String lastPathComponent() const;
String query() const;
String fragmentIdentifier() const;
bool hasFragmentIdentifier() const;
void copyParsedQueryTo(ParsedURLParameters&) const;
String baseAsString() const;
String prettyURL() const;
String fileSystemPath() const;
bool protocolIs(const char*) const;
bool protocolIsData() const { return protocolIs("data"); }
bool protocolIsInHTTPFamily() const;
bool isLocalFile() const;
bool setProtocol(const String&);
void setHost(const String&);
void removePort();
void setPort(unsigned short);
void setHostAndPort(const String&);
void setUser(const String&);
void setPass(const String&);
void setPath(const String&);
void setQuery(const String&);
void setFragmentIdentifier(const String&);
void removeFragmentIdentifier();
friend bool equalIgnoringFragmentIdentifier(const KURL&, const KURL&);
friend bool protocolHostAndPortAreEqual(const KURL&, const KURL&);
unsigned hostStart() const;
unsigned hostEnd() const;
unsigned pathStart() const;
unsigned pathEnd() const;
unsigned pathAfterLastSlash() const;
operator const String&() const { return string(); }
#if USE(CF)
KURL(CFURLRef);
CFURLRef createCFURL() const;
#endif
#if PLATFORM(MAC)
KURL(NSURL*);
operator NSURL*() const;
#endif
#ifdef __OBJC__
operator NSString*() const { return string(); }
#endif
#if PLATFORM(QT)
KURL(const QUrl&);
operator QUrl() const;
#endif
#if USE(GOOGLEURL)
const url_parse::Parsed& parsed() const { return m_url.m_parsed; }
const CString& utf8String() const { return m_url.utf8String(); }
#endif
#ifndef NDEBUG
void print() const;
#endif
bool protocolInHTTPFamily() const { return protocolIsInHTTPFamily(); }
private:
void invalidate();
bool isHierarchical() const;
static bool protocolIs(const String&, const char*);
#if USE(GOOGLEURL)
friend class KURLGooglePrivate;
void parse(const char* url, const String& originalString = String()) { parse(url, &originalString); };
void parse(const char* url, const String* originalString); void copyToBuffer(Vector<char, 512>& buffer) const; KURLGooglePrivate m_url;
#else // !USE(GOOGLEURL)
void init(const KURL&, const String&, const TextEncoding&);
void copyToBuffer(Vector<char, 512>& buffer) const;
void parse(const String&);
void parse(const char* url, const String& originalString = String());
String m_string;
bool m_isValid : 1;
bool m_protocolIsInHTTPFamily : 1;
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;
#endif
};
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 equalIgnoringFragmentIdentifier(const KURL&, const KURL&);
bool protocolHostAndPortAreEqual(const KURL&, const KURL&);
const KURL& blankURL();
bool protocolIs(const String& url, const char* protocol);
bool protocolIsInHTTPFamily(const String& url);
bool protocolIsJavaScript(const String& url);
bool isDefaultPortForProtocol(unsigned short port, const String& protocol);
bool portAllowed(const KURL&);
bool isValidProtocol(const String&);
String mimeTypeFromDataURL(const String& url);
String decodeURLEscapeSequences(const String&);
String decodeURLEscapeSequences(const String&, const TextEncoding&);
String encodeWithURLEscapeSequences(const 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();
}
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();
}
#if !USE(GOOGLEURL)
inline bool KURL::isNull() const
{
return m_string.isNull();
}
inline bool KURL::isEmpty() const
{
return m_string.isEmpty();
}
inline bool KURL::isValid() const
{
return m_isValid;
}
inline bool KURL::hasPort() const
{
return m_hostEnd < m_portEnd;
}
inline bool KURL::protocolIsInHTTPFamily() const
{
return m_protocolIsInHTTPFamily;
}
inline unsigned KURL::hostStart() const
{
return (m_passwordEnd == m_userStart) ? m_passwordEnd : m_passwordEnd + 1;
}
inline unsigned KURL::hostEnd() const
{
return m_hostEnd;
}
inline unsigned KURL::pathStart() const
{
return m_portEnd;
}
inline unsigned KURL::pathEnd() const
{
return m_pathEnd;
}
inline unsigned KURL::pathAfterLastSlash() const
{
return m_pathAfterLastSlash;
}
#endif // !USE(GOOGLEURL)
}
namespace WTF {
template<typename T> struct DefaultHash;
template<> struct DefaultHash<WebCore::KURL> {
typedef WebCore::KURLHash Hash;
};
}
#endif // KURL_h