OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/google/core/browser/google_util.h" | 5 #include "components/google/core/browser/google_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 host, | 50 host, |
51 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, | 51 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, |
52 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); | 52 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); |
53 if ((tld_length == 0) || (tld_length == std::string::npos)) | 53 if ((tld_length == 0) || (tld_length == std::string::npos)) |
54 return false; | 54 return false; |
55 // Removes the tld and the preceding dot. | 55 // Removes the tld and the preceding dot. |
56 std::string host_minus_tld(host, 0, host.length() - tld_length - 1); | 56 std::string host_minus_tld(host, 0, host.length() - tld_length - 1); |
57 if (base::LowerCaseEqualsASCII(host_minus_tld, domain_in_lower_case.c_str())) | 57 if (base::LowerCaseEqualsASCII(host_minus_tld, domain_in_lower_case.c_str())) |
58 return true; | 58 return true; |
59 if (subdomain_permission == google_util::ALLOW_SUBDOMAIN) | 59 if (subdomain_permission == google_util::ALLOW_SUBDOMAIN) |
60 return base::EndsWith(host_minus_tld, "." + domain_in_lower_case, false); | 60 return base::EndsWith(host_minus_tld, "." + domain_in_lower_case, |
| 61 base::CompareCase::INSENSITIVE_ASCII); |
61 return base::LowerCaseEqualsASCII(host_minus_tld, | 62 return base::LowerCaseEqualsASCII(host_minus_tld, |
62 ("www." + domain_in_lower_case).c_str()); | 63 ("www." + domain_in_lower_case).c_str()); |
63 } | 64 } |
64 | 65 |
65 // True if |url| is a valid URL with HTTP or HTTPS scheme. If |port_permission| | 66 // True if |url| is a valid URL with HTTP or HTTPS scheme. If |port_permission| |
66 // is DISALLOW_NON_STANDARD_PORTS, this also requires |url| to use the standard | 67 // is DISALLOW_NON_STANDARD_PORTS, this also requires |url| to use the standard |
67 // port for its scheme (80 for HTTP, 443 for HTTPS). | 68 // port for its scheme (80 for HTTP, 443 for HTTPS). |
68 bool IsValidURL(const GURL& url, google_util::PortPermission port_permission) { | 69 bool IsValidURL(const GURL& url, google_util::PortPermission port_permission) { |
69 return url.is_valid() && url.SchemeIsHTTPOrHTTPS() && | 70 return url.is_valid() && url.SchemeIsHTTPOrHTTPS() && |
70 (url.port().empty() || | 71 (url.port().empty() || |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 } | 211 } |
211 | 212 |
212 bool IsYoutubeDomainUrl(const GURL& url, | 213 bool IsYoutubeDomainUrl(const GURL& url, |
213 SubdomainPermission subdomain_permission, | 214 SubdomainPermission subdomain_permission, |
214 PortPermission port_permission) { | 215 PortPermission port_permission) { |
215 return IsValidURL(url, port_permission) && | 216 return IsValidURL(url, port_permission) && |
216 IsValidHostName(url.host(), "youtube", subdomain_permission); | 217 IsValidHostName(url.host(), "youtube", subdomain_permission); |
217 } | 218 } |
218 | 219 |
219 } // namespace google_util | 220 } // namespace google_util |
OLD | NEW |