summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/api
diff options
context:
space:
mode:
authormitchellwrosen@chromium.org <mitchellwrosen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-23 21:38:08 +0000
committermitchellwrosen@chromium.org <mitchellwrosen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-23 21:38:08 +0000
commit960927c01959244bad95b8b5600f0382e14bb8d4 (patch)
tree35eb49bf82da3f1e079a1fb87fcd92ce337e00e7 /chrome/browser/extensions/api
parent145219f706f4d0ee85430536e2360aaef6234f93 (diff)
downloadchromium_src-960927c01959244bad95b8b5600f0382e14bb8d4.zip
chromium_src-960927c01959244bad95b8b5600f0382e14bb8d4.tar.gz
chromium_src-960927c01959244bad95b8b5600f0382e14bb8d4.tar.bz2
Refactor chrome.cookies API to use JSON schema compiler.
BUG=121174 Review URL: https://chromiumcodereview.appspot.com/10702088 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147954 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/api')
-rw-r--r--chrome/browser/extensions/api/cookies/cookies_api.cc273
-rw-r--r--chrome/browser/extensions/api/cookies/cookies_api.h47
-rw-r--r--chrome/browser/extensions/api/cookies/cookies_api_constants.cc10
-rw-r--r--chrome/browser/extensions/api/cookies/cookies_api_constants.h10
-rw-r--r--chrome/browser/extensions/api/cookies/cookies_helpers.cc139
-rw-r--r--chrome/browser/extensions/api/cookies/cookies_helpers.h60
-rw-r--r--chrome/browser/extensions/api/cookies/cookies_unittest.cc129
7 files changed, 316 insertions, 352 deletions
diff --git a/chrome/browser/extensions/api/cookies/cookies_api.cc b/chrome/browser/extensions/api/cookies/cookies_api.cc
index d67246b..6ddbbeb 100644
--- a/chrome/browser/extensions/api/cookies/cookies_api.cc
+++ b/chrome/browser/extensions/api/cookies/cookies_api.cc
@@ -6,8 +6,12 @@
#include "chrome/browser/extensions/api/cookies/cookies_api.h"
+#include <vector>
+
#include "base/bind.h"
#include "base/json/json_writer.h"
+#include "base/memory/linked_ptr.h"
+#include "base/memory/scoped_ptr.h"
#include "base/values.h"
#include "chrome/browser/extensions/api/cookies/cookies_api_constants.h"
#include "chrome/browser/extensions/api/cookies/cookies_helpers.h"
@@ -16,6 +20,7 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/common/chrome_notification_types.h"
+#include "chrome/common/extensions/api/cookies.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_error_utils.h"
#include "content/public/browser/browser_thread.h"
@@ -26,14 +31,24 @@
#include "net/url_request/url_request_context_getter.h"
using content::BrowserThread;
+using extensions::api::cookies::Cookie;
+using extensions::api::cookies::CookieStore;
+
+namespace Get = extensions::api::cookies::Get;
+namespace GetAll = extensions::api::cookies::GetAll;
+namespace GetAllCookieStores = extensions::api::cookies::GetAllCookieStores;
+namespace Remove = extensions::api::cookies::Remove;
+namespace Set = extensions::api::cookies::Set;
namespace extensions {
namespace keys = cookies_api_constants;
ExtensionCookiesEventRouter::ExtensionCookiesEventRouter(Profile* profile)
- : profile_(profile) {}
+ : profile_(profile) {
+}
-ExtensionCookiesEventRouter::~ExtensionCookiesEventRouter() {}
+ExtensionCookiesEventRouter::~ExtensionCookiesEventRouter() {
+}
void ExtensionCookiesEventRouter::Init() {
CHECK(registrar_.IsEmpty());
@@ -68,10 +83,11 @@ void ExtensionCookiesEventRouter::CookieChanged(
ListValue args;
DictionaryValue* dict = new DictionaryValue();
dict->SetBoolean(keys::kRemovedKey, details->removed);
- dict->Set(
- keys::kCookieKey,
- cookies_helpers::CreateCookieValue(*details->cookie,
+
+ scoped_ptr<Cookie> cookie(
+ cookies_helpers::CreateCookie(*details->cookie,
cookies_helpers::GetStoreIdFromProfile(profile)));
+ dict->Set(keys::kCookieKey, cookie->ToValue().release());
// Map the interal cause to an external string.
std::string cause;
@@ -120,12 +136,8 @@ void ExtensionCookiesEventRouter::DispatchEvent(Profile* profile,
}
}
-bool CookiesFunction::ParseUrl(const DictionaryValue* details, GURL* url,
+bool CookiesFunction::ParseUrl(const std::string& url_string, GURL* url,
bool check_host_permissions) {
- DCHECK(details && url);
- std::string url_string;
- // Get the URL string or return false.
- EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kUrlKey, &url_string));
*url = GURL(url_string);
if (!url->is_valid()) {
error_ = ExtensionErrorUtils::FormatErrorMessage(
@@ -142,23 +154,17 @@ bool CookiesFunction::ParseUrl(const DictionaryValue* details, GURL* url,
return true;
}
-bool CookiesFunction::ParseStoreContext(const DictionaryValue* details,
- net::URLRequestContextGetter** context,
- std::string* store_id) {
- DCHECK(details && (context || store_id));
+bool CookiesFunction::ParseStoreContext(
+ std::string* store_id,
+ net::URLRequestContextGetter** context) {
+ DCHECK((context || store_id->empty()));
Profile* store_profile = NULL;
- if (details->HasKey(keys::kStoreIdKey)) {
- // The store ID was explicitly specified in the details dictionary.
- // Retrieve its corresponding cookie store.
- std::string store_id_value;
- // Get the store ID string or return false.
- EXTENSION_FUNCTION_VALIDATE(
- details->GetString(keys::kStoreIdKey, &store_id_value));
+ if (!store_id->empty()) {
store_profile = cookies_helpers::ChooseProfileFromStoreId(
- store_id_value, profile(), include_incognito());
+ *store_id, profile(), include_incognito());
if (!store_profile) {
error_ = ExtensionErrorUtils::FormatErrorMessage(
- keys::kInvalidStoreIdError, store_id_value);
+ keys::kInvalidStoreIdError, *store_id);
return false;
}
} else {
@@ -171,39 +177,39 @@ bool CookiesFunction::ParseStoreContext(const DictionaryValue* details,
return false;
}
store_profile = current_browser->profile();
+ *store_id = cookies_helpers::GetStoreIdFromProfile(store_profile);
}
- DCHECK(store_profile);
if (context)
*context = store_profile->GetRequestContext();
- if (store_id)
- *store_id = cookies_helpers::GetStoreIdFromProfile(store_profile);
+ DCHECK(context);
return true;
}
-GetCookieFunction::GetCookieFunction() {}
+GetCookieFunction::GetCookieFunction() {
+}
-GetCookieFunction::~GetCookieFunction() {}
+GetCookieFunction::~GetCookieFunction() {
+}
bool GetCookieFunction::RunImpl() {
- // Return false if the arguments are malformed.
- DictionaryValue* details;
- EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details));
- DCHECK(details);
+ parsed_args_ = Get::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(parsed_args_.get());
// Read/validate input parameters.
- if (!ParseUrl(details, &url_, true))
+ if (!ParseUrl(parsed_args_->details.url, &url_, true))
return false;
- // Get the cookie name string or return false.
- EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kNameKey, &name_));
-
+ std::string store_id = parsed_args_->details.store_id.get() ?
+ *parsed_args_->details.store_id : "";
net::URLRequestContextGetter* store_context = NULL;
- if (!ParseStoreContext(details, &store_context, &store_id_))
+ if (!ParseStoreContext(&store_id, &store_context))
return false;
+ store_context_ = store_context;
+ if (!parsed_args_->details.store_id.get())
+ parsed_args_->details.store_id.reset(new std::string(store_id));
- DCHECK(store_context && !store_id_.empty());
store_context_ = store_context;
bool rv = BrowserThread::PostTask(
@@ -230,8 +236,10 @@ void GetCookieFunction::GetCookieCallback(const net::CookieList& cookie_list) {
// 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_) {
- SetResult(cookies_helpers::CreateCookieValue(*it, store_id_));
+ if (it->Name() == parsed_args_->details.name) {
+ scoped_ptr<Cookie> cookie(
+ cookies_helpers::CreateCookie(*it, *parsed_args_->details.store_id));
+ results_ = Get::Results::Create(*cookie);
break;
}
}
@@ -251,24 +259,29 @@ void GetCookieFunction::RespondOnUIThread() {
SendResponse(true);
}
-GetAllCookiesFunction::GetAllCookiesFunction() : details_(NULL) {}
+GetAllCookiesFunction::GetAllCookiesFunction() {
+}
-GetAllCookiesFunction::~GetAllCookiesFunction() {}
+GetAllCookiesFunction::~GetAllCookiesFunction() {
+}
bool GetAllCookiesFunction::RunImpl() {
- // Return false if the arguments are malformed.
- EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details_));
- DCHECK(details_);
+ parsed_args_ = GetAll::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(parsed_args_.get());
- // Read/validate input parameters.
- if (details_->HasKey(keys::kUrlKey) && !ParseUrl(details_, &url_, false))
- return false;
+ if (parsed_args_->details.url.get()) {
+ if (!ParseUrl(*parsed_args_->details.url, &url_, false))
+ return false;
+ }
+ std::string store_id = parsed_args_->details.store_id.get() ?
+ *parsed_args_->details.store_id : "";
net::URLRequestContextGetter* store_context = NULL;
- if (!ParseStoreContext(details_, &store_context, &store_id_))
+ if (!ParseStoreContext(&store_id, &store_context))
return false;
- DCHECK(store_context);
store_context_ = store_context;
+ if (!parsed_args_->details.store_id.get())
+ parsed_args_->details.store_id.reset(new std::string(store_id));
bool rv = BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
@@ -292,11 +305,12 @@ void GetAllCookiesFunction::GetAllCookiesCallback(
const net::CookieList& cookie_list) {
const extensions::Extension* extension = GetExtension();
if (extension) {
- ListValue* matching_list = new ListValue();
- cookies_helpers::AppendMatchingCookiesToList(
- cookie_list, store_id_, url_, details_,
- GetExtension(), matching_list);
- SetResult(matching_list);
+ std::vector<linked_ptr<Cookie> > match_vector;
+ cookies_helpers::AppendMatchingCookiesToVector(
+ cookie_list, url_, &parsed_args_->details,
+ GetExtension(), &match_vector);
+
+ results_ = GetAll::Results::Create(match_vector);
}
bool rv = BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
@@ -309,67 +323,28 @@ void GetAllCookiesFunction::RespondOnUIThread() {
SendResponse(true);
}
-SetCookieFunction::SetCookieFunction()
- : secure_(false),
- http_only_(false),
- success_(false) {
+SetCookieFunction::SetCookieFunction() {
}
SetCookieFunction::~SetCookieFunction() {
}
bool SetCookieFunction::RunImpl() {
- // Return false if the arguments are malformed.
- DictionaryValue* details;
- EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details));
- DCHECK(details);
+ parsed_args_ = Set::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(parsed_args_.get());
// Read/validate input parameters.
- if (!ParseUrl(details, &url_, true))
+ if (!ParseUrl(parsed_args_->details.url, &url_, true))
return false;
- // The macros below return false if argument types are not as expected.
- if (details->HasKey(keys::kNameKey))
- EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kNameKey, &name_));
- if (details->HasKey(keys::kValueKey))
- EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kValueKey, &value_));
- if (details->HasKey(keys::kDomainKey))
- EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kDomainKey, &domain_));
- if (details->HasKey(keys::kPathKey))
- EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kPathKey, &path_));
-
- if (details->HasKey(keys::kSecureKey)) {
- EXTENSION_FUNCTION_VALIDATE(
- details->GetBoolean(keys::kSecureKey, &secure_));
- }
- if (details->HasKey(keys::kHttpOnlyKey)) {
- EXTENSION_FUNCTION_VALIDATE(
- details->GetBoolean(keys::kHttpOnlyKey, &http_only_));
- }
- if (details->HasKey(keys::kExpirationDateKey)) {
- Value* expiration_date_value;
- EXTENSION_FUNCTION_VALIDATE(details->Get(keys::kExpirationDateKey,
- &expiration_date_value));
- double expiration_date;
- if (expiration_date_value->IsType(Value::TYPE_INTEGER)) {
- int expiration_date_int;
- EXTENSION_FUNCTION_VALIDATE(
- expiration_date_value->GetAsInteger(&expiration_date_int));
- expiration_date = static_cast<double>(expiration_date_int);
- } else {
- EXTENSION_FUNCTION_VALIDATE(
- expiration_date_value->GetAsDouble(&expiration_date));
- }
- // Time::FromDoubleT converts double time 0 to empty Time object. So we need
- // to do special handling here.
- expiration_time_ = (expiration_date == 0) ?
- base::Time::UnixEpoch() : base::Time::FromDoubleT(expiration_date);
- }
+ std::string store_id = parsed_args_->details.store_id.get() ?
+ *parsed_args_->details.store_id : "";
net::URLRequestContextGetter* store_context = NULL;
- if (!ParseStoreContext(details, &store_context, NULL))
+ if (!ParseStoreContext(&store_id, &store_context))
return false;
- DCHECK(store_context);
store_context_ = store_context;
+ if (!parsed_args_->details.store_id.get())
+ parsed_args_->details.store_id.reset(new std::string(store_id));
bool rv = BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
@@ -385,9 +360,33 @@ void SetCookieFunction::SetCookieOnIOThread() {
net::CookieMonster* cookie_monster =
store_context_->GetURLRequestContext()->cookie_store()->
GetCookieMonster();
+
+ base::Time expiration_time;
+ if (parsed_args_->details.expiration_date.get()) {
+ // Time::FromDoubleT converts double time 0 to empty Time object. So we need
+ // to do special handling here.
+ expiration_time = (*parsed_args_->details.expiration_date == 0) ?
+ base::Time::UnixEpoch() :
+ base::Time::FromDoubleT(*parsed_args_->details.expiration_date);
+ }
+
+ if (parsed_args_->details.name.get())
+ LOG(INFO) << "Cookie name: " << *parsed_args_->details.name;
+
cookie_monster->SetCookieWithDetailsAsync(
- url_, name_, value_, domain_, path_, expiration_time_,
- secure_, http_only_, base::Bind(&SetCookieFunction::PullCookie, this));
+ url_,
+ parsed_args_->details.name.get() ? *parsed_args_->details.name : "",
+ parsed_args_->details.value.get() ? *parsed_args_->details.value : "",
+ parsed_args_->details.domain.get() ? *parsed_args_->details.domain : "",
+ parsed_args_->details.path.get() ? *parsed_args_->details.path : "",
+ expiration_time,
+ parsed_args_->details.secure.get() ?
+ *parsed_args_->details.secure.get() :
+ false,
+ parsed_args_->details.http_only.get() ?
+ *parsed_args_->details.http_only :
+ false,
+ base::Bind(&SetCookieFunction::PullCookie, this));
}
void SetCookieFunction::PullCookie(bool set_cookie_result) {
@@ -407,8 +406,12 @@ void SetCookieFunction::PullCookieCallback(const net::CookieList& cookie_list) {
// 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_) {
- SetResult(cookies_helpers::CreateCookieValue(*it, store_id_));
+ std::string name = parsed_args_->details.name.get() ?
+ *parsed_args_->details.name : "";
+ if (it->Name() == name) {
+ scoped_ptr<Cookie> cookie(
+ cookies_helpers::CreateCookie(*it, *parsed_args_->details.store_id));
+ results_ = Set::Results::Create(*cookie);
break;
}
}
@@ -422,8 +425,10 @@ void SetCookieFunction::PullCookieCallback(const net::CookieList& cookie_list) {
void SetCookieFunction::RespondOnUIThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (!success_) {
+ std::string name = parsed_args_->details.name.get() ?
+ *parsed_args_->details.name : "";
error_ = ExtensionErrorUtils::FormatErrorMessage(
- keys::kCookieSetFailedError, name_);
+ keys::kCookieSetFailedError, name);
}
SendResponse(success_);
}
@@ -435,23 +440,21 @@ RemoveCookieFunction::~RemoveCookieFunction() {
}
bool RemoveCookieFunction::RunImpl() {
- // Return false if the arguments are malformed.
- DictionaryValue* details;
- EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details));
- DCHECK(details);
+ parsed_args_ = Remove::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(parsed_args_.get());
// Read/validate input parameters.
- if (!ParseUrl(details, &url_, true))
+ if (!ParseUrl(parsed_args_->details.url, &url_, true))
return false;
- // Get the cookie name string or return false.
- EXTENSION_FUNCTION_VALIDATE(details->GetString(keys::kNameKey, &name_));
-
+ std::string store_id = parsed_args_->details.store_id.get() ?
+ *parsed_args_->details.store_id : "";
net::URLRequestContextGetter* store_context = NULL;
- if (!ParseStoreContext(details, &store_context, &store_id_))
+ if (!ParseStoreContext(&store_id, &store_context))
return false;
- DCHECK(store_context);
store_context_ = store_context;
+ if (!parsed_args_->details.store_id.get())
+ parsed_args_->details.store_id.reset(new std::string(store_id));
// Pass the work off to the IO thread.
bool rv = BrowserThread::PostTask(
@@ -470,17 +473,17 @@ void RemoveCookieFunction::RemoveCookieOnIOThread() {
net::CookieStore* cookie_store =
store_context_->GetURLRequestContext()->cookie_store();
cookie_store->DeleteCookieAsync(
- url_, name_,
+ url_, parsed_args_->details.name,
base::Bind(&RemoveCookieFunction::RemoveCookieCallback, this));
}
void RemoveCookieFunction::RemoveCookieCallback() {
// Build the callback result
- DictionaryValue* resultDictionary = new DictionaryValue();
- resultDictionary->SetString(keys::kNameKey, name_);
- resultDictionary->SetString(keys::kUrlKey, url_.spec());
- resultDictionary->SetString(keys::kStoreIdKey, store_id_);
- SetResult(resultDictionary);
+ Remove::Results::Details details;
+ details.name = parsed_args_->details.name;
+ details.url = url_.spec();
+ details.store_id = *parsed_args_->details.store_id;
+ results_ = Remove::Results::Create(details);
// Return to UI thread
bool rv = BrowserThread::PostTask(
@@ -514,28 +517,26 @@ bool GetAllCookieStoresFunction::RunImpl() {
iter != BrowserList::end(); ++iter) {
Browser* browser = *iter;
if (browser->profile() == original_profile) {
- cookies_helpers::AppendToTabIdList(browser,
- original_tab_ids.get());
+ cookies_helpers::AppendToTabIdList(browser, original_tab_ids.get());
} else if (incognito_tab_ids.get() &&
browser->profile() == incognito_profile) {
- cookies_helpers::AppendToTabIdList(browser,
- incognito_tab_ids.get());
+ cookies_helpers::AppendToTabIdList(browser, incognito_tab_ids.get());
}
}
// Return a list of all cookie stores with at least one open tab.
- ListValue* cookie_store_list = new ListValue();
+ std::vector<linked_ptr<CookieStore> > cookie_stores;
if (original_tab_ids->GetSize() > 0) {
- cookie_store_list->Append(
- cookies_helpers::CreateCookieStoreValue(
- original_profile, original_tab_ids.release()));
+ cookie_stores.push_back(make_linked_ptr(
+ cookies_helpers::CreateCookieStore(
+ original_profile, original_tab_ids.release()).release()));
}
if (incognito_tab_ids.get() && incognito_tab_ids->GetSize() > 0 &&
incognito_profile) {
- cookie_store_list->Append(
- cookies_helpers::CreateCookieStoreValue(
- incognito_profile, incognito_tab_ids.release()));
+ cookie_stores.push_back(make_linked_ptr(
+ cookies_helpers::CreateCookieStore(
+ incognito_profile, incognito_tab_ids.release()).release()));
}
- SetResult(cookie_store_list);
+ results_ = GetAllCookieStores::Results::Create(cookie_stores);
return true;
}
diff --git a/chrome/browser/extensions/api/cookies/cookies_api.h b/chrome/browser/extensions/api/cookies/cookies_api.h
index 45fb3ea..5be7ebc 100644
--- a/chrome/browser/extensions/api/cookies/cookies_api.h
+++ b/chrome/browser/extensions/api/cookies/cookies_api.h
@@ -11,10 +11,12 @@
#include <string>
#include "base/compiler_specific.h"
+#include "base/memory/scoped_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/time.h"
#include "chrome/browser/extensions/extension_function.h"
#include "chrome/browser/net/chrome_cookie_notification_details.h"
+#include "chrome/common/extensions/api/cookies.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "googleurl/src/gurl.h"
@@ -75,24 +77,19 @@ class CookiesFunction : public AsyncExtensionFunction {
protected:
virtual ~CookiesFunction() {}
- // Looks for a 'url' value in the given details dictionary and constructs a
- // GURL from it. Returns false and assigns the internal error_ value if the
- // URL is invalid or isn't found in the dictionary. If check_host_permissions
- // is true, the URL is also checked against the extension's host permissions,
- // and if there is no permission for the URL, this function returns false.
- bool ParseUrl(const base::DictionaryValue* details, GURL* url,
+ // Constructs a GURL from the given url string. Returns false and assigns the
+ // internal error_ value if the URL is invalid. If |check_host_permissions| is
+ // true, the URL is also checked against the extension's host permissions, and
+ // if there is no permission for the URL, this function returns false.
+ bool ParseUrl(const std::string& url_string, GURL* url,
bool check_host_permissions);
- // Checks the given details dictionary for a 'storeId' value, and retrieves
- // the cookie store context and the store ID associated with it. If the
- // 'storeId' value isn't found in the dictionary, the current execution
- // context's cookie store context is retrieved. Returns false on error and
- // assigns the internal error_ value if that occurs.
- // At least one of the output parameters store and store_id should be
- // non-NULL.
- bool ParseStoreContext(const base::DictionaryValue* details,
- net::URLRequestContextGetter** context,
- std::string* store_id);
+ // Gets the store identified by |store_id| and returns it in |context|.
+ // If |store_id| contains an empty string, retrieves the current execution
+ // context's store. In this case, |store_id| is populated with the found
+ // store, and |context| can be NULL if the caller only wants |store_id|.
+ bool ParseStoreContext(std::string* store_id,
+ net::URLRequestContextGetter** context);
};
// Implements the cookies.get() extension function.
@@ -113,10 +110,9 @@ class GetCookieFunction : public CookiesFunction {
void RespondOnUIThread();
void GetCookieCallback(const net::CookieList& cookie_list);
- std::string name_;
GURL url_;
- std::string store_id_;
scoped_refptr<net::URLRequestContextGetter> store_context_;
+ scoped_ptr<extensions::api::cookies::Get::Params> parsed_args_;
};
// Implements the cookies.getAll() extension function.
@@ -137,10 +133,9 @@ class GetAllCookiesFunction : public CookiesFunction {
void RespondOnUIThread();
void GetAllCookiesCallback(const net::CookieList& cookie_list);
- base::DictionaryValue* details_;
GURL url_;
- std::string store_id_;
scoped_refptr<net::URLRequestContextGetter> store_context_;
+ scoped_ptr<extensions::api::cookies::GetAll::Params> parsed_args_;
};
// Implements the cookies.set() extension function.
@@ -161,16 +156,9 @@ class SetCookieFunction : public CookiesFunction {
void PullCookieCallback(const net::CookieList& cookie_list);
GURL url_;
- std::string name_;
- std::string value_;
- std::string domain_;
- std::string path_;
- bool secure_;
- bool http_only_;
- base::Time expiration_time_;
bool success_;
- std::string store_id_;
scoped_refptr<net::URLRequestContextGetter> store_context_;
+ scoped_ptr<extensions::api::cookies::Set::Params> parsed_args_;
};
// Implements the cookies.remove() extension function.
@@ -192,9 +180,8 @@ class RemoveCookieFunction : public CookiesFunction {
void RemoveCookieCallback();
GURL url_;
- std::string name_;
- std::string store_id_;
scoped_refptr<net::URLRequestContextGetter> store_context_;
+ scoped_ptr<extensions::api::cookies::Remove::Params> parsed_args_;
};
// Implements the cookies.getAllCookieStores() extension function.
diff --git a/chrome/browser/extensions/api/cookies/cookies_api_constants.cc b/chrome/browser/extensions/api/cookies/cookies_api_constants.cc
index 2f28960..ebbde77 100644
--- a/chrome/browser/extensions/api/cookies/cookies_api_constants.cc
+++ b/chrome/browser/extensions/api/cookies/cookies_api_constants.cc
@@ -11,19 +11,9 @@ namespace cookies_api_constants {
const char kCauseKey[] = "cause";
const char kCookieKey[] = "cookie";
const char kDomainKey[] = "domain";
-const char kExpirationDateKey[] = "expirationDate";
-const char kHostOnlyKey[] = "hostOnly";
-const char kHttpOnlyKey[] = "httpOnly";
const char kIdKey[] = "id";
-const char kNameKey[] = "name";
-const char kPathKey[] = "path";
const char kRemovedKey[] = "removed";
-const char kSecureKey[] = "secure";
-const char kSessionKey[] = "session";
-const char kStoreIdKey[] = "storeId";
const char kTabIdsKey[] = "tabIds";
-const char kUrlKey[] = "url";
-const char kValueKey[] = "value";
// Cause Constants
extern const char kEvictedChangeCause[] = "evicted";
diff --git a/chrome/browser/extensions/api/cookies/cookies_api_constants.h b/chrome/browser/extensions/api/cookies/cookies_api_constants.h
index d6a1be8..dd63269 100644
--- a/chrome/browser/extensions/api/cookies/cookies_api_constants.h
+++ b/chrome/browser/extensions/api/cookies/cookies_api_constants.h
@@ -14,19 +14,9 @@ namespace cookies_api_constants {
extern const char kCauseKey[];
extern const char kCookieKey[];
extern const char kDomainKey[];
-extern const char kExpirationDateKey[];
-extern const char kHostOnlyKey[];
-extern const char kHttpOnlyKey[];
extern const char kIdKey[];
-extern const char kNameKey[];
-extern const char kPathKey[];
extern const char kRemovedKey[];
-extern const char kSecureKey[];
-extern const char kSessionKey[];
-extern const char kStoreIdKey[];
extern const char kTabIdsKey[];
-extern const char kUrlKey[];
-extern const char kValueKey[];
// Cause Constants
extern const char kEvictedChangeCause[];
diff --git a/chrome/browser/extensions/api/cookies/cookies_helpers.cc b/chrome/browser/extensions/api/cookies/cookies_helpers.cc
index 5bab1aa..6a82b62 100644
--- a/chrome/browser/extensions/api/cookies/cookies_helpers.cc
+++ b/chrome/browser/extensions/api/cookies/cookies_helpers.cc
@@ -6,7 +6,11 @@
#include "chrome/browser/extensions/api/cookies/cookies_helpers.h"
+#include <vector>
+
#include "base/logging.h"
+#include "base/memory/linked_ptr.h"
+#include "base/memory/scoped_ptr.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
@@ -16,6 +20,7 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/common/extensions/api/cookies.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/web_contents.h"
@@ -23,6 +28,11 @@
#include "net/cookies/canonical_cookie.h"
#include "net/cookies/cookie_util.h"
+using extensions::api::cookies::Cookie;
+using extensions::api::cookies::CookieStore;
+
+namespace GetAll = extensions::api::cookies::GetAll;
+
namespace extensions {
namespace keys = cookies_api_constants;
@@ -52,42 +62,45 @@ const char* GetStoreIdFromProfile(Profile* profile) {
kOffTheRecordProfileStoreId : kOriginalProfileStoreId;
}
-DictionaryValue* CreateCookieValue(const net::CanonicalCookie& cookie,
- const std::string& store_id) {
- DictionaryValue* result = new DictionaryValue();
-
- // A cookie is a raw byte sequence. By explicitly parsing it as UTF8, we
- // apply error correction, so the string can be safely passed to the
- // renderer.
- result->SetString(keys::kNameKey, UTF8ToUTF16(cookie.Name()));
- result->SetString(keys::kValueKey, UTF8ToUTF16(cookie.Value()));
- result->SetString(keys::kDomainKey, cookie.Domain());
- result->SetBoolean(keys::kHostOnlyKey,
- net::cookie_util::DomainIsHostOnly(cookie.Domain()));
-
+scoped_ptr<Cookie> CreateCookie(
+ const net::CanonicalCookie& canonical_cookie,
+ const std::string& store_id) {
+ scoped_ptr<Cookie> cookie(new Cookie());
+
+ // A cookie is a raw byte sequence. By explicitly parsing it as UTF-8, we
+ // apply error correction, so the string can be safely passed to the renderer.
+ cookie->name = UTF16ToUTF8(UTF8ToUTF16(canonical_cookie.Name()));
+ cookie->value = UTF16ToUTF8(UTF8ToUTF16(canonical_cookie.Value()));
+ cookie->domain = canonical_cookie.Domain();
+ cookie->host_only = net::cookie_util::DomainIsHostOnly(
+ canonical_cookie.Domain());
// A non-UTF8 path is invalid, so we just replace it with an empty string.
- result->SetString(keys::kPathKey,
- IsStringUTF8(cookie.Path()) ? cookie.Path() : "");
- result->SetBoolean(keys::kSecureKey, cookie.IsSecure());
- result->SetBoolean(keys::kHttpOnlyKey, cookie.IsHttpOnly());
- result->SetBoolean(keys::kSessionKey, !cookie.IsPersistent());
- if (cookie.IsPersistent()) {
- result->SetDouble(keys::kExpirationDateKey,
- cookie.ExpiryDate().ToDoubleT());
+ cookie->path = IsStringUTF8(canonical_cookie.Path()) ?
+ canonical_cookie.Path() : "";
+ cookie->secure = canonical_cookie.IsSecure();
+ cookie->http_only = canonical_cookie.IsHttpOnly();
+ cookie->session = !canonical_cookie.IsPersistent();
+ if (canonical_cookie.IsPersistent()) {
+ cookie->expiration_date.reset(
+ new double(canonical_cookie.ExpiryDate().ToDoubleT()));
}
- result->SetString(keys::kStoreIdKey, store_id);
+ cookie->store_id = store_id;
- return result;
+ return cookie.Pass();
}
-DictionaryValue* CreateCookieStoreValue(Profile* profile,
- ListValue* tab_ids) {
+scoped_ptr<CookieStore> CreateCookieStore(Profile* profile,
+ ListValue* tab_ids) {
DCHECK(profile);
DCHECK(tab_ids);
- DictionaryValue* result = new DictionaryValue();
- result->SetString(keys::kIdKey, GetStoreIdFromProfile(profile));
- result->Set(keys::kTabIdsKey, tab_ids);
- return result;
+ DictionaryValue dict;
+ dict.SetString(keys::kIdKey, GetStoreIdFromProfile(profile));
+ dict.Set(keys::kTabIdsKey, tab_ids);
+
+ CookieStore* cookie_store = new CookieStore();
+ bool rv = CookieStore::Populate(dict, cookie_store);
+ CHECK(rv);
+ return scoped_ptr<CookieStore>(cookie_store);
}
void GetCookieListFromStore(
@@ -112,12 +125,11 @@ GURL GetURLFromCanonicalCookie(const net::CanonicalCookie& cookie) {
return GURL(scheme + content::kStandardSchemeSeparator + host + "/");
}
-void AppendMatchingCookiesToList(
- const net::CookieList& all_cookies,
- const std::string& store_id,
- const GURL& url, const DictionaryValue* details,
- const Extension* extension,
- ListValue* match_list) {
+void AppendMatchingCookiesToVector(const net::CookieList& all_cookies,
+ const GURL& url,
+ const GetAll::Params::Details* details,
+ const Extension* extension,
+ LinkedCookieVec* match_vector) {
net::CookieList::const_iterator it;
for (it = all_cookies.begin(); it != all_cookies.end(); ++it) {
// Ignore any cookie whose domain doesn't match the extension's
@@ -127,8 +139,10 @@ void AppendMatchingCookiesToList(
continue;
// Filter the cookie using the match filter.
cookies_helpers::MatchFilter filter(details);
- if (filter.MatchesCookie(*it))
- match_list->Append(CreateCookieValue(*it, store_id));
+ if (filter.MatchesCookie(*it)) {
+ match_vector->push_back(make_linked_ptr(
+ CreateCookie(*it, *details->store_id).release()));
+ }
}
}
@@ -143,45 +157,38 @@ void AppendToTabIdList(Browser* browser, ListValue* tab_ids) {
}
}
-MatchFilter::MatchFilter(const DictionaryValue* details)
+MatchFilter::MatchFilter(const GetAll::Params::Details* details)
: details_(details) {
DCHECK(details_);
}
-bool MatchFilter::MatchesCookie(const net::CanonicalCookie& cookie) {
- return MatchesString(keys::kNameKey, cookie.Name()) &&
- MatchesDomain(cookie.Domain()) &&
- MatchesString(keys::kPathKey, cookie.Path()) &&
- MatchesBoolean(keys::kSecureKey, cookie.IsSecure()) &&
- MatchesBoolean(keys::kSessionKey, !cookie.IsPersistent());
-}
+bool MatchFilter::MatchesCookie(
+ const net::CanonicalCookie& cookie) {
+ if (details_->name.get() && *details_->name != cookie.Name())
+ return false;
-bool MatchFilter::MatchesString(const char* key, const std::string& value) {
- if (!details_->HasKey(key))
- return true;
- std::string filter_value;
- return (details_->GetString(key, &filter_value) &&
- value == filter_value);
-}
+ if (!MatchesDomain(cookie.Domain()))
+ return false;
-bool MatchFilter::MatchesBoolean(const char* key, bool value) {
- if (!details_->HasKey(key))
- return true;
- bool filter_value = false;
- return (details_->GetBoolean(key, &filter_value) &&
- value == filter_value);
+ if (details_->path.get() && *details_->path != cookie.Path())
+ return false;
+
+ if (details_->secure.get() && *details_->secure != cookie.IsSecure())
+ return false;
+
+ if (details_->session.get() && *details_->session != !cookie.IsPersistent())
+ return false;
+
+ return true;
}
bool MatchFilter::MatchesDomain(const std::string& domain) {
- if (!details_->HasKey(keys::kDomainKey))
+ if (!details_->domain.get())
return true;
- std::string filter_value;
- if (!details_->GetString(keys::kDomainKey, &filter_value))
- return false;
// Add a leading '.' character to the filter domain if it doesn't exist.
- if (net::cookie_util::DomainIsHostOnly(filter_value))
- filter_value.insert(0, ".");
+ if (net::cookie_util::DomainIsHostOnly(*details_->domain))
+ details_->domain->insert(0, ".");
std::string sub_domain(domain);
// Strip any leading '.' character from the input cookie domain.
@@ -190,8 +197,8 @@ bool MatchFilter::MatchesDomain(const std::string& domain) {
// Now check whether the domain argument is a subdomain of the filter domain.
for (sub_domain.insert(0, ".");
- sub_domain.length() >= filter_value.length();) {
- if (sub_domain == filter_value)
+ sub_domain.length() >= details_->domain->length();) {
+ if (sub_domain == *details_->domain)
return true;
const size_t next_dot = sub_domain.find('.', 1); // Skip over leading dot.
sub_domain.erase(0, next_dot);
diff --git a/chrome/browser/extensions/api/cookies/cookies_helpers.h b/chrome/browser/extensions/api/cookies/cookies_helpers.h
index 39e2087..86dd5d9 100644
--- a/chrome/browser/extensions/api/cookies/cookies_helpers.h
+++ b/chrome/browser/extensions/api/cookies/cookies_helpers.h
@@ -11,8 +11,13 @@
#define CHROME_BROWSER_EXTENSIONS_API_COOKIES_COOKIES_HELPERS_H_
#include <string>
+#include <vector>
+#include "base/memory/linked_ptr.h"
+#include "base/memory/scoped_ptr.h"
+#include "chrome/common/extensions/api/cookies.h"
#include "net/cookies/cookie_monster.h"
+#include "net/cookies/canonical_cookie.h"
class Browser;
class Profile;
@@ -32,6 +37,9 @@ class Extension;
namespace cookies_helpers {
+typedef std::vector<linked_ptr<extensions::api::cookies::Cookie> >
+ LinkedCookieVec;
+
// Returns either the original profile or the incognito profile, based on the
// given store ID. Returns NULL if the profile doesn't exist or is not allowed
// (e.g. if incognito mode is not enabled for the extension).
@@ -42,17 +50,17 @@ Profile* ChooseProfileFromStoreId(const std::string& store_id,
// Returns the store ID for a particular user profile.
const char* GetStoreIdFromProfile(Profile* profile);
-// Constructs a Cookie object as defined by the cookies API. This function
-// allocates a new DictionaryValue object; the caller is responsible for
-// freeing it.
-base::DictionaryValue* CreateCookieValue(const net::CanonicalCookie& cookie,
- const std::string& store_id);
+// Allocates and construct a new Cookie object representing a cookie as defined
+// by the cookies API.
+scoped_ptr<extensions::api::cookies::Cookie> CreateCookie(
+ const net::CanonicalCookie& cookie,
+ const std::string& store_id);
-// Constructs a CookieStore object as defined by the cookies API. This function
-// allocates a new DictionaryValue object; the caller is responsible for
-// freeing it.
-base::DictionaryValue* CreateCookieStoreValue(Profile* profile,
- base::ListValue* tab_ids);
+// Allocates and constructs a new CookieStore object as defined by the cookies
+// API.
+scoped_ptr<extensions::api::cookies::CookieStore> CreateCookieStore(
+ Profile* profile,
+ base::ListValue* tab_ids);
// Retrieves all cookies from the given cookie store corresponding to the given
// URL. If the URL is empty, all cookies in the cookie store are retrieved.
@@ -65,17 +73,16 @@ void GetCookieListFromStore(
// a cookie against the extension's host permissions. The Secure
// property of the cookie defines the URL scheme, and the cookie's
// domain becomes the URL host.
-GURL GetURLFromCanonicalCookie(const net::CanonicalCookie& cookie);
+GURL GetURLFromCanonicalCookie(
+ const net::CanonicalCookie& cookie);
// Looks through all cookies in the given cookie store, and appends to the
-// match list all the cookies that both match the given URL and cookie details
+// match vector all the cookies that both match the given URL and cookie details
// and are allowed by extension host permissions.
-void AppendMatchingCookiesToList(
- const net::CookieList& all_cookies,
- const std::string& store_id,
- const GURL& url, const base::DictionaryValue* details,
- const Extension* extension,
- base::ListValue* match_list);
+void AppendMatchingCookiesToVector(
+ const net::CookieList& all_cookies, const GURL& url,
+ const extensions::api::cookies::GetAll::Params::Details* details,
+ const Extension* extension, LinkedCookieVec* match_vector);
// Appends the IDs of all tabs belonging to the given browser to the
// given list.
@@ -90,25 +97,16 @@ void AppendToTabIdList(Browser* browser, base::ListValue* tab_ids);
class MatchFilter {
public:
// Takes the details dictionary argument given by the user as input.
- // This class does not take ownership of the lifetime of the DictionaryValue
+ // This class does not take ownership of the lifetime of the Details
// object.
- explicit MatchFilter(const base::DictionaryValue* details);
+ explicit MatchFilter(
+ const extensions::api::cookies::GetAll::Params::Details* details);
// Returns true if the given cookie matches the properties in the match
// filter.
bool MatchesCookie(const net::CanonicalCookie& cookie);
private:
- // Returns true if the details dictionary contains a string with the given
- // key and value. Also returns true if the dictionary doesn't contain the
- // given key at all (trival match).
- bool MatchesString(const char* key, const std::string& value);
-
- // Returns true if the details dictionary contains a boolean with the given
- // key and value. Also returns true if the dictionary doesn't contain the
- // given key at all (trival match).
- bool MatchesBoolean(const char* key, bool value);
-
// Returns true if the given cookie domain string matches the filter's
// domain. Any cookie domain which is equal to or is a subdomain of the
// filter's domain will be matched; leading '.' characters indicating
@@ -118,7 +116,7 @@ class MatchFilter {
// 'foo.bar.com', '.foo.bar.com', and 'baz.foo.bar.com'.
bool MatchesDomain(const std::string& domain);
- const base::DictionaryValue* details_;
+ const extensions::api::cookies::GetAll::Params::Details* details_;
};
} // namespace cookies_helpers
diff --git a/chrome/browser/extensions/api/cookies/cookies_unittest.cc b/chrome/browser/extensions/api/cookies/cookies_unittest.cc
index 960fc80..6d4ca9c 100644
--- a/chrome/browser/extensions/api/cookies/cookies_unittest.cc
+++ b/chrome/browser/extensions/api/cookies/cookies_unittest.cc
@@ -10,10 +10,16 @@
#include "base/values.h"
#include "chrome/browser/extensions/api/cookies/cookies_api_constants.h"
#include "chrome/browser/extensions/api/cookies/cookies_helpers.h"
+#include "chrome/common/extensions/api/cookies.h"
#include "chrome/test/base/testing_profile.h"
#include "googleurl/src/gurl.h"
#include "net/cookies/canonical_cookie.h"
+using extensions::api::cookies::Cookie;
+using extensions::api::cookies::CookieStore;
+
+namespace GetAll = extensions::api::cookies::GetAll;
+
namespace extensions {
namespace keys = cookies_api_constants;
@@ -105,63 +111,44 @@ TEST_F(ExtensionCookiesTest, StoreIdProfileConversion) {
}
TEST_F(ExtensionCookiesTest, ExtensionTypeCreation) {
- std::string string_value;
- bool boolean_value;
- double double_value;
- Value* value;
-
- net::CanonicalCookie cookie1(
+ net::CanonicalCookie canonical_cookie1(
GURL(), "ABC", "DEF", "www.foobar.com", "/",
std::string(), std::string(),
base::Time(), base::Time(), base::Time(),
false, false);
- scoped_ptr<DictionaryValue> cookie_value1(
- cookies_helpers::CreateCookieValue(
- cookie1, "some cookie store"));
- EXPECT_TRUE(cookie_value1->GetString(keys::kNameKey, &string_value));
- EXPECT_EQ("ABC", string_value);
- EXPECT_TRUE(cookie_value1->GetString(keys::kValueKey, &string_value));
- EXPECT_EQ("DEF", string_value);
- EXPECT_TRUE(cookie_value1->GetString(keys::kDomainKey, &string_value));
- EXPECT_EQ("www.foobar.com", string_value);
- EXPECT_TRUE(cookie_value1->GetBoolean(keys::kHostOnlyKey, &boolean_value));
- EXPECT_TRUE(boolean_value);
- EXPECT_TRUE(cookie_value1->GetString(keys::kPathKey, &string_value));
- EXPECT_EQ("/", string_value);
- EXPECT_TRUE(cookie_value1->GetBoolean(keys::kSecureKey, &boolean_value));
- EXPECT_FALSE(boolean_value);
- EXPECT_TRUE(cookie_value1->GetBoolean(keys::kHttpOnlyKey, &boolean_value));
- EXPECT_FALSE(boolean_value);
- EXPECT_TRUE(cookie_value1->GetBoolean(keys::kSessionKey, &boolean_value));
- EXPECT_TRUE(boolean_value);
- EXPECT_FALSE(
- cookie_value1->GetDouble(keys::kExpirationDateKey, &double_value));
- EXPECT_TRUE(cookie_value1->GetString(keys::kStoreIdKey, &string_value));
- EXPECT_EQ("some cookie store", string_value);
-
- net::CanonicalCookie cookie2(
+ scoped_ptr<Cookie> cookie1(
+ cookies_helpers::CreateCookie(
+ canonical_cookie1, "some cookie store"));
+ EXPECT_EQ("ABC", cookie1->name);
+ EXPECT_EQ("DEF", cookie1->value);
+ EXPECT_EQ("www.foobar.com", cookie1->domain);
+ EXPECT_TRUE(cookie1->host_only);
+ EXPECT_EQ("/", cookie1->path);
+ EXPECT_FALSE(cookie1->secure);
+ EXPECT_FALSE(cookie1->http_only);
+ EXPECT_TRUE(cookie1->session);
+ EXPECT_FALSE(cookie1->expiration_date.get());
+ EXPECT_EQ("some cookie store", cookie1->store_id);
+
+ net::CanonicalCookie canonical_cookie2(
GURL(), "ABC", "DEF", ".foobar.com", "/", std::string(), std::string(),
base::Time(), base::Time::FromDoubleT(10000), base::Time(),
false, false);
- scoped_ptr<DictionaryValue> cookie_value2(
- cookies_helpers::CreateCookieValue(
- cookie2, "some cookie store"));
- EXPECT_TRUE(cookie_value2->GetBoolean(keys::kHostOnlyKey, &boolean_value));
- EXPECT_FALSE(boolean_value);
- EXPECT_TRUE(cookie_value2->GetBoolean(keys::kSessionKey, &boolean_value));
- EXPECT_FALSE(boolean_value);
- EXPECT_TRUE(
- cookie_value2->GetDouble(keys::kExpirationDateKey, &double_value));
- EXPECT_EQ(10000, double_value);
+ scoped_ptr<Cookie> cookie2(
+ cookies_helpers::CreateCookie(
+ canonical_cookie2, "some cookie store"));
+ EXPECT_FALSE(cookie2->host_only);
+ EXPECT_FALSE(cookie2->session);
+ ASSERT_TRUE(cookie2->expiration_date.get());
+ EXPECT_EQ(10000, *cookie2->expiration_date);
TestingProfile profile;
- ListValue* tab_ids = new ListValue();
- scoped_ptr<DictionaryValue> cookie_store_value(
- cookies_helpers::CreateCookieStoreValue(&profile, tab_ids));
- EXPECT_TRUE(cookie_store_value->GetString(keys::kIdKey, &string_value));
- EXPECT_EQ("0", string_value);
- EXPECT_TRUE(cookie_store_value->Get(keys::kTabIdsKey, &value));
- EXPECT_EQ(tab_ids, value);
+ ListValue* tab_ids_list = new ListValue();
+ std::vector<int> tab_ids;
+ scoped_ptr<CookieStore> cookie_store(
+ cookies_helpers::CreateCookieStore(&profile, tab_ids_list));
+ EXPECT_EQ("0", cookie_store->id);
+ EXPECT_EQ(tab_ids, cookie_store->tab_ids);
}
TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) {
@@ -185,11 +172,12 @@ TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) {
}
TEST_F(ExtensionCookiesTest, EmptyDictionary) {
- scoped_ptr<DictionaryValue> details(new DictionaryValue());
- cookies_helpers::MatchFilter filter(details.get());
- std::string domain;
+ DictionaryValue dict;
+ GetAll::Params::Details details;
+ bool rv = GetAll::Params::Details::Populate(dict, &details);
+ ASSERT_TRUE(rv);
+ cookies_helpers::MatchFilter filter(&details);
net::CanonicalCookie cookie;
-
EXPECT_TRUE(filter.MatchesCookie(cookie));
}
@@ -204,29 +192,32 @@ TEST_F(ExtensionCookiesTest, DomainMatching) {
{ "foo.bar.com", ".bar.com", false }
};
- scoped_ptr<DictionaryValue> details(new DictionaryValue());
for (size_t i = 0; i < arraysize(tests); ++i) {
- details->SetString(keys::kDomainKey, std::string(tests[i].filter));
- cookies_helpers::MatchFilter filter(details.get());
- net::CanonicalCookie cookie(GURL(), "", "", tests[i].domain, "", "", "",
- base::Time(), base::Time(), base::Time(), false,
- false);
+ // Build up the Params struct.
+ ListValue args;
+ DictionaryValue* dict = new DictionaryValue();
+ dict->SetString(keys::kDomainKey, std::string(tests[i].filter));
+ args.Set(0, dict);
+ scoped_ptr<GetAll::Params> params(GetAll::Params::Create(args));
+
+ cookies_helpers::MatchFilter filter(&params->details);
+ net::CanonicalCookie cookie(GURL(), "", "", tests[i].domain,
+ "", "", "", base::Time(),
+ base::Time(), base::Time(),
+ false, false);
EXPECT_EQ(tests[i].matches, filter.MatchesCookie(cookie));
}
}
TEST_F(ExtensionCookiesTest, DecodeUTF8WithErrorHandling) {
- net::CanonicalCookie cookie(GURL(), "", "011Q255bNX_1!yd\203e+", "test.com",
- "/path\203", "", "", base::Time(), base::Time(),
- base::Time(), false, false);
- scoped_ptr<DictionaryValue> cookie_value(
- cookies_helpers::CreateCookieValue(
- cookie, "some cookie store"));
- std::string string_value;
- EXPECT_TRUE(cookie_value->GetString(keys::kValueKey, &string_value));
- EXPECT_EQ(std::string("011Q255bNX_1!yd\xEF\xBF\xBD" "e+"), string_value);
- EXPECT_TRUE(cookie_value->GetString(keys::kPathKey, &string_value));
- EXPECT_EQ(std::string(""), string_value);
+ net::CanonicalCookie canonical_cookie(
+ GURL(), "", "011Q255bNX_1!yd\203e+", "test.com", "/path\203", "", "",
+ base::Time(), base::Time(), base::Time(), false, false);
+ scoped_ptr<Cookie> cookie(
+ cookies_helpers::CreateCookie(
+ canonical_cookie, "some cookie store"));
+ EXPECT_EQ(std::string("011Q255bNX_1!yd\xEF\xBF\xBD" "e+"), cookie->value);
+ EXPECT_EQ(std::string(""), cookie->path);
}
} // namespace extensions