OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/common/cookie_service_impl.h" |
| 6 |
| 7 #include "net/cookies/canonical_cookie.h" |
| 8 #include "net/cookies/cookie_constants.h" |
| 9 #include "net/cookies/cookie_options.h" |
| 10 #include "net/cookies/cookie_store.h" |
| 11 #include "url/gurl.h" |
| 12 |
| 13 // Class to wrap a CookieDeletionFilterPtr and provide a predicate for |
| 14 // use by DeleteAllCreatedBetweenWithPredicateAsync. |
| 15 class PredicateWrapper { |
| 16 public: |
| 17 // TODO(rdsmith): Convert vectors into sets for faster processing. |
| 18 // TODO(rdsmith): Initialize booleans, similarly. |
| 19 PredicateWrapper(content::mojom::CookieDeletionFilterPtr filter) |
| 20 : filter_(std::move(filter)) {} |
| 21 |
| 22 bool Predicate(const net::CanonicalCookie& cookie) { |
| 23 // Ignore begin/end times; they're handled by method args. |
| 24 if (filter_->domain_blacklist.has_value()) { |
| 25 std::vector<std::string>& blacklist_array( |
| 26 filter_->domain_blacklist.value()); |
| 27 if (std::find(std::begin(blacklist_array), std::end(blacklist_array), |
| 28 cookie.Domain()) != std::end(blacklist_array)) { |
| 29 return true; |
| 30 } |
| 31 } |
| 32 |
| 33 if (filter_->domain_whitelist.has_value()) { |
| 34 std::vector<std::string>& whitelist_array( |
| 35 filter_->domain_whitelist.value()); |
| 36 if (std::find(std::begin(whitelist_array), std::end(whitelist_array), |
| 37 cookie.Domain()) == std::end(whitelist_array)) { |
| 38 return true; |
| 39 } |
| 40 } |
| 41 |
| 42 if ((filter_->session_control == |
| 43 content::mojom::CookieDeletionSessionControl::SESSION) && |
| 44 !cookie.IsPersistent()) |
| 45 return true; |
| 46 |
| 47 if (filter_->session_control == |
| 48 content::mojom::CookieDeletionSessionControl::PERSISTENT && |
| 49 cookie.IsPersistent()) |
| 50 return true; |
| 51 |
| 52 return false; |
| 53 } |
| 54 |
| 55 private: |
| 56 content::mojom::CookieDeletionFilterPtr filter_; |
| 57 DISALLOW_COPY_AND_ASSIGN(PredicateWrapper); |
| 58 }; |
| 59 |
| 60 namespace content { |
| 61 |
| 62 CookieServiceImpl::CookieServiceImpl(net::CookieStore* cookie_store) |
| 63 : cookie_store_(cookie_store) {} |
| 64 |
| 65 CookieServiceImpl::~CookieServiceImpl() {} |
| 66 |
| 67 void CookieServiceImpl::AddRequest( |
| 68 content::mojom::CookieServiceRequest request) { |
| 69 bindings_.AddBinding(this, std::move(request)); |
| 70 } |
| 71 |
| 72 void CookieServiceImpl::GetAllCookies(GetAllCookiesCallback callback) { |
| 73 cookie_store_->GetAllCookiesAsync(std::move(callback)); |
| 74 } |
| 75 |
| 76 void CookieServiceImpl::GetCookieList(const GURL& url, |
| 77 const net::CookieOptions& cookie_options, |
| 78 GetCookieListCallback callback) { |
| 79 cookie_store_->GetCookieListWithOptionsAsync(url, cookie_options, |
| 80 std::move(callback)); |
| 81 } |
| 82 |
| 83 void CookieServiceImpl::SetCanonicalCookie( |
| 84 const net::CanonicalCookie& cookie, |
| 85 bool secure_source, |
| 86 bool modify_http_only, |
| 87 SetCanonicalCookieCallback callback) { |
| 88 cookie_store_->SetCanonicalCookieAsync( |
| 89 base::MakeUnique<net::CanonicalCookie>(cookie), secure_source, |
| 90 modify_http_only, std::move(callback)); |
| 91 } |
| 92 |
| 93 void CookieServiceImpl::DeleteCookies( |
| 94 content::mojom::CookieDeletionFilterPtr filter, |
| 95 DeleteCookiesCallback callback) { |
| 96 base::Time start_time; |
| 97 base::Time end_time; |
| 98 |
| 99 if (filter->created_after_time.has_value()) |
| 100 end_time = filter->created_after_time.value(); |
| 101 |
| 102 if (filter->created_before_time.has_value()) |
| 103 start_time = filter->created_before_time.value(); |
| 104 |
| 105 cookie_store_->DeleteAllCreatedBetweenWithPredicateAsync( |
| 106 start_time, end_time, |
| 107 base::Bind(&PredicateWrapper::Predicate, |
| 108 base::MakeUnique<PredicateWrapper>(std::move(filter))), |
| 109 std::move(callback)); |
| 110 } |
| 111 |
| 112 void CookieServiceImpl::RequestNotification( |
| 113 const GURL& url, |
| 114 const std::string& name, |
| 115 mojom::CookieChangeNotificationRequest notification_interface, |
| 116 RequestNotificationCallback callback) {} |
| 117 |
| 118 void CookieServiceImpl::CloneInterface( |
| 119 mojom::CookieServiceRequest new_interface) { |
| 120 AddRequest(std::move(new_interface)); |
| 121 } |
| 122 |
| 123 } // namespace content |
OLD | NEW |