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

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: Dropping samples.json, addressing Jochen's 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
« no previous file with comments | « chrome/browser/extensions/extension_cookies_api.h ('k') | chrome/common/extensions/api/extension_api.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..5e32c0f9d815f7e13c0be7607d7c70aff1d2173f 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,14 @@ bool GetCookieFunction::RunImpl() {
}
void GetCookieFunction::GetCookieOnIOThread() {
+
jochen (gone - plz use gerrit) 2011/02/17 09:27:55 no empty line
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));
jochen (gone - plz use gerrit) 2011/02/17 09:27:55 no empty line
+ 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).
@@ -204,9 +196,17 @@ void GetCookieFunction::RespondOnUIThread() {
}
// The cookie doesn't exist; return null.
- if (it == cookie_list_.end())
+ 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 +241,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 +260,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);
}
@@ -343,6 +342,21 @@ void SetCookieFunction::SetCookieOnIOThread() {
url_, name_, value_, domain_, path_, expiration_time_,
secure_, http_only_);
+ // Pull the newly set cookie.
+ net::CookieList cookie_list =
+ extension_cookies_helpers::GetCookieListFromStore(cookie_monster, 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));
@@ -400,7 +414,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 +427,12 @@ bool RemoveCookieFunction::RunImpl() {
new RemoveCookieTask(url, name, make_scoped_refptr(store_context)));
DCHECK(rv);
+ DictionaryValue* resultDictionary = new DictionaryValue();
+ resultDictionary->SetString(keys::kNameKey, name);
+ resultDictionary->SetString(keys::kUrlKey, url.spec());
+ resultDictionary->SetString(keys::kStoreIdKey, store_id);
+ result_.reset(resultDictionary);
+
return true;
}
« no previous file with comments | « chrome/browser/extensions/extension_cookies_api.h ('k') | chrome/common/extensions/api/extension_api.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698