| 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 28 matching lines...) Expand all Loading... |
| 39 * and other provisions required by the GPL or the LGPL. If you do not delete | 39 * and other provisions required by the GPL or the LGPL. If you do not delete |
| 40 * the provisions above, a recipient may use your version of this file under | 40 * the provisions above, a recipient may use your version of this file under |
| 41 * the terms of any one of the MPL, the GPL or the LGPL. | 41 * the terms of any one of the MPL, the GPL or the LGPL. |
| 42 * | 42 * |
| 43 * ***** END LICENSE BLOCK ***** */ | 43 * ***** END LICENSE BLOCK ***** */ |
| 44 | 44 |
| 45 #include "net/cookies/cookie_monster.h" | 45 #include "net/cookies/cookie_monster.h" |
| 46 | 46 |
| 47 #include <algorithm> | 47 #include <algorithm> |
| 48 #include <functional> | 48 #include <functional> |
| 49 #include <memory> |
| 49 #include <set> | 50 #include <set> |
| 50 | 51 |
| 51 #include "base/bind.h" | 52 #include "base/bind.h" |
| 52 #include "base/callback.h" | 53 #include "base/callback.h" |
| 53 #include "base/location.h" | 54 #include "base/location.h" |
| 54 #include "base/logging.h" | 55 #include "base/logging.h" |
| 55 #include "base/macros.h" | 56 #include "base/macros.h" |
| 56 #include "base/memory/scoped_ptr.h" | 57 #include "base/memory/ptr_util.h" |
| 57 #include "base/metrics/field_trial.h" | 58 #include "base/metrics/field_trial.h" |
| 58 #include "base/metrics/histogram.h" | 59 #include "base/metrics/histogram.h" |
| 59 #include "base/profiler/scoped_tracker.h" | 60 #include "base/profiler/scoped_tracker.h" |
| 60 #include "base/single_thread_task_runner.h" | 61 #include "base/single_thread_task_runner.h" |
| 61 #include "base/strings/string_util.h" | 62 #include "base/strings/string_util.h" |
| 62 #include "base/strings/stringprintf.h" | 63 #include "base/strings/stringprintf.h" |
| 63 #include "base/thread_task_runner_handle.h" | 64 #include "base/thread_task_runner_handle.h" |
| 64 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 65 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 65 #include "net/cookies/canonical_cookie.h" | 66 #include "net/cookies/canonical_cookie.h" |
| 66 #include "net/cookies/cookie_util.h" | 67 #include "net/cookies/cookie_util.h" |
| (...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 | 971 |
| 971 return std::find(cookieable_schemes_.begin(), cookieable_schemes_.end(), | 972 return std::find(cookieable_schemes_.begin(), cookieable_schemes_.end(), |
| 972 scheme) != cookieable_schemes_.end(); | 973 scheme) != cookieable_schemes_.end(); |
| 973 } | 974 } |
| 974 | 975 |
| 975 const char* const CookieMonster::kDefaultCookieableSchemes[] = {"http", "https", | 976 const char* const CookieMonster::kDefaultCookieableSchemes[] = {"http", "https", |
| 976 "ws", "wss"}; | 977 "ws", "wss"}; |
| 977 const int CookieMonster::kDefaultCookieableSchemesCount = | 978 const int CookieMonster::kDefaultCookieableSchemesCount = |
| 978 arraysize(kDefaultCookieableSchemes); | 979 arraysize(kDefaultCookieableSchemes); |
| 979 | 980 |
| 980 scoped_ptr<CookieStore::CookieChangedSubscription> | 981 std::unique_ptr<CookieStore::CookieChangedSubscription> |
| 981 CookieMonster::AddCallbackForCookie(const GURL& gurl, | 982 CookieMonster::AddCallbackForCookie(const GURL& gurl, |
| 982 const std::string& name, | 983 const std::string& name, |
| 983 const CookieChangedCallback& callback) { | 984 const CookieChangedCallback& callback) { |
| 984 DCHECK(thread_checker_.CalledOnValidThread()); | 985 DCHECK(thread_checker_.CalledOnValidThread()); |
| 985 | 986 |
| 986 std::pair<GURL, std::string> key(gurl, name); | 987 std::pair<GURL, std::string> key(gurl, name); |
| 987 if (hook_map_.count(key) == 0) | 988 if (hook_map_.count(key) == 0) |
| 988 hook_map_[key] = make_linked_ptr(new CookieChangedCallbackList()); | 989 hook_map_[key] = make_linked_ptr(new CookieChangedCallbackList()); |
| 989 return hook_map_[key]->Add( | 990 return hook_map_[key]->Add( |
| 990 base::Bind(&RunAsync, base::ThreadTaskRunnerHandle::Get(), callback)); | 991 base::Bind(&RunAsync, base::ThreadTaskRunnerHandle::Get(), callback)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1029 // TODO(mmenke): This class assumes each cookie to have a unique creation | 1030 // TODO(mmenke): This class assumes each cookie to have a unique creation |
| 1030 // time. Allowing the caller to set the creation time violates that | 1031 // time. Allowing the caller to set the creation time violates that |
| 1031 // assumption. Worth fixing? Worth noting that time changes between browser | 1032 // assumption. Worth fixing? Worth noting that time changes between browser |
| 1032 // restarts can cause the same issue. | 1033 // restarts can cause the same issue. |
| 1033 base::Time actual_creation_time = creation_time; | 1034 base::Time actual_creation_time = creation_time; |
| 1034 if (creation_time.is_null()) { | 1035 if (creation_time.is_null()) { |
| 1035 actual_creation_time = CurrentTime(); | 1036 actual_creation_time = CurrentTime(); |
| 1036 last_time_seen_ = actual_creation_time; | 1037 last_time_seen_ = actual_creation_time; |
| 1037 } | 1038 } |
| 1038 | 1039 |
| 1039 scoped_ptr<CanonicalCookie> cc(CanonicalCookie::Create( | 1040 std::unique_ptr<CanonicalCookie> cc(CanonicalCookie::Create( |
| 1040 url, name, value, domain, path, actual_creation_time, expiration_time, | 1041 url, name, value, domain, path, actual_creation_time, expiration_time, |
| 1041 secure, http_only, same_site, enforce_strict_secure, priority)); | 1042 secure, http_only, same_site, enforce_strict_secure, priority)); |
| 1042 | 1043 |
| 1043 if (!cc.get()) | 1044 if (!cc.get()) |
| 1044 return false; | 1045 return false; |
| 1045 | 1046 |
| 1046 if (!last_access_time.is_null()) | 1047 if (!last_access_time.is_null()) |
| 1047 cc->SetLastAccessDate(last_access_time); | 1048 cc->SetLastAccessDate(last_access_time); |
| 1048 | 1049 |
| 1049 CookieOptions options; | 1050 CookieOptions options; |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1711 DCHECK(thread_checker_.CalledOnValidThread()); | 1712 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1712 | 1713 |
| 1713 VLOG(kVlogSetCookies) << "SetCookie() line: " << cookie_line; | 1714 VLOG(kVlogSetCookies) << "SetCookie() line: " << cookie_line; |
| 1714 | 1715 |
| 1715 Time creation_time = creation_time_or_null; | 1716 Time creation_time = creation_time_or_null; |
| 1716 if (creation_time.is_null()) { | 1717 if (creation_time.is_null()) { |
| 1717 creation_time = CurrentTime(); | 1718 creation_time = CurrentTime(); |
| 1718 last_time_seen_ = creation_time; | 1719 last_time_seen_ = creation_time; |
| 1719 } | 1720 } |
| 1720 | 1721 |
| 1721 scoped_ptr<CanonicalCookie> cc( | 1722 std::unique_ptr<CanonicalCookie> cc( |
| 1722 CanonicalCookie::Create(url, cookie_line, creation_time, options)); | 1723 CanonicalCookie::Create(url, cookie_line, creation_time, options)); |
| 1723 | 1724 |
| 1724 if (!cc.get()) { | 1725 if (!cc.get()) { |
| 1725 VLOG(kVlogSetCookies) << "WARNING: Failed to allocate CanonicalCookie"; | 1726 VLOG(kVlogSetCookies) << "WARNING: Failed to allocate CanonicalCookie"; |
| 1726 return false; | 1727 return false; |
| 1727 } | 1728 } |
| 1728 return SetCanonicalCookie(std::move(cc), options); | 1729 return SetCanonicalCookie(std::move(cc), options); |
| 1729 } | 1730 } |
| 1730 | 1731 |
| 1731 bool CookieMonster::SetCanonicalCookie(scoped_ptr<CanonicalCookie> cc, | 1732 bool CookieMonster::SetCanonicalCookie(std::unique_ptr<CanonicalCookie> cc, |
| 1732 const CookieOptions& options) { | 1733 const CookieOptions& options) { |
| 1733 DCHECK(thread_checker_.CalledOnValidThread()); | 1734 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1734 | 1735 |
| 1735 Time creation_time = cc->CreationDate(); | 1736 Time creation_time = cc->CreationDate(); |
| 1736 const std::string key(GetKey(cc->Domain())); | 1737 const std::string key(GetKey(cc->Domain())); |
| 1737 bool already_expired = cc->IsExpired(creation_time); | 1738 bool already_expired = cc->IsExpired(creation_time); |
| 1738 | 1739 |
| 1739 if (DeleteAnyEquivalentCookie(key, *cc, options.exclude_httponly(), | 1740 if (DeleteAnyEquivalentCookie(key, *cc, options.exclude_httponly(), |
| 1740 already_expired, | 1741 already_expired, |
| 1741 options.enforce_strict_secure())) { | 1742 options.enforce_strict_secure())) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1779 return true; | 1780 return true; |
| 1780 } | 1781 } |
| 1781 | 1782 |
| 1782 bool CookieMonster::SetCanonicalCookies(const CookieList& list) { | 1783 bool CookieMonster::SetCanonicalCookies(const CookieList& list) { |
| 1783 DCHECK(thread_checker_.CalledOnValidThread()); | 1784 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1784 | 1785 |
| 1785 CookieOptions options; | 1786 CookieOptions options; |
| 1786 options.set_include_httponly(); | 1787 options.set_include_httponly(); |
| 1787 | 1788 |
| 1788 for (const auto& cookie : list) { | 1789 for (const auto& cookie : list) { |
| 1789 if (!SetCanonicalCookie(make_scoped_ptr(new CanonicalCookie(cookie)), | 1790 if (!SetCanonicalCookie(base::WrapUnique(new CanonicalCookie(cookie)), |
| 1790 options)) { | 1791 options)) { |
| 1791 return false; | 1792 return false; |
| 1792 } | 1793 } |
| 1793 } | 1794 } |
| 1794 | 1795 |
| 1795 return true; | 1796 return true; |
| 1796 } | 1797 } |
| 1797 | 1798 |
| 1798 void CookieMonster::InternalUpdateCookieAccessTime(CanonicalCookie* cc, | 1799 void CookieMonster::InternalUpdateCookieAccessTime(CanonicalCookie* cc, |
| 1799 const Time& current) { | 1800 const Time& current) { |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2331 it != hook_map_.end(); ++it) { | 2332 it != hook_map_.end(); ++it) { |
| 2332 std::pair<GURL, std::string> key = it->first; | 2333 std::pair<GURL, std::string> key = it->first; |
| 2333 if (cookie.IncludeForRequestURL(key.first, opts) && | 2334 if (cookie.IncludeForRequestURL(key.first, opts) && |
| 2334 cookie.Name() == key.second) { | 2335 cookie.Name() == key.second) { |
| 2335 it->second->Notify(cookie, removed); | 2336 it->second->Notify(cookie, removed); |
| 2336 } | 2337 } |
| 2337 } | 2338 } |
| 2338 } | 2339 } |
| 2339 | 2340 |
| 2340 } // namespace net | 2341 } // namespace net |
| OLD | NEW |