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 // Implements the Chrome Extensions Cookies API. | 5 // Implements the Chrome Extensions Cookies API. |
6 | 6 |
7 #include "chrome/browser/extensions/api/cookies/cookies_api.h" | 7 #include "chrome/browser/extensions/api/cookies/cookies_api.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 136 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
137 dict->SetBoolean(keys::kRemovedKey, details->removed); | 137 dict->SetBoolean(keys::kRemovedKey, details->removed); |
138 | 138 |
139 cookies::Cookie cookie = cookies_helpers::CreateCookie( | 139 cookies::Cookie cookie = cookies_helpers::CreateCookie( |
140 *details->cookie, cookies_helpers::GetStoreIdFromProfile(profile)); | 140 *details->cookie, cookies_helpers::GetStoreIdFromProfile(profile)); |
141 dict->Set(keys::kCookieKey, cookie.ToValue()); | 141 dict->Set(keys::kCookieKey, cookie.ToValue()); |
142 | 142 |
143 // Map the internal cause to an external string. | 143 // Map the internal cause to an external string. |
144 std::string cause; | 144 std::string cause; |
145 switch (details->cause) { | 145 switch (details->cause) { |
146 case net::CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT: | 146 // Report an inserted cookie as an "explicit" change cause. All other causes |
| 147 // only make sense for deletions. |
| 148 case net::CookieStore::ChangeCause::INSERTED: |
| 149 case net::CookieStore::ChangeCause::EXPLICIT: |
147 cause = keys::kExplicitChangeCause; | 150 cause = keys::kExplicitChangeCause; |
148 break; | 151 break; |
149 | 152 |
150 case net::CookieMonsterDelegate::CHANGE_COOKIE_OVERWRITE: | 153 case net::CookieStore::ChangeCause::OVERWRITE: |
151 cause = keys::kOverwriteChangeCause; | 154 cause = keys::kOverwriteChangeCause; |
152 break; | 155 break; |
153 | 156 |
154 case net::CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED: | 157 case net::CookieStore::ChangeCause::EXPIRED: |
155 cause = keys::kExpiredChangeCause; | 158 cause = keys::kExpiredChangeCause; |
156 break; | 159 break; |
157 | 160 |
158 case net::CookieMonsterDelegate::CHANGE_COOKIE_EVICTED: | 161 case net::CookieStore::ChangeCause::EVICTED: |
159 cause = keys::kEvictedChangeCause; | 162 cause = keys::kEvictedChangeCause; |
160 break; | 163 break; |
161 | 164 |
162 case net::CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED_OVERWRITE: | 165 case net::CookieStore::ChangeCause::EXPIRED_OVERWRITE: |
163 cause = keys::kExpiredOverwriteChangeCause; | 166 cause = keys::kExpiredOverwriteChangeCause; |
164 break; | 167 break; |
165 | 168 |
166 default: | 169 case net::CookieStore::ChangeCause::UNKNOWN_DELETION: |
167 NOTREACHED(); | 170 NOTREACHED(); |
168 } | 171 } |
169 dict->SetString(keys::kCauseKey, cause); | 172 dict->SetString(keys::kCauseKey, cause); |
170 | 173 |
171 args->Append(std::move(dict)); | 174 args->Append(std::move(dict)); |
172 | 175 |
173 GURL cookie_domain = | 176 GURL cookie_domain = |
174 cookies_helpers::GetURLFromCanonicalCookie(*details->cookie); | 177 cookies_helpers::GetURLFromCanonicalCookie(*details->cookie); |
175 DispatchEvent(profile, events::COOKIES_ON_CHANGED, | 178 DispatchEvent(profile, events::COOKIES_ON_CHANGED, |
176 cookies::OnChanged::kEventName, std::move(args), cookie_domain); | 179 cookies::OnChanged::kEventName, std::move(args), cookie_domain); |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 BrowserContextKeyedAPIFactory<CookiesAPI>* CookiesAPI::GetFactoryInstance() { | 588 BrowserContextKeyedAPIFactory<CookiesAPI>* CookiesAPI::GetFactoryInstance() { |
586 return g_factory.Pointer(); | 589 return g_factory.Pointer(); |
587 } | 590 } |
588 | 591 |
589 void CookiesAPI::OnListenerAdded(const EventListenerInfo& details) { | 592 void CookiesAPI::OnListenerAdded(const EventListenerInfo& details) { |
590 cookies_event_router_.reset(new CookiesEventRouter(browser_context_)); | 593 cookies_event_router_.reset(new CookiesEventRouter(browser_context_)); |
591 EventRouter::Get(browser_context_)->UnregisterObserver(this); | 594 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
592 } | 595 } |
593 | 596 |
594 } // namespace extensions | 597 } // namespace extensions |
OLD | NEW |