summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-12 20:33:52 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-12 20:33:52 +0000
commit69bb5870fb38eb83ce767ed9b2434827a08f100d (patch)
treebb83b6bf8bcf5e89274e73a087ee3bf50625440e /net
parent0cac77dd89123d2fd1581127c44e7791392c5f53 (diff)
downloadchromium_src-69bb5870fb38eb83ce767ed9b2434827a08f100d.zip
chromium_src-69bb5870fb38eb83ce767ed9b2434827a08f100d.tar.gz
chromium_src-69bb5870fb38eb83ce767ed9b2434827a08f100d.tar.bz2
In the CookieMonster code, use the RegistryControlledDomainService only for
http and https URLs. For other schemes (like chrome-extension), use the host itself as the effective TLD. BUG=31867 Review URL: http://codereview.chromium.org/536017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36035 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/base/cookie_monster.cc22
1 files changed, 17 insertions, 5 deletions
diff --git a/net/base/cookie_monster.cc b/net/base/cookie_monster.cc
index 2af8a72..73e03ff 100644
--- a/net/base/cookie_monster.cc
+++ b/net/base/cookie_monster.cc
@@ -260,6 +260,19 @@ Time CookieMonster::ParseCookieTime(const std::string& time_string) {
return Time();
}
+// Returns the effective TLD+1 for a given host. This only makes sense for http
+// and https schemes. For other schemes, the host will be returned unchanged
+// (minus any leading .).
+static std::string GetEffectiveDomain(const std::string& scheme,
+ const std::string& host) {
+ if (scheme == "http" || scheme == "https")
+ return RegistryControlledDomainService::GetDomainAndRegistry(host);
+
+ if (!host.empty() && host[0] == '.')
+ return host.substr(1);
+ return host;
+}
+
// Determine the cookie domain key to use for setting the specified cookie.
// On success returns true, and sets cookie_domain_key to either a
// -host cookie key (ex: "google.com")
@@ -294,12 +307,13 @@ static bool GetCookieDomainKey(const GURL& url,
cookie_domain = "." + cookie_domain;
// Ensure |url| and |cookie_domain| have the same domain+registry.
+ const std::string url_scheme(url.scheme());
const std::string url_domain_and_registry(
- RegistryControlledDomainService::GetDomainAndRegistry(url));
+ GetEffectiveDomain(url_scheme, url_host));
if (url_domain_and_registry.empty())
return false; // IP addresses/intranet hosts can't set domain cookies.
const std::string cookie_domain_and_registry(
- RegistryControlledDomainService::GetDomainAndRegistry(cookie_domain));
+ GetEffectiveDomain(url_scheme, cookie_domain));
if (url_domain_and_registry != cookie_domain_and_registry)
return false; // Can't set a cookie on a different domain + registry.
@@ -312,7 +326,6 @@ static bool GetCookieDomainKey(const GURL& url,
cookie_domain.length(), cookie_domain))
return false;
-
*cookie_domain_key = cookie_domain;
return true;
}
@@ -853,8 +866,7 @@ void CookieMonster::FindCookiesForHostAndDomain(
FindCookiesForKey(key, url, options, current_time, cookies);
// See if we can search for domain cookies, i.e. if the host has a TLD + 1.
- const std::string domain(
- RegistryControlledDomainService::GetDomainAndRegistry(key));
+ const std::string domain(GetEffectiveDomain(url.scheme(), key));
if (domain.empty())
return;
DCHECK_LE(domain.length(), key.length());