| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/google/google_util.h" | 5 #include "chrome/browser/google/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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 // instance, in a regular Google search they'll be in the query but in a | 191 // instance, in a regular Google search they'll be in the query but in a |
| 192 // Google Instant search they can be in both. The ref is the correct one to | 192 // Google Instant search they can be in both. The ref is the correct one to |
| 193 // return in this case, so test the ref component first. | 193 // return in this case, so test the ref component first. |
| 194 if (ExtractSearchTermsFromComponent(url, &parsed_url.ref, &search_terms) || | 194 if (ExtractSearchTermsFromComponent(url, &parsed_url.ref, &search_terms) || |
| 195 ExtractSearchTermsFromComponent(url, &parsed_url.query, &search_terms)) { | 195 ExtractSearchTermsFromComponent(url, &parsed_url.query, &search_terms)) { |
| 196 return search_terms; | 196 return search_terms; |
| 197 } | 197 } |
| 198 return string16(); | 198 return string16(); |
| 199 } | 199 } |
| 200 | 200 |
| 201 bool IsGoogleDomainUrl(const std::string& url, SubdomainPermission permission) { | 201 bool IsGoogleDomainUrl(const std::string& url, |
| 202 SubdomainPermission subdomain_permission, |
| 203 PortPermission port_permission) { |
| 202 GURL original_url(url); | 204 GURL original_url(url); |
| 203 return original_url.is_valid() && original_url.port().empty() && | 205 return original_url.is_valid() && |
| 206 (original_url.port().empty() || port_permission == ALLOW_ALL_PORTS) && |
| 204 (original_url.SchemeIs("http") || original_url.SchemeIs("https")) && | 207 (original_url.SchemeIs("http") || original_url.SchemeIs("https")) && |
| 205 google_util::IsGoogleHostname(original_url.host(), permission); | 208 google_util::IsGoogleHostname(original_url.host(), subdomain_permission); |
| 206 } | 209 } |
| 207 | 210 |
| 208 bool IsGoogleHostname(const std::string& host, | 211 bool IsGoogleHostname(const std::string& host, |
| 209 SubdomainPermission permission) { | 212 SubdomainPermission subdomain_permission) { |
| 210 size_t tld_length = | 213 size_t tld_length = |
| 211 net::RegistryControlledDomainService::GetRegistryLength(host, false); | 214 net::RegistryControlledDomainService::GetRegistryLength(host, false); |
| 212 if ((tld_length == 0) || (tld_length == std::string::npos)) | 215 if ((tld_length == 0) || (tld_length == std::string::npos)) |
| 213 return false; | 216 return false; |
| 214 std::string host_minus_tld(host, 0, host.length() - tld_length); | 217 std::string host_minus_tld(host, 0, host.length() - tld_length); |
| 215 if (LowerCaseEqualsASCII(host_minus_tld, "google.")) | 218 if (LowerCaseEqualsASCII(host_minus_tld, "google.")) |
| 216 return true; | 219 return true; |
| 217 if (permission == ALLOW_SUBDOMAIN) | 220 if (subdomain_permission == ALLOW_SUBDOMAIN) |
| 218 return EndsWith(host_minus_tld, ".google.", false); | 221 return EndsWith(host_minus_tld, ".google.", false); |
| 219 return LowerCaseEqualsASCII(host_minus_tld, "www.google."); | 222 return LowerCaseEqualsASCII(host_minus_tld, "www.google."); |
| 220 } | 223 } |
| 221 | 224 |
| 222 bool IsGoogleHomePageUrl(const std::string& url) { | 225 bool IsGoogleHomePageUrl(const std::string& url) { |
| 223 GURL original_url(url); | 226 GURL original_url(url); |
| 224 | 227 |
| 225 // First check to see if this has a Google domain. | 228 // First check to see if this has a Google domain. |
| 226 if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN)) | 229 if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN, ALLOW_STANDARD_PORTS)) |
| 227 return false; | 230 return false; |
| 228 | 231 |
| 229 // Make sure the path is a known home page path. | 232 // Make sure the path is a known home page path. |
| 230 std::string path(original_url.path()); | 233 std::string path(original_url.path()); |
| 231 if (path != "/" && path != "/webhp" && | 234 if (path != "/" && path != "/webhp" && |
| 232 !StartsWithASCII(path, "/ig", false)) { | 235 !StartsWithASCII(path, "/ig", false)) { |
| 233 return false; | 236 return false; |
| 234 } | 237 } |
| 235 | 238 |
| 236 return true; | 239 return true; |
| 237 } | 240 } |
| 238 | 241 |
| 239 bool IsGoogleSearchUrl(const std::string& url) { | 242 bool IsGoogleSearchUrl(const std::string& url) { |
| 240 GURL original_url(url); | 243 GURL original_url(url); |
| 241 | 244 |
| 242 // First check to see if this has a Google domain. | 245 // First check to see if this has a Google domain. |
| 243 if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN)) | 246 if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN, ALLOW_STANDARD_PORTS)) |
| 244 return false; | 247 return false; |
| 245 | 248 |
| 246 // Make sure the path is a known search path. | 249 // Make sure the path is a known search path. |
| 247 std::string path(original_url.path()); | 250 std::string path(original_url.path()); |
| 248 bool has_valid_path = false; | 251 bool has_valid_path = false; |
| 249 bool is_home_page_base = false; | 252 bool is_home_page_base = false; |
| 250 if (path == "/search") { | 253 if (path == "/search") { |
| 251 has_valid_path = true; | 254 has_valid_path = true; |
| 252 } else if (path == "/webhp" || path == "/") { | 255 } else if (path == "/webhp" || path == "/") { |
| 253 // Note that we allow both "/" and "" paths, but GURL spits them | 256 // Note that we allow both "/" and "" paths, but GURL spits them |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 const char* const kBrands[] = { | 347 const char* const kBrands[] = { |
| 345 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", | 348 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", |
| 346 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM", | 349 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM", |
| 347 }; | 350 }; |
| 348 const char* const* end = &kBrands[arraysize(kBrands)]; | 351 const char* const* end = &kBrands[arraysize(kBrands)]; |
| 349 const char* const* found = std::find(&kBrands[0], end, brand); | 352 const char* const* found = std::find(&kBrands[0], end, brand); |
| 350 return found != end; | 353 return found != end; |
| 351 } | 354 } |
| 352 | 355 |
| 353 } // namespace google_util | 356 } // namespace google_util |
| OLD | NEW |