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

Side by Side Diff: net/cookies/cookie_monster.cc

Issue 1615773005: Rename first-party-only cookies to same-site cookies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tests. Created 4 years, 11 months 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 unified diff | Download patch
« no previous file with comments | « net/cookies/cookie_monster.h ('k') | net/cookies/cookie_monster_store_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Portions of this code based on Mozilla: 5 // Portions of this code based on Mozilla:
6 // (netwerk/cookie/src/nsCookieService.cpp) 6 // (netwerk/cookie/src/nsCookieService.cpp)
7 /* ***** BEGIN LICENSE BLOCK ***** 7 /* ***** BEGIN LICENSE BLOCK *****
8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
9 * 9 *
10 * The contents of this file are subject to the Mozilla Public License Version 10 * The contents of this file are subject to the Mozilla Public License Version
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 bool CookieMonster::ImportCookies(const CookieList& list) { 381 bool CookieMonster::ImportCookies(const CookieList& list) {
382 base::AutoLock autolock(lock_); 382 base::AutoLock autolock(lock_);
383 MarkCookieStoreAsInitialized(); 383 MarkCookieStoreAsInitialized();
384 if (ShouldFetchAllCookiesWhenFetchingAnyCookie()) 384 if (ShouldFetchAllCookiesWhenFetchingAnyCookie())
385 FetchAllCookiesIfNecessary(); 385 FetchAllCookiesIfNecessary();
386 for (CookieList::const_iterator iter = list.begin(); iter != list.end(); 386 for (CookieList::const_iterator iter = list.begin(); iter != list.end();
387 ++iter) { 387 ++iter) {
388 scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie(*iter)); 388 scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie(*iter));
389 CookieOptions options; 389 CookieOptions options;
390 options.set_include_httponly(); 390 options.set_include_httponly();
391 options.set_include_first_party_only_cookies(); 391 options.set_include_same_site();
392 if (!SetCanonicalCookie(&cookie, cookie->CreationDate(), options)) 392 if (!SetCanonicalCookie(&cookie, cookie->CreationDate(), options))
393 return false; 393 return false;
394 } 394 }
395 return true; 395 return true;
396 } 396 }
397 397
398 // Task classes for queueing the coming request. 398 // Task classes for queueing the coming request.
399 399
400 class CookieMonster::CookieMonsterTask 400 class CookieMonster::CookieMonsterTask
401 : public base::RefCountedThreadSafe<CookieMonsterTask> { 401 : public base::RefCountedThreadSafe<CookieMonsterTask> {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 public: 458 public:
459 SetCookieWithDetailsTask(CookieMonster* cookie_monster, 459 SetCookieWithDetailsTask(CookieMonster* cookie_monster,
460 const GURL& url, 460 const GURL& url,
461 const std::string& name, 461 const std::string& name,
462 const std::string& value, 462 const std::string& value,
463 const std::string& domain, 463 const std::string& domain,
464 const std::string& path, 464 const std::string& path,
465 const base::Time& expiration_time, 465 const base::Time& expiration_time,
466 bool secure, 466 bool secure,
467 bool http_only, 467 bool http_only,
468 bool first_party_only, 468 bool same_site,
469 bool enforce_prefixes, 469 bool enforce_prefixes,
470 bool enforce_strict_secure, 470 bool enforce_strict_secure,
471 CookiePriority priority, 471 CookiePriority priority,
472 const SetCookiesCallback& callback) 472 const SetCookiesCallback& callback)
473 : CookieMonsterTask(cookie_monster), 473 : CookieMonsterTask(cookie_monster),
474 url_(url), 474 url_(url),
475 name_(name), 475 name_(name),
476 value_(value), 476 value_(value),
477 domain_(domain), 477 domain_(domain),
478 path_(path), 478 path_(path),
479 expiration_time_(expiration_time), 479 expiration_time_(expiration_time),
480 secure_(secure), 480 secure_(secure),
481 http_only_(http_only), 481 http_only_(http_only),
482 first_party_only_(first_party_only), 482 same_site_(same_site),
483 enforce_prefixes_(enforce_prefixes), 483 enforce_prefixes_(enforce_prefixes),
484 enforce_strict_secure_(enforce_strict_secure), 484 enforce_strict_secure_(enforce_strict_secure),
485 priority_(priority), 485 priority_(priority),
486 callback_(callback) {} 486 callback_(callback) {}
487 487
488 // CookieMonsterTask: 488 // CookieMonsterTask:
489 void Run() override; 489 void Run() override;
490 490
491 protected: 491 protected:
492 ~SetCookieWithDetailsTask() override {} 492 ~SetCookieWithDetailsTask() override {}
493 493
494 private: 494 private:
495 GURL url_; 495 GURL url_;
496 std::string name_; 496 std::string name_;
497 std::string value_; 497 std::string value_;
498 std::string domain_; 498 std::string domain_;
499 std::string path_; 499 std::string path_;
500 base::Time expiration_time_; 500 base::Time expiration_time_;
501 bool secure_; 501 bool secure_;
502 bool http_only_; 502 bool http_only_;
503 bool first_party_only_; 503 bool same_site_;
504 bool enforce_prefixes_; 504 bool enforce_prefixes_;
505 bool enforce_strict_secure_; 505 bool enforce_strict_secure_;
506 CookiePriority priority_; 506 CookiePriority priority_;
507 SetCookiesCallback callback_; 507 SetCookiesCallback callback_;
508 508
509 DISALLOW_COPY_AND_ASSIGN(SetCookieWithDetailsTask); 509 DISALLOW_COPY_AND_ASSIGN(SetCookieWithDetailsTask);
510 }; 510 };
511 511
512 void CookieMonster::SetCookieWithDetailsTask::Run() { 512 void CookieMonster::SetCookieWithDetailsTask::Run() {
513 bool success = this->cookie_monster()->SetCookieWithDetails( 513 bool success = this->cookie_monster()->SetCookieWithDetails(
514 url_, name_, value_, domain_, path_, expiration_time_, secure_, 514 url_, name_, value_, domain_, path_, expiration_time_, secure_,
515 http_only_, first_party_only_, enforce_prefixes_, enforce_strict_secure_, 515 http_only_, same_site_, enforce_prefixes_, enforce_strict_secure_,
516 priority_); 516 priority_);
517 if (!callback_.is_null()) { 517 if (!callback_.is_null()) {
518 this->InvokeCallback(base::Bind(&SetCookiesCallback::Run, 518 this->InvokeCallback(base::Bind(&SetCookiesCallback::Run,
519 base::Unretained(&callback_), success)); 519 base::Unretained(&callback_), success));
520 } 520 }
521 } 521 }
522 522
523 // Task class for GetAllCookies call. 523 // Task class for GetAllCookies call.
524 class CookieMonster::GetAllCookiesTask : public CookieMonsterTask { 524 class CookieMonster::GetAllCookiesTask : public CookieMonsterTask {
525 public: 525 public:
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 954
955 void CookieMonster::SetCookieWithDetailsAsync( 955 void CookieMonster::SetCookieWithDetailsAsync(
956 const GURL& url, 956 const GURL& url,
957 const std::string& name, 957 const std::string& name,
958 const std::string& value, 958 const std::string& value,
959 const std::string& domain, 959 const std::string& domain,
960 const std::string& path, 960 const std::string& path,
961 const Time& expiration_time, 961 const Time& expiration_time,
962 bool secure, 962 bool secure,
963 bool http_only, 963 bool http_only,
964 bool first_party_only, 964 bool same_site,
965 bool enforce_prefixes, 965 bool enforce_prefixes,
966 bool enforce_strict_secure, 966 bool enforce_strict_secure,
967 CookiePriority priority, 967 CookiePriority priority,
968 const SetCookiesCallback& callback) { 968 const SetCookiesCallback& callback) {
969 scoped_refptr<SetCookieWithDetailsTask> task = new SetCookieWithDetailsTask( 969 scoped_refptr<SetCookieWithDetailsTask> task = new SetCookieWithDetailsTask(
970 this, url, name, value, domain, path, expiration_time, secure, http_only, 970 this, url, name, value, domain, path, expiration_time, secure, http_only,
971 first_party_only, enforce_prefixes, enforce_strict_secure, priority, 971 same_site, enforce_prefixes, enforce_strict_secure, priority, callback);
972 callback);
973 DoCookieTaskForURL(task, url); 972 DoCookieTaskForURL(task, url);
974 } 973 }
975 974
976 void CookieMonster::GetAllCookiesForURLWithOptionsAsync( 975 void CookieMonster::GetAllCookiesForURLWithOptionsAsync(
977 const GURL& url, 976 const GURL& url,
978 const CookieOptions& options, 977 const CookieOptions& options,
979 const GetCookieListCallback& callback) { 978 const GetCookieListCallback& callback) {
980 scoped_refptr<GetAllCookiesForURLWithOptionsTask> task = 979 scoped_refptr<GetAllCookiesForURLWithOptionsTask> task =
981 new GetAllCookiesForURLWithOptionsTask(this, url, options, callback); 980 new GetAllCookiesForURLWithOptionsTask(this, url, options, callback);
982 981
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 new GetCookiesWithOptionsTask(this, url, options, callback); 1039 new GetCookiesWithOptionsTask(this, url, options, callback);
1041 1040
1042 DoCookieTaskForURL(task, url); 1041 DoCookieTaskForURL(task, url);
1043 } 1042 }
1044 1043
1045 void CookieMonster::GetAllCookiesForURLAsync( 1044 void CookieMonster::GetAllCookiesForURLAsync(
1046 const GURL& url, 1045 const GURL& url,
1047 const GetCookieListCallback& callback) { 1046 const GetCookieListCallback& callback) {
1048 CookieOptions options; 1047 CookieOptions options;
1049 options.set_include_httponly(); 1048 options.set_include_httponly();
1050 options.set_include_first_party_only_cookies(); 1049 options.set_include_same_site();
1051 scoped_refptr<GetAllCookiesForURLWithOptionsTask> task = 1050 scoped_refptr<GetAllCookiesForURLWithOptionsTask> task =
1052 new GetAllCookiesForURLWithOptionsTask(this, url, options, callback); 1051 new GetAllCookiesForURLWithOptionsTask(this, url, options, callback);
1053 1052
1054 DoCookieTaskForURL(task, url); 1053 DoCookieTaskForURL(task, url);
1055 } 1054 }
1056 1055
1057 void CookieMonster::GetAllCookiesAsync(const GetCookieListCallback& callback) { 1056 void CookieMonster::GetAllCookiesAsync(const GetCookieListCallback& callback) {
1058 scoped_refptr<GetAllCookiesTask> task = new GetAllCookiesTask(this, callback); 1057 scoped_refptr<GetAllCookiesTask> task = new GetAllCookiesTask(this, callback);
1059 1058
1060 DoCookieTask(task); 1059 DoCookieTask(task);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 } 1183 }
1185 1184
1186 bool CookieMonster::SetCookieWithDetails(const GURL& url, 1185 bool CookieMonster::SetCookieWithDetails(const GURL& url,
1187 const std::string& name, 1186 const std::string& name,
1188 const std::string& value, 1187 const std::string& value,
1189 const std::string& domain, 1188 const std::string& domain,
1190 const std::string& path, 1189 const std::string& path,
1191 const base::Time& expiration_time, 1190 const base::Time& expiration_time,
1192 bool secure, 1191 bool secure,
1193 bool http_only, 1192 bool http_only,
1194 bool first_party_only, 1193 bool same_site,
1195 bool enforce_prefixes, 1194 bool enforce_prefixes,
1196 bool enforce_strict_secure, 1195 bool enforce_strict_secure,
1197 CookiePriority priority) { 1196 CookiePriority priority) {
1198 base::AutoLock autolock(lock_); 1197 base::AutoLock autolock(lock_);
1199 1198
1200 if (!HasCookieableScheme(url)) 1199 if (!HasCookieableScheme(url))
1201 return false; 1200 return false;
1202 1201
1203 Time creation_time = CurrentTime(); 1202 Time creation_time = CurrentTime();
1204 last_time_seen_ = creation_time; 1203 last_time_seen_ = creation_time;
1205 1204
1206 scoped_ptr<CanonicalCookie> cc(CanonicalCookie::Create( 1205 scoped_ptr<CanonicalCookie> cc(CanonicalCookie::Create(
1207 url, name, value, domain, path, creation_time, expiration_time, secure, 1206 url, name, value, domain, path, creation_time, expiration_time, secure,
1208 http_only, first_party_only, enforce_strict_secure, priority)); 1207 http_only, same_site, enforce_strict_secure, priority));
1209 1208
1210 if (!cc.get()) 1209 if (!cc.get())
1211 return false; 1210 return false;
1212 1211
1213 CookieOptions options; 1212 CookieOptions options;
1214 options.set_include_httponly(); 1213 options.set_include_httponly();
1215 options.set_include_first_party_only_cookies(); 1214 options.set_include_same_site();
1216 if (enforce_strict_secure) 1215 if (enforce_strict_secure)
1217 options.set_enforce_strict_secure(); 1216 options.set_enforce_strict_secure();
1218 return SetCanonicalCookie(&cc, creation_time, options); 1217 return SetCanonicalCookie(&cc, creation_time, options);
1219 } 1218 }
1220 1219
1221 CookieList CookieMonster::GetAllCookies() { 1220 CookieList CookieMonster::GetAllCookies() {
1222 base::AutoLock autolock(lock_); 1221 base::AutoLock autolock(lock_);
1223 1222
1224 // This function is being called to scrape the cookie list for management UI 1223 // This function is being called to scrape the cookie list for management UI
1225 // or similar. We shouldn't show expired cookies in this list since it will 1224 // or similar. We shouldn't show expired cookies in this list since it will
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 1390
1392 void CookieMonster::DeleteCookie(const GURL& url, 1391 void CookieMonster::DeleteCookie(const GURL& url,
1393 const std::string& cookie_name) { 1392 const std::string& cookie_name) {
1394 base::AutoLock autolock(lock_); 1393 base::AutoLock autolock(lock_);
1395 1394
1396 if (!HasCookieableScheme(url)) 1395 if (!HasCookieableScheme(url))
1397 return; 1396 return;
1398 1397
1399 CookieOptions options; 1398 CookieOptions options;
1400 options.set_include_httponly(); 1399 options.set_include_httponly();
1401 options.set_include_first_party_only_cookies(); 1400 options.set_include_same_site();
1402 // Get the cookies for this host and its domain(s). 1401 // Get the cookies for this host and its domain(s).
1403 std::vector<CanonicalCookie*> cookies; 1402 std::vector<CanonicalCookie*> cookies;
1404 FindCookiesForHostAndDomain(url, options, true, &cookies); 1403 FindCookiesForHostAndDomain(url, options, true, &cookies);
1405 std::set<CanonicalCookie*> matching_cookies; 1404 std::set<CanonicalCookie*> matching_cookies;
1406 1405
1407 for (std::vector<CanonicalCookie*>::const_iterator it = cookies.begin(); 1406 for (std::vector<CanonicalCookie*>::const_iterator it = cookies.begin();
1408 it != cookies.end(); ++it) { 1407 it != cookies.end(); ++it) {
1409 if ((*it)->Name() != cookie_name) 1408 if ((*it)->Name() != cookie_name)
1410 continue; 1409 continue;
1411 if (url.path().find((*it)->Path())) 1410 if (url.path().find((*it)->Path()))
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
1854 sync_to_store) 1853 sync_to_store)
1855 store_->AddCookie(*cc); 1854 store_->AddCookie(*cc);
1856 CookieMap::iterator inserted = 1855 CookieMap::iterator inserted =
1857 cookies_.insert(CookieMap::value_type(key, cc)); 1856 cookies_.insert(CookieMap::value_type(key, cc));
1858 if (delegate_.get()) { 1857 if (delegate_.get()) {
1859 delegate_->OnCookieChanged(*cc, false, 1858 delegate_->OnCookieChanged(*cc, false,
1860 CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT); 1859 CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT);
1861 } 1860 }
1862 1861
1863 // See InitializeHistograms() for details. 1862 // See InitializeHistograms() for details.
1864 int32_t cookie_type_sample = 1863 int32_t type_sample = cc->IsSameSite() ? 1 << COOKIE_TYPE_SAME_SITE : 0;
1865 cc->IsFirstPartyOnly() ? 1 << COOKIE_TYPE_FIRSTPARTYONLY : 0; 1864 type_sample |= cc->IsHttpOnly() ? 1 << COOKIE_TYPE_HTTPONLY : 0;
1866 cookie_type_sample |= cc->IsHttpOnly() ? 1 << COOKIE_TYPE_HTTPONLY : 0; 1865 type_sample |= cc->IsSecure() ? 1 << COOKIE_TYPE_SECURE : 0;
1867 cookie_type_sample |= cc->IsSecure() ? 1 << COOKIE_TYPE_SECURE : 0; 1866 histogram_cookie_type_->Add(type_sample);
1868 histogram_cookie_type_->Add(cookie_type_sample);
1869 1867
1870 // Histogram the type of scheme used on URLs that set cookies. This 1868 // Histogram the type of scheme used on URLs that set cookies. This
1871 // intentionally includes cookies that are set or overwritten by 1869 // intentionally includes cookies that are set or overwritten by
1872 // http:// URLs, but not cookies that are cleared by http:// URLs, to 1870 // http:// URLs, but not cookies that are cleared by http:// URLs, to
1873 // understand if the former behavior can be deprecated for Secure 1871 // understand if the former behavior can be deprecated for Secure
1874 // cookies. 1872 // cookies.
1875 if (!cc->Source().is_empty()) { 1873 if (!cc->Source().is_empty()) {
1876 CookieSource cookie_source_sample; 1874 CookieSource cookie_source_sample;
1877 if (cc->Source().SchemeIsCryptographic()) { 1875 if (cc->Source().SchemeIsCryptographic()) {
1878 cookie_source_sample = 1876 cookie_source_sample =
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
2467 std::set_difference(new_cookies->begin(), new_cookies->end(), 2465 std::set_difference(new_cookies->begin(), new_cookies->end(),
2468 old_cookies->begin(), old_cookies->end(), 2466 old_cookies->begin(), old_cookies->end(),
2469 std::inserter(*cookies_to_add, cookies_to_add->begin()), 2467 std::inserter(*cookies_to_add, cookies_to_add->begin()),
2470 FullDiffCookieSorter); 2468 FullDiffCookieSorter);
2471 } 2469 }
2472 2470
2473 void CookieMonster::RunCallbacks(const CanonicalCookie& cookie, bool removed) { 2471 void CookieMonster::RunCallbacks(const CanonicalCookie& cookie, bool removed) {
2474 lock_.AssertAcquired(); 2472 lock_.AssertAcquired();
2475 CookieOptions opts; 2473 CookieOptions opts;
2476 opts.set_include_httponly(); 2474 opts.set_include_httponly();
2477 opts.set_include_first_party_only_cookies(); 2475 opts.set_include_same_site();
2478 // Note that the callbacks in hook_map_ are wrapped with MakeAsync(), so they 2476 // Note that the callbacks in hook_map_ are wrapped with MakeAsync(), so they
2479 // are guaranteed to not take long - they just post a RunAsync task back to 2477 // are guaranteed to not take long - they just post a RunAsync task back to
2480 // the appropriate thread's message loop and return. It is important that this 2478 // the appropriate thread's message loop and return. It is important that this
2481 // method not run user-supplied callbacks directly, since the CookieMonster 2479 // method not run user-supplied callbacks directly, since the CookieMonster
2482 // lock is held and it is easy to accidentally introduce deadlocks. 2480 // lock is held and it is easy to accidentally introduce deadlocks.
2483 for (CookieChangedHookMap::iterator it = hook_map_.begin(); 2481 for (CookieChangedHookMap::iterator it = hook_map_.begin();
2484 it != hook_map_.end(); ++it) { 2482 it != hook_map_.end(); ++it) {
2485 std::pair<GURL, std::string> key = it->first; 2483 std::pair<GURL, std::string> key = it->first;
2486 if (cookie.IncludeForRequestURL(key.first, opts) && 2484 if (cookie.IncludeForRequestURL(key.first, opts) &&
2487 cookie.Name() == key.second) { 2485 cookie.Name() == key.second) {
2488 it->second->Notify(cookie, removed); 2486 it->second->Notify(cookie, removed);
2489 } 2487 }
2490 } 2488 }
2491 } 2489 }
2492 2490
2493 } // namespace net 2491 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/cookie_monster.h ('k') | net/cookies/cookie_monster_store_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698