#ifndef KURL_h
#define KURL_h
#include "platform/PlatformExport.h"
#include "wtf/Forward.h"
#include "wtf/HashTableDeletedValueType.h"
#include "wtf/OwnPtr.h"
#include "wtf/text/WTFString.h"
#include <url/third_party/mozilla/url_parse.h>
#include <url/url_canon.h>
namespace WTF {
class TextEncoding;
}
namespace WebCore {
struct KURLHash;
enum ParsedURLStringTag { ParsedURLString };
class PLATFORM_EXPORT KURL {
public:
KURL()
: m_isValid(false)
, m_protocolIsInHTTPFamily(false)
{
}
KURL(const KURL&);
KURL& operator=(const KURL&);
KURL(ParsedURLStringTag, const String&);
explicit KURL(WTF::HashTableDeletedValueType);
static KURL createIsolated(ParsedURLStringTag, const String&);
bool isHashTableDeletedValue() const { return string().isHashTableDeletedValue(); }
KURL(const KURL& base, const String& relative);
KURL(const KURL& base, const String& relative, const WTF::TextEncoding&);
KURL(const AtomicString& canonicalString, const url_parse::Parsed&, bool isValid);
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(); }
bool isHierarchical() const;
const String& string() const { return m_string; }
String elidedString() const;
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;
String baseAsString() const;
bool protocolIs(const char*) const;
bool protocolIsData() const { return protocolIs("data"); }
bool protocolIsInHTTPFamily() const;
bool isLocalFile() const;
bool isBlankURL() const;
bool setProtocol(const String&);
void setHost(const String&);
void removePort();
void setPort(unsigned short);
void setPort(const String&);
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();
PLATFORM_EXPORT friend bool equalIgnoringFragmentIdentifier(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(); }
const url_parse::Parsed& parsed() const { return m_parsed; }
const KURL* innerURL() const { return m_innerURL.get(); }
#ifndef NDEBUG
void print() const;
#endif
bool isSafeToSendToAnotherThread() const;
private:
void init(const KURL& base, const String& relative, const WTF::TextEncoding* queryEncoding);
String componentString(const url_parse::Component&) const;
String stringForInvalidComponent() const;
template<typename CHAR>
void replaceComponents(const url_canon::Replacements<CHAR>&);
template <typename CHAR>
void init(const KURL& base, const CHAR* relative, int relativeLength, const WTF::TextEncoding* queryEncoding);
void initInnerURL();
void initProtocolIsInHTTPFamily();
bool m_isValid;
bool m_protocolIsInHTTPFamily;
url_parse::Parsed m_parsed;
String m_string;
OwnPtr<KURL> m_innerURL;
};
PLATFORM_EXPORT bool operator==(const KURL&, const KURL&);
PLATFORM_EXPORT bool operator==(const KURL&, const String&);
PLATFORM_EXPORT bool operator==(const String&, const KURL&);
PLATFORM_EXPORT bool operator!=(const KURL&, const KURL&);
PLATFORM_EXPORT bool operator!=(const KURL&, const String&);
PLATFORM_EXPORT bool operator!=(const String&, const KURL&);
PLATFORM_EXPORT bool equalIgnoringFragmentIdentifier(const KURL&, const KURL&);
PLATFORM_EXPORT const KURL& blankURL();
PLATFORM_EXPORT bool protocolIs(const String& url, const char* protocol);
PLATFORM_EXPORT bool protocolIsJavaScript(const String& url);
PLATFORM_EXPORT bool isValidProtocol(const String&);
PLATFORM_EXPORT String decodeURLEscapeSequences(const String&);
PLATFORM_EXPORT String decodeURLEscapeSequences(const String&, const WTF::TextEncoding&);
PLATFORM_EXPORT 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();
}
}
namespace WTF {
template<typename T> struct DefaultHash;
template<> struct DefaultHash<WebCore::KURL> {
typedef WebCore::KURLHash Hash;
};
}
#endif