| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 bool IsPathHomePageBase(base::StringPiece path) { | 43 bool IsPathHomePageBase(base::StringPiece path) { |
| 44 return (path == "/") || (path == "/webhp"); | 44 return (path == "/") || (path == "/webhp"); |
| 45 } | 45 } |
| 46 | 46 |
| 47 // True if the given canonical |host| is "[www.]<domain_in_lower_case>.<TLD>" | 47 // True if the given canonical |host| is "[www.]<domain_in_lower_case>.<TLD>" |
| 48 // with a valid TLD. If |subdomain_permission| is ALLOW_SUBDOMAIN, we check | 48 // with a valid TLD. If |subdomain_permission| is ALLOW_SUBDOMAIN, we check |
| 49 // against host "*.<domain_in_lower_case>.<TLD>" instead. | 49 // against host "*.<domain_in_lower_case>.<TLD>" instead. |
| 50 bool IsValidHostName(base::StringPiece host, | 50 bool IsValidHostName(base::StringPiece host, |
| 51 base::StringPiece domain_in_lower_case, | 51 base::StringPiece domain_in_lower_case, |
| 52 SubdomainPermission subdomain_permission) { | 52 SubdomainPermission subdomain_permission) { |
| 53 // Fast path to avoid searching the registry set. |
| 54 if (host.find(domain_in_lower_case) == base::StringPiece::npos) |
| 55 return false; |
| 53 size_t tld_length = | 56 size_t tld_length = |
| 54 net::registry_controlled_domains::GetCanonicalHostRegistryLength( | 57 net::registry_controlled_domains::GetCanonicalHostRegistryLength( |
| 55 host, net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, | 58 host, net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, |
| 56 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); | 59 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); |
| 57 if ((tld_length == 0) || (tld_length == std::string::npos)) | 60 if ((tld_length == 0) || (tld_length == std::string::npos)) |
| 58 return false; | 61 return false; |
| 59 | 62 |
| 60 // Removes the tld and the preceding dot. | 63 // Removes the tld and the preceding dot. |
| 61 base::StringPiece host_minus_tld = | 64 base::StringPiece host_minus_tld = |
| 62 host.substr(0, host.length() - tld_length - 1); | 65 host.substr(0, host.length() - tld_length - 1); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 } | 230 } |
| 228 | 231 |
| 229 bool IsYoutubeDomainUrl(const GURL& url, | 232 bool IsYoutubeDomainUrl(const GURL& url, |
| 230 SubdomainPermission subdomain_permission, | 233 SubdomainPermission subdomain_permission, |
| 231 PortPermission port_permission) { | 234 PortPermission port_permission) { |
| 232 return IsValidURL(url, port_permission) && | 235 return IsValidURL(url, port_permission) && |
| 233 IsValidHostName(url.host_piece(), "youtube", subdomain_permission); | 236 IsValidHostName(url.host_piece(), "youtube", subdomain_permission); |
| 234 } | 237 } |
| 235 | 238 |
| 236 } // namespace google_util | 239 } // namespace google_util |
| OLD | NEW |