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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 const std::string& domain_in_lower_case, | 47 const std::string& domain_in_lower_case, |
48 google_util::SubdomainPermission subdomain_permission) { | 48 google_util::SubdomainPermission subdomain_permission) { |
49 size_t tld_length = net::registry_controlled_domains::GetRegistryLength( | 49 size_t tld_length = net::registry_controlled_domains::GetRegistryLength( |
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 (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 EndsWith(host_minus_tld, "." + domain_in_lower_case, false); | 60 return EndsWith(host_minus_tld, "." + domain_in_lower_case, false); |
61 return LowerCaseEqualsASCII(host_minus_tld, | 61 return base::LowerCaseEqualsASCII(host_minus_tld, |
62 ("www." + domain_in_lower_case).c_str()); | 62 ("www." + domain_in_lower_case).c_str()); |
63 } | 63 } |
64 | 64 |
65 // True if |url| is a valid URL with HTTP or HTTPS scheme. If |port_permission| | 65 // 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 | 66 // is DISALLOW_NON_STANDARD_PORTS, this also requires |url| to use the standard |
67 // port for its scheme (80 for HTTP, 443 for HTTPS). | 67 // port for its scheme (80 for HTTP, 443 for HTTPS). |
68 bool IsValidURL(const GURL& url, google_util::PortPermission port_permission) { | 68 bool IsValidURL(const GURL& url, google_util::PortPermission port_permission) { |
69 return url.is_valid() && url.SchemeIsHTTPOrHTTPS() && | 69 return url.is_valid() && url.SchemeIsHTTPOrHTTPS() && |
70 (url.port().empty() || | 70 (url.port().empty() || |
71 (port_permission == google_util::ALLOW_NON_STANDARD_PORTS)); | 71 (port_permission == google_util::ALLOW_NON_STANDARD_PORTS)); |
72 } | 72 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 } | 208 } |
209 | 209 |
210 bool IsYoutubeDomainUrl(const GURL& url, | 210 bool IsYoutubeDomainUrl(const GURL& url, |
211 SubdomainPermission subdomain_permission, | 211 SubdomainPermission subdomain_permission, |
212 PortPermission port_permission) { | 212 PortPermission port_permission) { |
213 return IsValidURL(url, port_permission) && | 213 return IsValidURL(url, port_permission) && |
214 IsValidHostName(url.host(), "youtube", subdomain_permission); | 214 IsValidHostName(url.host(), "youtube", subdomain_permission); |
215 } | 215 } |
216 | 216 |
217 } // namespace google_util | 217 } // namespace google_util |
OLD | NEW |