Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(516)

Unified Diff: components/google/core/browser/google_util.cc

Issue 2861183002: Google search subdomains included for Safesearch (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..e09d1586aa03b7553e579b3604b01ed9dd78bf8b 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 std::set<base::StringPiece> gGoogleSearchSubdomains{"ipv4.google.com",
Andrew T Wilson (Slow) 2017/05/09 13:36:47 This is a relatively complicated static which I th
igorcov 2017/05/10 13:25:20 Done.
+ "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./
Andrew T Wilson (Slow) 2017/05/09 13:36:47 Log a bug for this and add a link to the bug with
igorcov 2017/05/10 13:25:20 Done.
const size_t last_dot = google_hostname.find_last_of('.');
if (last_dot == std::string::npos) {
NOTREACHED();
@@ -215,9 +225,23 @@ 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);
+
+ return gGoogleSearchSubdomains.find(host) != gGoogleSearchSubdomains.end();
+}
+
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))
Andrew T Wilson (Slow) 2017/05/09 13:36:47 Multi-line if statements require braces.
igorcov 2017/05/10 13:25:20 Done.
return false;
// Make sure the path is a known home page path.
@@ -228,7 +252,9 @@ 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))
Andrew T Wilson (Slow) 2017/05/09 13:36:47 For a multi-line if statement, you need to use bra
igorcov 2017/05/10 13:25:21 Done.
return false;
// Make sure the path is a known search path.
« no previous file with comments | « components/google/core/browser/google_util.h ('k') | components/google/core/browser/google_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698