| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef URL_GURL_H_ | 5 #ifndef URL_GURL_H_ |
| 6 #define URL_GURL_H_ | 6 #define URL_GURL_H_ |
| 7 | 7 |
| 8 #include <iosfwd> | 8 #include <iosfwd> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 // version to assume the query parameter encoding should be the same as the | 34 // version to assume the query parameter encoding should be the same as the |
| 35 // input encoding. | 35 // input encoding. |
| 36 explicit GURL(const std::string& url_string /*, output_param_encoding*/); | 36 explicit GURL(const std::string& url_string /*, output_param_encoding*/); |
| 37 explicit GURL(const base::string16& url_string /*, output_param_encoding*/); | 37 explicit GURL(const base::string16& url_string /*, output_param_encoding*/); |
| 38 | 38 |
| 39 // Constructor for URLs that have already been parsed and canonicalized. This | 39 // Constructor for URLs that have already been parsed and canonicalized. This |
| 40 // is used for conversions from KURL, for example. The caller must supply all | 40 // is used for conversions from KURL, for example. The caller must supply all |
| 41 // information associated with the URL, which must be correct and consistent. | 41 // information associated with the URL, which must be correct and consistent. |
| 42 GURL(const char* canonical_spec, size_t canonical_spec_len, | 42 GURL(const char* canonical_spec, size_t canonical_spec_len, |
| 43 const url_parse::Parsed& parsed, bool is_valid); | 43 const url_parse::Parsed& parsed, bool is_valid); |
| 44 // Notice that we take the canonical_spec by value so that we can convert |
| 45 // from WebURL without copying the string. When we call this constructor |
| 46 // we pass in a temporary std::string, which lets the compiler skip the |
| 47 // copy and just move the std::string into the function argument. In the |
| 48 // implementation, we use swap to move the data into the GURL itself, |
| 49 // which means we end up with zero copies. |
| 50 GURL(std::string canonical_spec, |
| 51 const url_parse::Parsed& parsed, bool is_valid); |
| 44 | 52 |
| 45 ~GURL(); | 53 ~GURL(); |
| 46 | 54 |
| 47 GURL& operator=(const GURL& other); | 55 GURL& operator=(const GURL& other); |
| 48 | 56 |
| 49 // Returns true when this object represents a valid parsed URL. When not | 57 // Returns true when this object represents a valid parsed URL. When not |
| 50 // valid, other functions will still succeed, but you will not get canonical | 58 // valid, other functions will still succeed, but you will not get canonical |
| 51 // data out in the format you may be expecting. Instead, we keep something | 59 // data out in the format you may be expecting. Instead, we keep something |
| 52 // "reasonable looking" so that the user can see how it's busted if | 60 // "reasonable looking" so that the user can see how it's busted if |
| 53 // displayed to them. | 61 // displayed to them. |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 // This function may be called from any thread. | 336 // This function may be called from any thread. |
| 329 static const GURL& EmptyGURL(); | 337 static const GURL& EmptyGURL(); |
| 330 | 338 |
| 331 // Returns the inner URL of a nested URL [currently only non-null for | 339 // Returns the inner URL of a nested URL [currently only non-null for |
| 332 // filesystem: URLs]. | 340 // filesystem: URLs]. |
| 333 const GURL* inner_url() const { | 341 const GURL* inner_url() const { |
| 334 return inner_url_; | 342 return inner_url_; |
| 335 } | 343 } |
| 336 | 344 |
| 337 private: | 345 private: |
| 346 void InitializeFromCanonicalSpec(); |
| 347 |
| 338 // Returns the substring of the input identified by the given component. | 348 // Returns the substring of the input identified by the given component. |
| 339 std::string ComponentString(const url_parse::Component& comp) const { | 349 std::string ComponentString(const url_parse::Component& comp) const { |
| 340 if (comp.len <= 0) | 350 if (comp.len <= 0) |
| 341 return std::string(); | 351 return std::string(); |
| 342 return std::string(spec_, comp.begin, comp.len); | 352 return std::string(spec_, comp.begin, comp.len); |
| 343 } | 353 } |
| 344 | 354 |
| 345 // The actual text of the URL, in canonical ASCII form. | 355 // The actual text of the URL, in canonical ASCII form. |
| 346 std::string spec_; | 356 std::string spec_; |
| 347 | 357 |
| 348 // Set when the given URL is valid. Otherwise, we may still have a spec and | 358 // Set when the given URL is valid. Otherwise, we may still have a spec and |
| 349 // components, but they may not identify valid resources (for example, an | 359 // components, but they may not identify valid resources (for example, an |
| 350 // invalid port number, invalid characters in the scheme, etc.). | 360 // invalid port number, invalid characters in the scheme, etc.). |
| 351 bool is_valid_; | 361 bool is_valid_; |
| 352 | 362 |
| 353 // Identified components of the canonical spec. | 363 // Identified components of the canonical spec. |
| 354 url_parse::Parsed parsed_; | 364 url_parse::Parsed parsed_; |
| 355 | 365 |
| 356 // Used for nested schemes [currently only filesystem:]. | 366 // Used for nested schemes [currently only filesystem:]. |
| 357 GURL* inner_url_; | 367 GURL* inner_url_; |
| 358 | 368 |
| 359 // TODO bug 684583: Add encoding for query params. | 369 // TODO bug 684583: Add encoding for query params. |
| 360 }; | 370 }; |
| 361 | 371 |
| 362 // Stream operator so GURL can be used in assertion statements. | 372 // Stream operator so GURL can be used in assertion statements. |
| 363 URL_EXPORT std::ostream& operator<<(std::ostream& out, const GURL& url); | 373 URL_EXPORT std::ostream& operator<<(std::ostream& out, const GURL& url); |
| 364 | 374 |
| 365 #endif // URL_GURL_H_ | 375 #endif // URL_GURL_H_ |
| OLD | NEW |