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

Unified Diff: chrome/browser/google/google_util.cc

Issue 9705021: Clean up TemplateURL prepopulate data: (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 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
« no previous file with comments | « chrome/browser/google/google_util.h ('k') | chrome/browser/protector/histograms.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/google/google_util.cc
===================================================================
--- chrome/browser/google/google_util.cc (revision 126661)
+++ chrome/browser/google/google_util.cc (working copy)
@@ -44,33 +44,11 @@
return false;
}
-// True if |url| is an HTTP[S] request with host "[www.]google.<TLD>".
+// True if |url| is an HTTP[S] request with host "[www.]google.<TLD>" and no
+// explicit port.
bool IsGoogleDomainUrl(const GURL& url) {
- if (!url.is_valid())
- return false;
-
- // Make sure the scheme is valid.
- if (!url.SchemeIs("http") && !url.SchemeIs("https"))
- return false;
-
- // Make sure port is default for the respective scheme.
- if (!url.port().empty())
- return false;
-
- // Accept only valid TLD.
- size_t tld_length = net::RegistryControlledDomainService::GetRegistryLength(
- url, false);
- if (tld_length == 0 || tld_length == std::string::npos)
- return false;
-
- // We only accept "[www.]google." in front of the TLD.
- std::string host = url.host();
- host = host.substr(0, host.length() - tld_length);
- if (!LowerCaseEqualsASCII(host, "www.google.") &&
- !LowerCaseEqualsASCII(host, "google."))
- return false;
-
- return true;
+ return url.is_valid() && (url.SchemeIs("http") || url.SchemeIs("https")) &&
+ url.port().empty() && google_util::IsGoogleHostname(url.host());
}
} // anonymous namespace
@@ -164,6 +142,16 @@
#endif
+bool IsGoogleHostname(const std::string& host) {
+ 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.");
+}
+
bool IsGoogleHomePageUrl(const std::string& url) {
GURL original_url(url);
« no previous file with comments | « chrome/browser/google/google_util.h ('k') | chrome/browser/protector/histograms.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698