Chromium Code Reviews| Index: chrome/browser/extensions/extension_cookies_api.cc |
| diff --git a/chrome/browser/extensions/extension_cookies_api.cc b/chrome/browser/extensions/extension_cookies_api.cc |
| index 04d5600815c345b951a31555c29150db7b769e77..190670d87038c3ec3dbeb7b35435a54450c3bbc8 100644 |
| --- a/chrome/browser/extensions/extension_cookies_api.cc |
| +++ b/chrome/browser/extensions/extension_cookies_api.cc |
| @@ -1,4 +1,4 @@ |
| -// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| @@ -274,6 +274,10 @@ SetCookieFunction::~SetCookieFunction() { |
| } |
| bool SetCookieFunction::RunImpl() { |
| + // Start with "null" being returned to callback, in case things fail in |
|
Aaron Boodman
2011/02/15 22:26:04
There is no need to explicitly set the result to n
|
| + // this synchronous bit of the workflow. |
| + result_.reset(Value::CreateNullValue()); |
| + |
| // Return false if the arguments are malformed. |
| DictionaryValue* details; |
| EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); |
| @@ -337,12 +341,16 @@ bool SetCookieFunction::RunImpl() { |
| void SetCookieFunction::SetCookieOnIOThread() { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| - net::CookieMonster* cookie_monster = |
| - store_context_->GetCookieStore()->GetCookieMonster(); |
| + net::CookieStore* cookie_store = store_context_->GetCookieStore(); |
| + net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster(); |
| success_ = cookie_monster->SetCookieWithDetails( |
| url_, name_, value_, domain_, path_, expiration_time_, |
| secure_, http_only_); |
| + // Pull the newly set cookie. |
| + cookie_list_ = |
| + extension_cookies_helpers::GetCookieListFromStore(cookie_store, url_); |
| + |
| bool rv = BrowserThread::PostTask( |
| BrowserThread::UI, FROM_HERE, |
| NewRunnableMethod(this, &SetCookieFunction::RespondOnUIThread)); |
| @@ -354,7 +362,20 @@ void SetCookieFunction::RespondOnUIThread() { |
| if (!success_) { |
| error_ = ExtensionErrorUtils::FormatErrorMessage( |
| keys::kCookieSetFailedError, name_); |
| + } else { |
| + net::CookieList::iterator it; |
| + for (it = cookie_list_.begin(); it != cookie_list_.end(); ++it) { |
| + // Return the first matching cookie. Relies on the fact that the |
| + // CookieMonster returns them in canonical order (longest path, then |
| + // earliest creation time). |
| + if (it->Name() == name_) { |
| + result_.reset( |
| + extension_cookies_helpers::CreateCookieValue(*it, store_id_)); |
| + break; |
| + } |
| + } |
| } |
| + |
| SendResponse(success_); |
| } |
| @@ -385,6 +406,10 @@ class RemoveCookieTask : public Task { |
| } // namespace |
| bool RemoveCookieFunction::RunImpl() { |
| + // Start with "null" being returned to callback, in case things fail in |
| + // this syncronous bit of the workflow. |
| + result_.reset(Value::CreateNullValue()); |
| + |
| // Return false if the arguments are malformed. |
| DictionaryValue* details; |
| EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); |
| @@ -400,7 +425,8 @@ bool RemoveCookieFunction::RunImpl() { |
| EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kNameKey, &name)); |
| URLRequestContextGetter* store_context = NULL; |
| - if (!ParseStoreContext(details, &store_context, NULL)) |
| + std::string store_id_string; |
| + if (!ParseStoreContext(details, &store_context, &store_id_string)) |
| return false; |
| DCHECK(store_context); |
| @@ -412,6 +438,14 @@ bool RemoveCookieFunction::RunImpl() { |
| new RemoveCookieTask(url, name, make_scoped_refptr(store_context))); |
| DCHECK(rv); |
| + DictionaryValue* resultDictionary = new DictionaryValue(); |
| + std::string url_string; |
| + details->GetString(keys::kUrlKey, &url_string); |
| + resultDictionary->SetString(keys::kNameKey, name); |
| + resultDictionary->SetString(keys::kUrlKey, url_string); |
| + resultDictionary->SetString(keys::kStoreIdKey, store_id_string); |
| + result_.reset(resultDictionary); |
| + |
| return true; |
| } |