OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 } | 402 } |
403 | 403 |
404 void CookieMonster::SetExpiryAndKeyScheme(ExpiryAndKeyScheme key_scheme) { | 404 void CookieMonster::SetExpiryAndKeyScheme(ExpiryAndKeyScheme key_scheme) { |
405 DCHECK(!initialized_); | 405 DCHECK(!initialized_); |
406 expiry_and_key_scheme_ = key_scheme; | 406 expiry_and_key_scheme_ = key_scheme; |
407 } | 407 } |
408 | 408 |
409 // The system resolution is not high enough, so we can have multiple | 409 // The system resolution is not high enough, so we can have multiple |
410 // set cookies that result in the same system time. When this happens, we | 410 // set cookies that result in the same system time. When this happens, we |
411 // increment by one Time unit. Let's hope computers don't get too fast. | 411 // increment by one Time unit. Let's hope computers don't get too fast. |
412 Time CookieMonster::CurrentTime() { | 412 Time CookieMonster::StrictlyIncreasingTime() { |
413 return std::max(Time::Now(), | 413 return std::max(Time::Now(), |
414 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); | 414 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); |
415 } | 415 } |
416 | 416 |
417 // Parse a cookie expiration time. We try to be lenient, but we need to | 417 // Parse a cookie expiration time. We try to be lenient, but we need to |
418 // assume some order to distinguish the fields. The basic rules: | 418 // assume some order to distinguish the fields. The basic rules: |
419 // - The month name must be present and prefix the first 3 letters of the | 419 // - The month name must be present and prefix the first 3 letters of the |
420 // full month name (jan for January, jun for June). | 420 // full month name (jan for January, jun for June). |
421 // - If the year is <= 2 digits, it must occur after the day of month. | 421 // - If the year is <= 2 digits, it must occur after the day of month. |
422 // - The time must be of the format hh:mm:ss. | 422 // - The time must be of the format hh:mm:ss. |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 const GURL& url, | 763 const GURL& url, |
764 const std::string& cookie_line, | 764 const std::string& cookie_line, |
765 const Time& creation_time_or_null, | 765 const Time& creation_time_or_null, |
766 const CookieOptions& options) { | 766 const CookieOptions& options) { |
767 lock_.AssertAcquired(); | 767 lock_.AssertAcquired(); |
768 | 768 |
769 VLOG(kVlogSetCookies) << "SetCookie() line: " << cookie_line; | 769 VLOG(kVlogSetCookies) << "SetCookie() line: " << cookie_line; |
770 | 770 |
771 Time creation_time = creation_time_or_null; | 771 Time creation_time = creation_time_or_null; |
772 if (creation_time.is_null()) { | 772 if (creation_time.is_null()) { |
773 creation_time = CurrentTime(); | 773 creation_time = StrictlyIncreasingTime(); |
774 last_time_seen_ = creation_time; | 774 last_time_seen_ = creation_time; |
775 } | 775 } |
776 | 776 |
777 // Parse the cookie. | 777 // Parse the cookie. |
778 ParsedCookie pc(cookie_line); | 778 ParsedCookie pc(cookie_line); |
779 | 779 |
780 if (!pc.IsValid()) { | 780 if (!pc.IsValid()) { |
781 VLOG(kVlogSetCookies) << "WARNING: Couldn't parse cookie"; | 781 VLOG(kVlogSetCookies) << "WARNING: Couldn't parse cookie"; |
782 return false; | 782 return false; |
783 } | 783 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 const std::string& domain, const std::string& path, | 829 const std::string& domain, const std::string& path, |
830 const base::Time& expiration_time, bool secure, bool http_only) { | 830 const base::Time& expiration_time, bool secure, bool http_only) { |
831 | 831 |
832 AutoLock autolock(lock_); | 832 AutoLock autolock(lock_); |
833 | 833 |
834 if (!HasCookieableScheme(url)) | 834 if (!HasCookieableScheme(url)) |
835 return false; | 835 return false; |
836 | 836 |
837 InitIfNecessary(); | 837 InitIfNecessary(); |
838 | 838 |
839 Time creation_time = CurrentTime(); | 839 Time creation_time = StrictlyIncreasingTime(); |
840 last_time_seen_ = creation_time; | 840 last_time_seen_ = creation_time; |
841 | 841 |
842 scoped_ptr<CanonicalCookie> cc; | 842 scoped_ptr<CanonicalCookie> cc; |
843 cc.reset(CanonicalCookie::Create( | 843 cc.reset(CanonicalCookie::Create( |
844 url, name, value, domain, path, | 844 url, name, value, domain, path, |
845 creation_time, expiration_time, | 845 creation_time, expiration_time, |
846 secure, http_only)); | 846 secure, http_only)); |
847 | 847 |
848 if (!cc.get()) | 848 if (!cc.get()) |
849 return false; | 849 return false; |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1344 | 1344 |
1345 CookieList cookie_list; | 1345 CookieList cookie_list; |
1346 cookie_list.reserve(cookie_ptrs.size()); | 1346 cookie_list.reserve(cookie_ptrs.size()); |
1347 for (std::vector<CanonicalCookie*>::const_iterator it = cookie_ptrs.begin(); | 1347 for (std::vector<CanonicalCookie*>::const_iterator it = cookie_ptrs.begin(); |
1348 it != cookie_ptrs.end(); ++it) | 1348 it != cookie_ptrs.end(); ++it) |
1349 cookie_list.push_back(**it); | 1349 cookie_list.push_back(**it); |
1350 | 1350 |
1351 return cookie_list; | 1351 return cookie_list; |
1352 } | 1352 } |
1353 | 1353 |
1354 CookieMonster::CookieList CookieMonster::GetAllCookiesForURL(const GURL& url) { | 1354 CookieMonster::CookieList CookieMonster::GetAllCookiesForURLWithOptions( |
| 1355 const GURL& url, |
| 1356 const CookieOptions& options) { |
1355 AutoLock autolock(lock_); | 1357 AutoLock autolock(lock_); |
1356 InitIfNecessary(); | 1358 InitIfNecessary(); |
1357 | 1359 |
1358 CookieOptions options; | |
1359 options.set_include_httponly(); | |
1360 | |
1361 std::vector<CanonicalCookie*> cookie_ptrs; | 1360 std::vector<CanonicalCookie*> cookie_ptrs; |
1362 FindCookiesForHostAndDomain(url, options, false, &cookie_ptrs); | 1361 FindCookiesForHostAndDomain(url, options, false, &cookie_ptrs); |
1363 std::sort(cookie_ptrs.begin(), cookie_ptrs.end(), CookieSorter); | 1362 std::sort(cookie_ptrs.begin(), cookie_ptrs.end(), CookieSorter); |
1364 | 1363 |
1365 CookieList cookies; | 1364 CookieList cookies; |
1366 for (std::vector<CanonicalCookie*>::const_iterator it = cookie_ptrs.begin(); | 1365 for (std::vector<CanonicalCookie*>::const_iterator it = cookie_ptrs.begin(); |
1367 it != cookie_ptrs.end(); it++) | 1366 it != cookie_ptrs.end(); it++) |
1368 cookies.push_back(**it); | 1367 cookies.push_back(**it); |
1369 | 1368 |
1370 return cookies; | 1369 return cookies; |
1371 } | 1370 } |
1372 | 1371 |
| 1372 CookieMonster::CookieList CookieMonster::GetAllCookiesForURL(const GURL& url) { |
| 1373 CookieOptions options; |
| 1374 options.set_include_httponly(); |
| 1375 |
| 1376 return GetAllCookiesForURLWithOptions(url, options); |
| 1377 } |
| 1378 |
1373 void CookieMonster::FindCookiesForHostAndDomain( | 1379 void CookieMonster::FindCookiesForHostAndDomain( |
1374 const GURL& url, | 1380 const GURL& url, |
1375 const CookieOptions& options, | 1381 const CookieOptions& options, |
1376 bool update_access_time, | 1382 bool update_access_time, |
1377 std::vector<CanonicalCookie*>* cookies) { | 1383 std::vector<CanonicalCookie*>* cookies) { |
1378 lock_.AssertAcquired(); | 1384 lock_.AssertAcquired(); |
1379 | 1385 |
1380 const Time current_time(CurrentTime()); | 1386 const Time current_time(StrictlyIncreasingTime()); |
1381 | 1387 |
1382 // Probe to save statistics relatively frequently. We do it here rather | 1388 // Probe to save statistics relatively frequently. We do it here rather |
1383 // than in the set path as many websites won't set cookies, and we | 1389 // than in the set path as many websites won't set cookies, and we |
1384 // want to collect statistics whenever the browser's being used. | 1390 // want to collect statistics whenever the browser's being used. |
1385 RecordPeriodicStats(current_time); | 1391 RecordPeriodicStats(current_time); |
1386 | 1392 |
1387 if (expiry_and_key_scheme_ == EKS_DISCARD_RECENT_AND_PURGE_DOMAIN) { | 1393 if (expiry_and_key_scheme_ == EKS_DISCARD_RECENT_AND_PURGE_DOMAIN) { |
1388 // Can just dispatch to FindCookiesForKey | 1394 // Can just dispatch to FindCookiesForKey |
1389 const std::string key(GetKey(url.host())); | 1395 const std::string key(GetKey(url.host())); |
1390 FindCookiesForKey(key, url, options, current_time, | 1396 FindCookiesForKey(key, url, options, current_time, |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1991 return base::StringPrintf( | 1997 return base::StringPrintf( |
1992 "name: %s value: %s domain: %s path: %s creation: %" | 1998 "name: %s value: %s domain: %s path: %s creation: %" |
1993 PRId64, | 1999 PRId64, |
1994 name_.c_str(), value_.c_str(), | 2000 name_.c_str(), value_.c_str(), |
1995 domain_.c_str(), path_.c_str(), | 2001 domain_.c_str(), path_.c_str(), |
1996 static_cast<int64>(creation_date_.ToTimeT())); | 2002 static_cast<int64>(creation_date_.ToTimeT())); |
1997 } | 2003 } |
1998 | 2004 |
1999 } // namespace | 2005 } // namespace |
2000 | 2006 |
OLD | NEW |