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 "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 base::Bind(&GetCookieFunction::GetCookieCallback, this)); | 223 base::Bind(&GetCookieFunction::GetCookieCallback, this)); |
224 } | 224 } |
225 | 225 |
226 void GetCookieFunction::GetCookieCallback(const net::CookieList& cookie_list) { | 226 void GetCookieFunction::GetCookieCallback(const net::CookieList& cookie_list) { |
227 net::CookieList::const_iterator it; | 227 net::CookieList::const_iterator it; |
228 for (it = cookie_list.begin(); it != cookie_list.end(); ++it) { | 228 for (it = cookie_list.begin(); it != cookie_list.end(); ++it) { |
229 // Return the first matching cookie. Relies on the fact that the | 229 // Return the first matching cookie. Relies on the fact that the |
230 // CookieMonster returns them in canonical order (longest path, then | 230 // CookieMonster returns them in canonical order (longest path, then |
231 // earliest creation time). | 231 // earliest creation time). |
232 if (it->Name() == name_) { | 232 if (it->Name() == name_) { |
233 result_.reset( | 233 SetSingleResult( |
234 cookies_helpers::CreateCookieValue(*it, store_id_)); | 234 cookies_helpers::CreateCookieValue(*it, store_id_)); |
235 break; | 235 break; |
236 } | 236 } |
237 } | 237 } |
238 | 238 |
239 // The cookie doesn't exist; return null. | 239 // The cookie doesn't exist; return null. |
240 if (it == cookie_list.end()) | 240 if (it == cookie_list.end()) |
241 result_.reset(Value::CreateNullValue()); | 241 SetSingleResult(Value::CreateNullValue()); |
242 | 242 |
243 bool rv = BrowserThread::PostTask( | 243 bool rv = BrowserThread::PostTask( |
244 BrowserThread::UI, FROM_HERE, | 244 BrowserThread::UI, FROM_HERE, |
245 base::Bind(&GetCookieFunction::RespondOnUIThread, this)); | 245 base::Bind(&GetCookieFunction::RespondOnUIThread, this)); |
246 DCHECK(rv); | 246 DCHECK(rv); |
247 } | 247 } |
248 | 248 |
249 void GetCookieFunction::RespondOnUIThread() { | 249 void GetCookieFunction::RespondOnUIThread() { |
250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
251 SendResponse(true); | 251 SendResponse(true); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 } | 289 } |
290 | 290 |
291 void GetAllCookiesFunction::GetAllCookiesCallback( | 291 void GetAllCookiesFunction::GetAllCookiesCallback( |
292 const net::CookieList& cookie_list) { | 292 const net::CookieList& cookie_list) { |
293 const extensions::Extension* extension = GetExtension(); | 293 const extensions::Extension* extension = GetExtension(); |
294 if (extension) { | 294 if (extension) { |
295 ListValue* matching_list = new ListValue(); | 295 ListValue* matching_list = new ListValue(); |
296 cookies_helpers::AppendMatchingCookiesToList( | 296 cookies_helpers::AppendMatchingCookiesToList( |
297 cookie_list, store_id_, url_, details_, | 297 cookie_list, store_id_, url_, details_, |
298 GetExtension(), matching_list); | 298 GetExtension(), matching_list); |
299 result_.reset(matching_list); | 299 SetSingleResult(matching_list); |
300 } | 300 } |
301 bool rv = BrowserThread::PostTask( | 301 bool rv = BrowserThread::PostTask( |
302 BrowserThread::UI, FROM_HERE, | 302 BrowserThread::UI, FROM_HERE, |
303 base::Bind(&GetAllCookiesFunction::RespondOnUIThread, this)); | 303 base::Bind(&GetAllCookiesFunction::RespondOnUIThread, this)); |
304 DCHECK(rv); | 304 DCHECK(rv); |
305 } | 305 } |
306 | 306 |
307 void GetAllCookiesFunction::RespondOnUIThread() { | 307 void GetAllCookiesFunction::RespondOnUIThread() { |
308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
309 SendResponse(true); | 309 SendResponse(true); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 base::Bind(&SetCookieFunction::PullCookieCallback, this)); | 401 base::Bind(&SetCookieFunction::PullCookieCallback, this)); |
402 } | 402 } |
403 | 403 |
404 void SetCookieFunction::PullCookieCallback(const net::CookieList& cookie_list) { | 404 void SetCookieFunction::PullCookieCallback(const net::CookieList& cookie_list) { |
405 net::CookieList::const_iterator it; | 405 net::CookieList::const_iterator it; |
406 for (it = cookie_list.begin(); it != cookie_list.end(); ++it) { | 406 for (it = cookie_list.begin(); it != cookie_list.end(); ++it) { |
407 // Return the first matching cookie. Relies on the fact that the | 407 // Return the first matching cookie. Relies on the fact that the |
408 // CookieMonster returns them in canonical order (longest path, then | 408 // CookieMonster returns them in canonical order (longest path, then |
409 // earliest creation time). | 409 // earliest creation time). |
410 if (it->Name() == name_) { | 410 if (it->Name() == name_) { |
411 result_.reset( | 411 SetSingleResult( |
412 cookies_helpers::CreateCookieValue(*it, store_id_)); | 412 cookies_helpers::CreateCookieValue(*it, store_id_)); |
413 break; | 413 break; |
414 } | 414 } |
415 } | 415 } |
416 | 416 |
417 bool rv = BrowserThread::PostTask( | 417 bool rv = BrowserThread::PostTask( |
418 BrowserThread::UI, FROM_HERE, | 418 BrowserThread::UI, FROM_HERE, |
419 base::Bind(&SetCookieFunction::RespondOnUIThread, this)); | 419 base::Bind(&SetCookieFunction::RespondOnUIThread, this)); |
420 DCHECK(rv); | 420 DCHECK(rv); |
421 } | 421 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 url_, name_, | 474 url_, name_, |
475 base::Bind(&RemoveCookieFunction::RemoveCookieCallback, this)); | 475 base::Bind(&RemoveCookieFunction::RemoveCookieCallback, this)); |
476 } | 476 } |
477 | 477 |
478 void RemoveCookieFunction::RemoveCookieCallback() { | 478 void RemoveCookieFunction::RemoveCookieCallback() { |
479 // Build the callback result | 479 // Build the callback result |
480 DictionaryValue* resultDictionary = new DictionaryValue(); | 480 DictionaryValue* resultDictionary = new DictionaryValue(); |
481 resultDictionary->SetString(keys::kNameKey, name_); | 481 resultDictionary->SetString(keys::kNameKey, name_); |
482 resultDictionary->SetString(keys::kUrlKey, url_.spec()); | 482 resultDictionary->SetString(keys::kUrlKey, url_.spec()); |
483 resultDictionary->SetString(keys::kStoreIdKey, store_id_); | 483 resultDictionary->SetString(keys::kStoreIdKey, store_id_); |
484 result_.reset(resultDictionary); | 484 SetSingleResult(resultDictionary); |
485 | 485 |
486 // Return to UI thread | 486 // Return to UI thread |
487 bool rv = BrowserThread::PostTask( | 487 bool rv = BrowserThread::PostTask( |
488 BrowserThread::UI, FROM_HERE, | 488 BrowserThread::UI, FROM_HERE, |
489 base::Bind(&RemoveCookieFunction::RespondOnUIThread, this)); | 489 base::Bind(&RemoveCookieFunction::RespondOnUIThread, this)); |
490 DCHECK(rv); | 490 DCHECK(rv); |
491 } | 491 } |
492 | 492 |
493 void RemoveCookieFunction::RespondOnUIThread() { | 493 void RemoveCookieFunction::RespondOnUIThread() { |
494 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 494 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 cookie_store_list->Append( | 529 cookie_store_list->Append( |
530 cookies_helpers::CreateCookieStoreValue( | 530 cookies_helpers::CreateCookieStoreValue( |
531 original_profile, original_tab_ids.release())); | 531 original_profile, original_tab_ids.release())); |
532 } | 532 } |
533 if (incognito_tab_ids.get() && incognito_tab_ids->GetSize() > 0 && | 533 if (incognito_tab_ids.get() && incognito_tab_ids->GetSize() > 0 && |
534 incognito_profile) { | 534 incognito_profile) { |
535 cookie_store_list->Append( | 535 cookie_store_list->Append( |
536 cookies_helpers::CreateCookieStoreValue( | 536 cookies_helpers::CreateCookieStoreValue( |
537 incognito_profile, incognito_tab_ids.release())); | 537 incognito_profile, incognito_tab_ids.release())); |
538 } | 538 } |
539 result_.reset(cookie_store_list); | 539 SetSingleResult(cookie_store_list); |
540 return true; | 540 return true; |
541 } | 541 } |
542 | 542 |
543 void GetAllCookieStoresFunction::Run() { | 543 void GetAllCookieStoresFunction::Run() { |
544 SendResponse(RunImpl()); | 544 SendResponse(RunImpl()); |
545 } | 545 } |
546 | 546 |
547 } // namespace extensions | 547 } // namespace extensions |
OLD | NEW |