Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / public / platform / WebURL.h
blob07aa8fd24dad292c584b2c2ec6f75cc0a48d9dd5
1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef WebURL_h
32 #define WebURL_h
34 #include "WebCString.h"
35 #include "WebString.h"
36 #include <url/third_party/mozilla/url_parse.h>
38 #if !INSIDE_BLINK
39 #include <url/gurl.h>
40 #endif
42 namespace blink {
44 class KURL;
46 class WebURL {
47 public:
48 ~WebURL()
52 WebURL()
53 : m_isValid(false)
57 WebURL(const WebURL& url)
58 : m_string(url.m_string)
59 , m_parsed(url.m_parsed)
60 , m_isValid(url.m_isValid)
64 WebURL& operator=(const WebURL& url)
66 m_string = url.m_string;
67 m_parsed = url.m_parsed;
68 m_isValid = url.m_isValid;
69 return *this;
72 // FIXME: Remove this API.
73 WebCString spec() const
75 std::string spec = m_string.utf8();
76 return WebCString(spec.data(), spec.length());
79 const WebString& string() const
81 return m_string;
84 const url::Parsed& parsed() const
86 return m_parsed;
89 bool isValid() const
91 return m_isValid;
94 bool isEmpty() const
96 return m_string.isEmpty();
99 bool isNull() const
101 return m_string.isEmpty();
104 #if INSIDE_BLINK
105 BLINK_PLATFORM_EXPORT WebURL(const KURL&);
106 BLINK_PLATFORM_EXPORT WebURL& operator=(const KURL&);
107 BLINK_PLATFORM_EXPORT operator KURL() const;
108 #else
109 WebURL(const GURL& url)
110 : m_string(WebString::fromUTF8(url.possibly_invalid_spec()))
111 , m_parsed(url.parsed_for_possibly_invalid_spec())
112 , m_isValid(url.is_valid())
116 WebURL& operator=(const GURL& url)
118 m_string = WebString::fromUTF8(url.possibly_invalid_spec());
119 m_parsed = url.parsed_for_possibly_invalid_spec();
120 m_isValid = url.is_valid();
121 return *this;
124 operator GURL() const
126 return isNull() ? GURL() : GURL(m_string.utf8(), m_parsed, m_isValid);
128 #endif
130 private:
131 WebString m_string;
132 url::Parsed m_parsed;
133 bool m_isValid;
136 inline bool operator==(const WebURL& a, const WebURL& b)
138 return a.string().equals(b.string());
141 inline bool operator!=(const WebURL& a, const WebURL& b)
143 return !(a == b);
146 } // namespace blink
148 #endif