Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(720)

Side by Side Diff: Source/weborigin/KURL.h

Issue 54053006: Move weborigin/ under platform/ so that it may someday call platform APIs (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Stale refernence to weboriginexport in .gpyi Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/weborigin/DatabaseIdentifierTest.cpp ('k') | Source/weborigin/KURL.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All r ights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #ifndef KURL_h
27 #define KURL_h
28
29 #include "weborigin/WebOriginExport.h"
30 #include "wtf/Forward.h"
31 #include "wtf/HashMap.h"
32 #include "wtf/HashTableDeletedValueType.h"
33 #include "wtf/OwnPtr.h"
34 #include "wtf/text/CString.h"
35 #include "wtf/text/TextEncoding.h"
36 #include "wtf/text/WTFString.h"
37 #include <url/third_party/mozilla/url_parse.h>
38 #include <url/url_canon.h>
39
40 namespace WebCore {
41
42 struct KURLHash;
43
44 enum ParsedURLStringTag { ParsedURLString };
45
46 class WEBORIGIN_EXPORT KURL {
47 public:
48 KURL()
49 : m_isValid(false)
50 , m_protocolIsInHTTPFamily(false)
51 {
52 }
53
54 KURL(const KURL&);
55 KURL& operator=(const KURL&);
56
57 // The argument is an absolute URL string. The string is assumed to be
58 // output of KURL::string() called on a valid KURL object, or indiscernible
59 // from such. It is usually best to avoid repeatedly parsing a string,
60 // unless memory saving outweigh the possible slow-downs.
61 KURL(ParsedURLStringTag, const String&);
62 explicit KURL(WTF::HashTableDeletedValueType);
63
64 // Creates an isolated URL object suitable for sending to another thread.
65 static KURL createIsolated(ParsedURLStringTag, const String&);
66
67 bool isHashTableDeletedValue() const { return string().isHashTableDeletedVal ue(); }
68
69 // Resolves the relative URL with the given base URL. If provided, the
70 // TextEncoding is used to encode non-ASCII characers. The base URL can be
71 // null or empty, in which case the relative URL will be interpreted as
72 // absolute.
73 // FIXME: If the base URL is invalid, this always creates an invalid
74 // URL. Instead I think it would be better to treat all invalid base URLs
75 // the same way we treate null and empty base URLs.
76 KURL(const KURL& base, const String& relative);
77 KURL(const KURL& base, const String& relative, const WTF::TextEncoding&);
78
79 // For conversions from other structures that have already parsed and
80 // canonicalized the URL. The input must be exactly what KURL would have
81 // done with the same input.
82 KURL(const AtomicString& canonicalString, const url_parse::Parsed&, bool isV alid);
83
84 String strippedForUseAsReferrer() const;
85
86 // FIXME: The above functions should be harmonized so that passing a
87 // base of null or the empty string gives the same result as the
88 // standard String constructor.
89
90 // Makes a deep copy. Helpful only if you need to use a KURL on another
91 // thread. Since the underlying StringImpl objects are immutable, there's
92 // no other reason to ever prefer copy() over plain old assignment.
93 KURL copy() const;
94
95 bool isNull() const;
96 bool isEmpty() const;
97 bool isValid() const;
98
99 // Returns true if this URL has a path. Note that "http://foo.com/" has a
100 // path of "/", so this function will return true. Only invalid or
101 // non-hierarchical (like "javascript:") URLs will have no path.
102 bool hasPath() const;
103
104 // Returns true if you can set the host and port for the URL.
105 // Non-hierarchical URLs don't have a host and port.
106 bool canSetHostOrPort() const { return isHierarchical(); }
107
108 bool canSetPathname() const { return isHierarchical(); }
109 bool isHierarchical() const;
110
111 const String& string() const { return m_string; }
112
113 String elidedString() const;
114
115 String protocol() const;
116 String host() const;
117 unsigned short port() const;
118 bool hasPort() const;
119 String user() const;
120 String pass() const;
121 String path() const;
122 String lastPathComponent() const;
123 String query() const;
124 String fragmentIdentifier() const;
125 bool hasFragmentIdentifier() const;
126
127 String baseAsString() const;
128
129 // Returns true if the current URL's protocol is the same as the null-
130 // terminated ASCII argument. The argument must be lower-case.
131 bool protocolIs(const char*) const;
132 bool protocolIsData() const { return protocolIs("data"); }
133 bool protocolIsInHTTPFamily() const;
134 bool isLocalFile() const;
135 bool isBlankURL() const;
136
137 bool setProtocol(const String&);
138 void setHost(const String&);
139
140 void removePort();
141 void setPort(unsigned short);
142 void setPort(const String&);
143
144 // Input is like "foo.com" or "foo.com:8000".
145 void setHostAndPort(const String&);
146
147 void setUser(const String&);
148 void setPass(const String&);
149
150 // If you pass an empty path for HTTP or HTTPS URLs, the resulting path
151 // will be "/".
152 void setPath(const String&);
153
154 // The query may begin with a question mark, or, if not, one will be added
155 // for you. Setting the query to the empty string will leave a "?" in the
156 // URL (with nothing after it). To clear the query, pass a null string.
157 void setQuery(const String&);
158
159 void setFragmentIdentifier(const String&);
160 void removeFragmentIdentifier();
161
162 WEBORIGIN_EXPORT friend bool equalIgnoringFragmentIdentifier(const KURL&, co nst KURL&);
163
164 unsigned hostStart() const;
165 unsigned hostEnd() const;
166
167 unsigned pathStart() const;
168 unsigned pathEnd() const;
169 unsigned pathAfterLastSlash() const;
170
171 operator const String&() const { return string(); }
172
173 const url_parse::Parsed& parsed() const { return m_parsed; }
174
175 const KURL* innerURL() const { return m_innerURL.get(); }
176
177 #ifndef NDEBUG
178 void print() const;
179 #endif
180
181 bool isSafeToSendToAnotherThread() const;
182
183 private:
184 void init(const KURL& base, const String& relative, const WTF::TextEncoding* queryEncoding);
185
186 String componentString(const url_parse::Component&) const;
187 String stringForInvalidComponent() const;
188
189 template<typename CHAR>
190 void replaceComponents(const url_canon::Replacements<CHAR>&);
191
192 template <typename CHAR>
193 void init(const KURL& base, const CHAR* relative, int relativeLength, const WTF::TextEncoding* queryEncoding);
194 void initInnerURL();
195 void initProtocolIsInHTTPFamily();
196
197 bool m_isValid;
198 bool m_protocolIsInHTTPFamily;
199 url_parse::Parsed m_parsed;
200 String m_string;
201 OwnPtr<KURL> m_innerURL;
202 };
203
204 WEBORIGIN_EXPORT bool operator==(const KURL&, const KURL&);
205 WEBORIGIN_EXPORT bool operator==(const KURL&, const String&);
206 WEBORIGIN_EXPORT bool operator==(const String&, const KURL&);
207 WEBORIGIN_EXPORT bool operator!=(const KURL&, const KURL&);
208 WEBORIGIN_EXPORT bool operator!=(const KURL&, const String&);
209 WEBORIGIN_EXPORT bool operator!=(const String&, const KURL&);
210
211 WEBORIGIN_EXPORT bool equalIgnoringFragmentIdentifier(const KURL&, const KURL&);
212
213 WEBORIGIN_EXPORT const KURL& blankURL();
214
215 // Functions to do URL operations on strings.
216 // These are operations that aren't faster on a parsed URL.
217 // These are also different from the KURL functions in that they don't require t he string to be a valid and parsable URL.
218 // This is especially important because valid javascript URLs are not necessaril y considered valid by KURL.
219
220 WEBORIGIN_EXPORT bool protocolIs(const String& url, const char* protocol);
221 WEBORIGIN_EXPORT bool protocolIsJavaScript(const String& url);
222
223 WEBORIGIN_EXPORT bool isValidProtocol(const String&);
224
225 // Unescapes the given string using URL escaping rules, given an optional
226 // encoding (defaulting to UTF-8 otherwise). DANGER: If the URL has "%00"
227 // in it, the resulting string will have embedded null characters!
228 WEBORIGIN_EXPORT String decodeURLEscapeSequences(const String&);
229 WEBORIGIN_EXPORT String decodeURLEscapeSequences(const String&, const WTF::TextE ncoding&);
230
231 WEBORIGIN_EXPORT String encodeWithURLEscapeSequences(const String&);
232
233 // Inlines.
234
235 inline bool operator==(const KURL& a, const KURL& b)
236 {
237 return a.string() == b.string();
238 }
239
240 inline bool operator==(const KURL& a, const String& b)
241 {
242 return a.string() == b;
243 }
244
245 inline bool operator==(const String& a, const KURL& b)
246 {
247 return a == b.string();
248 }
249
250 inline bool operator!=(const KURL& a, const KURL& b)
251 {
252 return a.string() != b.string();
253 }
254
255 inline bool operator!=(const KURL& a, const String& b)
256 {
257 return a.string() != b;
258 }
259
260 inline bool operator!=(const String& a, const KURL& b)
261 {
262 return a != b.string();
263 }
264
265 } // namespace WebCore
266
267 namespace WTF {
268
269 // KURLHash is the default hash for String
270 template<typename T> struct DefaultHash;
271 template<> struct DefaultHash<WebCore::KURL> {
272 typedef WebCore::KURLHash Hash;
273 };
274
275 } // namespace WTF
276
277 #endif // KURL_h
OLDNEW
« no previous file with comments | « Source/weborigin/DatabaseIdentifierTest.cpp ('k') | Source/weborigin/KURL.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698