Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Unified Diff: chrome/browser/extensions/extension_cookies_api.cc

Issue 6525016: Adding callbacks to `chrome.cookies.{set,remove}`. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fixing variable names, clarifying a test, and restoring accidentally deleted comments. Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..88e8daf27770465fdc82cb5e52122f15ca96ed19 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.
@@ -177,22 +177,16 @@ bool GetCookieFunction::RunImpl() {
}
void GetCookieFunction::GetCookieOnIOThread() {
+ // Start with "null" as return value
+ result_.reset(Value::CreateNullValue());
jochen (gone - plz use gerrit) 2011/02/17 08:18:26 based on your comments, shouldn't get also return
Mike West 2011/02/17 09:11:00 You're right. Though I still don't like it. :)
+
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
net::CookieStore* cookie_store = store_context_->GetCookieStore();
- cookie_list_ =
- extension_cookies_helpers::GetCookieListFromStore(cookie_store, url_);
-
- bool rv = BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- NewRunnableMethod(this, &GetCookieFunction::RespondOnUIThread));
- DCHECK(rv);
-}
-
-void GetCookieFunction::RespondOnUIThread() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ net::CookieList cookie_list =
+ extension_cookies_helpers::GetCookieListFromStore(cookie_store, url_);
net::CookieList::iterator it;
- for (it = cookie_list_.begin(); it != cookie_list_.end(); ++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).
@@ -203,10 +197,14 @@ void GetCookieFunction::RespondOnUIThread() {
}
}
- // The cookie doesn't exist; return null.
- if (it == cookie_list_.end())
- result_.reset(Value::CreateNullValue());
+ bool rv = BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ NewRunnableMethod(this, &GetCookieFunction::RespondOnUIThread));
+ DCHECK(rv);
+}
+void GetCookieFunction::RespondOnUIThread() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
SendResponse(true);
}
@@ -241,9 +239,17 @@ bool GetAllCookiesFunction::RunImpl() {
void GetAllCookiesFunction::GetAllCookiesOnIOThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
net::CookieStore* cookie_store = store_context_->GetCookieStore();
- cookie_list_ =
+ net::CookieList cookie_list =
extension_cookies_helpers::GetCookieListFromStore(cookie_store, url_);
+ const Extension* extension = GetExtension();
+ if (extension) {
+ ListValue* matching_list = new ListValue();
+ extension_cookies_helpers::AppendMatchingCookiesToList(
+ cookie_list, store_id_, url_, details_,
+ GetExtension(), matching_list);
+ result_.reset(matching_list);
+ }
bool rv = BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
NewRunnableMethod(this, &GetAllCookiesFunction::RespondOnUIThread));
@@ -252,15 +258,6 @@ void GetAllCookiesFunction::GetAllCookiesOnIOThread() {
void GetAllCookiesFunction::RespondOnUIThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
- const Extension* extension = GetExtension();
- if (extension) {
- ListValue* matching_list = new ListValue();
- extension_cookies_helpers::AppendMatchingCookiesToList(
- cookie_list_, store_id_, url_, details_,
- GetExtension(), matching_list);
- result_.reset(matching_list);
- }
SendResponse(true);
}
@@ -337,12 +334,27 @@ 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();
jochen (gone - plz use gerrit) 2011/02/17 08:18:26 cookie monster implements cookie store, so you can
Mike West 2011/02/17 09:11:00 Done.
success_ = cookie_monster->SetCookieWithDetails(
url_, name_, value_, domain_, path_, expiration_time_,
secure_, http_only_);
+ // Pull the newly set cookie.
+ net::CookieList cookie_list =
+ extension_cookies_helpers::GetCookieListFromStore(cookie_store, url_);
+ 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;
+ }
+ }
+
bool rv = BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
NewRunnableMethod(this, &SetCookieFunction::RespondOnUIThread));
@@ -355,6 +367,7 @@ void SetCookieFunction::RespondOnUIThread() {
error_ = ExtensionErrorUtils::FormatErrorMessage(
keys::kCookieSetFailedError, name_);
}
+
jochen (gone - plz use gerrit) 2011/02/17 08:18:26 no empty line
Mike West 2011/02/17 09:11:00 Done.
SendResponse(success_);
}
@@ -400,7 +413,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;
+ if (!ParseStoreContext(details, &store_context, &store_id))
return false;
DCHECK(store_context);
@@ -412,6 +426,14 @@ bool RemoveCookieFunction::RunImpl() {
new RemoveCookieTask(url, name, make_scoped_refptr(store_context)));
DCHECK(rv);
+ DictionaryValue* resultDictionary = new DictionaryValue();
+ std::string url_string;
jochen (gone - plz use gerrit) 2011/02/17 08:18:26 Then use url.spec() instead
Mike West 2011/02/17 09:11:00 Done.
+ details->GetString(keys::kUrlKey, &url_string);
+ resultDictionary->SetString(keys::kNameKey, name);
+ resultDictionary->SetString(keys::kUrlKey, url_string);
+ resultDictionary->SetString(keys::kStoreIdKey, store_id);
+ result_.reset(resultDictionary);
+
return true;
}

Powered by Google App Engine
This is Rietveld 408576698