diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2015-10-13 13:24:50 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2015-10-14 10:57:25 +0000 |
commit | af3d4809763ef308f08ced947a73b624729ac7ea (patch) | |
tree | 4402b911e30383f6c6dace1e8cf3b8e85355db3a /chromium/net/cookies | |
parent | 0e8ff63a407fe323e215bb1a2c423c09a4747c8a (diff) | |
download | qtwebengine-chromium-af3d4809763ef308f08ced947a73b624729ac7ea.tar.gz |
BASELINE: Update Chromium to 47.0.2526.14
Also adding in sources needed for spellchecking.
Change-Id: Idd44170fa1616f26315188970a8d5ba7d472b18a
Reviewed-by: Michael BrĂ¼ning <michael.bruning@theqtcompany.com>
Diffstat (limited to 'chromium/net/cookies')
-rw-r--r-- | chromium/net/cookies/OWNERS | 2 | ||||
-rw-r--r-- | chromium/net/cookies/canonical_cookie.cc | 19 | ||||
-rw-r--r-- | chromium/net/cookies/canonical_cookie.h | 13 | ||||
-rw-r--r-- | chromium/net/cookies/canonical_cookie_unittest.cc | 33 | ||||
-rw-r--r-- | chromium/net/cookies/cookie_constants.cc | 3 | ||||
-rw-r--r-- | chromium/net/cookies/cookie_monster.cc | 159 | ||||
-rw-r--r-- | chromium/net/cookies/cookie_monster.h | 51 | ||||
-rw-r--r-- | chromium/net/cookies/cookie_monster_unittest.cc | 136 | ||||
-rw-r--r-- | chromium/net/cookies/cookie_options.cc | 16 | ||||
-rw-r--r-- | chromium/net/cookies/cookie_options.h | 9 | ||||
-rw-r--r-- | chromium/net/cookies/cookie_store_unittest.h | 39 | ||||
-rw-r--r-- | chromium/net/cookies/cookie_util.cc | 3 | ||||
-rw-r--r-- | chromium/net/cookies/parsed_cookie.cc | 2 |
13 files changed, 241 insertions, 244 deletions
diff --git a/chromium/net/cookies/OWNERS b/chromium/net/cookies/OWNERS index 82e44d8afb0..3f8456354bd 100644 --- a/chromium/net/cookies/OWNERS +++ b/chromium/net/cookies/OWNERS @@ -1 +1 @@ -erikwright@chromium.org +mkwst@chromium.org diff --git a/chromium/net/cookies/canonical_cookie.cc b/chromium/net/cookies/canonical_cookie.cc index eae8298fc78..fcc8e3d9f4a 100644 --- a/chromium/net/cookies/canonical_cookie.cc +++ b/chromium/net/cookies/canonical_cookie.cc @@ -135,7 +135,7 @@ CanonicalCookie::CanonicalCookie(const GURL& url, bool httponly, bool firstpartyonly, CookiePriority priority) - : source_(GetCookieSourceFromURL(url)), + : source_(url.SchemeIsFile() ? url : url.GetOrigin()), name_(name), value_(value), domain_(domain), @@ -146,11 +146,10 @@ CanonicalCookie::CanonicalCookie(const GURL& url, secure_(secure), httponly_(httponly), first_party_only_(firstpartyonly), - priority_(priority) { -} + priority_(priority) {} CanonicalCookie::CanonicalCookie(const GURL& url, const ParsedCookie& pc) - : source_(GetCookieSourceFromURL(url)), + : source_(url.SchemeIsFile() ? url : url.GetOrigin()), name_(pc.Name()), value_(pc.Value()), path_(CanonPath(url, pc)), @@ -180,18 +179,6 @@ CanonicalCookie::CanonicalCookie(const GURL& url, const ParsedCookie& pc) CanonicalCookie::~CanonicalCookie() { } -std::string CanonicalCookie::GetCookieSourceFromURL(const GURL& url) { - if (url.SchemeIsFile()) - return url.spec(); - - url::Replacements<char> replacements; - replacements.ClearPort(); - if (url.SchemeIsCryptographic()) - replacements.SetScheme("http", url::Component(0, 4)); - - return url.GetOrigin().ReplaceComponents(replacements).spec(); -} - // static std::string CanonicalCookie::CanonPath(const GURL& url, const ParsedCookie& pc) { diff --git a/chromium/net/cookies/canonical_cookie.h b/chromium/net/cookies/canonical_cookie.h index 30fb3e764aa..30ddcabf645 100644 --- a/chromium/net/cookies/canonical_cookie.h +++ b/chromium/net/cookies/canonical_cookie.h @@ -72,7 +72,7 @@ class NET_EXPORT CanonicalCookie { bool first_party_only, CookiePriority priority); - const std::string& Source() const { return source_; } + const GURL& Source() const { return source_; } const std::string& Name() const { return name_; } const std::string& Value() const { return value_; } const std::string& Domain() const { return domain_; } @@ -128,9 +128,6 @@ class NET_EXPORT CanonicalCookie { std::string DebugString() const; - // Returns the cookie source when cookies are set for |url|. This function - // is public for unit test purposes only. - static std::string GetCookieSourceFromURL(const GURL& url); static std::string CanonPath(const GURL& url, const ParsedCookie& pc); static base::Time CanonExpiration(const ParsedCookie& pc, const base::Time& current, @@ -150,14 +147,14 @@ class NET_EXPORT CanonicalCookie { private: // The source member of a canonical cookie is the origin of the URL that tried - // to set this cookie, minus the port number if any. This field is not - // persistent though; its only used in the in-tab cookies dialog to show the - // user the source URL. This is used for both allowed and blocked cookies. + // to set this cookie. This field is not persistent though; its only used in + // the in-tab cookies dialog to show the user the source URL. This is used for + // both allowed and blocked cookies. // When a CanonicalCookie is constructed from the backing store (common case) // this field will be null. CanonicalCookie consumers should not rely on // this field unless they guarantee that the creator of those // CanonicalCookies properly initialized the field. - std::string source_; + GURL source_; std::string name_; std::string value_; std::string domain_; diff --git a/chromium/net/cookies/canonical_cookie_unittest.cc b/chromium/net/cookies/canonical_cookie_unittest.cc index fc0d45374cd..9b10d13ff3b 100644 --- a/chromium/net/cookies/canonical_cookie_unittest.cc +++ b/chromium/net/cookies/canonical_cookie_unittest.cc @@ -12,27 +12,6 @@ namespace net { -TEST(CanonicalCookieTest, GetCookieSourceFromURL) { - EXPECT_EQ("http://example.com/", CanonicalCookie::GetCookieSourceFromURL( - GURL("http://example.com"))); - EXPECT_EQ("http://example.com/", CanonicalCookie::GetCookieSourceFromURL( - GURL("http://example.com/"))); - EXPECT_EQ("http://example.com/", CanonicalCookie::GetCookieSourceFromURL( - GURL("http://example.com/test"))); - EXPECT_EQ("file:///tmp/test.html", CanonicalCookie::GetCookieSourceFromURL( - GURL("file:///tmp/test.html"))); - EXPECT_EQ("http://example.com/", CanonicalCookie::GetCookieSourceFromURL( - GURL("http://example.com:1234/"))); - EXPECT_EQ("http://example.com/", CanonicalCookie::GetCookieSourceFromURL( - GURL("https://example.com/"))); - EXPECT_EQ("http://example.com/", CanonicalCookie::GetCookieSourceFromURL( - GURL("http://user:pwd@example.com/"))); - EXPECT_EQ("http://example.com/", CanonicalCookie::GetCookieSourceFromURL( - GURL("http://example.com/test?foo"))); - EXPECT_EQ("http://example.com/", CanonicalCookie::GetCookieSourceFromURL( - GURL("http://example.com/test#foo"))); -} - TEST(CanonicalCookieTest, Constructor) { GURL url("http://www.example.com/test"); base::Time current_time = base::Time::Now(); @@ -40,7 +19,7 @@ TEST(CanonicalCookieTest, Constructor) { CanonicalCookie cookie(url, "A", "2", "www.example.com", "/test", current_time, base::Time(), current_time, false, false, false, COOKIE_PRIORITY_DEFAULT); - EXPECT_EQ(url.GetOrigin().spec(), cookie.Source()); + EXPECT_EQ(url.GetOrigin(), cookie.Source()); EXPECT_EQ("A", cookie.Name()); EXPECT_EQ("2", cookie.Value()); EXPECT_EQ("www.example.com", cookie.Domain()); @@ -52,7 +31,7 @@ TEST(CanonicalCookieTest, Constructor) { CanonicalCookie cookie2(url, "A", "2", std::string(), std::string(), current_time, base::Time(), current_time, false, false, false, COOKIE_PRIORITY_DEFAULT); - EXPECT_EQ(url.GetOrigin().spec(), cookie.Source()); + EXPECT_EQ(url.GetOrigin(), cookie.Source()); EXPECT_EQ("A", cookie2.Name()); EXPECT_EQ("2", cookie2.Value()); EXPECT_EQ("", cookie2.Domain()); @@ -70,7 +49,7 @@ TEST(CanonicalCookieTest, Create) { scoped_ptr<CanonicalCookie> cookie( CanonicalCookie::Create(url, "A=2", creation_time, options)); - EXPECT_EQ(url.GetOrigin().spec(), cookie->Source()); + EXPECT_EQ(url.GetOrigin(), cookie->Source()); EXPECT_EQ("A", cookie->Name()); EXPECT_EQ("2", cookie->Value()); EXPECT_EQ("www.example.com", cookie->Domain()); @@ -79,7 +58,7 @@ TEST(CanonicalCookieTest, Create) { GURL url2("http://www.foo.com"); cookie.reset(CanonicalCookie::Create(url2, "B=1", creation_time, options)); - EXPECT_EQ(url2.GetOrigin().spec(), cookie->Source()); + EXPECT_EQ(url2.GetOrigin(), cookie->Source()); EXPECT_EQ("B", cookie->Name()); EXPECT_EQ("1", cookie->Value()); EXPECT_EQ("www.foo.com", cookie->Domain()); @@ -116,7 +95,7 @@ TEST(CanonicalCookieTest, Create) { cookie.reset(CanonicalCookie::Create( url, "A", "2", "www.example.com", "/test", creation_time, base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT)); - EXPECT_EQ(url.GetOrigin().spec(), cookie->Source()); + EXPECT_EQ(url.GetOrigin(), cookie->Source()); EXPECT_EQ("A", cookie->Name()); EXPECT_EQ("2", cookie->Value()); EXPECT_EQ(".www.example.com", cookie->Domain()); @@ -128,7 +107,7 @@ TEST(CanonicalCookieTest, Create) { cookie.reset(CanonicalCookie::Create( url, "A", "2", ".www.example.com", "/test", creation_time, base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT)); - EXPECT_EQ(url.GetOrigin().spec(), cookie->Source()); + EXPECT_EQ(url.GetOrigin(), cookie->Source()); EXPECT_EQ("A", cookie->Name()); EXPECT_EQ("2", cookie->Value()); EXPECT_EQ(".www.example.com", cookie->Domain()); diff --git a/chromium/net/cookies/cookie_constants.cc b/chromium/net/cookies/cookie_constants.cc index 0afe6ef8580..05fe22ea437 100644 --- a/chromium/net/cookies/cookie_constants.cc +++ b/chromium/net/cookies/cookie_constants.cc @@ -30,8 +30,7 @@ NET_EXPORT const std::string CookiePriorityToString(CookiePriority priority) { } NET_EXPORT CookiePriority StringToCookiePriority(const std::string& priority) { - std::string priority_comp(priority); - base::StringToLowerASCII(&priority_comp); + std::string priority_comp = base::ToLowerASCII(priority); if (priority_comp == kPriorityHigh) return COOKIE_PRIORITY_HIGH; diff --git a/chromium/net/cookies/cookie_monster.cc b/chromium/net/cookies/cookie_monster.cc index b47461636d4..2292f8c25a7 100644 --- a/chromium/net/cookies/cookie_monster.cc +++ b/chromium/net/cookies/cookie_monster.cc @@ -146,7 +146,6 @@ struct OrderByCreationTimeDesc { // Constants for use in VLOG const int kVlogPerCookieMonster = 1; -const int kVlogPeriodic = 3; const int kVlogGarbageCollection = 5; const int kVlogSetCookies = 7; const int kVlogGetCookies = 9; @@ -917,37 +916,6 @@ int CookieMonster::DeleteSessionCookiesTask::RunDeleteTask() { return this->cookie_monster()->DeleteSessionCookies(); } -// Task class for HasCookiesForETLDP1Task call. -class CookieMonster::HasCookiesForETLDP1Task : public CookieMonsterTask { - public: - HasCookiesForETLDP1Task(CookieMonster* cookie_monster, - const std::string& etldp1, - const HasCookiesForETLDP1Callback& callback) - : CookieMonsterTask(cookie_monster), - etldp1_(etldp1), - callback_(callback) {} - - // CookieMonsterTask: - void Run() override; - - protected: - ~HasCookiesForETLDP1Task() override {} - - private: - std::string etldp1_; - HasCookiesForETLDP1Callback callback_; - - DISALLOW_COPY_AND_ASSIGN(HasCookiesForETLDP1Task); -}; - -void CookieMonster::HasCookiesForETLDP1Task::Run() { - bool result = this->cookie_monster()->HasCookiesForETLDP1(etldp1_); - if (!callback_.is_null()) { - this->InvokeCallback(base::Bind(&HasCookiesForETLDP1Callback::Run, - base::Unretained(&callback_), result)); - } -} - // Asynchronous CookieMonster API void CookieMonster::SetCookieWithDetailsAsync( @@ -996,15 +964,6 @@ void CookieMonster::GetAllCookiesForURLAsync( DoCookieTaskForURL(task, url); } -void CookieMonster::HasCookiesForETLDP1Async( - const std::string& etldp1, - const HasCookiesForETLDP1Callback& callback) { - scoped_refptr<HasCookiesForETLDP1Task> task = - new HasCookiesForETLDP1Task(this, etldp1, callback); - - DoCookieTaskForURL(task, GURL("http://" + etldp1)); -} - void CookieMonster::DeleteAllAsync(const DeleteCallback& callback) { scoped_refptr<DeleteAllTask> task = new DeleteAllTask(this, callback); @@ -1345,8 +1304,11 @@ void CookieMonster::SetCookieableSchemes(const char* const schemes[], size_t num_schemes) { base::AutoLock autolock(lock_); - // Cookieable Schemes must be set before first use of function. - DCHECK(!initialized_); + // Calls to this method will have no effect if made after a WebView or + // CookieManager instance has been created. + if (initialized_) { + return; + } cookieable_schemes_.clear(); cookieable_schemes_.insert(cookieable_schemes_.end(), schemes, @@ -1447,15 +1409,6 @@ int CookieMonster::DeleteSessionCookies() { return num_deleted; } -bool CookieMonster::HasCookiesForETLDP1(const std::string& etldp1) { - base::AutoLock autolock(lock_); - - const std::string key(GetKey(etldp1)); - - CookieMapItPair its = cookies_.equal_range(key); - return its.first != its.second; -} - CookieMonster* CookieMonster::GetCookieMonster() { return this; } @@ -1662,8 +1615,6 @@ void CookieMonster::InvokeQueue() { void CookieMonster::EnsureCookiesMapIsValid() { lock_.AssertAcquired(); - int num_duplicates_trimmed = 0; - // Iterate through all the of the cookies, grouped by host. CookieMap::iterator prev_range_end = cookies_.begin(); while (prev_range_end != cookies_.end()) { @@ -1673,18 +1624,13 @@ void CookieMonster::EnsureCookiesMapIsValid() { prev_range_end = cur_range_end; // Ensure no equivalent cookies for this host. - num_duplicates_trimmed += - TrimDuplicateCookiesForKey(key, cur_range_begin, cur_range_end); + TrimDuplicateCookiesForKey(key, cur_range_begin, cur_range_end); } - - // Record how many duplicates were found in the database. - // See InitializeHistograms() for details. - histogram_number_duplicate_db_cookies_->Add(num_duplicates_trimmed); } -int CookieMonster::TrimDuplicateCookiesForKey(const std::string& key, - CookieMap::iterator begin, - CookieMap::iterator end) { +void CookieMonster::TrimDuplicateCookiesForKey(const std::string& key, + CookieMap::iterator begin, + CookieMap::iterator end) { lock_.AssertAcquired(); // Set of cookies ordered by creation time. @@ -1719,7 +1665,7 @@ int CookieMonster::TrimDuplicateCookiesForKey(const std::string& key, // If there were no duplicates, we are done! if (num_duplicates == 0) - return 0; + return; // Make sure we find everything below that we did above. int num_duplicates_found = 0; @@ -1755,8 +1701,6 @@ int CookieMonster::TrimDuplicateCookiesForKey(const std::string& key, } } DCHECK_EQ(num_duplicates, num_duplicates_found); - - return num_duplicates; } // Note: file must be the last scheme. @@ -1882,10 +1826,31 @@ CookieMonster::CookieMap::iterator CookieMonster::InternalInsertCookie( } // See InitializeHistograms() for details. - int32_t sample = cc->IsFirstPartyOnly() ? 1 << COOKIE_TYPE_FIRSTPARTYONLY : 0; - sample |= cc->IsHttpOnly() ? 1 << COOKIE_TYPE_HTTPONLY : 0; - sample |= cc->IsSecure() ? 1 << COOKIE_TYPE_SECURE : 0; - histogram_cookie_type_->Add(sample); + int32_t cookie_type_sample = + cc->IsFirstPartyOnly() ? 1 << COOKIE_TYPE_FIRSTPARTYONLY : 0; + cookie_type_sample |= cc->IsHttpOnly() ? 1 << COOKIE_TYPE_HTTPONLY : 0; + cookie_type_sample |= cc->IsSecure() ? 1 << COOKIE_TYPE_SECURE : 0; + histogram_cookie_type_->Add(cookie_type_sample); + + // Histogram the type of scheme used on URLs that set cookies. This + // intentionally includes cookies that are set or overwritten by + // http:// URLs, but not cookies that are cleared by http:// URLs, to + // understand if the former behavior can be deprecated for Secure + // cookies. + if (!cc->Source().is_empty()) { + CookieSource cookie_source_sample; + if (cc->Source().SchemeIsCryptographic()) { + cookie_source_sample = + cc->IsSecure() ? COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME + : COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME; + } else { + cookie_source_sample = + cc->IsSecure() + ? COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME + : COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME; + } + histogram_cookie_source_scheme_->Add(cookie_source_sample); + } RunCallbacks(*cc, false); @@ -1985,10 +1950,6 @@ void CookieMonster::InternalUpdateCookieAccessTime(CanonicalCookie* cc, if ((current - cc->LastAccessDate()) < last_access_threshold_) return; - // See InitializeHistograms() for details. - histogram_between_access_interval_minutes_->Add( - (current - cc->LastAccessDate()).InMinutes()); - cc->SetLastAccessDate(current); if ((cc->IsPersistent() || persist_session_cookies_) && store_.get()) store_->UpdateCookieAccessTime(*cc); @@ -2255,36 +2216,6 @@ void CookieMonster::RecordPeriodicStats(const base::Time& current_time) { histogram_count_->Add(cookies_.size()); // More detailed statistics on cookie counts at different granularities. - TimeTicks beginning_of_time(TimeTicks::Now()); - - for (CookieMap::const_iterator it_key = cookies_.begin(); - it_key != cookies_.end();) { - const std::string& key(it_key->first); - - int key_count = 0; - typedef std::map<std::string, unsigned int> DomainMap; - DomainMap domain_map; - CookieMapItPair its_cookies = cookies_.equal_range(key); - while (its_cookies.first != its_cookies.second) { - key_count++; - const std::string& cookie_domain(its_cookies.first->second->Domain()); - domain_map[cookie_domain]++; - - its_cookies.first++; - } - histogram_etldp1_count_->Add(key_count); - histogram_domain_per_etldp1_count_->Add(domain_map.size()); - for (DomainMap::const_iterator domain_map_it = domain_map.begin(); - domain_map_it != domain_map.end(); domain_map_it++) - histogram_domain_count_->Add(domain_map_it->second); - - it_key = its_cookies.second; - } - - VLOG(kVlogPeriodic) << "Time for recording cookie stats (us): " - << (TimeTicks::Now() - beginning_of_time) - .InMicroseconds(); - last_statistic_record_time_ = current_time; } @@ -2316,28 +2247,11 @@ void CookieMonster::InitializeHistograms() { histogram_expiration_duration_minutes_ = base::Histogram::FactoryGet( "Cookie.ExpirationDurationMinutes", 1, kMinutesInTenYears, 50, base::Histogram::kUmaTargetedHistogramFlag); - histogram_between_access_interval_minutes_ = base::Histogram::FactoryGet( - "Cookie.BetweenAccessIntervalMinutes", 1, kMinutesInTenYears, 50, - base::Histogram::kUmaTargetedHistogramFlag); histogram_evicted_last_access_minutes_ = base::Histogram::FactoryGet( "Cookie.EvictedLastAccessMinutes", 1, kMinutesInTenYears, 50, base::Histogram::kUmaTargetedHistogramFlag); histogram_count_ = base::Histogram::FactoryGet( "Cookie.Count", 1, 4000, 50, base::Histogram::kUmaTargetedHistogramFlag); - histogram_domain_count_ = - base::Histogram::FactoryGet("Cookie.DomainCount", 1, 4000, 50, - base::Histogram::kUmaTargetedHistogramFlag); - histogram_etldp1_count_ = - base::Histogram::FactoryGet("Cookie.Etldp1Count", 1, 4000, 50, - base::Histogram::kUmaTargetedHistogramFlag); - histogram_domain_per_etldp1_count_ = - base::Histogram::FactoryGet("Cookie.DomainPerEtldp1Count", 1, 4000, 50, - base::Histogram::kUmaTargetedHistogramFlag); - - // From UMA_HISTOGRAM_COUNTS_10000 & UMA_HISTOGRAM_CUSTOM_COUNTS - histogram_number_duplicate_db_cookies_ = - base::Histogram::FactoryGet("Net.NumDuplicateCookiesInDb", 1, 10000, 50, - base::Histogram::kUmaTargetedHistogramFlag); // From UMA_HISTOGRAM_ENUMERATION histogram_cookie_deletion_cause_ = base::LinearHistogram::FactoryGet( @@ -2346,6 +2260,9 @@ void CookieMonster::InitializeHistograms() { histogram_cookie_type_ = base::LinearHistogram::FactoryGet( "Cookie.Type", 1, (1 << COOKIE_TYPE_LAST_ENTRY) - 1, 1 << COOKIE_TYPE_LAST_ENTRY, base::Histogram::kUmaTargetedHistogramFlag); + histogram_cookie_source_scheme_ = base::LinearHistogram::FactoryGet( + "Cookie.CookieSourceScheme", 1, COOKIE_SOURCE_LAST_ENTRY - 1, + COOKIE_SOURCE_LAST_ENTRY, base::Histogram::kUmaTargetedHistogramFlag); // From UMA_HISTOGRAM_{CUSTOM_,}TIMES histogram_time_blocked_on_load_ = base::Histogram::FactoryTimeGet( diff --git a/chromium/net/cookies/cookie_monster.h b/chromium/net/cookies/cookie_monster.h index db6e90561f1..ced1c235f7f 100644 --- a/chromium/net/cookies/cookie_monster.h +++ b/chromium/net/cookies/cookie_monster.h @@ -152,7 +152,6 @@ class NET_EXPORT CookieMonster : public CookieStore { typedef base::Callback<void(const CookieList& cookies)> GetCookieListCallback; typedef base::Callback<void(bool success)> DeleteCookieCallback; - typedef base::Callback<void(bool cookies_exist)> HasCookiesForETLDP1Callback; // Sets a cookie given explicit user-provided cookie attributes. The cookie // name, value, domain, etc. are each provided as separate strings. This @@ -201,13 +200,9 @@ class NET_EXPORT CookieMonster : public CookieStore { void DeleteCanonicalCookieAsync(const CanonicalCookie& cookie, const DeleteCookieCallback& callback); - // Checks whether for a given ETLD+1, there currently exist any cookies. - void HasCookiesForETLDP1Async(const std::string& etldp1, - const HasCookiesForETLDP1Callback& callback); - - // Resets the list of cookieable schemes to the supplied schemes. - // If this this method is called, it must be called before first use of - // the instance (i.e. as part of the instance initialization process). + // Resets the list of cookieable schemes to the supplied schemes. Does + // nothing if called after first use of the instance (i.e. after the + // instance initialization process). void SetCookieableSchemes(const char* const schemes[], size_t num_schemes); // Instructs the cookie monster to not delete expired cookies. This is used @@ -338,7 +333,6 @@ class NET_EXPORT CookieMonster : public CookieStore { class SetCookieWithDetailsTask; class SetCookieWithOptionsTask; class DeleteSessionCookiesTask; - class HasCookiesForETLDP1Task; // Testing support. // For SetCookieWithCreationTime. @@ -366,6 +360,9 @@ class NET_EXPORT CookieMonster : public CookieStore { // For ComputeCookieDiff. FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, ComputeCookieDiff); + // For CookieSource histogram enum. + FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, CookieSourceHistogram); + // Internal reasons for deletion, used to populate informative histograms // and to provide a public cause for onCookieChange notifications. // @@ -416,6 +413,26 @@ class NET_EXPORT CookieMonster : public CookieStore { COOKIE_TYPE_LAST_ENTRY }; + // Used to populate a histogram containing information about the + // sources of Secure and non-Secure cookies: that is, whether such + // cookies are set by origins with cryptographic or non-cryptographic + // schemes. Please do not reorder the list when adding new + // entries. New items MUST be added at the end of the list, just + // before COOKIE_SOURCE_LAST_ENTRY. + // + // COOKIE_SOURCE_(NON)SECURE_COOKIE_(NON)CRYPTOGRAPHIC_SCHEME means + // that a cookie was set or overwritten from a URL with the given type + // of scheme. This enum should not be used when cookies are *cleared*, + // because its purpose is to understand if Chrome can deprecate the + // ability of HTTP urls to set/overwrite Secure cookies. + enum CookieSource { + COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME = 0, + COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, + COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, + COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, + COOKIE_SOURCE_LAST_ENTRY + }; + // The strategy for fetching cookies. Controlled by Finch experiment. enum FetchStrategy { // Fetches all cookies only when they're needed. @@ -484,8 +501,6 @@ class NET_EXPORT CookieMonster : public CookieStore { int DeleteSessionCookies(); - bool HasCookiesForETLDP1(const std::string& etldp1); - // The first access to the cookie store initializes it. This method should be // called before any access to the cookie store. void MarkCookieStoreAsInitialized(); @@ -529,10 +544,9 @@ class NET_EXPORT CookieMonster : public CookieStore { // Checks for any duplicate cookies for CookieMap key |key| which lie between // |begin| and |end|. If any are found, all but the most recent are deleted. - // Returns the number of duplicate cookies that were deleted. - int TrimDuplicateCookiesForKey(const std::string& key, - CookieMap::iterator begin, - CookieMap::iterator end); + void TrimDuplicateCookiesForKey(const std::string& key, + CookieMap::iterator begin, + CookieMap::iterator end); void SetDefaultCookieableSchemes(); @@ -663,16 +677,11 @@ class NET_EXPORT CookieMonster : public CookieStore { // Histogram variables; see CookieMonster::InitializeHistograms() in // cookie_monster.cc for details. base::HistogramBase* histogram_expiration_duration_minutes_; - base::HistogramBase* histogram_between_access_interval_minutes_; base::HistogramBase* histogram_evicted_last_access_minutes_; base::HistogramBase* histogram_count_; - base::HistogramBase* histogram_domain_count_; - base::HistogramBase* histogram_etldp1_count_; - base::HistogramBase* histogram_domain_per_etldp1_count_; - base::HistogramBase* histogram_number_duplicate_db_cookies_; base::HistogramBase* histogram_cookie_deletion_cause_; base::HistogramBase* histogram_cookie_type_; - base::HistogramBase* histogram_time_mac_; + base::HistogramBase* histogram_cookie_source_scheme_; base::HistogramBase* histogram_time_blocked_on_load_; CookieMap cookies_; diff --git a/chromium/net/cookies/cookie_monster_unittest.cc b/chromium/net/cookies/cookie_monster_unittest.cc index 6f3c0b616fb..c4df76558d7 100644 --- a/chromium/net/cookies/cookie_monster_unittest.cc +++ b/chromium/net/cookies/cookie_monster_unittest.cc @@ -13,7 +13,6 @@ #include "base/location.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" -#include "base/memory/scoped_vector.h" #include "base/message_loop/message_loop.h" #include "base/metrics/histogram.h" #include "base/metrics/histogram_samples.h" @@ -23,6 +22,7 @@ #include "base/strings/string_split.h" #include "base/strings/string_tokenizer.h" #include "base/strings/stringprintf.h" +#include "base/test/histogram_tester.h" #include "base/thread_task_runner_handle.h" #include "base/threading/thread.h" #include "base/time/time.h" @@ -97,7 +97,7 @@ struct CookieMonsterTestTraits { static const bool is_cookie_monster = true; static const bool supports_http_only = true; static const bool supports_non_dotted_domains = true; - static const bool supports_trailing_dots = true; + static const bool preserves_trailing_dots = true; static const bool filters_schemes = true; static const bool has_path_prefix_bug = false; static const int creation_time_granularity_in_ms = 0; @@ -778,7 +778,7 @@ class DeferredCookieTaskTest : public CookieMonsterTest { // Declares an expectation that PersistentCookieStore::LoadCookiesForKey // will be called, saving the provided callback and sending a quit to the // message loop. - void ExpectLoadForKeyCall(std::string key, bool quit_queue) { + void ExpectLoadForKeyCall(const std::string& key, bool quit_queue) { if (quit_queue) EXPECT_CALL(*persistent_store_.get(), LoadCookiesForKey(key, testing::_)) .WillOnce( @@ -1355,6 +1355,33 @@ TEST_F(CookieMonsterTest, GetAllCookiesForURLPathMatching) { ASSERT_TRUE(++it == cookies.end()); } +TEST_F(CookieMonsterTest, CookieSorting) { + scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); + + EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B1; path=/")); + EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B2; path=/foo")); + EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B3; path=/foo/bar")); + EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=A1; path=/")); + EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=A2; path=/foo")); + EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=A3; path=/foo/bar")); + + // Re-set cookie which should not change sort order. + EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B3; path=/foo/bar")); + + CookieList cookies = GetAllCookies(cm.get()); + ASSERT_EQ(6u, cookies.size()); + // According to RFC 6265 5.3 (11) re-setting this cookie should retain the + // initial creation-time from above, and the sort order should not change. + // Chrome's current implementation deviates from the spec so capturing this to + // avoid any inadvertent changes to this behavior. + EXPECT_EQ("A3", cookies[0].Value()); + EXPECT_EQ("B3", cookies[1].Value()); + EXPECT_EQ("B2", cookies[2].Value()); + EXPECT_EQ("A2", cookies[3].Value()); + EXPECT_EQ("B1", cookies[4].Value()); + EXPECT_EQ("A1", cookies[5].Value()); +} + TEST_F(CookieMonsterTest, DeleteCookieByName) { scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); @@ -1752,29 +1779,30 @@ TEST_F(CookieMonsterTest, UniqueCreationTime) { // SetCookie, SetCookieWithOptions, SetCookieWithDetails - SetCookie(cm.get(), url_google_, "SetCookie1=A"); - SetCookie(cm.get(), url_google_, "SetCookie2=A"); - SetCookie(cm.get(), url_google_, "SetCookie3=A"); - - SetCookieWithOptions(cm.get(), url_google_, "setCookieWithOptions1=A", - options); - SetCookieWithOptions(cm.get(), url_google_, "setCookieWithOptions2=A", - options); - SetCookieWithOptions(cm.get(), url_google_, "setCookieWithOptions3=A", - options); - - SetCookieWithDetails(cm.get(), url_google_, "setCookieWithDetails1", "A", - ".google.com", "/", Time(), false, false, false, - COOKIE_PRIORITY_DEFAULT); - SetCookieWithDetails(cm.get(), url_google_, "setCookieWithDetails2", "A", - ".google.com", "/", Time(), false, false, false, - COOKIE_PRIORITY_DEFAULT); - SetCookieWithDetails(cm.get(), url_google_, "setCookieWithDetails3", "A", - ".google.com", "/", Time(), false, false, false, - COOKIE_PRIORITY_DEFAULT); + EXPECT_TRUE(SetCookie(cm.get(), url_google_, "SetCookie1=A")); + EXPECT_TRUE(SetCookie(cm.get(), url_google_, "SetCookie2=A")); + EXPECT_TRUE(SetCookie(cm.get(), url_google_, "SetCookie3=A")); + + EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, + "setCookieWithOptions1=A", options)); + EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, + "setCookieWithOptions2=A", options)); + EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, + "setCookieWithOptions3=A", options)); + + EXPECT_TRUE(SetCookieWithDetails( + cm.get(), url_google_, "setCookieWithDetails1", "A", ".google.izzle", "/", + Time(), false, false, false, COOKIE_PRIORITY_DEFAULT)); + EXPECT_TRUE(SetCookieWithDetails( + cm.get(), url_google_, "setCookieWithDetails2", "A", ".google.izzle", "/", + Time(), false, false, false, COOKIE_PRIORITY_DEFAULT)); + EXPECT_TRUE(SetCookieWithDetails( + cm.get(), url_google_, "setCookieWithDetails3", "A", ".google.izzle", "/", + Time(), false, false, false, COOKIE_PRIORITY_DEFAULT)); // Now we check CookieList cookie_list(GetAllCookies(cm.get())); + EXPECT_EQ(9u, cookie_list.size()); typedef std::map<int64, CanonicalCookie> TimeCookieMap; TimeCookieMap check_map; for (CookieList::const_iterator it = cookie_list.begin(); @@ -2811,6 +2839,68 @@ TEST_F(CookieMonsterTest, ControlCharacterPurge) { EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url)); } +// Test that cookie source schemes are histogrammed correctly. +TEST_F(CookieMonsterTest, CookieSourceHistogram) { + base::HistogramTester histograms; + const std::string cookie_source_histogram = "Cookie.CookieSourceScheme"; + + scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); + scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); + + histograms.ExpectTotalCount(cookie_source_histogram, 0); + + // Set a Secure cookie on a cryptographic scheme. + EXPECT_TRUE(SetCookie(cm.get(), url_google_secure_, "A=B; path=/; Secure")); + histograms.ExpectTotalCount(cookie_source_histogram, 1); + histograms.ExpectBucketCount( + cookie_source_histogram, + CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); + + // Set a non-Secure cookie on a cryptographic scheme. + EXPECT_TRUE(SetCookie(cm.get(), url_google_secure_, "C=D; path=/;")); + histograms.ExpectTotalCount(cookie_source_histogram, 2); + histograms.ExpectBucketCount( + cookie_source_histogram, + CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); + + // Set a Secure cookie on a non-cryptographic scheme. + EXPECT_TRUE(SetCookie(cm.get(), url_google_, "D=E; path=/; Secure")); + histograms.ExpectTotalCount(cookie_source_histogram, 3); + histograms.ExpectBucketCount( + cookie_source_histogram, + CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 1); + + // Overwrite a Secure cookie (set by a cryptographic scheme) on a + // non-cryptographic scheme. + EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B; path=/; Secure")); + histograms.ExpectTotalCount(cookie_source_histogram, 4); + histograms.ExpectBucketCount( + cookie_source_histogram, + CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME, 1); + histograms.ExpectBucketCount( + cookie_source_histogram, + CookieMonster::COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 2); + + // Test that clearing a Secure cookie on a http:// URL does not get + // counted. + EXPECT_TRUE(SetCookie(cm.get(), url_google_secure_, "F=G; path=/; Secure")); + histograms.ExpectTotalCount(cookie_source_histogram, 5); + std::string cookies1 = GetCookies(cm.get(), url_google_secure_); + EXPECT_NE(std::string::npos, cookies1.find("F=G")); + EXPECT_TRUE(SetCookie(cm.get(), url_google_, + "F=G; path=/; Expires=Thu, 01-Jan-1970 00:00:01 GMT")); + std::string cookies2 = GetCookies(cm.get(), url_google_secure_); + EXPECT_EQ(std::string::npos, cookies2.find("F=G")); + histograms.ExpectTotalCount(cookie_source_histogram, 5); + + // Set a non-Secure cookie on a non-cryptographic scheme. + EXPECT_TRUE(SetCookie(cm.get(), url_google_, "H=I; path=/")); + histograms.ExpectTotalCount(cookie_source_histogram, 6); + histograms.ExpectBucketCount( + cookie_source_histogram, + CookieMonster::COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME, 1); +} + class CookieMonsterNotificationTest : public CookieMonsterTest { public: CookieMonsterNotificationTest() diff --git a/chromium/net/cookies/cookie_options.cc b/chromium/net/cookies/cookie_options.cc new file mode 100644 index 00000000000..5cacb6bb77d --- /dev/null +++ b/chromium/net/cookies/cookie_options.cc @@ -0,0 +1,16 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Brought to you by number 42. + +#include "net/cookies/cookie_options.h" + +namespace net { + +CookieOptions::CookieOptions() + : exclude_httponly_(true), + include_first_party_only_(false), + server_time_() {} + +} // namespace net diff --git a/chromium/net/cookies/cookie_options.h b/chromium/net/cookies/cookie_options.h index a7ed5a9aac6..d3d7fd056b7 100644 --- a/chromium/net/cookies/cookie_options.h +++ b/chromium/net/cookies/cookie_options.h @@ -7,11 +7,13 @@ #ifndef NET_COOKIES_COOKIE_OPTIONS_H_ #define NET_COOKIES_COOKIE_OPTIONS_H_ +#include "base/time/time.h" +#include "net/base/net_export.h" #include "url/gurl.h" namespace net { -class CookieOptions { +class NET_EXPORT CookieOptions { public: // Default is to exclude httponly completely, and exclude first-party from // being read, which means: @@ -21,10 +23,7 @@ class CookieOptions { // // If a first-party URL is set, then first-party cookies which match that URL // will be returned. - CookieOptions() - : exclude_httponly_(true), - include_first_party_only_(false), - server_time_() {} + CookieOptions(); void set_exclude_httponly() { exclude_httponly_ = true; } void set_include_httponly() { exclude_httponly_ = false; } diff --git a/chromium/net/cookies/cookie_store_unittest.h b/chromium/net/cookies/cookie_store_unittest.h index 763b6bf730b..ee135242f89 100644 --- a/chromium/net/cookies/cookie_store_unittest.h +++ b/chromium/net/cookies/cookie_store_unittest.h @@ -18,6 +18,10 @@ #include "testing/gtest/include/gtest/gtest.h" #include "url/gurl.h" +#if defined(OS_IOS) +#include "base/ios/ios_util.h" +#endif + // This file declares unittest templates that can be used to test common // behavior of any CookieStore implementation. // See cookie_monster_unittest.cc for an example of an implementation. @@ -54,9 +58,9 @@ const char kValidDomainCookieLine[] = "A=B; path=/; domain=google.izzle"; // // and the "com" domains. // static const bool supports_non_dotted_domains; // -// // The cookie store handles the domains with trailing dots (such as "com.") -// // correctly. -// static const bool supports_trailing_dots; +// // The cookie store does not fold domains with trailing dots (so "com." and +// "com" are different domains). +// static const bool preserves_trailing_dots; // // // The cookie store rejects cookies for invalid schemes such as ftp. // static const bool filters_schemes; @@ -506,16 +510,12 @@ TYPED_TEST_P(CookieStoreTest, TestNonDottedAndTLD) { // http://com. should be treated the same as http://com. scoped_refptr<CookieStore> cs(this->GetCookieStore()); GURL url("http://com./index.html"); - if (TypeParam::supports_trailing_dots) { - EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1")); - this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url)); - this->MatchCookieLines( - std::string(), - this->GetCookies(cs.get(), - GURL("http://hopefully-no-cookies.com./"))); - } else { - EXPECT_FALSE(this->SetCookie(cs.get(), url, "a=1")); - } + EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1")); + this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url)); + this->MatchCookieLines( + std::string(), + this->GetCookies(cs.get(), + GURL("http://hopefully-no-cookies.com./"))); } { // Should not be able to set host cookie from a subdomain. @@ -567,18 +567,21 @@ TYPED_TEST_P(CookieStoreTest, TestHostEndsWithDot) { EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1")); this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url)); - if (TypeParam::supports_trailing_dots) { - // Do not share cookie space with the dot version of domain. - // Note: this is not what FireFox does, but it _is_ what IE+Safari do. + // Do not share cookie space with the dot version of domain. + // Note: this is not what FireFox does, but it _is_ what IE+Safari do. + if (TypeParam::preserves_trailing_dots) { EXPECT_FALSE( this->SetCookie(cs.get(), url, "b=2; domain=.www.google.com.")); this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url)); - EXPECT_TRUE( this->SetCookie(cs.get(), url_with_dot, "b=2; domain=.google.com.")); this->MatchCookieLines("b=2", this->GetCookies(cs.get(), url_with_dot)); } else { - EXPECT_TRUE(this->SetCookie(cs.get(), url, "b=2; domain=.www.google.com.")); + EXPECT_TRUE( + this->SetCookie(cs.get(), url, "b=2; domain=.www.google.com.")); + this->MatchCookieLines("a=1 b=2", this->GetCookies(cs.get(), url)); + // Setting this cookie should fail, since the trailing dot on the domain + // isn't preserved, and then the domain mismatches the URL. EXPECT_FALSE( this->SetCookie(cs.get(), url_with_dot, "b=2; domain=.google.com.")); } diff --git a/chromium/net/cookies/cookie_util.cc b/chromium/net/cookies/cookie_util.cc index 2723363e2fb..b9c7e8d601f 100644 --- a/chromium/net/cookies/cookie_util.cc +++ b/chromium/net/cookies/cookie_util.cc @@ -125,7 +125,8 @@ base::Time ParseCookieTime(const std::string& time_string) { if (!found_month) { for (int i = 0; i < kMonthsLen; ++i) { // Match prefix, so we could match January, etc - if (base::strncasecmp(token.c_str(), kMonths[i], 3) == 0) { + if (base::StartsWith(token, base::StringPiece(kMonths[i], 3), + base::CompareCase::INSENSITIVE_ASCII)) { exploded.month = i + 1; found_month = true; break; diff --git a/chromium/net/cookies/parsed_cookie.cc b/chromium/net/cookies/parsed_cookie.cc index 3f281a6ddab..bd8b0dc2270 100644 --- a/chromium/net/cookies/parsed_cookie.cc +++ b/chromium/net/cookies/parsed_cookie.cc @@ -398,7 +398,7 @@ void ParsedCookie::ParseTokenValuePairs(const std::string& cookie_line) { // From RFC2109: "Attributes (names) (attr) are case-insensitive." if (pair_num != 0) - base::StringToLowerASCII(&pair.first); + pair.first = base::ToLowerASCII(pair.first); // Ignore Set-Cookie directives contaning control characters. See // http://crbug.com/238041. if (!IsValidCookieAttributeValue(pair.first) || |