summaryrefslogtreecommitdiffstats
path: root/chrome/browser/google
diff options
context:
space:
mode:
authorstevet@chromium.org <stevet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-02 14:05:44 +0000
committerstevet@chromium.org <stevet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-02 14:05:44 +0000
commit274647e044b45a0eb150a9dca590157344d7fab3 (patch)
tree08a3b328ddc6f079090909fa96272cd06ebdb5f7 /chrome/browser/google
parentf4b40c369913c720c7752669c3fc2f3f98a6106b (diff)
downloadchromium_src-274647e044b45a0eb150a9dca590157344d7fab3.zip
chromium_src-274647e044b45a0eb150a9dca590157344d7fab3.tar.gz
chromium_src-274647e044b45a0eb150a9dca590157344d7fab3.tar.bz2
Transmit a X-Chrome-UMA-Enabled bit to Google domains from clients that have UMA enabled.
This requires a change to the ChromeResourceDispatcherHostDelegate and profiles where we feed the incognito and metrics-enabled states into the object at creation time, so we can check that field when doing our header setting. This was originally committed as r134625, but reverted due to CrOS failures, which are now fixed in this patch (see delta from patch sets 1 to 2). BUG=123609 TEST=With UMA enabled (not Chromium), visit www.google.com and ensure that the request header includes X-Chrome-UMA-Enabled with value "1". Ensure that disabling UMA also disables the transmission of this header entirely. Also, ensure that unit_tests GoogleUtilTests all pass. TBR=pkasting,ivankr Review URL: http://codereview.chromium.org/10273028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134902 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/google')
-rw-r--r--chrome/browser/google/google_util.cc28
-rw-r--r--chrome/browser/google/google_util.h17
-rw-r--r--chrome/browser/google/google_util_unittest.cc49
3 files changed, 80 insertions, 14 deletions
diff --git a/chrome/browser/google/google_util.cc b/chrome/browser/google/google_util.cc
index d95b116..22b17fc 100644
--- a/chrome/browser/google/google_util.cc
+++ b/chrome/browser/google/google_util.cc
@@ -44,13 +44,6 @@ bool HasQueryParameter(const std::string& str) {
return false;
}
-// True if |url| is an HTTP[S] request with host "[www.]google.<TLD>" and no
-// explicit port.
-bool IsGoogleDomainUrl(const GURL& url) {
- return url.is_valid() && (url.SchemeIs("http") || url.SchemeIs("https")) &&
- url.port().empty() && google_util::IsGoogleHostname(url.host());
-}
-
} // anonymous namespace
namespace google_util {
@@ -142,21 +135,32 @@ bool GetReactivationBrand(std::string* brand) {
#endif
-bool IsGoogleHostname(const std::string& host) {
+bool IsGoogleDomainUrl(const std::string& url, SubdomainPermission permission) {
+ GURL original_url(url);
+ return original_url.is_valid() && original_url.port().empty() &&
+ (original_url.SchemeIs("http") || original_url.SchemeIs("https")) &&
+ google_util::IsGoogleHostname(original_url.host(), permission);
+}
+
+bool IsGoogleHostname(const std::string& host,
+ SubdomainPermission permission) {
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.");
+ if (LowerCaseEqualsASCII(host_minus_tld, "google."))
+ return true;
+ if (permission == ALLOW_SUBDOMAIN)
+ return EndsWith(host_minus_tld, ".google.", false);
+ return LowerCaseEqualsASCII(host_minus_tld, "www.google.");
}
bool IsGoogleHomePageUrl(const std::string& url) {
GURL original_url(url);
// First check to see if this has a Google domain.
- if (!IsGoogleDomainUrl(original_url))
+ if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN))
return false;
// Make sure the path is a known home page path.
@@ -173,7 +177,7 @@ bool IsGoogleSearchUrl(const std::string& url) {
GURL original_url(url);
// First check to see if this has a Google domain.
- if (!IsGoogleDomainUrl(original_url))
+ if (!IsGoogleDomainUrl(url, DISALLOW_SUBDOMAIN))
return false;
// Make sure the path is a known search path.
diff --git a/chrome/browser/google/google_util.h b/chrome/browser/google/google_util.h
index 95ae4b9..670591a 100644
--- a/chrome/browser/google/google_util.h
+++ b/chrome/browser/google/google_util.h
@@ -46,8 +46,21 @@ bool GetReactivationBrand(std::string* brand);
// need to restrict some behavior to only happen on Google's officially-owned
// domains, use TransportSecurityState::IsGooglePinnedProperty() instead.
-// True if |host| is "[www.]google.<TLD>" with a valid TLD.
-bool IsGoogleHostname(const std::string& host);
+// Designate whether or not a URL checking function also checks for specific
+// subdomains, or only "www" and empty subdomains.
+enum SubdomainPermission {
+ ALLOW_SUBDOMAIN,
+ DISALLOW_SUBDOMAIN,
+};
+
+// True if |url| is an HTTP[S] request with host "[www.]google.<TLD>" and no
+// explicit port. If |permission| is ALLOW_SUBDOMAIN, we check against host
+// "*.google.<TLD>" instead.
+bool IsGoogleDomainUrl(const std::string& url, SubdomainPermission permission);
+// True if |host| is "[www.]google.<TLD>" with a valid TLD. If
+// |permission| is ALLOW_SUBDOMAIN, we check against host "*.google.<TLD>"
+// instead.
+bool IsGoogleHostname(const std::string& host, SubdomainPermission permission);
// True if |url| represents a valid Google home page URL.
bool IsGoogleHomePageUrl(const std::string& url);
// True if |url| represents a valid Google search URL.
diff --git a/chrome/browser/google/google_util_unittest.cc b/chrome/browser/google/google_util_unittest.cc
index f51460c..5c0bfbb 100644
--- a/chrome/browser/google/google_util_unittest.cc
+++ b/chrome/browser/google/google_util_unittest.cc
@@ -6,6 +6,7 @@
#include "chrome/browser/google/google_util.h"
#include "testing/gtest/include/gtest/gtest.h"
+using google_util::IsGoogleDomainUrl;
using google_util::IsGoogleHomePageUrl;
using google_util::IsGoogleSearchUrl;
@@ -241,3 +242,51 @@ TEST(GoogleUtilTest, BadSearches) {
EXPECT_FALSE(IsGoogleSearchUrl(
"http://www.google.com/WEBHP#q=something"));
}
+
+TEST(GoogleUtilTest, GoogleDomains) {
+ // Test some good Google domains (valid TLDs).
+ EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.com",
+ google_util::ALLOW_SUBDOMAIN));
+ EXPECT_TRUE(IsGoogleDomainUrl("http://google.com",
+ google_util::ALLOW_SUBDOMAIN));
+ EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.ca",
+ google_util::ALLOW_SUBDOMAIN));
+ EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.biz.tj",
+ google_util::ALLOW_SUBDOMAIN));
+ EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.com/search?q=something",
+ google_util::ALLOW_SUBDOMAIN));
+ EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.com/webhp",
+ google_util::ALLOW_SUBDOMAIN));
+
+ // Test some bad Google domains (invalid TLDs).
+ EXPECT_FALSE(IsGoogleDomainUrl("http://www.google.notrealtld",
+ google_util::ALLOW_SUBDOMAIN));
+ EXPECT_FALSE(IsGoogleDomainUrl("http://www.google.faketld/search?q=something",
+ google_util::ALLOW_SUBDOMAIN));
+ EXPECT_FALSE(IsGoogleDomainUrl("http://www.yahoo.com",
+ google_util::ALLOW_SUBDOMAIN));
+
+ // Test subdomain checks.
+ EXPECT_TRUE(IsGoogleDomainUrl("http://images.google.com",
+ google_util::ALLOW_SUBDOMAIN));
+ EXPECT_FALSE(IsGoogleDomainUrl("http://images.google.com",
+ google_util::DISALLOW_SUBDOMAIN));
+ EXPECT_TRUE(IsGoogleDomainUrl("http://google.com",
+ google_util::DISALLOW_SUBDOMAIN));
+ EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.com",
+ google_util::DISALLOW_SUBDOMAIN));
+
+ // Port and scheme checks.
+ EXPECT_TRUE(IsGoogleDomainUrl("http://www.google.com:80",
+ google_util::DISALLOW_SUBDOMAIN));
+ EXPECT_FALSE(IsGoogleDomainUrl("http://www.google.com:123",
+ google_util::DISALLOW_SUBDOMAIN));
+ EXPECT_TRUE(IsGoogleDomainUrl("https://www.google.com:443",
+ google_util::DISALLOW_SUBDOMAIN));
+ EXPECT_FALSE(IsGoogleDomainUrl("https://www.google.com:123",
+ google_util::DISALLOW_SUBDOMAIN));
+ EXPECT_FALSE(IsGoogleDomainUrl("file://www.google.com",
+ google_util::DISALLOW_SUBDOMAIN));
+ EXPECT_FALSE(IsGoogleDomainUrl("doesnotexist://www.google.com",
+ google_util::DISALLOW_SUBDOMAIN));
+}