| 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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 return cookie_line; | 324 return cookie_line; |
| 325 } | 325 } |
| 326 | 326 |
| 327 void RunAsync(scoped_refptr<base::TaskRunner> proxy, | 327 void RunAsync(scoped_refptr<base::TaskRunner> proxy, |
| 328 const CookieStore::CookieChangedCallback& callback, | 328 const CookieStore::CookieChangedCallback& callback, |
| 329 const CanonicalCookie& cookie, | 329 const CanonicalCookie& cookie, |
| 330 bool removed) { | 330 bool removed) { |
| 331 proxy->PostTask(FROM_HERE, base::Bind(callback, cookie, removed)); | 331 proxy->PostTask(FROM_HERE, base::Bind(callback, cookie, removed)); |
| 332 } | 332 } |
| 333 | 333 |
| 334 bool CheckCookiePrefix(CanonicalCookie* cc, const CookieOptions& options) { | |
| 335 const char kSecurePrefix[] = "$Secure-"; | |
| 336 if (cc->Name().find(kSecurePrefix) == 0) | |
| 337 return cc->IsSecure() && cc->Source().SchemeIsCryptographic(); | |
| 338 return true; | |
| 339 } | |
| 340 | |
| 341 } // namespace | 334 } // namespace |
| 342 | 335 |
| 343 CookieMonster::CookieMonster(PersistentCookieStore* store, | 336 CookieMonster::CookieMonster(PersistentCookieStore* store, |
| 344 CookieMonsterDelegate* delegate) | 337 CookieMonsterDelegate* delegate) |
| 345 : initialized_(false), | 338 : initialized_(false), |
| 346 started_fetching_all_cookies_(false), | 339 started_fetching_all_cookies_(false), |
| 347 finished_fetching_all_cookies_(false), | 340 finished_fetching_all_cookies_(false), |
| 348 fetch_strategy_(kUnknownFetch), | 341 fetch_strategy_(kUnknownFetch), |
| 349 store_(store), | 342 store_(store), |
| 350 last_access_threshold_( | 343 last_access_threshold_( |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 SetCookieWithDetailsTask(CookieMonster* cookie_monster, | 432 SetCookieWithDetailsTask(CookieMonster* cookie_monster, |
| 440 const GURL& url, | 433 const GURL& url, |
| 441 const std::string& name, | 434 const std::string& name, |
| 442 const std::string& value, | 435 const std::string& value, |
| 443 const std::string& domain, | 436 const std::string& domain, |
| 444 const std::string& path, | 437 const std::string& path, |
| 445 const base::Time& expiration_time, | 438 const base::Time& expiration_time, |
| 446 bool secure, | 439 bool secure, |
| 447 bool http_only, | 440 bool http_only, |
| 448 bool first_party_only, | 441 bool first_party_only, |
| 449 bool enforce_prefixes, | |
| 450 CookiePriority priority, | 442 CookiePriority priority, |
| 451 const SetCookiesCallback& callback) | 443 const SetCookiesCallback& callback) |
| 452 : CookieMonsterTask(cookie_monster), | 444 : CookieMonsterTask(cookie_monster), |
| 453 url_(url), | 445 url_(url), |
| 454 name_(name), | 446 name_(name), |
| 455 value_(value), | 447 value_(value), |
| 456 domain_(domain), | 448 domain_(domain), |
| 457 path_(path), | 449 path_(path), |
| 458 expiration_time_(expiration_time), | 450 expiration_time_(expiration_time), |
| 459 secure_(secure), | 451 secure_(secure), |
| 460 http_only_(http_only), | 452 http_only_(http_only), |
| 461 first_party_only_(first_party_only), | 453 first_party_only_(first_party_only), |
| 462 enforce_prefixes_(enforce_prefixes), | |
| 463 priority_(priority), | 454 priority_(priority), |
| 464 callback_(callback) {} | 455 callback_(callback) {} |
| 465 | 456 |
| 466 // CookieMonsterTask: | 457 // CookieMonsterTask: |
| 467 void Run() override; | 458 void Run() override; |
| 468 | 459 |
| 469 protected: | 460 protected: |
| 470 ~SetCookieWithDetailsTask() override {} | 461 ~SetCookieWithDetailsTask() override {} |
| 471 | 462 |
| 472 private: | 463 private: |
| 473 GURL url_; | 464 GURL url_; |
| 474 std::string name_; | 465 std::string name_; |
| 475 std::string value_; | 466 std::string value_; |
| 476 std::string domain_; | 467 std::string domain_; |
| 477 std::string path_; | 468 std::string path_; |
| 478 base::Time expiration_time_; | 469 base::Time expiration_time_; |
| 479 bool secure_; | 470 bool secure_; |
| 480 bool http_only_; | 471 bool http_only_; |
| 481 bool first_party_only_; | 472 bool first_party_only_; |
| 482 bool enforce_prefixes_; | |
| 483 CookiePriority priority_; | 473 CookiePriority priority_; |
| 484 SetCookiesCallback callback_; | 474 SetCookiesCallback callback_; |
| 485 | 475 |
| 486 DISALLOW_COPY_AND_ASSIGN(SetCookieWithDetailsTask); | 476 DISALLOW_COPY_AND_ASSIGN(SetCookieWithDetailsTask); |
| 487 }; | 477 }; |
| 488 | 478 |
| 489 void CookieMonster::SetCookieWithDetailsTask::Run() { | 479 void CookieMonster::SetCookieWithDetailsTask::Run() { |
| 490 bool success = this->cookie_monster()->SetCookieWithDetails( | 480 bool success = this->cookie_monster()->SetCookieWithDetails( |
| 491 url_, name_, value_, domain_, path_, expiration_time_, secure_, | 481 url_, name_, value_, domain_, path_, expiration_time_, secure_, |
| 492 http_only_, first_party_only_, enforce_prefixes_, priority_); | 482 http_only_, first_party_only_, priority_); |
| 493 if (!callback_.is_null()) { | 483 if (!callback_.is_null()) { |
| 494 this->InvokeCallback(base::Bind(&SetCookiesCallback::Run, | 484 this->InvokeCallback(base::Bind(&SetCookiesCallback::Run, |
| 495 base::Unretained(&callback_), success)); | 485 base::Unretained(&callback_), success)); |
| 496 } | 486 } |
| 497 } | 487 } |
| 498 | 488 |
| 499 // Task class for GetAllCookies call. | 489 // Task class for GetAllCookies call. |
| 500 class CookieMonster::GetAllCookiesTask : public CookieMonsterTask { | 490 class CookieMonster::GetAllCookiesTask : public CookieMonsterTask { |
| 501 public: | 491 public: |
| 502 GetAllCookiesTask(CookieMonster* cookie_monster, | 492 GetAllCookiesTask(CookieMonster* cookie_monster, |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 void CookieMonster::SetCookieWithDetailsAsync( | 921 void CookieMonster::SetCookieWithDetailsAsync( |
| 932 const GURL& url, | 922 const GURL& url, |
| 933 const std::string& name, | 923 const std::string& name, |
| 934 const std::string& value, | 924 const std::string& value, |
| 935 const std::string& domain, | 925 const std::string& domain, |
| 936 const std::string& path, | 926 const std::string& path, |
| 937 const Time& expiration_time, | 927 const Time& expiration_time, |
| 938 bool secure, | 928 bool secure, |
| 939 bool http_only, | 929 bool http_only, |
| 940 bool first_party_only, | 930 bool first_party_only, |
| 941 bool enforce_prefixes, | |
| 942 CookiePriority priority, | 931 CookiePriority priority, |
| 943 const SetCookiesCallback& callback) { | 932 const SetCookiesCallback& callback) { |
| 944 scoped_refptr<SetCookieWithDetailsTask> task = new SetCookieWithDetailsTask( | 933 scoped_refptr<SetCookieWithDetailsTask> task = new SetCookieWithDetailsTask( |
| 945 this, url, name, value, domain, path, expiration_time, secure, http_only, | 934 this, url, name, value, domain, path, expiration_time, secure, http_only, |
| 946 first_party_only, enforce_prefixes, priority, callback); | 935 first_party_only, priority, callback); |
| 947 DoCookieTaskForURL(task, url); | 936 DoCookieTaskForURL(task, url); |
| 948 } | 937 } |
| 949 | 938 |
| 950 void CookieMonster::GetAllCookiesAsync(const GetCookieListCallback& callback) { | 939 void CookieMonster::GetAllCookiesAsync(const GetCookieListCallback& callback) { |
| 951 scoped_refptr<GetAllCookiesTask> task = new GetAllCookiesTask(this, callback); | 940 scoped_refptr<GetAllCookiesTask> task = new GetAllCookiesTask(this, callback); |
| 952 | 941 |
| 953 DoCookieTask(task); | 942 DoCookieTask(task); |
| 954 } | 943 } |
| 955 | 944 |
| 956 void CookieMonster::GetAllCookiesForURLWithOptionsAsync( | 945 void CookieMonster::GetAllCookiesForURLWithOptionsAsync( |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1116 | 1105 |
| 1117 bool CookieMonster::SetCookieWithDetails(const GURL& url, | 1106 bool CookieMonster::SetCookieWithDetails(const GURL& url, |
| 1118 const std::string& name, | 1107 const std::string& name, |
| 1119 const std::string& value, | 1108 const std::string& value, |
| 1120 const std::string& domain, | 1109 const std::string& domain, |
| 1121 const std::string& path, | 1110 const std::string& path, |
| 1122 const base::Time& expiration_time, | 1111 const base::Time& expiration_time, |
| 1123 bool secure, | 1112 bool secure, |
| 1124 bool http_only, | 1113 bool http_only, |
| 1125 bool first_party_only, | 1114 bool first_party_only, |
| 1126 bool enforce_prefixes, | |
| 1127 CookiePriority priority) { | 1115 CookiePriority priority) { |
| 1128 base::AutoLock autolock(lock_); | 1116 base::AutoLock autolock(lock_); |
| 1129 | 1117 |
| 1130 if (!HasCookieableScheme(url)) | 1118 if (!HasCookieableScheme(url)) |
| 1131 return false; | 1119 return false; |
| 1132 | 1120 |
| 1133 Time creation_time = CurrentTime(); | 1121 Time creation_time = CurrentTime(); |
| 1134 last_time_seen_ = creation_time; | 1122 last_time_seen_ = creation_time; |
| 1135 | 1123 |
| 1136 scoped_ptr<CanonicalCookie> cc; | 1124 scoped_ptr<CanonicalCookie> cc; |
| 1137 cc.reset(CanonicalCookie::Create(url, name, value, domain, path, | 1125 cc.reset(CanonicalCookie::Create(url, name, value, domain, path, |
| 1138 creation_time, expiration_time, secure, | 1126 creation_time, expiration_time, secure, |
| 1139 http_only, first_party_only, priority)); | 1127 http_only, first_party_only, priority)); |
| 1140 | 1128 |
| 1141 if (!cc.get()) | 1129 if (!cc.get()) |
| 1142 return false; | 1130 return false; |
| 1143 | 1131 |
| 1144 CookieOptions options; | 1132 CookieOptions options; |
| 1145 options.set_include_httponly(); | 1133 options.set_include_httponly(); |
| 1146 options.set_include_first_party_only(); | 1134 options.set_include_first_party_only(); |
| 1147 if (enforce_prefixes) | |
| 1148 options.set_enforce_prefixes(); | |
| 1149 return SetCanonicalCookie(&cc, creation_time, options); | 1135 return SetCanonicalCookie(&cc, creation_time, options); |
| 1150 } | 1136 } |
| 1151 | 1137 |
| 1152 bool CookieMonster::ImportCookies(const CookieList& list) { | 1138 bool CookieMonster::ImportCookies(const CookieList& list) { |
| 1153 base::AutoLock autolock(lock_); | 1139 base::AutoLock autolock(lock_); |
| 1154 MarkCookieStoreAsInitialized(); | 1140 MarkCookieStoreAsInitialized(); |
| 1155 if (ShouldFetchAllCookiesWhenFetchingAnyCookie()) | 1141 if (ShouldFetchAllCookiesWhenFetchingAnyCookie()) |
| 1156 FetchAllCookiesIfNecessary(); | 1142 FetchAllCookiesIfNecessary(); |
| 1157 for (CookieList::const_iterator iter = list.begin(); iter != list.end(); | 1143 for (CookieList::const_iterator iter = list.begin(); iter != list.end(); |
| 1158 ++iter) { | 1144 ++iter) { |
| (...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1895 } | 1881 } |
| 1896 return SetCanonicalCookie(&cc, creation_time, options); | 1882 return SetCanonicalCookie(&cc, creation_time, options); |
| 1897 } | 1883 } |
| 1898 | 1884 |
| 1899 bool CookieMonster::SetCanonicalCookie(scoped_ptr<CanonicalCookie>* cc, | 1885 bool CookieMonster::SetCanonicalCookie(scoped_ptr<CanonicalCookie>* cc, |
| 1900 const Time& creation_time, | 1886 const Time& creation_time, |
| 1901 const CookieOptions& options) { | 1887 const CookieOptions& options) { |
| 1902 const std::string key(GetKey((*cc)->Domain())); | 1888 const std::string key(GetKey((*cc)->Domain())); |
| 1903 bool already_expired = (*cc)->IsExpired(creation_time); | 1889 bool already_expired = (*cc)->IsExpired(creation_time); |
| 1904 | 1890 |
| 1905 if (options.enforce_prefixes() && !CheckCookiePrefix(cc->get(), options)) { | |
| 1906 VLOG(kVlogSetCookies) << "SetCookie() not storing cookie '" << (*cc)->Name() | |
| 1907 << "' that violates prefix rules."; | |
| 1908 return false; | |
| 1909 } | |
| 1910 | |
| 1911 if (DeleteAnyEquivalentCookie(key, **cc, options.exclude_httponly(), | 1891 if (DeleteAnyEquivalentCookie(key, **cc, options.exclude_httponly(), |
| 1912 already_expired)) { | 1892 already_expired)) { |
| 1913 VLOG(kVlogSetCookies) << "SetCookie() not clobbering httponly cookie"; | 1893 VLOG(kVlogSetCookies) << "SetCookie() not clobbering httponly cookie"; |
| 1914 return false; | 1894 return false; |
| 1915 } | 1895 } |
| 1916 | 1896 |
| 1917 VLOG(kVlogSetCookies) << "SetCookie() key: " << key | 1897 VLOG(kVlogSetCookies) << "SetCookie() key: " << key |
| 1918 << " cc: " << (*cc)->DebugString(); | 1898 << " cc: " << (*cc)->DebugString(); |
| 1919 | 1899 |
| 1920 // Realize that we might be setting an expired cookie, and the only point | 1900 // Realize that we might be setting an expired cookie, and the only point |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2375 it != hook_map_.end(); ++it) { | 2355 it != hook_map_.end(); ++it) { |
| 2376 std::pair<GURL, std::string> key = it->first; | 2356 std::pair<GURL, std::string> key = it->first; |
| 2377 if (cookie.IncludeForRequestURL(key.first, opts) && | 2357 if (cookie.IncludeForRequestURL(key.first, opts) && |
| 2378 cookie.Name() == key.second) { | 2358 cookie.Name() == key.second) { |
| 2379 it->second->Notify(cookie, removed); | 2359 it->second->Notify(cookie, removed); |
| 2380 } | 2360 } |
| 2381 } | 2361 } |
| 2382 } | 2362 } |
| 2383 | 2363 |
| 2384 } // namespace net | 2364 } // namespace net |
| OLD | NEW |