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 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
758 this->cookie_monster()->ComputeCookieDiff(&old_cookies, &list_, | 758 this->cookie_monster()->ComputeCookieDiff(&old_cookies, &list_, |
759 &positive_diff, &negative_diff); | 759 &positive_diff, &negative_diff); |
760 | 760 |
761 for (CookieList::const_iterator it = negative_diff.begin(); | 761 for (CookieList::const_iterator it = negative_diff.begin(); |
762 it != negative_diff.end(); ++it) { | 762 it != negative_diff.end(); ++it) { |
763 this->cookie_monster()->DeleteCanonicalCookie(*it); | 763 this->cookie_monster()->DeleteCanonicalCookie(*it); |
764 } | 764 } |
765 | 765 |
766 bool result = true; | 766 bool result = true; |
767 if (positive_diff.size() > 0) | 767 if (positive_diff.size() > 0) |
768 result = this->cookie_monster()->SetCanonicalCookies(list_); | 768 result = this->cookie_monster()->SetAllCookies(list_); |
769 | 769 |
770 if (!callback_.is_null()) | 770 if (!callback_.is_null()) |
771 callback_.Run(result); | 771 callback_.Run(result); |
772 } | 772 } |
773 | 773 |
774 // Task class for GetCookiesWithOptions call. | 774 // Task class for GetCookiesWithOptions call. |
775 class CookieMonster::GetCookiesWithOptionsTask : public CookieMonsterTask { | 775 class CookieMonster::GetCookiesWithOptionsTask : public CookieMonsterTask { |
776 public: | 776 public: |
777 GetCookiesWithOptionsTask(CookieMonster* cookie_monster, | 777 GetCookiesWithOptionsTask(CookieMonster* cookie_monster, |
778 const GURL& url, | 778 const GURL& url, |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1079 } | 1079 } |
1080 | 1080 |
1081 // Validate consistency of passed arguments. | 1081 // Validate consistency of passed arguments. |
1082 if (ParsedCookie::ParseTokenString(name) != name || | 1082 if (ParsedCookie::ParseTokenString(name) != name || |
1083 ParsedCookie::ParseValueString(value) != value || | 1083 ParsedCookie::ParseValueString(value) != value || |
1084 ParsedCookie::ParseValueString(domain) != domain || | 1084 ParsedCookie::ParseValueString(domain) != domain || |
1085 ParsedCookie::ParseValueString(path) != path) { | 1085 ParsedCookie::ParseValueString(path) != path) { |
1086 return false; | 1086 return false; |
1087 } | 1087 } |
1088 | 1088 |
1089 // Validate passed arguments against URL. | |
1090 if (secure && !url.SchemeIsCryptographic()) | |
1091 return false; | |
1092 | |
1093 std::string cookie_domain; | 1089 std::string cookie_domain; |
1094 if (!cookie_util::GetCookieDomainWithString(url, domain, &cookie_domain)) | 1090 if (!cookie_util::GetCookieDomainWithString(url, domain, &cookie_domain)) |
1095 return false; | 1091 return false; |
1096 | 1092 |
1097 std::string cookie_path = CanonicalCookie::CanonPathWithString(url, path); | 1093 std::string cookie_path = CanonicalCookie::CanonPathWithString(url, path); |
1098 if (!path.empty() && cookie_path != path) | 1094 if (!path.empty() && cookie_path != path) |
1099 return false; | 1095 return false; |
1100 | 1096 |
1101 // Canonicalize path again to make sure it escapes characters as needed. | 1097 // Canonicalize path again to make sure it escapes characters as needed. |
1102 url::Component path_component(0, cookie_path.length()); | 1098 url::Component path_component(0, cookie_path.length()); |
1103 url::RawCanonOutputT<char> canon_path; | 1099 url::RawCanonOutputT<char> canon_path; |
1104 url::Component canon_path_component; | 1100 url::Component canon_path_component; |
1105 url::CanonicalizePath(cookie_path.data(), path_component, &canon_path, | 1101 url::CanonicalizePath(cookie_path.data(), path_component, &canon_path, |
1106 &canon_path_component); | 1102 &canon_path_component); |
1107 cookie_path = std::string(canon_path.data() + canon_path_component.begin, | 1103 cookie_path = std::string(canon_path.data() + canon_path_component.begin, |
1108 canon_path_component.len); | 1104 canon_path_component.len); |
1109 | 1105 |
1110 std::unique_ptr<CanonicalCookie> cc(base::MakeUnique<CanonicalCookie>( | 1106 std::unique_ptr<CanonicalCookie> cc(base::MakeUnique<CanonicalCookie>( |
1111 name, value, cookie_domain, cookie_path, actual_creation_time, | 1107 name, value, cookie_domain, cookie_path, actual_creation_time, |
1112 expiration_time, last_access_time, secure, http_only, same_site, | 1108 expiration_time, last_access_time, secure, http_only, same_site, |
1113 priority)); | 1109 priority)); |
1114 | 1110 |
1115 CookieOptions options; | 1111 return SetCanonicalCookie(std::move(cc), url.SchemeIsCryptographic(), true); |
1116 options.set_include_httponly(); | |
1117 options.set_same_site_cookie_mode( | |
1118 CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX); | |
1119 return SetCanonicalCookie(std::move(cc), url, options); | |
1120 } | 1112 } |
1121 | 1113 |
1122 CookieList CookieMonster::GetAllCookies() { | 1114 CookieList CookieMonster::GetAllCookies() { |
1123 DCHECK(thread_checker_.CalledOnValidThread()); | 1115 DCHECK(thread_checker_.CalledOnValidThread()); |
1124 | 1116 |
1125 // This function is being called to scrape the cookie list for management UI | 1117 // This function is being called to scrape the cookie list for management UI |
1126 // or similar. We shouldn't show expired cookies in this list since it will | 1118 // or similar. We shouldn't show expired cookies in this list since it will |
1127 // just be confusing to users, and this function is called rarely enough (and | 1119 // just be confusing to users, and this function is called rarely enough (and |
1128 // is already slow enough) that it's OK to take the time to garbage collect | 1120 // is already slow enough) that it's OK to take the time to garbage collect |
1129 // the expired cookies now. | 1121 // the expired cookies now. |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1428 // Even if a key is expired, insert it so it can be garbage collected, | 1420 // Even if a key is expired, insert it so it can be garbage collected, |
1429 // removed, and sync'd. | 1421 // removed, and sync'd. |
1430 CookieItVector cookies_with_control_chars; | 1422 CookieItVector cookies_with_control_chars; |
1431 | 1423 |
1432 for (auto& cookie : cookies) { | 1424 for (auto& cookie : cookies) { |
1433 int64_t cookie_creation_time = cookie->CreationDate().ToInternalValue(); | 1425 int64_t cookie_creation_time = cookie->CreationDate().ToInternalValue(); |
1434 | 1426 |
1435 if (creation_times_.insert(cookie_creation_time).second) { | 1427 if (creation_times_.insert(cookie_creation_time).second) { |
1436 CanonicalCookie* cookie_ptr = cookie.get(); | 1428 CanonicalCookie* cookie_ptr = cookie.get(); |
1437 CookieMap::iterator inserted = InternalInsertCookie( | 1429 CookieMap::iterator inserted = InternalInsertCookie( |
1438 GetKey(cookie_ptr->Domain()), std::move(cookie), GURL(), false); | 1430 GetKey(cookie_ptr->Domain()), std::move(cookie), false); |
1439 const Time cookie_access_time(cookie_ptr->LastAccessDate()); | 1431 const Time cookie_access_time(cookie_ptr->LastAccessDate()); |
1440 if (earliest_access_time_.is_null() || | 1432 if (earliest_access_time_.is_null() || |
1441 cookie_access_time < earliest_access_time_) | 1433 cookie_access_time < earliest_access_time_) |
1442 earliest_access_time_ = cookie_access_time; | 1434 earliest_access_time_ = cookie_access_time; |
1443 | 1435 |
1444 if (ContainsControlCharacter(cookie_ptr->Name()) || | 1436 if (ContainsControlCharacter(cookie_ptr->Name()) || |
1445 ContainsControlCharacter(cookie_ptr->Value())) { | 1437 ContainsControlCharacter(cookie_ptr->Value())) { |
1446 cookies_with_control_chars.push_back(inserted); | 1438 cookies_with_control_chars.push_back(inserted); |
1447 } | 1439 } |
1448 } else { | 1440 } else { |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1642 // time if we've been requested to do so. | 1634 // time if we've been requested to do so. |
1643 if (options.update_access_time()) { | 1635 if (options.update_access_time()) { |
1644 InternalUpdateCookieAccessTime(cc, current); | 1636 InternalUpdateCookieAccessTime(cc, current); |
1645 } | 1637 } |
1646 cookies->push_back(cc); | 1638 cookies->push_back(cc); |
1647 } | 1639 } |
1648 } | 1640 } |
1649 | 1641 |
1650 bool CookieMonster::DeleteAnyEquivalentCookie(const std::string& key, | 1642 bool CookieMonster::DeleteAnyEquivalentCookie(const std::string& key, |
1651 const CanonicalCookie& ecc, | 1643 const CanonicalCookie& ecc, |
1652 const GURL& source_url, | 1644 bool source_secure, |
1653 bool skip_httponly, | 1645 bool skip_httponly, |
1654 bool already_expired) { | 1646 bool already_expired) { |
1655 DCHECK(thread_checker_.CalledOnValidThread()); | 1647 DCHECK(thread_checker_.CalledOnValidThread()); |
1656 | 1648 |
1657 bool found_equivalent_cookie = false; | 1649 bool found_equivalent_cookie = false; |
1658 bool skipped_httponly = false; | 1650 bool skipped_httponly = false; |
1659 bool skipped_secure_cookie = false; | 1651 bool skipped_secure_cookie = false; |
1660 | 1652 |
1661 histogram_cookie_delete_equivalent_->Add(COOKIE_DELETE_EQUIVALENT_ATTEMPT); | 1653 histogram_cookie_delete_equivalent_->Add(COOKIE_DELETE_EQUIVALENT_ATTEMPT); |
1662 | 1654 |
1663 for (CookieMapItPair its = cookies_.equal_range(key); | 1655 for (CookieMapItPair its = cookies_.equal_range(key); |
1664 its.first != its.second;) { | 1656 its.first != its.second;) { |
1665 CookieMap::iterator curit = its.first; | 1657 CookieMap::iterator curit = its.first; |
1666 CanonicalCookie* cc = curit->second.get(); | 1658 CanonicalCookie* cc = curit->second.get(); |
1667 ++its.first; | 1659 ++its.first; |
1668 | 1660 |
1669 // If the cookie is being set from an insecure scheme, then if a cookie | 1661 // If the cookie is being set from an insecure scheme, then if a cookie |
1670 // already exists with the same name and it is Secure, then the cookie | 1662 // already exists with the same name and it is Secure, then the cookie |
1671 // should *not* be updated if they domain-match and ignoring the path | 1663 // should *not* be updated if they domain-match and ignoring the path |
1672 // attribute. | 1664 // attribute. |
1673 // | 1665 // |
1674 // See: https://tools.ietf.org/html/draft-ietf-httpbis-cookie-alone | 1666 // See: https://tools.ietf.org/html/draft-ietf-httpbis-cookie-alone |
1675 if (cc->IsSecure() && !source_url.SchemeIsCryptographic() && | 1667 if (cc->IsSecure() && !source_secure && |
1676 ecc.IsEquivalentForSecureCookieMatching(*cc)) { | 1668 ecc.IsEquivalentForSecureCookieMatching(*cc)) { |
1677 skipped_secure_cookie = true; | 1669 skipped_secure_cookie = true; |
1678 histogram_cookie_delete_equivalent_->Add( | 1670 histogram_cookie_delete_equivalent_->Add( |
1679 COOKIE_DELETE_EQUIVALENT_SKIPPING_SECURE); | 1671 COOKIE_DELETE_EQUIVALENT_SKIPPING_SECURE); |
1680 // If the cookie is equivalent to the new cookie and wouldn't have been | 1672 // If the cookie is equivalent to the new cookie and wouldn't have been |
1681 // skipped for being HTTP-only, record that it is a skipped secure cookie | 1673 // skipped for being HTTP-only, record that it is a skipped secure cookie |
1682 // that would have been deleted otherwise. | 1674 // that would have been deleted otherwise. |
1683 if (ecc.IsEquivalent(*cc)) { | 1675 if (ecc.IsEquivalent(*cc)) { |
1684 found_equivalent_cookie = true; | 1676 found_equivalent_cookie = true; |
1685 | 1677 |
(...skipping 20 matching lines...) Expand all Loading... | |
1706 } | 1698 } |
1707 found_equivalent_cookie = true; | 1699 found_equivalent_cookie = true; |
1708 } | 1700 } |
1709 } | 1701 } |
1710 return skipped_httponly || skipped_secure_cookie; | 1702 return skipped_httponly || skipped_secure_cookie; |
1711 } | 1703 } |
1712 | 1704 |
1713 CookieMonster::CookieMap::iterator CookieMonster::InternalInsertCookie( | 1705 CookieMonster::CookieMap::iterator CookieMonster::InternalInsertCookie( |
1714 const std::string& key, | 1706 const std::string& key, |
1715 std::unique_ptr<CanonicalCookie> cc, | 1707 std::unique_ptr<CanonicalCookie> cc, |
1716 const GURL& source_url, | |
1717 bool sync_to_store) { | 1708 bool sync_to_store) { |
1718 DCHECK(thread_checker_.CalledOnValidThread()); | 1709 DCHECK(thread_checker_.CalledOnValidThread()); |
1719 CanonicalCookie* cc_ptr = cc.get(); | 1710 CanonicalCookie* cc_ptr = cc.get(); |
1720 | 1711 |
1721 if ((cc_ptr->IsPersistent() || persist_session_cookies_) && store_.get() && | 1712 if ((cc_ptr->IsPersistent() || persist_session_cookies_) && store_.get() && |
1722 sync_to_store) | 1713 sync_to_store) |
1723 store_->AddCookie(*cc_ptr); | 1714 store_->AddCookie(*cc_ptr); |
1724 CookieMap::iterator inserted = | 1715 CookieMap::iterator inserted = |
1725 cookies_.insert(CookieMap::value_type(key, std::move(cc))); | 1716 cookies_.insert(CookieMap::value_type(key, std::move(cc))); |
1726 if (delegate_.get()) { | 1717 if (delegate_.get()) { |
1727 delegate_->OnCookieChanged(*cc_ptr, false, | 1718 delegate_->OnCookieChanged(*cc_ptr, false, |
1728 CookieStore::ChangeCause::INSERTED); | 1719 CookieStore::ChangeCause::INSERTED); |
1729 } | 1720 } |
1730 | 1721 |
1731 // See InitializeHistograms() for details. | 1722 // See InitializeHistograms() for details. |
1732 int32_t type_sample = cc_ptr->SameSite() != CookieSameSite::NO_RESTRICTION | 1723 int32_t type_sample = cc_ptr->SameSite() != CookieSameSite::NO_RESTRICTION |
1733 ? 1 << COOKIE_TYPE_SAME_SITE | 1724 ? 1 << COOKIE_TYPE_SAME_SITE |
1734 : 0; | 1725 : 0; |
1735 type_sample |= cc_ptr->IsHttpOnly() ? 1 << COOKIE_TYPE_HTTPONLY : 0; | 1726 type_sample |= cc_ptr->IsHttpOnly() ? 1 << COOKIE_TYPE_HTTPONLY : 0; |
1736 type_sample |= cc_ptr->IsSecure() ? 1 << COOKIE_TYPE_SECURE : 0; | 1727 type_sample |= cc_ptr->IsSecure() ? 1 << COOKIE_TYPE_SECURE : 0; |
1737 histogram_cookie_type_->Add(type_sample); | 1728 histogram_cookie_type_->Add(type_sample); |
1738 | 1729 |
1739 // Histogram the type of scheme used on URLs that set cookies. This | |
1740 // intentionally includes cookies that are set or overwritten by | |
1741 // http:// URLs, but not cookies that are cleared by http:// URLs, to | |
1742 // understand if the former behavior can be deprecated for Secure | |
1743 // cookies. | |
1744 if (!source_url.is_empty()) { | |
1745 CookieSource cookie_source_sample; | |
1746 if (source_url.SchemeIsCryptographic()) { | |
1747 cookie_source_sample = | |
1748 cc_ptr->IsSecure() | |
1749 ? COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME | |
1750 : COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME; | |
1751 } else { | |
1752 cookie_source_sample = | |
1753 cc_ptr->IsSecure() | |
1754 ? COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME | |
1755 : COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME; | |
1756 } | |
1757 histogram_cookie_source_scheme_->Add(cookie_source_sample); | |
1758 } | |
1759 | |
1760 RunCookieChangedCallbacks(*cc_ptr, CookieStore::ChangeCause::INSERTED); | 1730 RunCookieChangedCallbacks(*cc_ptr, CookieStore::ChangeCause::INSERTED); |
1761 | 1731 |
1762 return inserted; | 1732 return inserted; |
1763 } | 1733 } |
1764 | 1734 |
1765 bool CookieMonster::SetCookieWithCreationTimeAndOptions( | 1735 bool CookieMonster::SetCookieWithCreationTimeAndOptions( |
1766 const GURL& url, | 1736 const GURL& url, |
1767 const std::string& cookie_line, | 1737 const std::string& cookie_line, |
1768 const Time& creation_time_or_null, | 1738 const Time& creation_time_or_null, |
1769 const CookieOptions& options) { | 1739 const CookieOptions& options) { |
1770 DCHECK(thread_checker_.CalledOnValidThread()); | 1740 DCHECK(thread_checker_.CalledOnValidThread()); |
1771 | 1741 |
1772 VLOG(kVlogSetCookies) << "SetCookie() line: " << cookie_line; | 1742 VLOG(kVlogSetCookies) << "SetCookie() line: " << cookie_line; |
1773 | 1743 |
1774 Time creation_time = creation_time_or_null; | 1744 Time creation_time = creation_time_or_null; |
1775 if (creation_time.is_null()) { | 1745 if (creation_time.is_null()) { |
1776 creation_time = CurrentTime(); | 1746 creation_time = CurrentTime(); |
1777 last_time_seen_ = creation_time; | 1747 last_time_seen_ = creation_time; |
1778 } | 1748 } |
1779 | 1749 |
1780 std::unique_ptr<CanonicalCookie> cc( | 1750 std::unique_ptr<CanonicalCookie> cc( |
1781 CanonicalCookie::Create(url, cookie_line, creation_time, options)); | 1751 CanonicalCookie::Create(url, cookie_line, creation_time, options)); |
1782 | 1752 |
1783 if (!cc.get()) { | 1753 if (!cc.get()) { |
1784 VLOG(kVlogSetCookies) << "WARNING: Failed to allocate CanonicalCookie"; | 1754 VLOG(kVlogSetCookies) << "WARNING: Failed to allocate CanonicalCookie"; |
1785 return false; | 1755 return false; |
1786 } | 1756 } |
1787 return SetCanonicalCookie(std::move(cc), url, options); | 1757 return SetCanonicalCookie(std::move(cc), url.SchemeIsCryptographic(), |
1758 !options.exclude_httponly()); | |
1788 } | 1759 } |
1789 | 1760 |
1790 bool CookieMonster::SetCanonicalCookie(std::unique_ptr<CanonicalCookie> cc, | 1761 bool CookieMonster::SetCanonicalCookie(std::unique_ptr<CanonicalCookie> cc, |
1791 const GURL& source_url, | 1762 bool secure_source, |
1792 const CookieOptions& options) { | 1763 bool modify_http_only) { |
1793 DCHECK(thread_checker_.CalledOnValidThread()); | 1764 DCHECK(thread_checker_.CalledOnValidThread()); |
1794 | 1765 |
1766 if (cc->IsSecure() && !secure_source) | |
1767 return false; | |
1768 | |
1795 Time creation_time = cc->CreationDate(); | 1769 Time creation_time = cc->CreationDate(); |
1796 const std::string key(GetKey(cc->Domain())); | 1770 const std::string key(GetKey(cc->Domain())); |
1797 bool already_expired = cc->IsExpired(creation_time); | 1771 bool already_expired = cc->IsExpired(creation_time); |
1798 | 1772 |
1799 if (DeleteAnyEquivalentCookie(key, *cc, source_url, | 1773 if (DeleteAnyEquivalentCookie(key, *cc, secure_source, !modify_http_only, |
1800 options.exclude_httponly(), already_expired)) { | 1774 already_expired)) { |
1801 std::string error; | 1775 std::string error; |
1802 error = | 1776 error = |
1803 "SetCookie() not clobbering httponly cookie or secure cookie for " | 1777 "SetCookie() not clobbering httponly cookie or secure cookie for " |
1804 "insecure scheme"; | 1778 "insecure scheme"; |
1805 | 1779 |
1806 VLOG(kVlogSetCookies) << error; | 1780 VLOG(kVlogSetCookies) << error; |
1807 return false; | 1781 return false; |
1808 } | 1782 } |
1809 | 1783 |
1810 VLOG(kVlogSetCookies) << "SetCookie() key: " << key | 1784 VLOG(kVlogSetCookies) << "SetCookie() key: " << key |
1811 << " cc: " << cc->DebugString(); | 1785 << " cc: " << cc->DebugString(); |
1812 | 1786 |
1813 // Realize that we might be setting an expired cookie, and the only point | 1787 // Realize that we might be setting an expired cookie, and the only point |
1814 // was to delete the cookie which we've already done. | 1788 // was to delete the cookie which we've already done. |
1815 if (!already_expired) { | 1789 if (!already_expired) { |
1816 // See InitializeHistograms() for details. | 1790 // See InitializeHistograms() for details. |
1817 if (cc->IsPersistent()) { | 1791 if (cc->IsPersistent()) { |
1818 histogram_expiration_duration_minutes_->Add( | 1792 histogram_expiration_duration_minutes_->Add( |
1819 (cc->ExpiryDate() - creation_time).InMinutes()); | 1793 (cc->ExpiryDate() - creation_time).InMinutes()); |
1820 } | 1794 } |
1821 | 1795 |
1822 InternalInsertCookie(key, std::move(cc), source_url, true); | 1796 // Histogram the type of scheme used on URLs that set cookies. This |
1797 // intentionally includes cookies that are set or overwritten by | |
1798 // http:// URLs, but not cookies that are cleared by http:// URLs, to | |
1799 // understand if the former behavior can be deprecated for Secure | |
1800 // cookies. | |
1801 CookieSource cookie_source_sample = | |
1802 (secure_source | |
1803 ? (cc->IsSecure() | |
1804 ? COOKIE_SOURCE_SECURE_COOKIE_CRYPTOGRAPHIC_SCHEME | |
1805 : COOKIE_SOURCE_NONSECURE_COOKIE_CRYPTOGRAPHIC_SCHEME) | |
1806 : (cc->IsSecure() | |
1807 ? COOKIE_SOURCE_SECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME | |
1808 : COOKIE_SOURCE_NONSECURE_COOKIE_NONCRYPTOGRAPHIC_SCHEME)); | |
1809 histogram_cookie_source_scheme_->Add(cookie_source_sample); | |
1810 | |
1811 InternalInsertCookie(key, std::move(cc), true); | |
1823 } else { | 1812 } else { |
1824 VLOG(kVlogSetCookies) << "SetCookie() not storing already expired cookie."; | 1813 VLOG(kVlogSetCookies) << "SetCookie() not storing already expired cookie."; |
1825 } | 1814 } |
1826 | 1815 |
1827 // We assume that hopefully setting a cookie will be less common than | 1816 // We assume that hopefully setting a cookie will be less common than |
1828 // querying a cookie. Since setting a cookie can put us over our limits, | 1817 // querying a cookie. Since setting a cookie can put us over our limits, |
1829 // make sure that we garbage collect... We can also make the assumption that | 1818 // make sure that we garbage collect... We can also make the assumption that |
1830 // if a cookie was set, in the common case it will be used soon after, | 1819 // if a cookie was set, in the common case it will be used soon after, |
1831 // and we will purge the expired cookies in GetCookies(). | 1820 // and we will purge the expired cookies in GetCookies(). |
1832 GarbageCollect(creation_time, key); | 1821 GarbageCollect(creation_time, key); |
1833 | 1822 |
1834 return true; | 1823 return true; |
1835 } | 1824 } |
1836 | 1825 |
1837 bool CookieMonster::SetCanonicalCookies(const CookieList& list) { | 1826 bool CookieMonster::SetAllCookies(const CookieList& list) { |
1838 DCHECK(thread_checker_.CalledOnValidThread()); | 1827 DCHECK(thread_checker_.CalledOnValidThread()); |
1828 for (const auto& cookie : list) { | |
1829 const std::string key(GetKey(cookie.Domain())); | |
1830 Time creation_time = cookie.CreationDate(); | |
1831 bool already_expired = cookie.IsExpired(creation_time); | |
1839 | 1832 |
1840 CookieOptions options; | 1833 bool result = |
1841 options.set_include_httponly(); | 1834 DeleteAnyEquivalentCookie(key, cookie, true, false, already_expired); |
1835 DCHECK(!result); | |
1842 | 1836 |
1843 for (const auto& cookie : list) { | 1837 if (already_expired) |
1844 // Use an empty GURL. This method does not support setting secure cookies. | 1838 continue; |
1845 if (!SetCanonicalCookie(base::MakeUnique<CanonicalCookie>(cookie), GURL(), | 1839 |
1846 options)) { | 1840 if (cookie.IsPersistent()) { |
1847 return false; | 1841 histogram_expiration_duration_minutes_->Add( |
1842 (cookie.ExpiryDate() - creation_time).InMinutes()); | |
1848 } | 1843 } |
1844 | |
1845 InternalInsertCookie(key, base::MakeUnique<CanonicalCookie>(cookie), true); | |
mmenke
2017/06/19 18:00:18
I don't think this was done?
Randy Smith (Not in Mondays)
2017/06/20 21:04:03
Whoops, sorry. I *remember* doing it--I wonder wh
| |
1849 } | 1846 } |
1850 | 1847 |
1848 // TODO(rdsmith): If this function always returns the same value, it | |
1849 // shouldn't have a return value. But it should also be deleted (see | |
1850 // https://codereview.chromium.org/2882063002/#msg64), which would | |
1851 // solve the return value problem. | |
1851 return true; | 1852 return true; |
1852 } | 1853 } |
1853 | 1854 |
1854 void CookieMonster::InternalUpdateCookieAccessTime(CanonicalCookie* cc, | 1855 void CookieMonster::InternalUpdateCookieAccessTime(CanonicalCookie* cc, |
1855 const Time& current) { | 1856 const Time& current) { |
1856 DCHECK(thread_checker_.CalledOnValidThread()); | 1857 DCHECK(thread_checker_.CalledOnValidThread()); |
1857 | 1858 |
1858 // Based off the Mozilla code. When a cookie has been accessed recently, | 1859 // Based off the Mozilla code. When a cookie has been accessed recently, |
1859 // don't bother updating its access time again. This reduces the number of | 1860 // don't bother updating its access time again. This reduces the number of |
1860 // updates we do during pageload, which in turn reduces the chance our storage | 1861 // updates we do during pageload, which in turn reduces the chance our storage |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2442 it != hook_map_.end(); ++it) { | 2443 it != hook_map_.end(); ++it) { |
2443 std::pair<GURL, std::string> key = it->first; | 2444 std::pair<GURL, std::string> key = it->first; |
2444 if (cookie.IncludeForRequestURL(key.first, opts) && | 2445 if (cookie.IncludeForRequestURL(key.first, opts) && |
2445 cookie.Name() == key.second) { | 2446 cookie.Name() == key.second) { |
2446 it->second->Notify(cookie, cause); | 2447 it->second->Notify(cookie, cause); |
2447 } | 2448 } |
2448 } | 2449 } |
2449 } | 2450 } |
2450 | 2451 |
2451 } // namespace net | 2452 } // namespace net |
OLD | NEW |