Left: | ||
Right: |
OLD | NEW |
---|---|
1 // Copyright 2007, Google Inc. | 1 // Copyright 2007, Google Inc. |
2 // All rights reserved. | 2 // 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 // this URL is not a standard URL, then the result will be an empty, | 203 // this URL is not a standard URL, then the result will be an empty, |
204 // invalid GURL. If the URL has neither username nor password, this | 204 // invalid GURL. If the URL has neither username nor password, this |
205 // degenerates to GetWithEmptyPath(). | 205 // degenerates to GetWithEmptyPath(). |
206 // | 206 // |
207 // It is an error to get the origin of an invalid URL. The result | 207 // It is an error to get the origin of an invalid URL. The result |
208 // will be the empty URL. | 208 // will be the empty URL. |
209 GURL_API GURL GetOrigin() const; | 209 GURL_API GURL GetOrigin() const; |
210 | 210 |
211 // Returns true if the scheme for the current URL is a known "standard" | 211 // Returns true if the scheme for the current URL is a known "standard" |
212 // scheme. Standard schemes have an authority and a path section. This | 212 // scheme. Standard schemes have an authority and a path section. This |
213 // includes file:, which some callers may want to filter out explicitly by | 213 // includes file: and filesystem:, which some callers may want to filter out |
214 // calling SchemeIsFile. | 214 // explicitly by calling SchemeIsFile[System]. |
215 GURL_API bool IsStandard() const; | 215 GURL_API bool IsStandard() const; |
216 | 216 |
217 // Returns true if the given parameter (should be lower-case ASCII to match | 217 // Returns true if the given parameter (should be lower-case ASCII to match |
218 // the canonicalized scheme) is the scheme for this URL. This call is more | 218 // the canonicalized scheme) is the scheme for this URL. This call is more |
219 // efficient than getting the scheme and comparing it because no copies or | 219 // efficient than getting the scheme and comparing it because no copies or |
220 // object constructions are done. | 220 // object constructions are done. |
221 GURL_API bool SchemeIs(const char* lower_ascii_scheme) const; | 221 GURL_API bool SchemeIs(const char* lower_ascii_scheme) const; |
222 | 222 |
223 // We often need to know if this is a file URL. File URLs are "standard", but | 223 // We often need to know if this is a file URL. File URLs are "standard", but |
224 // are often treated separately by some programs. | 224 // are often treated separately by some programs. |
225 bool SchemeIsFile() const { | 225 bool SchemeIsFile() const { |
226 return SchemeIs("file"); | 226 return SchemeIs("file"); |
227 } | 227 } |
228 | 228 |
229 // FileSystem URLs need to be treated differently in some cases. | |
230 bool SchemeIsFileSystem() const { | |
231 return SchemeIs("filesystem"); | |
232 } | |
233 | |
229 // If the scheme indicates a secure connection | 234 // If the scheme indicates a secure connection |
230 bool SchemeIsSecure() const { | 235 bool SchemeIsSecure() const { |
231 return SchemeIs("https"); | 236 return SchemeIs("https") || |
237 (SchemeIsFileSystem() && inner_url() && inner_url()->SchemeIsSecure()); | |
232 } | 238 } |
233 | 239 |
234 // Returns true if the hostname is an IP address. Note: this function isn't | 240 // Returns true if the hostname is an IP address. Note: this function isn't |
235 // as cheap as a simple getter because it re-parses the hostname to verify. | 241 // as cheap as a simple getter because it re-parses the hostname to verify. |
236 // This currently identifies only IPv4 addresses (bug 822685). | 242 // This currently identifies only IPv4 addresses (bug 822685). |
237 GURL_API bool HostIsIPAddress() const; | 243 GURL_API bool HostIsIPAddress() const; |
238 | 244 |
239 // Getters for various components of the URL. The returned string will be | 245 // Getters for various components of the URL. The returned string will be |
240 // empty if the component is empty or is not present. | 246 // empty if the component is empty or is not present. |
241 std::string scheme() const { // Not including the colon. See also SchemeIs. | 247 std::string scheme() const { // Not including the colon. See also SchemeIs. |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 | 346 |
341 // Swaps the contents of this GURL object with the argument without doing | 347 // Swaps the contents of this GURL object with the argument without doing |
342 // any memory allocations. | 348 // any memory allocations. |
343 GURL_API void Swap(GURL* other); | 349 GURL_API void Swap(GURL* other); |
344 | 350 |
345 // Returns a reference to a singleton empty GURL. This object is for callers | 351 // Returns a reference to a singleton empty GURL. This object is for callers |
346 // who return references but don't have anything to return in some cases. | 352 // who return references but don't have anything to return in some cases. |
347 // This function may be called from any thread. | 353 // This function may be called from any thread. |
348 GURL_API static const GURL& EmptyGURL(); | 354 GURL_API static const GURL& EmptyGURL(); |
349 | 355 |
356 // Returns the inner URL of a nested URL [currently only non-null for | |
357 // filesystem: URLs]. | |
358 const GURL* inner_url() const { | |
359 return inner_url_; | |
360 } | |
361 | |
350 private: | 362 private: |
351 // Returns the substring of the input identified by the given component. | 363 // Returns the substring of the input identified by the given component. |
352 std::string ComponentString(const url_parse::Component& comp) const { | 364 std::string ComponentString(const url_parse::Component& comp) const { |
353 if (comp.len <= 0) | 365 if (comp.len <= 0) |
354 return std::string(); | 366 return std::string(); |
355 return std::string(spec_, comp.begin, comp.len); | 367 return std::string(spec_, comp.begin, comp.len); |
356 } | 368 } |
357 | 369 |
358 // The actual text of the URL, in canonical ASCII form. | 370 // The actual text of the URL, in canonical ASCII form. |
359 std::string spec_; | 371 std::string spec_; |
360 | 372 |
361 // Set when the given URL is valid. Otherwise, we may still have a spec and | 373 // Set when the given URL is valid. Otherwise, we may still have a spec and |
362 // components, but they may not identify valid resources (for example, an | 374 // components, but they may not identify valid resources (for example, an |
363 // invalid port number, invalid characters in the scheme, etc.). | 375 // invalid port number, invalid characters in the scheme, etc.). |
364 bool is_valid_; | 376 bool is_valid_; |
365 | 377 |
366 // Identified components of the canonical spec. | 378 // Identified components of the canonical spec. |
367 url_parse::Parsed parsed_; | 379 url_parse::Parsed parsed_; |
368 | 380 |
381 // Used for nested schemes [currently only filesystem:]. | |
382 GURL* inner_url_; | |
abarth
2011/11/16 22:02:43
Should this be a scoped_ptr?
ericu
2011/11/16 22:13:37
I was wondering about that myself. I'd love to us
| |
383 | |
369 // TODO bug 684583: Add encoding for query params. | 384 // TODO bug 684583: Add encoding for query params. |
370 }; | 385 }; |
371 | 386 |
372 // Stream operator so GURL can be used in assertion statements. | 387 // Stream operator so GURL can be used in assertion statements. |
373 GURL_API std::ostream& operator<<(std::ostream& out, const GURL& url); | 388 GURL_API std::ostream& operator<<(std::ostream& out, const GURL& url); |
374 | 389 |
375 #endif // GOOGLEURL_SRC_GURL_H__ | 390 #endif // GOOGLEURL_SRC_GURL_H__ |
OLD | NEW |