| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef WebURL_h | 31 #ifndef WebURL_h |
| 32 #define WebURL_h | 32 #define WebURL_h |
| 33 | 33 |
| 34 #include "WebCString.h" | 34 #include "WebCString.h" |
| 35 #include "WebString.h" |
| 35 #include <url/url_parse.h> | 36 #include <url/url_parse.h> |
| 36 | 37 |
| 37 #if WEBKIT_IMPLEMENTATION | 38 #if WEBKIT_IMPLEMENTATION |
| 38 namespace WebCore { class KURL; } | 39 namespace WebCore { class KURL; } |
| 39 #else | 40 #else |
| 40 #include <url/gurl.h> | 41 #include <url/gurl.h> |
| 41 #endif | 42 #endif |
| 42 | 43 |
| 43 namespace WebKit { | 44 namespace WebKit { |
| 44 | 45 |
| 45 class WebURL { | 46 class WebURL { |
| 46 public: | 47 public: |
| 47 ~WebURL() | 48 ~WebURL() |
| 48 { | 49 { |
| 49 } | 50 } |
| 50 | 51 |
| 51 WebURL() : m_isValid(false) | 52 WebURL() |
| 53 : m_isValid(false) |
| 52 { | 54 { |
| 53 } | 55 } |
| 54 | 56 |
| 55 WebURL(const WebCString& spec, const url_parse::Parsed& parsed, bool isValid
) | 57 WebURL(const WebURL& url) |
| 56 : m_spec(spec) | 58 : m_string(url.m_string) |
| 57 , m_parsed(parsed) | 59 , m_parsed(url.m_parsed) |
| 58 , m_isValid(isValid) | 60 , m_isValid(url.m_isValid) |
| 59 { | 61 { |
| 60 } | 62 } |
| 61 | 63 |
| 62 WebURL(const WebURL& s) | 64 WebURL& operator=(const WebURL& url) |
| 63 : m_spec(s.m_spec) | |
| 64 , m_parsed(s.m_parsed) | |
| 65 , m_isValid(s.m_isValid) | |
| 66 { | 65 { |
| 67 } | 66 m_string = url.m_string; |
| 68 | 67 m_parsed = url.m_parsed; |
| 69 WebURL& operator=(const WebURL& s) | 68 m_isValid = url.m_isValid; |
| 70 { | |
| 71 m_spec = s.m_spec; | |
| 72 m_parsed = s.m_parsed; | |
| 73 m_isValid = s.m_isValid; | |
| 74 return *this; | 69 return *this; |
| 75 } | 70 } |
| 76 | 71 |
| 77 void assign(const WebCString& spec, const url_parse::Parsed& parsed, bool is
Valid) | 72 // FIXME: Remove this API. |
| 73 WebCString spec() const |
| 78 { | 74 { |
| 79 m_spec = spec; | 75 std::string spec = m_string.utf8(); |
| 80 m_parsed = parsed; | 76 return WebCString(spec.data(), spec.length()); |
| 81 m_isValid = isValid; | |
| 82 } | 77 } |
| 83 | 78 |
| 84 const WebCString& spec() const | 79 const WebString& string() const |
| 85 { | 80 { |
| 86 return m_spec; | 81 return m_string; |
| 87 } | 82 } |
| 88 | 83 |
| 89 const url_parse::Parsed& parsed() const | 84 const url_parse::Parsed& parsed() const |
| 90 { | 85 { |
| 91 return m_parsed; | 86 return m_parsed; |
| 92 } | 87 } |
| 93 | 88 |
| 94 bool isValid() const | 89 bool isValid() const |
| 95 { | 90 { |
| 96 return m_isValid; | 91 return m_isValid; |
| 97 } | 92 } |
| 98 | 93 |
| 99 bool isEmpty() const | 94 bool isEmpty() const |
| 100 { | 95 { |
| 101 return m_spec.isEmpty(); | 96 return m_string.isEmpty(); |
| 102 } | 97 } |
| 103 | 98 |
| 104 bool isNull() const | 99 bool isNull() const |
| 105 { | 100 { |
| 106 return m_spec.isEmpty(); | 101 return m_string.isEmpty(); |
| 107 } | 102 } |
| 108 | 103 |
| 109 #if WEBKIT_IMPLEMENTATION | 104 #if WEBKIT_IMPLEMENTATION |
| 110 WebURL(const WebCore::KURL&); | 105 WebURL(const WebCore::KURL&); |
| 111 WebURL& operator=(const WebCore::KURL&); | 106 WebURL& operator=(const WebCore::KURL&); |
| 112 operator WebCore::KURL() const; | 107 operator WebCore::KURL() const; |
| 113 #else | 108 #else |
| 114 WebURL(const GURL& g) | 109 WebURL(const GURL& url) |
| 115 : m_spec(g.possibly_invalid_spec()) | 110 : m_string(WebString::fromUTF8(url.possibly_invalid_spec())) |
| 116 , m_parsed(g.parsed_for_possibly_invalid_spec()) | 111 , m_parsed(url.parsed_for_possibly_invalid_spec()) |
| 117 , m_isValid(g.is_valid()) | 112 , m_isValid(url.is_valid()) |
| 118 { | 113 { |
| 119 } | 114 } |
| 120 | 115 |
| 121 WebURL& operator=(const GURL& g) | 116 WebURL& operator=(const GURL& url) |
| 122 { | 117 { |
| 123 m_spec = g.possibly_invalid_spec(); | 118 m_string = WebString::fromUTF8(url.possibly_invalid_spec()); |
| 124 m_parsed = g.parsed_for_possibly_invalid_spec(); | 119 m_parsed = url.parsed_for_possibly_invalid_spec(); |
| 125 m_isValid = g.is_valid(); | 120 m_isValid = url.is_valid(); |
| 126 return *this; | 121 return *this; |
| 127 } | 122 } |
| 128 | 123 |
| 129 operator GURL() const | 124 operator GURL() const |
| 130 { | 125 { |
| 131 return isNull() ? GURL() : GURL(m_spec.data(), m_spec.length(), m_parsed
, m_isValid); | 126 return isNull() ? GURL() : GURL(m_string.utf8(), m_parsed, m_isValid); |
| 132 } | 127 } |
| 133 #endif | 128 #endif |
| 134 | 129 |
| 135 private: | 130 private: |
| 136 WebCString m_spec; // UTF-8 encoded | 131 WebString m_string; |
| 137 url_parse::Parsed m_parsed; | 132 url_parse::Parsed m_parsed; |
| 138 bool m_isValid; | 133 bool m_isValid; |
| 139 }; | 134 }; |
| 140 | 135 |
| 141 inline bool operator==(const WebURL& a, const WebURL& b) | 136 inline bool operator==(const WebURL& a, const WebURL& b) |
| 142 { | 137 { |
| 143 return !a.spec().compare(b.spec()); | 138 return a.string().equals(b.string()); |
| 144 } | 139 } |
| 145 | 140 |
| 146 inline bool operator!=(const WebURL& a, const WebURL& b) | 141 inline bool operator!=(const WebURL& a, const WebURL& b) |
| 147 { | 142 { |
| 148 return !(a == b); | 143 return !(a == b); |
| 149 } | 144 } |
| 150 | 145 |
| 151 } // namespace WebKit | 146 } // namespace WebKit |
| 152 | 147 |
| 153 #endif | 148 #endif |
| OLD | NEW |