| Index: chrome/browser/google/google_util.cc
|
| ===================================================================
|
| --- chrome/browser/google/google_util.cc (revision 209004)
|
| +++ chrome/browser/google/google_util.cc (working copy)
|
| @@ -35,16 +35,25 @@
|
| #define LINKDOCTOR_SERVER_REQUEST_URL std::string()
|
| #endif
|
|
|
| +
|
| +// Helpers --------------------------------------------------------------------
|
| +
|
| namespace {
|
|
|
| const char* brand_for_testing = NULL;
|
| -
|
| bool gUseMockLinkDoctorBaseURLForTesting = false;
|
|
|
| -} // anonymous namespace
|
| +bool IsPathHomePageBase(const std::string& path) {
|
| + return (path == "/") || (path == "/webhp");
|
| +}
|
|
|
| +} // namespace
|
| +
|
| +
|
| namespace google_util {
|
|
|
| +// Global functions -----------------------------------------------------------
|
| +
|
| bool HasGoogleSearchQueryParam(const std::string& str) {
|
| url_parse::Component query(0, str.length()), key, value;
|
| while (url_parse::ExtractQueryKeyValue(str.c_str(), &query, &key,
|
| @@ -65,15 +74,6 @@
|
| gUseMockLinkDoctorBaseURLForTesting = true;
|
| }
|
|
|
| -BrandForTesting::BrandForTesting(const std::string& brand) : brand_(brand) {
|
| - DCHECK(brand_for_testing == NULL);
|
| - brand_for_testing = brand_.c_str();
|
| -}
|
| -
|
| -BrandForTesting::~BrandForTesting() {
|
| - brand_for_testing = NULL;
|
| -}
|
| -
|
| GURL AppendGoogleLocaleParam(const GURL& url) {
|
| // Google does not yet recognize 'nb' for Norwegian Bokmal, but it uses
|
| // 'no' for that.
|
| @@ -152,14 +152,6 @@
|
|
|
| #endif
|
|
|
| -bool IsGoogleDomainUrl(const GURL& url,
|
| - SubdomainPermission subdomain_permission,
|
| - PortPermission port_permission) {
|
| - return url.is_valid() && (url.SchemeIs("http") || url.SchemeIs("https")) &&
|
| - (url.port().empty() || (port_permission == ALLOW_NON_STANDARD_PORTS)) &&
|
| - google_util::IsGoogleHostname(url.host(), subdomain_permission);
|
| -}
|
| -
|
| bool IsGoogleHostname(const std::string& host,
|
| SubdomainPermission subdomain_permission) {
|
| size_t tld_length = net::registry_controlled_domains::GetRegistryLength(
|
| @@ -176,6 +168,14 @@
|
| return LowerCaseEqualsASCII(host_minus_tld, "www.google.");
|
| }
|
|
|
| +bool IsGoogleDomainUrl(const GURL& url,
|
| + SubdomainPermission subdomain_permission,
|
| + PortPermission port_permission) {
|
| + return url.is_valid() && (url.SchemeIs("http") || url.SchemeIs("https")) &&
|
| + (url.port().empty() || (port_permission == ALLOW_NON_STANDARD_PORTS)) &&
|
| + google_util::IsGoogleHostname(url.host(), subdomain_permission);
|
| +}
|
| +
|
| bool IsGoogleHomePageUrl(const GURL& url) {
|
| // First check to see if this has a Google domain.
|
| if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN, DISALLOW_NON_STANDARD_PORTS))
|
| @@ -183,12 +183,7 @@
|
|
|
| // Make sure the path is a known home page path.
|
| std::string path(url.path());
|
| - if (path != "/" && path != "/webhp" &&
|
| - !StartsWithASCII(path, "/ig", false)) {
|
| - return false;
|
| - }
|
| -
|
| - return true;
|
| + return IsPathHomePageBase(path) || StartsWithASCII(path, "/ig", false);
|
| }
|
|
|
| bool IsGoogleSearchUrl(const GURL& url) {
|
| @@ -198,25 +193,14 @@
|
|
|
| // Make sure the path is a known search path.
|
| std::string path(url.path());
|
| - bool has_valid_path = false;
|
| - bool is_home_page_base = false;
|
| - if (path == "/search") {
|
| - has_valid_path = true;
|
| - } else if (path == "/webhp" || path == "/") {
|
| - // Note that we allow both "/" and "" paths, but GURL spits them
|
| - // both out as just "/".
|
| - has_valid_path = true;
|
| - is_home_page_base = true;
|
| - }
|
| - if (!has_valid_path)
|
| + bool is_home_page_base = IsPathHomePageBase(path);
|
| + if (!is_home_page_base && (path != "/search"))
|
| return false;
|
|
|
| // Check for query parameter in URL parameter and hash fragment, depending on
|
| // the path type.
|
| - std::string query(url.query());
|
| - std::string ref(url.ref());
|
| - return HasGoogleSearchQueryParam(ref) ||
|
| - (!is_home_page_base && HasGoogleSearchQueryParam(query));
|
| + return HasGoogleSearchQueryParam(url.ref()) ||
|
| + (!is_home_page_base && HasGoogleSearchQueryParam(url.query()));
|
| }
|
|
|
| bool IsOrganic(const std::string& brand) {
|
| @@ -280,4 +264,17 @@
|
| return found != end;
|
| }
|
|
|
| +
|
| +// BrandForTesting ------------------------------------------------------------
|
| +
|
| +BrandForTesting::BrandForTesting(const std::string& brand) : brand_(brand) {
|
| + DCHECK(brand_for_testing == NULL);
|
| + brand_for_testing = brand_.c_str();
|
| +}
|
| +
|
| +BrandForTesting::~BrandForTesting() {
|
| + brand_for_testing = NULL;
|
| +}
|
| +
|
| +
|
| } // namespace google_util
|
|
|