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