Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Side by Side Diff: url/url_util.cc

Issue 2287483002: Provide the equivalent of GURL::DomainIs for url::Origin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 void EncodeURIComponent(const char* input, int length, CanonOutput* output) { 609 void EncodeURIComponent(const char* input, int length, CanonOutput* output) {
610 for (int i = 0; i < length; ++i) { 610 for (int i = 0; i < length; ++i) {
611 unsigned char c = static_cast<unsigned char>(input[i]); 611 unsigned char c = static_cast<unsigned char>(input[i]);
612 if (IsComponentChar(c)) 612 if (IsComponentChar(c))
613 output->push_back(c); 613 output->push_back(c);
614 else 614 else
615 AppendEscapedChar(c, output); 615 AppendEscapedChar(c, output);
616 } 616 }
617 } 617 }
618 618
619 bool DomainIs(base::StringPiece canonicalized_host,
620 base::StringPiece lower_ascii_domain) {
621 DCHECK(!canonicalized_host.empty());
engedy 2016/08/26 16:48:14 I think it would be safer if this shared stuff did
pkalinnikov 2016/08/29 09:53:00 Done.
622 DCHECK(!lower_ascii_domain.empty());
623
624 // If the host name ends with a dot but the input domain doesn't, then we
625 // ignore the dot in the host name.
626 size_t host_len = canonicalized_host.length();
627 if (canonicalized_host.back() == '.' && lower_ascii_domain.back() != '.')
628 --host_len;
629
630 if (host_len < lower_ascii_domain.length())
631 return false;
632
633 // |host_first_pos| is the start of the compared part of the host name, not
634 // start of the whole host name.
635 const char* host_first_pos =
636 canonicalized_host.data() + host_len - lower_ascii_domain.length();
637
638 if (!base::LowerCaseEqualsASCII(
639 base::StringPiece(host_first_pos, lower_ascii_domain.length()),
640 lower_ascii_domain)) {
641 return false;
642 }
643
644 // Make sure there aren't extra characters in host before the compared part;
645 // if the host name is longer than the input domain name, then the character
646 // immediately before the compared part should be a dot. For example,
647 // www.google.com has domain "google.com", but www.iamnotgoogle.com does not.
648 if (lower_ascii_domain[0] != '.' && host_len > lower_ascii_domain.length() &&
649 *(host_first_pos - 1) != '.') {
650 return false;
651 }
652
653 return true;
654 }
655
619 bool CompareSchemeComponent(const char* spec, 656 bool CompareSchemeComponent(const char* spec,
620 const Component& component, 657 const Component& component,
621 const char* compare_to) { 658 const char* compare_to) {
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
OLDNEW
« url/url_util.h ('K') | « url/url_util.h ('k') | url/url_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698