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

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: Address review comments, PSO checks for good/bad URLs 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
« no previous file with comments | « chrome/browser/google/google_util.h ('k') | chrome/browser/google/google_util_unittest.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 111916)
+++ chrome/browser/google/google_util.cc (working copy)
@@ -128,6 +128,43 @@
#endif
+bool IsGoogleHomePageUrl(const std::string& url) {
+ 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())
+ 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.") &&
+ !LowerCaseEqualsASCII(host, "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;
+}
+
bool IsOrganic(const std::string& brand) {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kOrganicInstall))
« no previous file with comments | « chrome/browser/google/google_util.h ('k') | chrome/browser/google/google_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698