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 // Implements the Chrome Extensions Cookies API. | 5 // Implements the Chrome Extensions Cookies API. |
6 | 6 |
7 #include "chrome/browser/extensions/extension_cookies_api.h" | 7 #include "chrome/browser/extensions/extension_cookies_api.h" |
8 | 8 |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/task.h" | 10 #include "base/task.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 if (context) | 138 if (context) |
139 *context = store_profile->GetRequestContext(); | 139 *context = store_profile->GetRequestContext(); |
140 if (store_id) | 140 if (store_id) |
141 *store_id = extension_cookies_helpers::GetStoreIdFromProfile(store_profile); | 141 *store_id = extension_cookies_helpers::GetStoreIdFromProfile(store_profile); |
142 | 142 |
143 return true; | 143 return true; |
144 } | 144 } |
145 | 145 |
146 GetCookieFunction::GetCookieFunction() {} | 146 GetCookieFunction::GetCookieFunction() {} |
147 | 147 |
| 148 GetCookieFunction::~GetCookieFunction() {} |
| 149 |
148 bool GetCookieFunction::RunImpl() { | 150 bool GetCookieFunction::RunImpl() { |
149 // Return false if the arguments are malformed. | 151 // Return false if the arguments are malformed. |
150 DictionaryValue* details; | 152 DictionaryValue* details; |
151 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); | 153 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); |
152 DCHECK(details); | 154 DCHECK(details); |
153 | 155 |
154 // Read/validate input parameters. | 156 // Read/validate input parameters. |
155 if (!ParseUrl(details, &url_, true)) | 157 if (!ParseUrl(details, &url_, true)) |
156 return false; | 158 return false; |
157 | 159 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 205 |
204 // The cookie doesn't exist; return null. | 206 // The cookie doesn't exist; return null. |
205 if (it == cookie_list_.end()) | 207 if (it == cookie_list_.end()) |
206 result_.reset(Value::CreateNullValue()); | 208 result_.reset(Value::CreateNullValue()); |
207 | 209 |
208 SendResponse(true); | 210 SendResponse(true); |
209 } | 211 } |
210 | 212 |
211 GetAllCookiesFunction::GetAllCookiesFunction() : details_(NULL) {} | 213 GetAllCookiesFunction::GetAllCookiesFunction() : details_(NULL) {} |
212 | 214 |
| 215 GetAllCookiesFunction::~GetAllCookiesFunction() {} |
| 216 |
213 bool GetAllCookiesFunction::RunImpl() { | 217 bool GetAllCookiesFunction::RunImpl() { |
214 // Return false if the arguments are malformed. | 218 // Return false if the arguments are malformed. |
215 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details_)); | 219 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details_)); |
216 DCHECK(details_); | 220 DCHECK(details_); |
217 | 221 |
218 // Read/validate input parameters. | 222 // Read/validate input parameters. |
219 if (details_->HasKey(keys::kUrlKey) && !ParseUrl(details_, &url_, false)) | 223 if (details_->HasKey(keys::kUrlKey) && !ParseUrl(details_, &url_, false)) |
220 return false; | 224 return false; |
221 | 225 |
222 URLRequestContextGetter* store_context = NULL; | 226 URLRequestContextGetter* store_context = NULL; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 } | 263 } |
260 SendResponse(true); | 264 SendResponse(true); |
261 } | 265 } |
262 | 266 |
263 SetCookieFunction::SetCookieFunction() | 267 SetCookieFunction::SetCookieFunction() |
264 : secure_(false), | 268 : secure_(false), |
265 http_only_(false), | 269 http_only_(false), |
266 success_(false) { | 270 success_(false) { |
267 } | 271 } |
268 | 272 |
| 273 SetCookieFunction::~SetCookieFunction() { |
| 274 } |
| 275 |
269 bool SetCookieFunction::RunImpl() { | 276 bool SetCookieFunction::RunImpl() { |
270 // Return false if the arguments are malformed. | 277 // Return false if the arguments are malformed. |
271 DictionaryValue* details; | 278 DictionaryValue* details; |
272 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); | 279 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); |
273 DCHECK(details); | 280 DCHECK(details); |
274 | 281 |
275 // Read/validate input parameters. | 282 // Read/validate input parameters. |
276 if (!ParseUrl(details, &url_, true)) | 283 if (!ParseUrl(details, &url_, true)) |
277 return false; | 284 return false; |
278 // The macros below return false if argument types are not as expected. | 285 // The macros below return false if argument types are not as expected. |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 // CookieMonster is only ever accessed on the IO thread, so any other accesses | 408 // CookieMonster is only ever accessed on the IO thread, so any other accesses |
402 // should happen after this. | 409 // should happen after this. |
403 bool rv = ChromeThread::PostTask( | 410 bool rv = ChromeThread::PostTask( |
404 ChromeThread::IO, FROM_HERE, | 411 ChromeThread::IO, FROM_HERE, |
405 new RemoveCookieTask(url, name, store_context)); | 412 new RemoveCookieTask(url, name, store_context)); |
406 DCHECK(rv); | 413 DCHECK(rv); |
407 | 414 |
408 return true; | 415 return true; |
409 } | 416 } |
410 | 417 |
| 418 void RemoveCookieFunction::Run() { |
| 419 SendResponse(RunImpl()); |
| 420 } |
| 421 |
411 bool GetAllCookieStoresFunction::RunImpl() { | 422 bool GetAllCookieStoresFunction::RunImpl() { |
412 Profile* original_profile = profile(); | 423 Profile* original_profile = profile(); |
413 DCHECK(original_profile); | 424 DCHECK(original_profile); |
414 scoped_ptr<ListValue> original_tab_ids(new ListValue()); | 425 scoped_ptr<ListValue> original_tab_ids(new ListValue()); |
415 Profile* incognito_profile = NULL; | 426 Profile* incognito_profile = NULL; |
416 scoped_ptr<ListValue> incognito_tab_ids; | 427 scoped_ptr<ListValue> incognito_tab_ids; |
417 if (include_incognito()) { | 428 if (include_incognito()) { |
418 incognito_profile = profile()->GetOffTheRecordProfile(); | 429 incognito_profile = profile()->GetOffTheRecordProfile(); |
419 if (incognito_profile) | 430 if (incognito_profile) |
420 incognito_tab_ids.reset(new ListValue()); | 431 incognito_tab_ids.reset(new ListValue()); |
(...skipping 23 matching lines...) Expand all Loading... |
444 original_profile, original_tab_ids.release())); | 455 original_profile, original_tab_ids.release())); |
445 } | 456 } |
446 if (incognito_tab_ids.get() && incognito_tab_ids->GetSize() > 0) { | 457 if (incognito_tab_ids.get() && incognito_tab_ids->GetSize() > 0) { |
447 cookie_store_list->Append( | 458 cookie_store_list->Append( |
448 extension_cookies_helpers::CreateCookieStoreValue( | 459 extension_cookies_helpers::CreateCookieStoreValue( |
449 incognito_profile, incognito_tab_ids.release())); | 460 incognito_profile, incognito_tab_ids.release())); |
450 } | 461 } |
451 result_.reset(cookie_store_list); | 462 result_.reset(cookie_store_list); |
452 return true; | 463 return true; |
453 } | 464 } |
| 465 |
| 466 void GetAllCookieStoresFunction::Run() { |
| 467 SendResponse(RunImpl()); |
| 468 } |
OLD | NEW |