Chromium Code Reviews| Index: components/google/core/browser/google_util.cc |
| diff --git a/components/google/core/browser/google_util.cc b/components/google/core/browser/google_util.cc |
| index a16d55eaafdd0daa4d89de8523ad121be7cc5f84..f081f6b82145206435a82eaf41160d09ed16fcef 100644 |
| --- a/components/google/core/browser/google_util.cc |
| +++ b/components/google/core/browser/google_util.cc |
| @@ -41,6 +41,9 @@ namespace { |
| bool gUseMockLinkDoctorBaseURLForTesting = false; |
| +const char* const gGoogleSearchSubdomains[] = {"ipv4.google.com", |
| + "ipv6.google.com"}; |
| + |
| bool IsPathHomePageBase(base::StringPiece path) { |
| return (path == "/") || (path == "/webhp"); |
| } |
| @@ -104,6 +107,11 @@ bool IsCanonicalHostGoogleHostname(base::StringPiece canonical_host, |
| if (!IsValidHostName(canonical_host, "google", subdomain_permission, &tld)) |
| return false; |
| + // Remove the trailing dot from tld if present, as for google domain it's the |
| + // same page. |
| + if (tld.ends_with(".")) |
| + tld = tld.substr(0, tld.length() - 1); |
| + |
| CR_DEFINE_STATIC_LOCAL(std::set<std::string>, google_tlds, |
| ({GOOGLE_TLD_LIST})); |
| return base::ContainsKey(google_tlds, tld.as_string()); |
| @@ -148,6 +156,8 @@ GURL AppendGoogleLocaleParam(const GURL& url, |
| std::string GetGoogleCountryCode(const GURL& google_homepage_url) { |
| base::StringPiece google_hostname = google_homepage_url.host_piece(); |
| + // TODO(igorcov): This needs a fix for case when the host has a trailing dot, |
| + // like "google.com./". https://crbug.com/720295. |
| const size_t last_dot = google_hostname.find_last_of('.'); |
| if (last_dot == std::string::npos) { |
| NOTREACHED(); |
| @@ -215,10 +225,27 @@ bool IsGoogleDomainUrl(const GURL& url, |
| IsCanonicalHostGoogleHostname(url.host_piece(), subdomain_permission); |
| } |
| +bool IsGoogleSearchSubdomainUrl(const GURL& url, |
| + PortPermission port_permission) { |
| + if (!IsValidURL(url, port_permission)) |
| + return false; |
| + |
| + base::StringPiece host(url.host_piece()); |
| + if (host.ends_with(".")) |
| + host = host.substr(0, host.length() - 1); |
|
Andrew T Wilson (Slow)
2017/05/10 14:54:17
This is fine, but if we do this anywhere else we m
igorcov
2017/05/10 16:19:56
Done, thanks.
|
| + |
| + return std::binary_search( |
| + gGoogleSearchSubdomains, |
|
Andrew T Wilson (Slow)
2017/05/10 14:54:17
Binary search is probably overkill for a two-item
igorcov
2017/05/10 16:19:56
Right, forgot to put the comment. Don't know which
|
| + gGoogleSearchSubdomains + arraysize(gGoogleSearchSubdomains), host); |
| +} |
| + |
| bool IsGoogleHomePageUrl(const GURL& url) { |
| // First check to see if this has a Google domain. |
| - if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN, DISALLOW_NON_STANDARD_PORTS)) |
| + if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN, |
| + DISALLOW_NON_STANDARD_PORTS) && |
| + !IsGoogleSearchSubdomainUrl(url, DISALLOW_NON_STANDARD_PORTS)) { |
| return false; |
| + } |
| // Make sure the path is a known home page path. |
| base::StringPiece path(url.path_piece()); |
| @@ -228,8 +255,11 @@ bool IsGoogleHomePageUrl(const GURL& url) { |
| bool IsGoogleSearchUrl(const GURL& url) { |
| // First check to see if this has a Google domain. |
| - if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN, DISALLOW_NON_STANDARD_PORTS)) |
| + if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN, |
| + DISALLOW_NON_STANDARD_PORTS) && |
| + !IsGoogleSearchSubdomainUrl(url, DISALLOW_NON_STANDARD_PORTS)) { |
| return false; |
| + } |
| // Make sure the path is a known search path. |
| base::StringPiece path(url.path_piece()); |