Index: chrome/browser/google/google_util.cc |
diff --git a/chrome/browser/google/google_util.cc b/chrome/browser/google/google_util.cc |
index d95b116045a0246ec9d7e3f54b07d9bc7865c328..22b17fc1edae237796b5296a60a9a6490ee8e221 100644 |
--- a/chrome/browser/google/google_util.cc |
+++ b/chrome/browser/google/google_util.cc |
@@ -44,13 +44,6 @@ bool HasQueryParameter(const std::string& str) { |
return false; |
} |
-// True if |url| is an HTTP[S] request with host "[www.]google.<TLD>" and no |
-// explicit port. |
-bool IsGoogleDomainUrl(const GURL& url) { |
- return url.is_valid() && (url.SchemeIs("http") || url.SchemeIs("https")) && |
- url.port().empty() && google_util::IsGoogleHostname(url.host()); |
-} |
- |
} // anonymous namespace |
namespace google_util { |
@@ -142,21 +135,32 @@ bool GetReactivationBrand(std::string* brand) { |
#endif |
-bool IsGoogleHostname(const std::string& host) { |
+bool IsGoogleDomainUrl(const std::string& url, SubdomainPermission permission) { |
+ GURL original_url(url); |
+ return original_url.is_valid() && original_url.port().empty() && |
+ (original_url.SchemeIs("http") || original_url.SchemeIs("https")) && |
+ google_util::IsGoogleHostname(original_url.host(), permission); |
+} |
+ |
+bool IsGoogleHostname(const std::string& host, |
+ SubdomainPermission permission) { |
size_t tld_length = |
net::RegistryControlledDomainService::GetRegistryLength(host, false); |
if ((tld_length == 0) || (tld_length == std::string::npos)) |
return false; |
std::string host_minus_tld(host, 0, host.length() - tld_length); |
- return LowerCaseEqualsASCII(host_minus_tld, "www.google.") || |
- LowerCaseEqualsASCII(host_minus_tld, "google."); |
+ if (LowerCaseEqualsASCII(host_minus_tld, "google.")) |
+ return true; |
+ if (permission == ALLOW_SUBDOMAIN) |
+ return EndsWith(host_minus_tld, ".google.", false); |
+ return LowerCaseEqualsASCII(host_minus_tld, "www.google."); |
} |
bool IsGoogleHomePageUrl(const std::string& url) { |
GURL original_url(url); |
// First check to see if this has a Google domain. |
- if (!IsGoogleDomainUrl(original_url)) |
+ if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN)) |
return false; |
// Make sure the path is a known home page path. |
@@ -173,7 +177,7 @@ bool IsGoogleSearchUrl(const std::string& url) { |
GURL original_url(url); |
// First check to see if this has a Google domain. |
- if (!IsGoogleDomainUrl(original_url)) |
+ if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN)) |
return false; |
// Make sure the path is a known search path. |