| OLD | NEW |
| 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 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 public: | 407 public: |
| 408 SetCookieWithDetailsTask(CookieMonster* cookie_monster, | 408 SetCookieWithDetailsTask(CookieMonster* cookie_monster, |
| 409 const GURL& url, | 409 const GURL& url, |
| 410 const std::string& name, | 410 const std::string& name, |
| 411 const std::string& value, | 411 const std::string& value, |
| 412 const std::string& domain, | 412 const std::string& domain, |
| 413 const std::string& path, | 413 const std::string& path, |
| 414 const base::Time& expiration_time, | 414 const base::Time& expiration_time, |
| 415 bool secure, | 415 bool secure, |
| 416 bool http_only, | 416 bool http_only, |
| 417 bool first_party_only, |
| 417 CookiePriority priority, | 418 CookiePriority priority, |
| 418 const SetCookiesCallback& callback) | 419 const SetCookiesCallback& callback) |
| 419 : CookieMonsterTask(cookie_monster), | 420 : CookieMonsterTask(cookie_monster), |
| 420 url_(url), | 421 url_(url), |
| 421 name_(name), | 422 name_(name), |
| 422 value_(value), | 423 value_(value), |
| 423 domain_(domain), | 424 domain_(domain), |
| 424 path_(path), | 425 path_(path), |
| 425 expiration_time_(expiration_time), | 426 expiration_time_(expiration_time), |
| 426 secure_(secure), | 427 secure_(secure), |
| 427 http_only_(http_only), | 428 http_only_(http_only), |
| 429 first_party_only_(first_party_only), |
| 428 priority_(priority), | 430 priority_(priority), |
| 429 callback_(callback) {} | 431 callback_(callback) {} |
| 430 | 432 |
| 431 // CookieMonsterTask: | 433 // CookieMonsterTask: |
| 432 void Run() override; | 434 void Run() override; |
| 433 | 435 |
| 434 protected: | 436 protected: |
| 435 ~SetCookieWithDetailsTask() override {} | 437 ~SetCookieWithDetailsTask() override {} |
| 436 | 438 |
| 437 private: | 439 private: |
| 438 GURL url_; | 440 GURL url_; |
| 439 std::string name_; | 441 std::string name_; |
| 440 std::string value_; | 442 std::string value_; |
| 441 std::string domain_; | 443 std::string domain_; |
| 442 std::string path_; | 444 std::string path_; |
| 443 base::Time expiration_time_; | 445 base::Time expiration_time_; |
| 444 bool secure_; | 446 bool secure_; |
| 445 bool http_only_; | 447 bool http_only_; |
| 448 bool first_party_only_; |
| 446 CookiePriority priority_; | 449 CookiePriority priority_; |
| 447 SetCookiesCallback callback_; | 450 SetCookiesCallback callback_; |
| 448 | 451 |
| 449 DISALLOW_COPY_AND_ASSIGN(SetCookieWithDetailsTask); | 452 DISALLOW_COPY_AND_ASSIGN(SetCookieWithDetailsTask); |
| 450 }; | 453 }; |
| 451 | 454 |
| 452 void CookieMonster::SetCookieWithDetailsTask::Run() { | 455 void CookieMonster::SetCookieWithDetailsTask::Run() { |
| 453 bool success = this->cookie_monster()->SetCookieWithDetails( | 456 bool success = this->cookie_monster()->SetCookieWithDetails( |
| 454 url_, name_, value_, domain_, path_, expiration_time_, secure_, | 457 url_, name_, value_, domain_, path_, expiration_time_, secure_, |
| 455 http_only_, priority_); | 458 http_only_, first_party_only_, priority_); |
| 456 if (!callback_.is_null()) { | 459 if (!callback_.is_null()) { |
| 457 this->InvokeCallback(base::Bind(&SetCookiesCallback::Run, | 460 this->InvokeCallback(base::Bind(&SetCookiesCallback::Run, |
| 458 base::Unretained(&callback_), success)); | 461 base::Unretained(&callback_), success)); |
| 459 } | 462 } |
| 460 } | 463 } |
| 461 | 464 |
| 462 // Task class for GetAllCookies call. | 465 // Task class for GetAllCookies call. |
| 463 class CookieMonster::GetAllCookiesTask : public CookieMonsterTask { | 466 class CookieMonster::GetAllCookiesTask : public CookieMonsterTask { |
| 464 public: | 467 public: |
| 465 GetAllCookiesTask(CookieMonster* cookie_monster, | 468 GetAllCookiesTask(CookieMonster* cookie_monster, |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 | 880 |
| 878 void CookieMonster::SetCookieWithDetailsAsync( | 881 void CookieMonster::SetCookieWithDetailsAsync( |
| 879 const GURL& url, | 882 const GURL& url, |
| 880 const std::string& name, | 883 const std::string& name, |
| 881 const std::string& value, | 884 const std::string& value, |
| 882 const std::string& domain, | 885 const std::string& domain, |
| 883 const std::string& path, | 886 const std::string& path, |
| 884 const Time& expiration_time, | 887 const Time& expiration_time, |
| 885 bool secure, | 888 bool secure, |
| 886 bool http_only, | 889 bool http_only, |
| 890 bool first_party_only, |
| 887 CookiePriority priority, | 891 CookiePriority priority, |
| 888 const SetCookiesCallback& callback) { | 892 const SetCookiesCallback& callback) { |
| 889 scoped_refptr<SetCookieWithDetailsTask> task = new SetCookieWithDetailsTask( | 893 scoped_refptr<SetCookieWithDetailsTask> task = new SetCookieWithDetailsTask( |
| 890 this, url, name, value, domain, path, expiration_time, secure, http_only, | 894 this, url, name, value, domain, path, expiration_time, secure, http_only, |
| 891 priority, callback); | 895 first_party_only, priority, callback); |
| 892 DoCookieTaskForURL(task, url); | 896 DoCookieTaskForURL(task, url); |
| 893 } | 897 } |
| 894 | 898 |
| 895 void CookieMonster::GetAllCookiesAsync(const GetCookieListCallback& callback) { | 899 void CookieMonster::GetAllCookiesAsync(const GetCookieListCallback& callback) { |
| 896 scoped_refptr<GetAllCookiesTask> task = new GetAllCookiesTask(this, callback); | 900 scoped_refptr<GetAllCookiesTask> task = new GetAllCookiesTask(this, callback); |
| 897 | 901 |
| 898 DoCookieTask(task); | 902 DoCookieTask(task); |
| 899 } | 903 } |
| 900 | 904 |
| 901 void CookieMonster::GetAllCookiesForURLWithOptionsAsync( | 905 void CookieMonster::GetAllCookiesForURLWithOptionsAsync( |
| 902 const GURL& url, | 906 const GURL& url, |
| 903 const CookieOptions& options, | 907 const CookieOptions& options, |
| 904 const GetCookieListCallback& callback) { | 908 const GetCookieListCallback& callback) { |
| 905 scoped_refptr<GetAllCookiesForURLWithOptionsTask> task = | 909 scoped_refptr<GetAllCookiesForURLWithOptionsTask> task = |
| 906 new GetAllCookiesForURLWithOptionsTask(this, url, options, callback); | 910 new GetAllCookiesForURLWithOptionsTask(this, url, options, callback); |
| 907 | 911 |
| 908 DoCookieTaskForURL(task, url); | 912 DoCookieTaskForURL(task, url); |
| 909 } | 913 } |
| 910 | 914 |
| 911 void CookieMonster::GetAllCookiesForURLAsync( | 915 void CookieMonster::GetAllCookiesForURLAsync( |
| 912 const GURL& url, | 916 const GURL& url, |
| 913 const GetCookieListCallback& callback) { | 917 const GetCookieListCallback& callback) { |
| 914 CookieOptions options; | 918 CookieOptions options; |
| 915 options.set_include_httponly(); | 919 options.set_include_httponly(); |
| 920 options.set_include_first_party_only(); |
| 916 scoped_refptr<GetAllCookiesForURLWithOptionsTask> task = | 921 scoped_refptr<GetAllCookiesForURLWithOptionsTask> task = |
| 917 new GetAllCookiesForURLWithOptionsTask(this, url, options, callback); | 922 new GetAllCookiesForURLWithOptionsTask(this, url, options, callback); |
| 918 | 923 |
| 919 DoCookieTaskForURL(task, url); | 924 DoCookieTaskForURL(task, url); |
| 920 } | 925 } |
| 921 | 926 |
| 922 void CookieMonster::HasCookiesForETLDP1Async( | 927 void CookieMonster::HasCookiesForETLDP1Async( |
| 923 const std::string& etldp1, | 928 const std::string& etldp1, |
| 924 const HasCookiesForETLDP1Callback& callback) { | 929 const HasCookiesForETLDP1Callback& callback) { |
| 925 scoped_refptr<HasCookiesForETLDP1Task> task = | 930 scoped_refptr<HasCookiesForETLDP1Task> task = |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 } | 1063 } |
| 1059 | 1064 |
| 1060 bool CookieMonster::SetCookieWithDetails(const GURL& url, | 1065 bool CookieMonster::SetCookieWithDetails(const GURL& url, |
| 1061 const std::string& name, | 1066 const std::string& name, |
| 1062 const std::string& value, | 1067 const std::string& value, |
| 1063 const std::string& domain, | 1068 const std::string& domain, |
| 1064 const std::string& path, | 1069 const std::string& path, |
| 1065 const base::Time& expiration_time, | 1070 const base::Time& expiration_time, |
| 1066 bool secure, | 1071 bool secure, |
| 1067 bool http_only, | 1072 bool http_only, |
| 1073 bool first_party_only, |
| 1068 CookiePriority priority) { | 1074 CookiePriority priority) { |
| 1069 base::AutoLock autolock(lock_); | 1075 base::AutoLock autolock(lock_); |
| 1070 | 1076 |
| 1071 if (!HasCookieableScheme(url)) | 1077 if (!HasCookieableScheme(url)) |
| 1072 return false; | 1078 return false; |
| 1073 | 1079 |
| 1074 Time creation_time = CurrentTime(); | 1080 Time creation_time = CurrentTime(); |
| 1075 last_time_seen_ = creation_time; | 1081 last_time_seen_ = creation_time; |
| 1076 | 1082 |
| 1077 scoped_ptr<CanonicalCookie> cc; | 1083 scoped_ptr<CanonicalCookie> cc; |
| 1078 cc.reset(CanonicalCookie::Create(url, name, value, domain, path, | 1084 cc.reset(CanonicalCookie::Create(url, name, value, domain, path, |
| 1079 creation_time, expiration_time, secure, | 1085 creation_time, expiration_time, secure, |
| 1080 http_only, priority)); | 1086 http_only, first_party_only, priority)); |
| 1081 | 1087 |
| 1082 if (!cc.get()) | 1088 if (!cc.get()) |
| 1083 return false; | 1089 return false; |
| 1084 | 1090 |
| 1085 CookieOptions options; | 1091 CookieOptions options; |
| 1086 options.set_include_httponly(); | 1092 options.set_include_httponly(); |
| 1093 options.set_include_first_party_only(); |
| 1087 return SetCanonicalCookie(&cc, creation_time, options); | 1094 return SetCanonicalCookie(&cc, creation_time, options); |
| 1088 } | 1095 } |
| 1089 | 1096 |
| 1090 bool CookieMonster::ImportCookies(const CookieList& list) { | 1097 bool CookieMonster::ImportCookies(const CookieList& list) { |
| 1091 base::AutoLock autolock(lock_); | 1098 base::AutoLock autolock(lock_); |
| 1092 InitIfNecessary(); | 1099 InitIfNecessary(); |
| 1093 for (net::CookieList::const_iterator iter = list.begin(); iter != list.end(); | 1100 for (net::CookieList::const_iterator iter = list.begin(); iter != list.end(); |
| 1094 ++iter) { | 1101 ++iter) { |
| 1095 scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie(*iter)); | 1102 scoped_ptr<CanonicalCookie> cookie(new CanonicalCookie(*iter)); |
| 1096 net::CookieOptions options; | 1103 net::CookieOptions options; |
| 1097 options.set_include_httponly(); | 1104 options.set_include_httponly(); |
| 1105 options.set_include_first_party_only(); |
| 1098 if (!SetCanonicalCookie(&cookie, cookie->CreationDate(), options)) | 1106 if (!SetCanonicalCookie(&cookie, cookie->CreationDate(), options)) |
| 1099 return false; | 1107 return false; |
| 1100 } | 1108 } |
| 1101 return true; | 1109 return true; |
| 1102 } | 1110 } |
| 1103 | 1111 |
| 1104 CookieList CookieMonster::GetAllCookies() { | 1112 CookieList CookieMonster::GetAllCookies() { |
| 1105 base::AutoLock autolock(lock_); | 1113 base::AutoLock autolock(lock_); |
| 1106 | 1114 |
| 1107 // This function is being called to scrape the cookie list for management UI | 1115 // This function is being called to scrape the cookie list for management UI |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1146 for (std::vector<CanonicalCookie*>::const_iterator it = cookie_ptrs.begin(); | 1154 for (std::vector<CanonicalCookie*>::const_iterator it = cookie_ptrs.begin(); |
| 1147 it != cookie_ptrs.end(); it++) | 1155 it != cookie_ptrs.end(); it++) |
| 1148 cookies.push_back(**it); | 1156 cookies.push_back(**it); |
| 1149 | 1157 |
| 1150 return cookies; | 1158 return cookies; |
| 1151 } | 1159 } |
| 1152 | 1160 |
| 1153 CookieList CookieMonster::GetAllCookiesForURL(const GURL& url) { | 1161 CookieList CookieMonster::GetAllCookiesForURL(const GURL& url) { |
| 1154 CookieOptions options; | 1162 CookieOptions options; |
| 1155 options.set_include_httponly(); | 1163 options.set_include_httponly(); |
| 1164 options.set_first_party_url(url); |
| 1156 | 1165 |
| 1157 return GetAllCookiesForURLWithOptions(url, options); | 1166 return GetAllCookiesForURLWithOptions(url, options); |
| 1158 } | 1167 } |
| 1159 | 1168 |
| 1160 int CookieMonster::DeleteAll(bool sync_to_store) { | 1169 int CookieMonster::DeleteAll(bool sync_to_store) { |
| 1161 base::AutoLock autolock(lock_); | 1170 base::AutoLock autolock(lock_); |
| 1162 | 1171 |
| 1163 int num_deleted = 0; | 1172 int num_deleted = 0; |
| 1164 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { | 1173 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { |
| 1165 CookieMap::iterator curit = it; | 1174 CookieMap::iterator curit = it; |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1312 | 1321 |
| 1313 void CookieMonster::DeleteCookie(const GURL& url, | 1322 void CookieMonster::DeleteCookie(const GURL& url, |
| 1314 const std::string& cookie_name) { | 1323 const std::string& cookie_name) { |
| 1315 base::AutoLock autolock(lock_); | 1324 base::AutoLock autolock(lock_); |
| 1316 | 1325 |
| 1317 if (!HasCookieableScheme(url)) | 1326 if (!HasCookieableScheme(url)) |
| 1318 return; | 1327 return; |
| 1319 | 1328 |
| 1320 CookieOptions options; | 1329 CookieOptions options; |
| 1321 options.set_include_httponly(); | 1330 options.set_include_httponly(); |
| 1331 options.set_include_first_party_only(); |
| 1322 // Get the cookies for this host and its domain(s). | 1332 // Get the cookies for this host and its domain(s). |
| 1323 std::vector<CanonicalCookie*> cookies; | 1333 std::vector<CanonicalCookie*> cookies; |
| 1324 FindCookiesForHostAndDomain(url, options, true, &cookies); | 1334 FindCookiesForHostAndDomain(url, options, true, &cookies); |
| 1325 std::set<CanonicalCookie*> matching_cookies; | 1335 std::set<CanonicalCookie*> matching_cookies; |
| 1326 | 1336 |
| 1327 for (std::vector<CanonicalCookie*>::const_iterator it = cookies.begin(); | 1337 for (std::vector<CanonicalCookie*>::const_iterator it = cookies.begin(); |
| 1328 it != cookies.end(); ++it) { | 1338 it != cookies.end(); ++it) { |
| 1329 if ((*it)->Name() != cookie_name) | 1339 if ((*it)->Name() != cookie_name) |
| 1330 continue; | 1340 continue; |
| 1331 if (url.path().find((*it)->Path())) | 1341 if (url.path().find((*it)->Path())) |
| (...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2288 if (hook_map_.count(key) == 0) | 2298 if (hook_map_.count(key) == 0) |
| 2289 hook_map_[key] = make_linked_ptr(new CookieChangedCallbackList()); | 2299 hook_map_[key] = make_linked_ptr(new CookieChangedCallbackList()); |
| 2290 return hook_map_[key]->Add( | 2300 return hook_map_[key]->Add( |
| 2291 base::Bind(&RunAsync, base::MessageLoopProxy::current(), callback)); | 2301 base::Bind(&RunAsync, base::MessageLoopProxy::current(), callback)); |
| 2292 } | 2302 } |
| 2293 | 2303 |
| 2294 void CookieMonster::RunCallbacks(const CanonicalCookie& cookie, bool removed) { | 2304 void CookieMonster::RunCallbacks(const CanonicalCookie& cookie, bool removed) { |
| 2295 lock_.AssertAcquired(); | 2305 lock_.AssertAcquired(); |
| 2296 CookieOptions opts; | 2306 CookieOptions opts; |
| 2297 opts.set_include_httponly(); | 2307 opts.set_include_httponly(); |
| 2308 opts.set_include_first_party_only(); |
| 2298 // Note that the callbacks in hook_map_ are wrapped with MakeAsync(), so they | 2309 // Note that the callbacks in hook_map_ are wrapped with MakeAsync(), so they |
| 2299 // are guaranteed to not take long - they just post a RunAsync task back to | 2310 // are guaranteed to not take long - they just post a RunAsync task back to |
| 2300 // the appropriate thread's message loop and return. It is important that this | 2311 // the appropriate thread's message loop and return. It is important that this |
| 2301 // method not run user-supplied callbacks directly, since the CookieMonster | 2312 // method not run user-supplied callbacks directly, since the CookieMonster |
| 2302 // lock is held and it is easy to accidentally introduce deadlocks. | 2313 // lock is held and it is easy to accidentally introduce deadlocks. |
| 2303 for (CookieChangedHookMap::iterator it = hook_map_.begin(); | 2314 for (CookieChangedHookMap::iterator it = hook_map_.begin(); |
| 2304 it != hook_map_.end(); ++it) { | 2315 it != hook_map_.end(); ++it) { |
| 2305 std::pair<GURL, std::string> key = it->first; | 2316 std::pair<GURL, std::string> key = it->first; |
| 2306 if (cookie.IncludeForRequestURL(key.first, opts) && | 2317 if (cookie.IncludeForRequestURL(key.first, opts) && |
| 2307 cookie.Name() == key.second) { | 2318 cookie.Name() == key.second) { |
| 2308 it->second->Notify(cookie, removed); | 2319 it->second->Notify(cookie, removed); |
| 2309 } | 2320 } |
| 2310 } | 2321 } |
| 2311 } | 2322 } |
| 2312 | 2323 |
| 2313 } // namespace net | 2324 } // namespace net |
| OLD | NEW |