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 #include "url/gurl.h" | 5 #include "url/gurl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <ostream> | 10 #include <ostream> |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
484 | 484 |
485 const GURL& GURL::EmptyGURL() { | 485 const GURL& GURL::EmptyGURL() { |
486 // Avoid static object construction/destruction on startup/shutdown. | 486 // Avoid static object construction/destruction on startup/shutdown. |
487 pthread_once(&empty_gurl_once, EmptyGURLOnce); | 487 pthread_once(&empty_gurl_once, EmptyGURLOnce); |
488 return *empty_gurl; | 488 return *empty_gurl; |
489 } | 489 } |
490 | 490 |
491 #endif // WIN32 | 491 #endif // WIN32 |
492 | 492 |
493 bool GURL::DomainIs(base::StringPiece lower_ascii_domain) const { | 493 bool GURL::DomainIs(base::StringPiece lower_ascii_domain) const { |
494 if (!is_valid_ || lower_ascii_domain.empty()) | 494 if (!is_valid_ || lower_ascii_domain.empty()) |
engedy
2016/08/30 17:13:13
nit: The second argument of this OR condition is n
pkalinnikov
2016/08/31 08:43:10
Done.
| |
495 return false; | 495 return false; |
496 | 496 |
497 // FileSystem URLs have empty parsed_.host, so check this first. | 497 // FileSystem URLs have empty parsed_.host, so check this first. |
498 if (SchemeIsFileSystem() && inner_url_) | 498 if (SchemeIsFileSystem() && inner_url_) |
499 return inner_url_->DomainIs(lower_ascii_domain); | 499 return inner_url_->DomainIs(lower_ascii_domain); |
500 | 500 return url::DomainIs(host_piece(), lower_ascii_domain); |
501 if (!parsed_.host.is_nonempty()) | |
502 return false; | |
503 | |
504 // If the host name ends with a dot but the input domain doesn't, | |
505 // then we ignore the dot in the host name. | |
506 const char* host_last_pos = spec_.data() + parsed_.host.end() - 1; | |
507 int host_len = parsed_.host.len; | |
508 int domain_len = lower_ascii_domain.length(); | |
509 if ('.' == *host_last_pos && '.' != lower_ascii_domain[domain_len - 1]) { | |
510 host_last_pos--; | |
511 host_len--; | |
512 } | |
513 | |
514 if (host_len < domain_len) | |
515 return false; | |
516 | |
517 // |host_first_pos| is the start of the compared part of the host name, not | |
518 // start of the whole host name. | |
519 const char* host_first_pos = spec_.data() + parsed_.host.begin + | |
520 host_len - domain_len; | |
521 | |
522 if (!base::LowerCaseEqualsASCII( | |
523 base::StringPiece(host_first_pos, domain_len), lower_ascii_domain)) | |
524 return false; | |
525 | |
526 // Make sure there aren't extra characters in host before the compared part; | |
527 // if the host name is longer than the input domain name, then the character | |
528 // immediately before the compared part should be a dot. For example, | |
529 // www.google.com has domain "google.com", but www.iamnotgoogle.com does not. | |
530 if ('.' != lower_ascii_domain[0] && host_len > domain_len && | |
531 '.' != *(host_first_pos - 1)) | |
532 return false; | |
533 | |
534 return true; | |
535 } | 501 } |
536 | 502 |
537 void GURL::Swap(GURL* other) { | 503 void GURL::Swap(GURL* other) { |
538 spec_.swap(other->spec_); | 504 spec_.swap(other->spec_); |
539 std::swap(is_valid_, other->is_valid_); | 505 std::swap(is_valid_, other->is_valid_); |
540 std::swap(parsed_, other->parsed_); | 506 std::swap(parsed_, other->parsed_); |
541 inner_url_.swap(other->inner_url_); | 507 inner_url_.swap(other->inner_url_); |
542 } | 508 } |
543 | 509 |
544 std::ostream& operator<<(std::ostream& out, const GURL& url) { | 510 std::ostream& operator<<(std::ostream& out, const GURL& url) { |
545 return out << url.possibly_invalid_spec(); | 511 return out << url.possibly_invalid_spec(); |
546 } | 512 } |
OLD | NEW |