| 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 #ifdef WIN32 | 5 #ifdef WIN32 |
| 6 #include <windows.h> | 6 #include <windows.h> |
| 7 #else | 7 #else |
| 8 #include <pthread.h> | 8 #include <pthread.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 } | 54 } |
| 55 | 55 |
| 56 const std::string& EmptyStringForGURL() { | 56 const std::string& EmptyStringForGURL() { |
| 57 // Avoid static object construction/destruction on startup/shutdown. | 57 // Avoid static object construction/destruction on startup/shutdown. |
| 58 pthread_once(&empty_string_once, EmptyStringForGURLOnce); | 58 pthread_once(&empty_string_once, EmptyStringForGURLOnce); |
| 59 return *empty_string; | 59 return *empty_string; |
| 60 } | 60 } |
| 61 | 61 |
| 62 #endif // WIN32 | 62 #endif // WIN32 |
| 63 | 63 |
| 64 } // namespace | 64 } // namespace |
| 65 | 65 |
| 66 GURL::GURL() : is_valid_(false) { | 66 GURL::GURL() : is_valid_(false) { |
| 67 } | 67 } |
| 68 | 68 |
| 69 GURL::GURL(const GURL& other) | 69 GURL::GURL(const GURL& other) |
| 70 : spec_(other.spec_), | 70 : spec_(other.spec_), |
| 71 is_valid_(other.is_valid_), | 71 is_valid_(other.is_valid_), |
| 72 parsed_(other.parsed_) { | 72 parsed_(other.parsed_) { |
| 73 if (other.inner_url_) | 73 if (other.inner_url_) |
| 74 inner_url_.reset(new GURL(*other.inner_url_)); | 74 inner_url_.reset(new GURL(*other.inner_url_)); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 void GURL::InitializeFromCanonicalSpec() { | 125 void GURL::InitializeFromCanonicalSpec() { |
| 126 if (is_valid_ && SchemeIsFileSystem()) { | 126 if (is_valid_ && SchemeIsFileSystem()) { |
| 127 inner_url_.reset( | 127 inner_url_.reset( |
| 128 new GURL(spec_.data(), parsed_.Length(), | 128 new GURL(spec_.data(), parsed_.Length(), |
| 129 *parsed_.inner_parsed(), true)); | 129 *parsed_.inner_parsed(), true)); |
| 130 } | 130 } |
| 131 | 131 |
| 132 #ifndef NDEBUG | 132 #ifndef NDEBUG |
| 133 // For testing purposes, check that the parsed canonical URL is identical to | 133 // For testing purposes, check that the parsed canonical URL is identical to |
| 134 // what we would have produced. Skip checking for invalid URLs have no meaning | 134 // what we would have produced. Skip checking for invalid URLs have no meaning |
| 135 // and we can't always canonicalize then reproducabely. | 135 // and we can't always canonicalize then reproducibly. |
| 136 if (is_valid_) { | 136 if (is_valid_) { |
| 137 url::Component scheme; | 137 url::Component scheme; |
| 138 // We can't do this check on the inner_url of a filesystem URL, as | 138 // We can't do this check on the inner_url of a filesystem URL, as |
| 139 // canonical_spec actually points to the start of the outer URL, so we'd | 139 // canonical_spec actually points to the start of the outer URL, so we'd |
| 140 // end up with infinite recursion in this constructor. | 140 // end up with infinite recursion in this constructor. |
| 141 if (!url::FindAndCompareScheme(spec_.data(), spec_.length(), | 141 if (!url::FindAndCompareScheme(spec_.data(), spec_.length(), |
| 142 url::kFileSystemScheme, &scheme) || | 142 url::kFileSystemScheme, &scheme) || |
| 143 scheme.begin == parsed_.scheme.begin) { | 143 scheme.begin == parsed_.scheme.begin) { |
| 144 // We need to retain trailing whitespace on path URLs, as the |parsed_| | 144 // We need to retain trailing whitespace on path URLs, as the |parsed_| |
| 145 // spec we originally received may legitimately contain trailing white- | 145 // spec we originally received may legitimately contain trailing white- |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 output.Complete(); | 304 output.Complete(); |
| 305 if (result.is_valid_ && result.SchemeIsFileSystem()) { | 305 if (result.is_valid_ && result.SchemeIsFileSystem()) { |
| 306 result.inner_url_.reset(new GURL(spec_.data(), result.parsed_.Length(), | 306 result.inner_url_.reset(new GURL(spec_.data(), result.parsed_.Length(), |
| 307 *result.parsed_.inner_parsed(), true)); | 307 *result.parsed_.inner_parsed(), true)); |
| 308 } | 308 } |
| 309 return result; | 309 return result; |
| 310 } | 310 } |
| 311 | 311 |
| 312 GURL GURL::GetOrigin() const { | 312 GURL GURL::GetOrigin() const { |
| 313 // This doesn't make sense for invalid or nonstandard URLs, so return | 313 // This doesn't make sense for invalid or nonstandard URLs, so return |
| 314 // the empty URL | 314 // the empty URL. |
| 315 if (!is_valid_ || !IsStandard()) | 315 if (!is_valid_ || !IsStandard()) |
| 316 return GURL(); | 316 return GURL(); |
| 317 | 317 |
| 318 if (SchemeIsFileSystem()) | 318 if (SchemeIsFileSystem()) |
| 319 return inner_url_->GetOrigin(); | 319 return inner_url_->GetOrigin(); |
| 320 | 320 |
| 321 url::Replacements<char> replacements; | 321 url::Replacements<char> replacements; |
| 322 replacements.ClearUsername(); | 322 replacements.ClearUsername(); |
| 323 replacements.ClearPassword(); | 323 replacements.ClearPassword(); |
| 324 replacements.ClearPath(); | 324 replacements.ClearPath(); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 return int_port; | 401 return int_port; |
| 402 } | 402 } |
| 403 | 403 |
| 404 std::string GURL::ExtractFileName() const { | 404 std::string GURL::ExtractFileName() const { |
| 405 url::Component file_component; | 405 url::Component file_component; |
| 406 url::ExtractFileName(spec_.data(), parsed_.path, &file_component); | 406 url::ExtractFileName(spec_.data(), parsed_.path, &file_component); |
| 407 return ComponentString(file_component); | 407 return ComponentString(file_component); |
| 408 } | 408 } |
| 409 | 409 |
| 410 std::string GURL::PathForRequest() const { | 410 std::string GURL::PathForRequest() const { |
| 411 DCHECK(parsed_.path.len > 0) << "Canonical path for requests should be non-emp
ty"; | 411 DCHECK(parsed_.path.len > 0) |
| 412 << "Canonical path for requests should be non-empty"; |
| 412 if (parsed_.ref.len >= 0) { | 413 if (parsed_.ref.len >= 0) { |
| 413 // Clip off the reference when it exists. The reference starts after the # | 414 // Clip off the reference when it exists. The reference starts after the |
| 414 // sign, so we have to subtract one to also remove it. | 415 // #-sign, so we have to subtract one to also remove it. |
| 415 return std::string(spec_, parsed_.path.begin, | 416 return std::string(spec_, parsed_.path.begin, |
| 416 parsed_.ref.begin - parsed_.path.begin - 1); | 417 parsed_.ref.begin - parsed_.path.begin - 1); |
| 417 } | 418 } |
| 418 // Compute the actual path length, rather than depending on the spec's | 419 // Compute the actual path length, rather than depending on the spec's |
| 419 // terminator. If we're an inner_url, our spec continues on into our outer | 420 // terminator. If we're an inner_url, our spec continues on into our outer |
| 420 // url's path/query/ref. | 421 // URL's path/query/ref. |
| 421 int path_len = parsed_.path.len; | 422 int path_len = parsed_.path.len; |
| 422 if (parsed_.query.is_valid()) | 423 if (parsed_.query.is_valid()) |
| 423 path_len = parsed_.query.end() - parsed_.path.begin; | 424 path_len = parsed_.query.end() - parsed_.path.begin; |
| 424 | 425 |
| 425 return std::string(spec_, parsed_.path.begin, path_len); | 426 return std::string(spec_, parsed_.path.begin, path_len); |
| 426 } | 427 } |
| 427 | 428 |
| 428 std::string GURL::HostNoBrackets() const { | 429 std::string GURL::HostNoBrackets() const { |
| 429 // If host looks like an IPv6 literal, strip the square brackets. | 430 // If host looks like an IPv6 literal, strip the square brackets. |
| 430 url::Component h(parsed_.host); | 431 url::Component h(parsed_.host); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 void GURL::Swap(GURL* other) { | 530 void GURL::Swap(GURL* other) { |
| 530 spec_.swap(other->spec_); | 531 spec_.swap(other->spec_); |
| 531 std::swap(is_valid_, other->is_valid_); | 532 std::swap(is_valid_, other->is_valid_); |
| 532 std::swap(parsed_, other->parsed_); | 533 std::swap(parsed_, other->parsed_); |
| 533 inner_url_.swap(other->inner_url_); | 534 inner_url_.swap(other->inner_url_); |
| 534 } | 535 } |
| 535 | 536 |
| 536 std::ostream& operator<<(std::ostream& out, const GURL& url) { | 537 std::ostream& operator<<(std::ostream& out, const GURL& url) { |
| 537 return out << url.possibly_invalid_spec(); | 538 return out << url.possibly_invalid_spec(); |
| 538 } | 539 } |
| OLD | NEW |