 Chromium Code Reviews
 Chromium Code Reviews Issue 1270443006:
  Proof-read comments in src/url/.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1270443006:
  Proof-read comments in src/url/.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 // The exception is for empty() URLs (which are !is_valid()) but this will | 85 // The exception is for empty() URLs (which are !is_valid()) but this will | 
| 86 // return the empty string without asserting. | 86 // return the empty string without asserting. | 
| 87 // | 87 // | 
| 88 // Used invalid_spec() below to get the unusable spec of an invalid URL. This | 88 // Used invalid_spec() below to get the unusable spec of an invalid URL. This | 
| 89 // separation is designed to prevent errors that may cause security problems | 89 // separation is designed to prevent errors that may cause security problems | 
| 90 // that could result from the mistaken use of an invalid URL. | 90 // that could result from the mistaken use of an invalid URL. | 
| 91 const std::string& spec() const; | 91 const std::string& spec() const; | 
| 92 | 92 | 
| 93 // Returns the potentially invalid spec for a the URL. This spec MUST NOT be | 93 // Returns the potentially invalid spec for a the URL. This spec MUST NOT be | 
| 94 // modified or sent over the network. It is designed to be displayed in error | 94 // modified or sent over the network. It is designed to be displayed in error | 
| 95 // messages to the user, as the apperance of the spec may explain the error. | 95 // messages to the user, as the appearance of the spec may explain the error. | 
| 96 // If the spec is valid, the valid spec will be returned. | 96 // If the spec is valid, the valid spec will be returned. | 
| 97 // | 97 // | 
| 98 // The returned string is guaranteed to be valid UTF-8. | 98 // The returned string is guaranteed to be valid UTF-8. | 
| 99 const std::string& possibly_invalid_spec() const { | 99 const std::string& possibly_invalid_spec() const { | 
| 100 return spec_; | 100 return spec_; | 
| 101 } | 101 } | 
| 102 | 102 | 
| 103 // Getter for the raw parsed structure. This allows callers to locate parts | 103 // Getter for the raw parsed structure. This allows callers to locate parts | 
| 104 // of the URL within the spec themselves. Most callers should consider using | 104 // of the URL within the spec themselves. Most callers should consider using | 
| 105 // the individual component getters below. | 105 // the individual component getters below. | 
| (...skipping 12 matching lines...) Expand all Loading... | |
| 118 | 118 | 
| 119 // Allows GURL to used as a key in STL (for example, a std::set or std::map). | 119 // Allows GURL to used as a key in STL (for example, a std::set or std::map). | 
| 120 bool operator<(const GURL& other) const; | 120 bool operator<(const GURL& other) const; | 
| 121 bool operator>(const GURL& other) const; | 121 bool operator>(const GURL& other) const; | 
| 122 | 122 | 
| 123 // Resolves a URL that's possibly relative to this object's URL, and returns | 123 // Resolves a URL that's possibly relative to this object's URL, and returns | 
| 124 // it. Absolute URLs are also handled according to the rules of URLs on web | 124 // it. Absolute URLs are also handled according to the rules of URLs on web | 
| 125 // pages. | 125 // pages. | 
| 126 // | 126 // | 
| 127 // It may be impossible to resolve the URLs properly. If the input is not | 127 // It may be impossible to resolve the URLs properly. If the input is not | 
| 128 // "standard" (SchemeIsStandard() == false) and the input looks relative, we | 128 // "standard" (IsStandard() == false) and the input looks relative, we can't | 
| 
qyearsley
2015/08/04 22:16:43
(It looks like there is no method called SchemeIsS
 | |
| 129 // can't resolve it. In these cases, the result will be an empty, invalid | 129 // resolve it. In these cases, the result will be an empty, invalid GURL. | 
| 130 // GURL. | |
| 131 // | 130 // | 
| 132 // The result may also be a nonempty, invalid URL if the input has some kind | 131 // The result may also be a nonempty, invalid URL if the input has some kind | 
| 133 // of encoding error. In these cases, we will try to construct a "good" URL | 132 // of encoding error. In these cases, we will try to construct a "good" URL | 
| 134 // that may have meaning to the user, but it will be marked invalid. | 133 // that may have meaning to the user, but it will be marked invalid. | 
| 135 // | 134 // | 
| 136 // It is an error to resolve a URL relative to an invalid URL. The result | 135 // It is an error to resolve a URL relative to an invalid URL. The result | 
| 137 // will be the empty URL. | 136 // will be the empty URL. | 
| 138 GURL Resolve(const std::string& relative) const; | 137 GURL Resolve(const std::string& relative) const; | 
| 139 GURL Resolve(const base::string16& relative) const; | 138 GURL Resolve(const base::string16& relative) const; | 
| 140 | 139 | 
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 std::string path() const { // Including first slash following host | 275 std::string path() const { // Including first slash following host | 
| 277 return ComponentString(parsed_.path); | 276 return ComponentString(parsed_.path); | 
| 278 } | 277 } | 
| 279 std::string query() const { // Stuff following '?' | 278 std::string query() const { // Stuff following '?' | 
| 280 return ComponentString(parsed_.query); | 279 return ComponentString(parsed_.query); | 
| 281 } | 280 } | 
| 282 std::string ref() const { // Stuff following '#' | 281 std::string ref() const { // Stuff following '#' | 
| 283 return ComponentString(parsed_.ref); | 282 return ComponentString(parsed_.ref); | 
| 284 } | 283 } | 
| 285 | 284 | 
| 286 // Existance querying. These functions will return true if the corresponding | 285 // Existence querying. These functions will return true if the corresponding | 
| 287 // URL component exists in this URL. Note that existance is different than | 286 // URL component exists in this URL. Note that existence is different than | 
| 288 // being nonempty. http://www.google.com/? has a query that just happens to | 287 // being nonempty. http://www.google.com/? has a query that just happens to | 
| 289 // be empty, and has_query() will return true. | 288 // be empty, and has_query() will return true. | 
| 290 bool has_scheme() const { | 289 bool has_scheme() const { | 
| 291 return parsed_.scheme.len >= 0; | 290 return parsed_.scheme.len >= 0; | 
| 292 } | 291 } | 
| 293 bool has_username() const { | 292 bool has_username() const { | 
| 294 return parsed_.username.len >= 0; | 293 return parsed_.username.len >= 0; | 
| 295 } | 294 } | 
| 296 bool has_password() const { | 295 bool has_password() const { | 
| 297 return parsed_.password.len >= 0; | 296 return parsed_.password.len >= 0; | 
| 298 } | 297 } | 
| 299 bool has_host() const { | 298 bool has_host() const { | 
| 300 // Note that hosts are special, absense of host means length 0. | 299 // Note that hosts are special, absence of host means length 0. | 
| 301 return parsed_.host.len > 0; | 300 return parsed_.host.len > 0; | 
| 302 } | 301 } | 
| 303 bool has_port() const { | 302 bool has_port() const { | 
| 304 return parsed_.port.len >= 0; | 303 return parsed_.port.len >= 0; | 
| 305 } | 304 } | 
| 306 bool has_path() const { | 305 bool has_path() const { | 
| 307 // Note that http://www.google.com/" has a path, the path is "/". This can | 306 // Note that http://www.google.com/" has a path, the path is "/". This can | 
| 308 // return false only for invalid or nonstandard URLs. | 307 // return false only for invalid or nonstandard URLs. | 
| 309 return parsed_.path.len >= 0; | 308 return parsed_.path.len >= 0; | 
| 310 } | 309 } | 
| (...skipping 29 matching lines...) Expand all Loading... | |
| 340 // the given input string. For example, if the hostname of the URL is | 339 // the given input string. For example, if the hostname of the URL is | 
| 341 // "www.google.com", this will return true for "com", "google.com", and | 340 // "www.google.com", this will return true for "com", "google.com", and | 
| 342 // "www.google.com". | 341 // "www.google.com". | 
| 343 // | 342 // | 
| 344 // The input domain should be lower-case ASCII to match the canonicalized | 343 // The input domain should be lower-case ASCII to match the canonicalized | 
| 345 // scheme. This call is more efficient than getting the host and check | 344 // scheme. This call is more efficient than getting the host and check | 
| 346 // whether host has the specific domain or not because no copies or | 345 // whether host has the specific domain or not because no copies or | 
| 347 // object constructions are done. | 346 // object constructions are done. | 
| 348 bool DomainIs(base::StringPiece lower_ascii_domain) const; | 347 bool DomainIs(base::StringPiece lower_ascii_domain) const; | 
| 349 | 348 | 
| 350 // Swaps the contents of this GURL object with the argument without doing | 349 // Swaps the contents of this GURL object with |other|, without doing | 
| 351 // any memory allocations. | 350 // any memory allocations. | 
| 352 void Swap(GURL* other); | 351 void Swap(GURL* other); | 
| 353 | 352 | 
| 354 // Returns a reference to a singleton empty GURL. This object is for callers | 353 // Returns a reference to a singleton empty GURL. This object is for callers | 
| 355 // who return references but don't have anything to return in some cases. | 354 // who return references but don't have anything to return in some cases. | 
| 356 // This function may be called from any thread. | 355 // This function may be called from any thread. | 
| 357 static const GURL& EmptyGURL(); | 356 static const GURL& EmptyGURL(); | 
| 358 | 357 | 
| 359 // Returns the inner URL of a nested URL [currently only non-null for | 358 // Returns the inner URL of a nested URL [currently only non-null for | 
| 360 // filesystem: URLs]. | 359 // filesystem: URLs]. | 
| 361 const GURL* inner_url() const { | 360 const GURL* inner_url() const { | 
| 362 return inner_url_.get(); | 361 return inner_url_.get(); | 
| 363 } | 362 } | 
| 364 | 363 | 
| 365 private: | 364 private: | 
| 366 // Variant of the string parsing constructor that allows the caller to elect | 365 // Variant of the string parsing constructor that allows the caller to elect | 
| 367 // retain trailing whitespace, if any, on the passed URL spec but only if the | 366 // retain trailing whitespace, if any, on the passed URL spec, but only if | 
| 368 // scheme is one that allows trailing whitespace. The primary use-case is | 367 // the scheme is one that allows trailing whitespace. The primary use-case is | 
| 369 // for data: URLs. In most cases, you want to use the single parameter | 368 // for data: URLs. In most cases, you want to use the single parameter | 
| 370 // constructor above. | 369 // constructor above. | 
| 371 enum RetainWhiteSpaceSelector { RETAIN_TRAILING_PATH_WHITEPACE }; | 370 enum RetainWhiteSpaceSelector { RETAIN_TRAILING_PATH_WHITEPACE }; | 
| 372 GURL(const std::string& url_string, RetainWhiteSpaceSelector); | 371 GURL(const std::string& url_string, RetainWhiteSpaceSelector); | 
| 373 | 372 | 
| 374 template<typename STR> | 373 template<typename STR> | 
| 375 void InitCanonical(const STR& input_spec, bool trim_path_end); | 374 void InitCanonical(const STR& input_spec, bool trim_path_end); | 
| 376 | 375 | 
| 377 void InitializeFromCanonicalSpec(); | 376 void InitializeFromCanonicalSpec(); | 
| 378 | 377 | 
| (...skipping 18 matching lines...) Expand all Loading... | |
| 397 // Used for nested schemes [currently only filesystem:]. | 396 // Used for nested schemes [currently only filesystem:]. | 
| 398 scoped_ptr<GURL> inner_url_; | 397 scoped_ptr<GURL> inner_url_; | 
| 399 | 398 | 
| 400 // TODO bug 684583: Add encoding for query params. | 399 // TODO bug 684583: Add encoding for query params. | 
| 401 }; | 400 }; | 
| 402 | 401 | 
| 403 // Stream operator so GURL can be used in assertion statements. | 402 // Stream operator so GURL can be used in assertion statements. | 
| 404 URL_EXPORT std::ostream& operator<<(std::ostream& out, const GURL& url); | 403 URL_EXPORT std::ostream& operator<<(std::ostream& out, const GURL& url); | 
| 405 | 404 | 
| 406 #endif // URL_GURL_H_ | 405 #endif // URL_GURL_H_ | 
| OLD | NEW |