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/url_util.h" | 5 #include "url/url_util.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 return DoFindAndCompareScheme(str, str_len, compare, found_scheme); | 481 return DoFindAndCompareScheme(str, str_len, compare, found_scheme); |
482 } | 482 } |
483 | 483 |
484 bool FindAndCompareScheme(const base::char16* str, | 484 bool FindAndCompareScheme(const base::char16* str, |
485 int str_len, | 485 int str_len, |
486 const char* compare, | 486 const char* compare, |
487 Component* found_scheme) { | 487 Component* found_scheme) { |
488 return DoFindAndCompareScheme(str, str_len, compare, found_scheme); | 488 return DoFindAndCompareScheme(str, str_len, compare, found_scheme); |
489 } | 489 } |
490 | 490 |
| 491 bool DomainIs(base::StringPiece canonicalized_host, |
| 492 base::StringPiece lower_ascii_domain) { |
| 493 if (canonicalized_host.empty() || lower_ascii_domain.empty()) |
| 494 return false; |
| 495 |
| 496 // If the host name ends with a dot but the input domain doesn't, then we |
| 497 // ignore the dot in the host name. |
| 498 size_t host_len = canonicalized_host.length(); |
| 499 if (canonicalized_host.back() == '.' && lower_ascii_domain.back() != '.') |
| 500 --host_len; |
| 501 |
| 502 if (host_len < lower_ascii_domain.length()) |
| 503 return false; |
| 504 |
| 505 // |host_first_pos| is the start of the compared part of the host name, not |
| 506 // start of the whole host name. |
| 507 const char* host_first_pos = |
| 508 canonicalized_host.data() + host_len - lower_ascii_domain.length(); |
| 509 |
| 510 if (!base::LowerCaseEqualsASCII( |
| 511 base::StringPiece(host_first_pos, lower_ascii_domain.length()), |
| 512 lower_ascii_domain)) { |
| 513 return false; |
| 514 } |
| 515 |
| 516 // Make sure there aren't extra characters in host before the compared part; |
| 517 // if the host name is longer than the input domain name, then the character |
| 518 // immediately before the compared part should be a dot. For example, |
| 519 // www.google.com has domain "google.com", but www.iamnotgoogle.com does not. |
| 520 if (lower_ascii_domain[0] != '.' && host_len > lower_ascii_domain.length() && |
| 521 *(host_first_pos - 1) != '.') { |
| 522 return false; |
| 523 } |
| 524 |
| 525 return true; |
| 526 } |
| 527 |
491 bool Canonicalize(const char* spec, | 528 bool Canonicalize(const char* spec, |
492 int spec_len, | 529 int spec_len, |
493 bool trim_path_end, | 530 bool trim_path_end, |
494 CharsetConverter* charset_converter, | 531 CharsetConverter* charset_converter, |
495 CanonOutput* output, | 532 CanonOutput* output, |
496 Parsed* output_parsed) { | 533 Parsed* output_parsed) { |
497 return DoCanonicalize(spec, spec_len, trim_path_end, charset_converter, | 534 return DoCanonicalize(spec, spec_len, trim_path_end, charset_converter, |
498 output, output_parsed); | 535 output, output_parsed); |
499 } | 536 } |
500 | 537 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 return DoCompareSchemeComponent(spec, component, compare_to); | 659 return DoCompareSchemeComponent(spec, component, compare_to); |
623 } | 660 } |
624 | 661 |
625 bool CompareSchemeComponent(const base::char16* spec, | 662 bool CompareSchemeComponent(const base::char16* spec, |
626 const Component& component, | 663 const Component& component, |
627 const char* compare_to) { | 664 const char* compare_to) { |
628 return DoCompareSchemeComponent(spec, component, compare_to); | 665 return DoCompareSchemeComponent(spec, component, compare_to); |
629 } | 666 } |
630 | 667 |
631 } // namespace url | 668 } // namespace url |
OLD | NEW |