summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-17 09:46:07 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-17 09:46:07 +0000
commit71c94e1056f1219b10746d7a189d4fe61e4ea272 (patch)
treeab69719d2c9829e148558efa99bf276d02cb7cf6 /chrome
parentf4f2f518ac6af432660b65554ee8edf161156030 (diff)
downloadchromium_src-71c94e1056f1219b10746d7a189d4fe61e4ea272.zip
chromium_src-71c94e1056f1219b10746d7a189d4fe61e4ea272.tar.gz
chromium_src-71c94e1056f1219b10746d7a189d4fe61e4ea272.tar.bz2
Adding callbacks to `chrome.cookies.{set,remove}`.
Currently, neither `.set` nor `.remove` give the user the ability to take action after the asynchronous cookie monster does its thing in the background. One can listen for events, but can't distinguish between events generated from one's own code, and events generated through normal interaction with the web. This makes infinite loops much easier to write than they should be. Callbacks make that class of problem simpler to deal with. BUG=70102 TEST=Check that `.set` and `.remove` callbacks are triggered. Review URL: http://codereview.chromium.org/6525016 Patch from Mike West <mkwst@chromium.org>. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75242 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/extensions/extension_cookies_api.cc69
-rw-r--r--chrome/browser/extensions/extension_cookies_api.h5
-rw-r--r--chrome/common/extensions/api/extension_api.json28
-rw-r--r--chrome/common/extensions/docs/cookies.html493
-rw-r--r--chrome/test/data/extensions/api_test/cookies/api/tab.html86
5 files changed, 643 insertions, 38 deletions
diff --git a/chrome/browser/extensions/extension_cookies_api.cc b/chrome/browser/extensions/extension_cookies_api.cc
index 04d5600..22b29da 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.
@@ -179,20 +179,10 @@ bool GetCookieFunction::RunImpl() {
void GetCookieFunction::GetCookieOnIOThread() {
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_);
-
- bool rv = BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- NewRunnableMethod(this, &GetCookieFunction::RespondOnUIThread));
- DCHECK(rv);
-}
-
-void GetCookieFunction::RespondOnUIThread() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
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 +194,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 +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);
}
@@ -343,6 +340,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 +412,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 +425,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;
}
diff --git a/chrome/browser/extensions/extension_cookies_api.h b/chrome/browser/extensions/extension_cookies_api.h
index dc81731..4f2c97b 100644
--- a/chrome/browser/extensions/extension_cookies_api.h
+++ b/chrome/browser/extensions/extension_cookies_api.h
@@ -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.
@@ -106,7 +106,6 @@ class GetCookieFunction : public CookiesFunction {
GURL url_;
std::string store_id_;
scoped_refptr<URLRequestContextGetter> store_context_;
- net::CookieList cookie_list_;
};
// Implements the cookies.getAll() extension function.
@@ -125,7 +124,6 @@ class GetAllCookiesFunction : public CookiesFunction {
GURL url_;
std::string store_id_;
scoped_refptr<URLRequestContextGetter> store_context_;
- net::CookieList cookie_list_;
};
// Implements the cookies.set() extension function.
@@ -149,6 +147,7 @@ class SetCookieFunction : public CookiesFunction {
bool http_only_;
base::Time expiration_time_;
bool success_;
+ std::string store_id_;
scoped_refptr<URLRequestContextGetter> store_context_;
};
diff --git a/chrome/common/extensions/api/extension_api.json b/chrome/common/extensions/api/extension_api.json
index b5f19e0b..a8ef0e1 100644
--- a/chrome/common/extensions/api/extension_api.json
+++ b/chrome/common/extensions/api/extension_api.json
@@ -3186,6 +3186,16 @@
"expirationDate": {"type": "number", "optional": true, "description": "The expiration date of the cookie as the number of seconds since the UNIX epoch. If omitted, the cookie becomes a session cookie."},
"storeId": {"type": "string", "optional": true, "description": "The ID of the cookie store in which to set the cookie. By default, the cookie is set in the current execution context's cookie store."}
}
+ },
+ {
+ "type": "function",
+ "name": "callback",
+ "optional": true,
+ "parameters": [
+ {
+ "name": "cookie", "$ref": "Cookie", "optional": true, "description": "Contains details about the cookie that's been set. If setting failed for any reason, this will be \"null\", and \"chrome.extension.lastError\" will be set."
+ }
+ ]
}
]
},
@@ -3203,6 +3213,24 @@
"name": {"type": "string", "description": "The name of the cookie to remove."},
"storeId": {"type": "string", "optional": true, "description": "The ID of the cookie store to look in for the cookie. If unspecified, the cookie is looked for by default in the current execution context's cookie store."}
}
+ },
+ {
+ "type": "function",
+ "name": "callback",
+ "optional": true,
+ "parameters": [
+ {
+ "name": "details",
+ "type": "object",
+ "description": "Contains details about the cookie that's been removed. If removal failed for any reason, this will be \"null\", and \"chrome.extension.lastError\" will be set.",
+ "optional": true,
+ "properties": {
+ "url": {"type": "string", "description": "The URL associated with the cookie that's been removed."},
+ "name": {"type": "string", "description": "The name of the cookie that's been removed."},
+ "storeId": {"type": "string", "description": "The ID of the cookie store from which the cookie was removed."}
+ }
+ }
+ ]
}
]
},
diff --git a/chrome/common/extensions/docs/cookies.html b/chrome/common/extensions/docs/cookies.html
index 247b976..14c8cf6 100644
--- a/chrome/common/extensions/docs/cookies.html
+++ b/chrome/common/extensions/docs/cookies.html
@@ -1824,7 +1824,8 @@ see <a href="samples.html">Samples</a>.
<div class="summary"><span style="display: none; ">void</span>
<!-- Note: intentionally longer 80 columns -->
<span>chrome.cookies.remove</span>(<span class="null"><span style="display: none; ">, </span><span>object</span>
- <var><span>details</span></var></span>)</div>
+ <var><span>details</span></var></span><span class="optional"><span>, </span><span>function</span>
+ <var><span>callback</span></var></span>)</div>
<div class="description">
<p class="todo" style="display: none; ">Undocumented.</p>
@@ -2102,6 +2103,76 @@ see <a href="samples.html">Samples</a>.
</dd>
</div>
+ </div><div>
+ <div>
+ <dt>
+ <var>callback</var>
+ <em>
+
+ <!-- TYPE -->
+ <div style="display:inline">
+ (
+ <span class="optional">optional</span>
+ <span class="enum" style="display: none; ">enumerated</span>
+ <span id="typeTemplate">
+ <span style="display: none; ">
+ <a> Type</a>
+ </span>
+ <span>
+ <span style="display: none; ">
+ array of <span><span></span></span>
+ </span>
+ <span>function</span>
+ <span style="display: none; "></span>
+ </span>
+ </span>
+ )
+ </div>
+
+ </em>
+ </dt>
+ <dd class="todo">
+ Undocumented.
+ </dd>
+ <dd style="display: none; ">
+ Description of this parameter from the json schema.
+ </dd>
+ <dd style="display: none; ">
+ This parameter was added in version
+ <b><span></span></b>.
+ You must omit this parameter in earlier versions,
+ and you may omit it in any version. If you require this
+ parameter, the manifest key
+ <a href="manifest.html#minimum_chrome_version">minimum_chrome_version</a>
+ can ensure that your extension won't be run in an earlier browser version.
+ </dd>
+
+ <!-- OBJECT PROPERTIES -->
+ <dd style="display: none; ">
+ <dl>
+ <div>
+ <div>
+ </div>
+ </div>
+ </dl>
+ </dd>
+
+ <!-- OBJECT METHODS -->
+ <dd style="display: none; ">
+ <div></div>
+ </dd>
+
+ <!-- OBJECT EVENT FIELDS -->
+ <dd style="display: none; ">
+ <div></div>
+ </dd>
+
+ <!-- FUNCTION PARAMETERS -->
+ <dd style="display: none; ">
+ <div></div>
+ </dd>
+
+ </div>
</div>
</dl>
@@ -2115,10 +2186,10 @@ see <a href="samples.html">Samples</a>.
</dl>
<!-- CALLBACK -->
- <div style="display: none; ">
+ <div>
<div>
<h4>Callback function</h4>
- <p>
+ <p style="display: none; ">
The callback <em>parameter</em> should specify a function
that looks like this:
</p>
@@ -2128,11 +2199,277 @@ see <a href="samples.html">Samples</a>.
</p>
<!-- Note: intentionally longer 80 columns -->
- <pre>function(<span>Type param1, Type param2</span>) <span class="subdued">{...}</span>;</pre>
+ <pre>function(<span>object details</span>) <span class="subdued">{...}</span>;</pre>
<dl>
<div>
<div>
- </div>
+ <dt>
+ <var>details</var>
+ <em>
+
+ <!-- TYPE -->
+ <div style="display:inline">
+ (
+ <span class="optional">optional</span>
+ <span class="enum" style="display: none; ">enumerated</span>
+ <span id="typeTemplate">
+ <span style="display: none; ">
+ <a> Type</a>
+ </span>
+ <span>
+ <span style="display: none; ">
+ array of <span><span></span></span>
+ </span>
+ <span>object</span>
+ <span style="display: none; "></span>
+ </span>
+ </span>
+ )
+ </div>
+
+ </em>
+ </dt>
+ <dd class="todo" style="display: none; ">
+ Undocumented.
+ </dd>
+ <dd>Contains details about the cookie that's been removed. If removal failed for any reason, this will be "null", and "chrome.extension.lastError" will be set.</dd>
+ <dd style="display: none; ">
+ This parameter was added in version
+ <b><span></span></b>.
+ You must omit this parameter in earlier versions,
+ and you may omit it in any version. If you require this
+ parameter, the manifest key
+ <a href="manifest.html#minimum_chrome_version">minimum_chrome_version</a>
+ can ensure that your extension won't be run in an earlier browser version.
+ </dd>
+
+ <!-- OBJECT PROPERTIES -->
+ <dd>
+ <dl>
+ <div>
+ <div>
+ <dt>
+ <var>url</var>
+ <em>
+
+ <!-- TYPE -->
+ <div style="display:inline">
+ (
+ <span class="optional" style="display: none; ">optional</span>
+ <span class="enum" style="display: none; ">enumerated</span>
+ <span id="typeTemplate">
+ <span style="display: none; ">
+ <a> Type</a>
+ </span>
+ <span>
+ <span style="display: none; ">
+ array of <span><span></span></span>
+ </span>
+ <span>string</span>
+ <span style="display: none; "></span>
+ </span>
+ </span>
+ )
+ </div>
+
+ </em>
+ </dt>
+ <dd class="todo" style="display: none; ">
+ Undocumented.
+ </dd>
+ <dd>The URL associated with the cookie that's been removed.</dd>
+ <dd style="display: none; ">
+ This parameter was added in version
+ <b><span></span></b>.
+ You must omit this parameter in earlier versions,
+ and you may omit it in any version. If you require this
+ parameter, the manifest key
+ <a href="manifest.html#minimum_chrome_version">minimum_chrome_version</a>
+ can ensure that your extension won't be run in an earlier browser version.
+ </dd>
+
+ <!-- OBJECT PROPERTIES -->
+ <dd style="display: none; ">
+ <dl>
+ <div>
+ <div>
+ </div>
+ </div>
+ </dl>
+ </dd>
+
+ <!-- OBJECT METHODS -->
+ <dd style="display: none; ">
+ <div></div>
+ </dd>
+
+ <!-- OBJECT EVENT FIELDS -->
+ <dd style="display: none; ">
+ <div></div>
+ </dd>
+
+ <!-- FUNCTION PARAMETERS -->
+ <dd style="display: none; ">
+ <div></div>
+ </dd>
+
+ </div>
+ </div><div>
+ <div>
+ <dt>
+ <var>name</var>
+ <em>
+
+ <!-- TYPE -->
+ <div style="display:inline">
+ (
+ <span class="optional" style="display: none; ">optional</span>
+ <span class="enum" style="display: none; ">enumerated</span>
+ <span id="typeTemplate">
+ <span style="display: none; ">
+ <a> Type</a>
+ </span>
+ <span>
+ <span style="display: none; ">
+ array of <span><span></span></span>
+ </span>
+ <span>string</span>
+ <span style="display: none; "></span>
+ </span>
+ </span>
+ )
+ </div>
+
+ </em>
+ </dt>
+ <dd class="todo" style="display: none; ">
+ Undocumented.
+ </dd>
+ <dd>The name of the cookie that's been removed.</dd>
+ <dd style="display: none; ">
+ This parameter was added in version
+ <b><span></span></b>.
+ You must omit this parameter in earlier versions,
+ and you may omit it in any version. If you require this
+ parameter, the manifest key
+ <a href="manifest.html#minimum_chrome_version">minimum_chrome_version</a>
+ can ensure that your extension won't be run in an earlier browser version.
+ </dd>
+
+ <!-- OBJECT PROPERTIES -->
+ <dd style="display: none; ">
+ <dl>
+ <div>
+ <div>
+ </div>
+ </div>
+ </dl>
+ </dd>
+
+ <!-- OBJECT METHODS -->
+ <dd style="display: none; ">
+ <div></div>
+ </dd>
+
+ <!-- OBJECT EVENT FIELDS -->
+ <dd style="display: none; ">
+ <div></div>
+ </dd>
+
+ <!-- FUNCTION PARAMETERS -->
+ <dd style="display: none; ">
+ <div></div>
+ </dd>
+
+ </div>
+ </div><div>
+ <div>
+ <dt>
+ <var>storeId</var>
+ <em>
+
+ <!-- TYPE -->
+ <div style="display:inline">
+ (
+ <span class="optional" style="display: none; ">optional</span>
+ <span class="enum" style="display: none; ">enumerated</span>
+ <span id="typeTemplate">
+ <span style="display: none; ">
+ <a> Type</a>
+ </span>
+ <span>
+ <span style="display: none; ">
+ array of <span><span></span></span>
+ </span>
+ <span>string</span>
+ <span style="display: none; "></span>
+ </span>
+ </span>
+ )
+ </div>
+
+ </em>
+ </dt>
+ <dd class="todo" style="display: none; ">
+ Undocumented.
+ </dd>
+ <dd>The ID of the cookie store from which the cookie was removed.</dd>
+ <dd style="display: none; ">
+ This parameter was added in version
+ <b><span></span></b>.
+ You must omit this parameter in earlier versions,
+ and you may omit it in any version. If you require this
+ parameter, the manifest key
+ <a href="manifest.html#minimum_chrome_version">minimum_chrome_version</a>
+ can ensure that your extension won't be run in an earlier browser version.
+ </dd>
+
+ <!-- OBJECT PROPERTIES -->
+ <dd style="display: none; ">
+ <dl>
+ <div>
+ <div>
+ </div>
+ </div>
+ </dl>
+ </dd>
+
+ <!-- OBJECT METHODS -->
+ <dd style="display: none; ">
+ <div></div>
+ </dd>
+
+ <!-- OBJECT EVENT FIELDS -->
+ <dd style="display: none; ">
+ <div></div>
+ </dd>
+
+ <!-- FUNCTION PARAMETERS -->
+ <dd style="display: none; ">
+ <div></div>
+ </dd>
+
+ </div>
+ </div>
+ </dl>
+ </dd>
+
+ <!-- OBJECT METHODS -->
+ <dd style="display: none; ">
+ <div></div>
+ </dd>
+
+ <!-- OBJECT EVENT FIELDS -->
+ <dd style="display: none; ">
+ <div></div>
+ </dd>
+
+ <!-- FUNCTION PARAMETERS -->
+ <dd style="display: none; ">
+ <div></div>
+ </dd>
+
+ </div>
</div>
</dl>
</div>
@@ -2154,7 +2491,8 @@ see <a href="samples.html">Samples</a>.
<div class="summary"><span style="display: none; ">void</span>
<!-- Note: intentionally longer 80 columns -->
<span>chrome.cookies.set</span>(<span class="null"><span style="display: none; ">, </span><span>object</span>
- <var><span>details</span></var></span>)</div>
+ <var><span>details</span></var></span><span class="optional"><span>, </span><span>function</span>
+ <var><span>callback</span></var></span>)</div>
<div class="description">
<p class="todo" style="display: none; ">Undocumented.</p>
@@ -2840,6 +3178,76 @@ see <a href="samples.html">Samples</a>.
</dd>
</div>
+ </div><div>
+ <div>
+ <dt>
+ <var>callback</var>
+ <em>
+
+ <!-- TYPE -->
+ <div style="display:inline">
+ (
+ <span class="optional">optional</span>
+ <span class="enum" style="display: none; ">enumerated</span>
+ <span id="typeTemplate">
+ <span style="display: none; ">
+ <a> Type</a>
+ </span>
+ <span>
+ <span style="display: none; ">
+ array of <span><span></span></span>
+ </span>
+ <span>function</span>
+ <span style="display: none; "></span>
+ </span>
+ </span>
+ )
+ </div>
+
+ </em>
+ </dt>
+ <dd class="todo">
+ Undocumented.
+ </dd>
+ <dd style="display: none; ">
+ Description of this parameter from the json schema.
+ </dd>
+ <dd style="display: none; ">
+ This parameter was added in version
+ <b><span></span></b>.
+ You must omit this parameter in earlier versions,
+ and you may omit it in any version. If you require this
+ parameter, the manifest key
+ <a href="manifest.html#minimum_chrome_version">minimum_chrome_version</a>
+ can ensure that your extension won't be run in an earlier browser version.
+ </dd>
+
+ <!-- OBJECT PROPERTIES -->
+ <dd style="display: none; ">
+ <dl>
+ <div>
+ <div>
+ </div>
+ </div>
+ </dl>
+ </dd>
+
+ <!-- OBJECT METHODS -->
+ <dd style="display: none; ">
+ <div></div>
+ </dd>
+
+ <!-- OBJECT EVENT FIELDS -->
+ <dd style="display: none; ">
+ <div></div>
+ </dd>
+
+ <!-- FUNCTION PARAMETERS -->
+ <dd style="display: none; ">
+ <div></div>
+ </dd>
+
+ </div>
</div>
</dl>
@@ -2853,10 +3261,10 @@ see <a href="samples.html">Samples</a>.
</dl>
<!-- CALLBACK -->
- <div style="display: none; ">
+ <div>
<div>
<h4>Callback function</h4>
- <p>
+ <p style="display: none; ">
The callback <em>parameter</em> should specify a function
that looks like this:
</p>
@@ -2866,11 +3274,76 @@ see <a href="samples.html">Samples</a>.
</p>
<!-- Note: intentionally longer 80 columns -->
- <pre>function(<span>Type param1, Type param2</span>) <span class="subdued">{...}</span>;</pre>
+ <pre>function(<span>Cookie cookie</span>) <span class="subdued">{...}</span>;</pre>
<dl>
<div>
<div>
- </div>
+ <dt>
+ <var>cookie</var>
+ <em>
+
+ <!-- TYPE -->
+ <div style="display:inline">
+ (
+ <span class="optional">optional</span>
+ <span class="enum" style="display: none; ">enumerated</span>
+ <span id="typeTemplate">
+ <span>
+ <a href="cookies.html#type-Cookie">Cookie</a>
+ </span>
+ <span style="display: none; ">
+ <span>
+ array of <span><span></span></span>
+ </span>
+ <span>paramType</span>
+ <span></span>
+ </span>
+ </span>
+ )
+ </div>
+
+ </em>
+ </dt>
+ <dd class="todo" style="display: none; ">
+ Undocumented.
+ </dd>
+ <dd>Contains details about the cookie that's been set. If setting failed for any reason, this will be "null", and "chrome.extension.lastError" will be set.</dd>
+ <dd style="display: none; ">
+ This parameter was added in version
+ <b><span></span></b>.
+ You must omit this parameter in earlier versions,
+ and you may omit it in any version. If you require this
+ parameter, the manifest key
+ <a href="manifest.html#minimum_chrome_version">minimum_chrome_version</a>
+ can ensure that your extension won't be run in an earlier browser version.
+ </dd>
+
+ <!-- OBJECT PROPERTIES -->
+ <dd style="display: none; ">
+ <dl>
+ <div>
+ <div>
+ </div>
+ </div>
+ </dl>
+ </dd>
+
+ <!-- OBJECT METHODS -->
+ <dd style="display: none; ">
+ <div></div>
+ </dd>
+
+ <!-- OBJECT EVENT FIELDS -->
+ <dd style="display: none; ">
+ <div></div>
+ </dd>
+
+ <!-- FUNCTION PARAMETERS -->
+ <dd style="display: none; ">
+ <div></div>
+ </dd>
+
+ </div>
</div>
</dl>
</div>
diff --git a/chrome/test/data/extensions/api_test/cookies/api/tab.html b/chrome/test/data/extensions/api_test/cookies/api/tab.html
index 9a85056..6427bb1 100644
--- a/chrome/test/data/extensions/api_test/cookies/api/tab.html
+++ b/chrome/test/data/extensions/api_test/cookies/api/tab.html
@@ -62,6 +62,10 @@ function expectNullCookie(cookie) {
chrome.test.assertEq(null, cookie);
}
+function expectUndefinedCookie(cookie) {
+ chrome.test.assertEq(undefined, cookie);
+}
+
function removeTestCookies() {
chrome.cookies.remove(
{url: TEST_URL, name: TEST_BASIC_COOKIE.name});
@@ -207,6 +211,63 @@ chrome.test.runTests([
chrome.test.assertEq(TEST_ODD_PATH, unescape(cookie.path));
}));
},
+ function setCookiesWithCallbacks() {
+ removeTestCookies();
+ // Basics.
+ chrome.cookies.set(
+ TEST_BASIC_COOKIE,
+ pass(function(cookie) {
+ expectValidCookie(cookie);
+ chrome.test.assertEq(TEST_BASIC_COOKIE.name, cookie.name);
+ chrome.test.assertEq(TEST_BASIC_COOKIE.value, cookie.value);
+ chrome.test.assertEq(TEST_HOST, cookie.domain);
+ chrome.test.assertEq(true, cookie.hostOnly);
+ chrome.test.assertEq('/', cookie.path);
+ chrome.test.assertEq(false, cookie.secure);
+ chrome.test.assertEq(false, cookie.httpOnly);
+ chrome.test.assertEq(true, cookie.session);
+ chrome.test.assertTrue(typeof cookie.expirationDate === 'undefined',
+ 'Session cookie should not have expirationDate property.');
+ chrome.test.assertTrue(typeof cookie.storeId !== 'undefined',
+ 'Cookie store ID not provided.');
+ }));
+ // Invalid values generate callback with no arguments, and error messages
+ chrome.cookies.set(
+ {url: TEST_UNPERMITTED_URL, name: 'abcd', domain: TEST_DOMAIN},
+ fail(
+ 'No host permissions for cookies at url: "'
+ + TEST_UNPERMITTED_URL + '".',
+ expectUndefinedCookie));
+ chrome.cookies.set(
+ {url: TEST_URL, name: 'abcd=efg'},
+ fail('Failed to parse or set cookie named "abcd=efg".',
+ expectUndefinedCookie));
+ chrome.cookies.set(
+ {url: TEST_URL, name: 'abcd', value: 'HI;LO'},
+ fail('Failed to parse or set cookie named "abcd".',
+ expectUndefinedCookie));
+ chrome.cookies.set(
+ {url: TEST_URL, name: 'abcd', domain: 'cookies.com\r'},
+ fail('Failed to parse or set cookie named "abcd".',
+ expectUndefinedCookie));
+ chrome.cookies.set(
+ {url: TEST_URL, name: 'abcd', domain: 'somedomain.com'},
+ fail('Failed to parse or set cookie named "abcd".',
+ expectUndefinedCookie));
+ // Expired cookies generate callback with "null" cookie
+ chrome.cookies.set(TEST_BASIC_EXPIRED_COOKIE, pass(expectUndefinedCookie));
+ // Odd (but valid!) URLs get callbacks too!
+ chrome.cookies.set({
+ url: TEST_ODD_URL,
+ name: 'abcd',
+ domain: TEST_ODD_DOMAIN,
+ path: TEST_ODD_PATH
+ }, pass(function(cookie) {
+ expectValidCookie(cookie);
+ chrome.test.assertEq(TEST_ODD_DOMAIN, unescape(cookie.domain));
+ chrome.test.assertEq(TEST_ODD_PATH, unescape(cookie.path));
+ }));
+ },
function removeCookie() {
removeTestCookies();
chrome.cookies.set(TEST_BASIC_COOKIE);
@@ -239,6 +300,31 @@ chrome.test.runTests([
{url: TEST_URL2, name: TEST_DOMAIN_COOKIE.name},
pass(expectValidCookie));
},
+ function removeCookiesWithCallbacks() {
+ removeTestCookies();
+ chrome.cookies.set(TEST_BASIC_COOKIE);
+ chrome.cookies.get(
+ {url: TEST_URL, name: TEST_BASIC_COOKIE.name},
+ pass(expectValidCookie));
+ // Removal with any domain-matching URL will trigger callback with the
+ // removed cookie's "url" and "name" fields.
+ chrome.cookies.remove(
+ {url: TEST_URL4, name: TEST_BASIC_COOKIE.name}, pass(function(data) {
+ chrome.test.assertEq(TEST_URL4, data.url);
+ chrome.test.assertEq(TEST_BASIC_COOKIE.name, data.name);
+ chrome.test.assertTrue(typeof data.storeId !== 'undefined',
+ 'Cookie store ID not provided.');
+ }));
+ // Removal with a disallowed URL should trigger the callback with no
+ // arguments, and a set error message.
+ chrome.cookies.set(TEST_DOMAIN_COOKIE);
+ chrome.cookies.remove(
+ {url: TEST_UNPERMITTED_URL, name: TEST_DOMAIN_COOKIE.name},
+ fail(
+ 'No host permissions for cookies at url: "'
+ + TEST_UNPERMITTED_URL + '".',
+ expectUndefinedCookie));
+ },
function getAllCookies() {
removeTestCookies();
chrome.cookies.getAll({}, pass(function(cookies) {