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

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

Issue 8728004: Add more flexible handling of what is considered a google home page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix using directive Created 9 years, 1 month 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: chrome/browser/google/google_util.cc
===================================================================
--- chrome/browser/google/google_util.cc (revision 111693)
+++ chrome/browser/google/google_util.cc (working copy)
@@ -82,6 +82,42 @@
return AppendParam(url, "sd", google_domain.substr(first_dot + 1));
}
+bool IsGoogleHomePageUrl(const std::string& url) {
SteveT 2011/11/28 21:04:49 Nit: Move down to roughly match header order.
Roger Tawa OOO till Jul 10th 2011/11/29 16:00:09 Done.
+ GURL original_url(url);
+ if (!original_url.is_valid())
+ return false;
+
+ // Make sure the scheme is valid.
+ if (!original_url.SchemeIs("http") && !original_url.SchemeIs("https"))
+ return false;
+
+ // Make sure port is default for the respective scheme.
+ if (!original_url.port().empty())
SteveT 2011/11/28 21:04:49 Do we want to allow :80 and :443 for http and http
Roger Tawa OOO till Jul 10th 2011/11/29 16:00:09 GURL does not make it easy to detect default port
+ return false;
+
+ // Accept only valid TLD.
+ size_t tld_length = net::RegistryControlledDomainService::GetRegistryLength(
+ original_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 = original_url.host();
+ host = host.substr(0, host.length() - tld_length);
+ if (!LowerCaseEqualsASCII(host, "www.google."))
+ return false;
+
+ // Make sure the path is a known home page path.
+ std::string path(original_url.path());
+ if (!LowerCaseEqualsASCII(path, "/") &&
+ !LowerCaseEqualsASCII(path, "/webhp") &&
+ !StartsWithASCII(path, "/ig", false)) {
+ return false;
+ }
+
+ return true;
+}
+
#if defined(OS_WIN)
bool GetBrand(std::string* brand) {

Powered by Google App Engine
This is Rietveld 408576698