summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
authorarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-21 23:30:15 +0000
committerarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-21 23:30:15 +0000
commit438c97d23785f28465304e1cb521b5125e9ea469 (patch)
tree5bc5c6ae6c72b9c8567c13a0b32d491b25e81f88 /chrome/browser/extensions
parent69e297f187425f2b31db37bfe51af86f28c38275 (diff)
downloadchromium_src-438c97d23785f28465304e1cb521b5125e9ea469.zip
chromium_src-438c97d23785f28465304e1cb521b5125e9ea469.tar.gz
chromium_src-438c97d23785f28465304e1cb521b5125e9ea469.tar.bz2
Update extension functions to always pass a list of arguments, even when one argument was passed.
BUG=36301 TEST=Updated tests and ran all the existing tests. Review URL: http://codereview.chromium.org/2137012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47972 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/execute_code_in_tab_function.cc7
-rw-r--r--chrome/browser/extensions/extension_accessibility_api.cc2
-rw-r--r--chrome/browser/extensions/extension_bookmark_manager_api.cc33
-rw-r--r--chrome/browser/extensions/extension_bookmarks_module.cc94
-rw-r--r--chrome/browser/extensions/extension_bookmarks_module.h6
-rw-r--r--chrome/browser/extensions/extension_browser_actions_api.cc4
-rw-r--r--chrome/browser/extensions/extension_browser_actions_api.h2
-rw-r--r--chrome/browser/extensions/extension_clipboard_api.cc2
-rw-r--r--chrome/browser/extensions/extension_context_menu_api.cc13
-rw-r--r--chrome/browser/extensions/extension_cookies_api.cc16
-rw-r--r--chrome/browser/extensions/extension_dom_ui.cc2
-rw-r--r--chrome/browser/extensions/extension_dom_ui.h2
-rw-r--r--chrome/browser/extensions/extension_function.cc8
-rw-r--r--chrome/browser/extensions/extension_function.h13
-rw-r--r--chrome/browser/extensions/extension_function_dispatcher.cc2
-rw-r--r--chrome/browser/extensions/extension_function_dispatcher.h4
-rw-r--r--chrome/browser/extensions/extension_history_api.cc20
-rw-r--r--chrome/browser/extensions/extension_host.cc2
-rw-r--r--chrome/browser/extensions/extension_host.h2
-rw-r--r--chrome/browser/extensions/extension_idle_api.cc2
-rw-r--r--chrome/browser/extensions/extension_infobar_module.cc4
-rw-r--r--chrome/browser/extensions/extension_metrics_module.cc17
-rw-r--r--chrome/browser/extensions/extension_page_actions_module.cc33
-rw-r--r--chrome/browser/extensions/extension_popup_api.cc7
-rw-r--r--chrome/browser/extensions/extension_processes_api.cc2
-rw-r--r--chrome/browser/extensions/extension_tabs_module.cc68
-rw-r--r--chrome/browser/extensions/extension_test_api.cc6
-rw-r--r--chrome/browser/extensions/extension_toolstrip_api.cc10
-rw-r--r--chrome/browser/extensions/extensions_quota_service.cc4
-rw-r--r--chrome/browser/extensions/extensions_quota_service.h7
-rw-r--r--chrome/browser/extensions/extensions_quota_service_unittest.cc11
31 files changed, 170 insertions, 235 deletions
diff --git a/chrome/browser/extensions/execute_code_in_tab_function.cc b/chrome/browser/extensions/execute_code_in_tab_function.cc
index fca1a17..c391db8 100644
--- a/chrome/browser/extensions/execute_code_in_tab_function.cc
+++ b/chrome/browser/extensions/execute_code_in_tab_function.cc
@@ -18,11 +18,8 @@
namespace keys = extension_tabs_module_constants;
bool ExecuteCodeInTabFunction::RunImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST));
- const ListValue* args = args_as_list();
-
DictionaryValue* script_info;
- EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &script_info));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &script_info));
size_t number_of_value = script_info->size();
if (number_of_value == 0) {
error_ = keys::kNoCodeOrFileToExecuteError;
@@ -46,7 +43,7 @@ bool ExecuteCodeInTabFunction::RunImpl() {
// If |tab_id| is specified, look for it. Otherwise default to selected tab
// in the current window.
Value* tab_value = NULL;
- EXTENSION_FUNCTION_VALIDATE(args->Get(0, &tab_value));
+ EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &tab_value));
if (tab_value->IsType(Value::TYPE_NULL)) {
browser = GetCurrentBrowser();
if (!browser) {
diff --git a/chrome/browser/extensions/extension_accessibility_api.cc b/chrome/browser/extensions/extension_accessibility_api.cc
index aebdda2..8b4630e 100644
--- a/chrome/browser/extensions/extension_accessibility_api.cc
+++ b/chrome/browser/extensions/extension_accessibility_api.cc
@@ -182,7 +182,7 @@ void ExtensionAccessibilityEventRouter::DispatchEvent(
bool SetAccessibilityEnabledFunction::RunImpl() {
bool enabled;
- EXTENSION_FUNCTION_VALIDATE(args_->GetAsBoolean(&enabled));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(0, &enabled));
ExtensionAccessibilityEventRouter::GetInstance()
->SetAccessibilityEnabled(enabled);
return true;
diff --git a/chrome/browser/extensions/extension_bookmark_manager_api.cc b/chrome/browser/extensions/extension_bookmark_manager_api.cc
index 66bc9fa..9b796d2 100644
--- a/chrome/browser/extensions/extension_bookmark_manager_api.cc
+++ b/chrome/browser/extensions/extension_bookmark_manager_api.cc
@@ -30,9 +30,9 @@ namespace {
// Returns a single bookmark node from the argument ID.
// This returns NULL in case of failure.
const BookmarkNode* GetNodeFromArguments(BookmarkModel* model,
- const Value* args) {
+ const ListValue* args) {
std::string id_string;
- if (!args->GetAsString(&id_string))
+ if (!args->GetString(0, &id_string))
return NULL;
int64 id;
if (!StringToInt64(id_string, &id))
@@ -42,8 +42,13 @@ const BookmarkNode* GetNodeFromArguments(BookmarkModel* model,
// Gets a vector of bookmark nodes from the argument list of IDs.
// This returns false in the case of failure.
-bool GetNodesFromArguments(BookmarkModel* model, const ListValue* ids,
+bool GetNodesFromArguments(BookmarkModel* model, const ListValue* args,
std::vector<const BookmarkNode*>* nodes) {
+
+ ListValue* ids;
+ if (!args->GetList(0, &ids))
+ return false;
+
size_t count = ids->GetSize();
if (count == 0)
return false;
@@ -208,7 +213,7 @@ void ExtensionBookmarkManagerEventRouter::ClearBookmarkDragData() {
bool ClipboardBookmarkManagerFunction::CopyOrCut(bool cut) {
BookmarkModel* model = profile()->GetBookmarkModel();
std::vector<const BookmarkNode*> nodes;
- EXTENSION_FUNCTION_VALIDATE(GetNodesFromArguments(model, args_as_list(),
+ EXTENSION_FUNCTION_VALIDATE(GetNodesFromArguments(model, args_.get(),
&nodes));
bookmark_utils::CopyToClipboard(model, nodes, cut);
return true;
@@ -335,7 +340,7 @@ bool StartDragBookmarkManagerFunction::RunImpl() {
BookmarkModel* model = profile()->GetBookmarkModel();
std::vector<const BookmarkNode*> nodes;
EXTENSION_FUNCTION_VALIDATE(
- GetNodesFromArguments(model, args_as_list(), &nodes));
+ GetNodesFromArguments(model, args_.get(), &nodes));
if (dispatcher()->render_view_host()->delegate()->GetRenderViewType() ==
ViewType::TAB_CONTENTS) {
@@ -354,16 +359,10 @@ bool StartDragBookmarkManagerFunction::RunImpl() {
bool DropBookmarkManagerFunction::RunImpl() {
BookmarkModel* model = profile()->GetBookmarkModel();
- // TODO(arv): The arguments change between a list and a value depending on the
- // parameters. See http://crbug.com/36301
int64 id;
std::string id_string;
- if (args_->IsType(Value::TYPE_STRING)) {
- EXTENSION_FUNCTION_VALIDATE(args_->GetAsString(&id_string));
- } else {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST));
- EXTENSION_FUNCTION_VALIDATE(args_as_list()->GetString(0, &id_string));
- }
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id_string));
+
if (!StringToInt64(id_string, &id)) {
error_ = keys::kInvalidIdError;
return false;
@@ -376,8 +375,8 @@ bool DropBookmarkManagerFunction::RunImpl() {
}
int drop_index;
- if (args_as_list()->GetSize() == 2)
- EXTENSION_FUNCTION_VALIDATE(args_as_list()->GetInteger(1, &drop_index));
+ if (args_->GetSize() == 2)
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &drop_index));
else
drop_index = drop_parent->GetChildCount();
@@ -412,9 +411,9 @@ bool GetSubtreeBookmarkManagerFunction::RunImpl() {
const BookmarkNode* node;
int64 id;
std::string id_string;
- EXTENSION_FUNCTION_VALIDATE(args_as_list()->GetString(0, &id_string));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id_string));
bool folders_only;
- EXTENSION_FUNCTION_VALIDATE(args_as_list()->GetBoolean(1, &folders_only));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &folders_only));
if (id_string == "") {
node = model->root_node();
} else {
diff --git a/chrome/browser/extensions/extension_bookmarks_module.cc b/chrome/browser/extensions/extension_bookmarks_module.cc
index 8361b82..a07179e 100644
--- a/chrome/browser/extensions/extension_bookmarks_module.cc
+++ b/chrome/browser/extensions/extension_bookmarks_module.cc
@@ -228,8 +228,10 @@ void ExtensionBookmarkEventRouter::BookmarkImportEnding(BookmarkModel* model) {
bool GetBookmarksFunction::RunImpl() {
BookmarkModel* model = profile()->GetBookmarkModel();
scoped_ptr<ListValue> json(new ListValue());
- if (args_->IsType(Value::TYPE_LIST)) {
- const ListValue* ids = args_as_list();
+ Value* arg0;
+ EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &arg0));
+ if (arg0->IsType(Value::TYPE_LIST)) {
+ const ListValue* ids = static_cast<const ListValue*>(arg0);
size_t count = ids->GetSize();
EXTENSION_FUNCTION_VALIDATE(count > 0);
for (size_t i = 0; i < count; ++i) {
@@ -249,7 +251,7 @@ bool GetBookmarksFunction::RunImpl() {
} else {
int64 id;
std::string id_string;
- EXTENSION_FUNCTION_VALIDATE(args_->GetAsString(&id_string));
+ EXTENSION_FUNCTION_VALIDATE(arg0->GetAsString(&id_string));
if (!GetBookmarkIdAsInt64(id_string, &id))
return false;
const BookmarkNode* node = model->GetNodeByID(id);
@@ -268,7 +270,7 @@ bool GetBookmarkChildrenFunction::RunImpl() {
BookmarkModel* model = profile()->GetBookmarkModel();
int64 id;
std::string id_string;
- EXTENSION_FUNCTION_VALIDATE(args_->GetAsString(&id_string));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &id_string));
if (!GetBookmarkIdAsInt64(id_string, &id))
return false;
scoped_ptr<ListValue> json(new ListValue());
@@ -288,9 +290,8 @@ bool GetBookmarkChildrenFunction::RunImpl() {
}
bool GetBookmarkRecentFunction::RunImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_INTEGER));
int number_of_items;
- EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&number_of_items));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &number_of_items));
if (number_of_items < 1)
return false;
@@ -317,10 +318,8 @@ bool GetBookmarkTreeFunction::RunImpl() {
}
bool SearchBookmarksFunction::RunImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_STRING));
-
std::wstring query;
- EXTENSION_FUNCTION_VALIDATE(args_->GetAsString(&query));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &query));
BookmarkModel* model = profile()->GetBookmarkModel();
ListValue* json = new ListValue();
@@ -340,35 +339,17 @@ bool SearchBookmarksFunction::RunImpl() {
}
// static
-bool RemoveBookmarkFunction::ExtractIds(const Value* args,
- std::list<int64>* ids, bool* invalid_id) {
+bool RemoveBookmarkFunction::ExtractIds(const ListValue* args,
+ std::list<int64>* ids,
+ bool* invalid_id) {
std::string id_string;
- if (args->IsType(Value::TYPE_STRING) &&
- args->GetAsString(&id_string)) {
- int64 id;
- if (StringToInt64(id_string, &id))
- ids->push_back(id);
- else
- *invalid_id = true;
- } else {
- if (!args->IsType(Value::TYPE_LIST))
- return false;
- const ListValue* ids_list = static_cast<const ListValue*>(args);
- size_t count = ids_list->GetSize();
- if (count <= 0)
- return false;
- for (size_t i = 0; i < count; ++i) {
- if (!ids_list->GetString(i, &id_string))
- return false;
- int64 id;
- if (StringToInt64(id_string, &id)) {
- ids->push_back(id);
- } else {
- *invalid_id = true;
- break;
- }
- }
- }
+ if (!args->GetString(0, &id_string))
+ return false;
+ int64 id;
+ if (StringToInt64(id_string, &id))
+ ids->push_back(id);
+ else
+ *invalid_id = true;
return true;
}
@@ -395,8 +376,9 @@ bool RemoveBookmarkFunction::RunImpl() {
}
bool CreateBookmarkFunction::RunImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
- const DictionaryValue* json = args_as_dictionary();
+ DictionaryValue* json;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &json));
+ EXTENSION_FUNCTION_VALIDATE(json != NULL);
BookmarkModel* model = profile()->GetBookmarkModel();
int64 parentId;
@@ -460,7 +442,7 @@ bool CreateBookmarkFunction::RunImpl() {
}
// static
-bool MoveBookmarkFunction::ExtractIds(const Value* args,
+bool MoveBookmarkFunction::ExtractIds(const ListValue* args,
std::list<int64>* ids,
bool* invalid_id) {
// For now, Move accepts ID parameters in the same way as an Update.
@@ -476,10 +458,9 @@ bool MoveBookmarkFunction::RunImpl() {
return false;
}
EXTENSION_FUNCTION_VALIDATE(ids.size() == 1);
- const ListValue* args = args_as_list();
DictionaryValue* destination;
- EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &destination));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &destination));
BookmarkModel* model = profile()->GetBookmarkModel();
const BookmarkNode* node = model->GetNodeByID(ids.front());
@@ -540,21 +521,11 @@ bool MoveBookmarkFunction::RunImpl() {
}
// static
-bool UpdateBookmarkFunction::ExtractIds(const Value* args,
+bool UpdateBookmarkFunction::ExtractIds(const ListValue* args,
std::list<int64>* ids,
bool* invalid_id) {
- std::string id_string;
- if (!args->IsType(Value::TYPE_LIST))
- return false;
- const ListValue* args_list = static_cast<const ListValue*>(args);
- if (!args_list->GetString(0, &id_string))
- return false;
- int64 id;
- if (StringToInt64(id_string, &id))
- ids->push_back(id);
- else
- *invalid_id = true;
- return true;
+ // For now, Update accepts ID parameters in the same way as an Remove.
+ return RemoveBookmarkFunction::ExtractIds(args, ids, invalid_id);
}
bool UpdateBookmarkFunction::RunImpl() {
@@ -567,9 +538,8 @@ bool UpdateBookmarkFunction::RunImpl() {
}
EXTENSION_FUNCTION_VALIDATE(ids.size() == 1);
- const ListValue* args = args_as_list();
DictionaryValue* updates;
- EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &updates));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &updates));
std::wstring title;
std::string url_string;
@@ -636,12 +606,12 @@ class CreateBookmarkBucketMapper : public BookmarkBucketMapper<std::string> {
explicit CreateBookmarkBucketMapper(Profile* profile) : profile_(profile) {}
// TODO(tim): This should share code with CreateBookmarkFunction::RunImpl,
// but I can't figure out a good way to do that with all the macros.
- virtual void GetBucketsForArgs(const Value* args, BucketList* buckets) {
- if (!args->IsType(Value::TYPE_DICTIONARY))
+ virtual void GetBucketsForArgs(const ListValue* args, BucketList* buckets) {
+ DictionaryValue* json;
+ if (!args->GetDictionary(0, &json))
return;
std::string parent_id;
- const DictionaryValue* json = static_cast<const DictionaryValue*>(args);
if (json->HasKey(keys::kParentIdKey)) {
if (!json->GetString(keys::kParentIdKey, &parent_id))
return;
@@ -671,7 +641,7 @@ class CreateBookmarkBucketMapper : public BookmarkBucketMapper<std::string> {
class RemoveBookmarksBucketMapper : public BookmarkBucketMapper<std::string> {
public:
explicit RemoveBookmarksBucketMapper(Profile* profile) : profile_(profile) {}
- virtual void GetBucketsForArgs(const Value* args, BucketList* buckets) {
+ virtual void GetBucketsForArgs(const ListValue* args, BucketList* buckets) {
typedef std::list<int64> IdList;
IdList ids;
bool invalid_id = false;
@@ -705,7 +675,7 @@ template <class FunctionType>
class BookmarkIdMapper : public BookmarkBucketMapper<int64> {
public:
typedef std::list<int64> IdList;
- virtual void GetBucketsForArgs(const Value* args, BucketList* buckets) {
+ virtual void GetBucketsForArgs(const ListValue* args, BucketList* buckets) {
IdList ids;
bool invalid_id = false;
if (!FunctionType::ExtractIds(args, &ids, &invalid_id) || invalid_id)
diff --git a/chrome/browser/extensions/extension_bookmarks_module.h b/chrome/browser/extensions/extension_bookmarks_module.h
index cb25755..1a26b02 100644
--- a/chrome/browser/extensions/extension_bookmarks_module.h
+++ b/chrome/browser/extensions/extension_bookmarks_module.h
@@ -124,7 +124,7 @@ class RemoveBookmarkFunction : public BookmarksFunction {
public:
// Returns true on successful parse and sets invalid_id to true if conversion
// from id string to int64 failed.
- static bool ExtractIds(const Value* args, std::list<int64>* ids,
+ static bool ExtractIds(const ListValue* args, std::list<int64>* ids,
bool* invalid_id);
virtual bool RunImpl();
virtual void GetQuotaLimitHeuristics(
@@ -148,7 +148,7 @@ class CreateBookmarkFunction : public BookmarksFunction {
class MoveBookmarkFunction : public BookmarksFunction {
public:
- static bool ExtractIds(const Value* args, std::list<int64>* ids,
+ static bool ExtractIds(const ListValue* args, std::list<int64>* ids,
bool* invalid_id);
virtual void GetQuotaLimitHeuristics(
std::list<QuotaLimitHeuristic*>* heuristics) const;
@@ -159,7 +159,7 @@ class MoveBookmarkFunction : public BookmarksFunction {
class UpdateBookmarkFunction : public BookmarksFunction {
public:
- static bool ExtractIds(const Value* args, std::list<int64>* ids,
+ static bool ExtractIds(const ListValue* args, std::list<int64>* ids,
bool* invalid_id);
virtual void GetQuotaLimitHeuristics(
std::list<QuotaLimitHeuristic*>* heuristics) const;
diff --git a/chrome/browser/extensions/extension_browser_actions_api.cc b/chrome/browser/extensions/extension_browser_actions_api.cc
index c1ffe8e..dfcf2ad 100644
--- a/chrome/browser/extensions/extension_browser_actions_api.cc
+++ b/chrome/browser/extensions/extension_browser_actions_api.cc
@@ -19,8 +19,8 @@ const char kIconIndexOutOfBounds[] =
}
bool BrowserActionFunction::RunImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
- details_ = args_as_dictionary();
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details_));
+ EXTENSION_FUNCTION_VALIDATE(details_ != NULL);
if (details_->HasKey(L"tabId"))
EXTENSION_FUNCTION_VALIDATE(details_->GetInteger(L"tabId", &tab_id_));
diff --git a/chrome/browser/extensions/extension_browser_actions_api.h b/chrome/browser/extensions/extension_browser_actions_api.h
index 742eecd..c958cb3 100644
--- a/chrome/browser/extensions/extension_browser_actions_api.h
+++ b/chrome/browser/extensions/extension_browser_actions_api.h
@@ -20,7 +20,7 @@ class BrowserActionFunction : public SyncExtensionFunction {
// All the browser action APIs take a single argument called details that is
// a dictionary.
- const DictionaryValue* details_;
+ DictionaryValue* details_;
// The tab id the browser action function should apply to, if any, or
// kDefaultTabId if none was specified.
diff --git a/chrome/browser/extensions/extension_clipboard_api.cc b/chrome/browser/extensions/extension_clipboard_api.cc
index dbfe664..22a6253 100644
--- a/chrome/browser/extensions/extension_clipboard_api.cc
+++ b/chrome/browser/extensions/extension_clipboard_api.cc
@@ -18,7 +18,7 @@ const char kNoTabError[] = "No tab with id: *.";
bool ClipboardFunction::RunImpl() {
int tab_id;
- EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&tab_id));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id));
TabContents* contents = NULL;
if (!ExtensionTabUtil::GetTabById(tab_id, profile(), include_incognito(),
diff --git a/chrome/browser/extensions/extension_context_menu_api.cc b/chrome/browser/extensions/extension_context_menu_api.cc
index 08afa51..ab748f0 100644
--- a/chrome/browser/extensions/extension_context_menu_api.cc
+++ b/chrome/browser/extensions/extension_context_menu_api.cc
@@ -135,8 +135,8 @@ bool ExtensionContextMenuFunction::GetParent(
}
bool CreateContextMenuFunction::RunImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
- const DictionaryValue* properties = args_as_dictionary();
+ DictionaryValue* properties;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &properties));
EXTENSION_FUNCTION_VALIDATE(properties != NULL);
std::string title;
@@ -201,10 +201,8 @@ bool CreateContextMenuFunction::RunImpl() {
}
bool UpdateContextMenuFunction::RunImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST));
- const ListValue* args = args_as_list();
int item_id = 0;
- EXTENSION_FUNCTION_VALIDATE(args->GetInteger(0, &item_id));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &item_id));
ExtensionsService* service = profile()->GetExtensionsService();
ExtensionMenuManager* manager = service->menu_manager();
@@ -215,7 +213,7 @@ bool UpdateContextMenuFunction::RunImpl() {
}
DictionaryValue *properties = NULL;
- EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &properties));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &properties));
EXTENSION_FUNCTION_VALIDATE(properties != NULL);
ExtensionMenuManager* menu_manager =
@@ -273,9 +271,8 @@ bool UpdateContextMenuFunction::RunImpl() {
}
bool RemoveContextMenuFunction::RunImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_INTEGER));
int id = 0;
- EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&id));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &id));
ExtensionsService* service = profile()->GetExtensionsService();
ExtensionMenuManager* manager = service->menu_manager();
diff --git a/chrome/browser/extensions/extension_cookies_api.cc b/chrome/browser/extensions/extension_cookies_api.cc
index c9c2d09..05415cf 100644
--- a/chrome/browser/extensions/extension_cookies_api.cc
+++ b/chrome/browser/extensions/extension_cookies_api.cc
@@ -62,8 +62,8 @@ bool CookiesFunction::ParseCookieStore(const DictionaryValue* details,
}
bool GetCookieFunction::RunImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
- const DictionaryValue* details = args_as_dictionary();
+ DictionaryValue* details;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details));
DCHECK(details);
// Read/validate input parameters.
@@ -103,8 +103,8 @@ bool GetCookieFunction::RunImpl() {
}
bool GetAllCookiesFunction::RunImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
- const DictionaryValue* details = args_as_dictionary();
+ DictionaryValue* details;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details));
// Read/validate input parameters.
GURL url;
@@ -125,8 +125,8 @@ bool GetAllCookiesFunction::RunImpl() {
}
bool SetCookieFunction::RunImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
- const DictionaryValue* details = args_as_dictionary();
+ DictionaryValue* details;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details));
// Read/validate input parameters.
GURL url;
@@ -195,8 +195,8 @@ bool SetCookieFunction::RunImpl() {
}
bool RemoveCookieFunction::RunImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
- const DictionaryValue* details = args_as_dictionary();
+ DictionaryValue* details;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details));
// Read/validate input parameters.
GURL url;
diff --git a/chrome/browser/extensions/extension_dom_ui.cc b/chrome/browser/extensions/extension_dom_ui.cc
index ddbf605..93cfa69 100644
--- a/chrome/browser/extensions/extension_dom_ui.cc
+++ b/chrome/browser/extensions/extension_dom_ui.cc
@@ -109,7 +109,7 @@ void ExtensionDOMUI::RenderViewReused(RenderViewHost* render_view_host) {
}
void ExtensionDOMUI::ProcessDOMUIMessage(const std::string& message,
- const Value* content,
+ const ListValue* content,
const GURL& source_url,
int request_id,
bool has_callback) {
diff --git a/chrome/browser/extensions/extension_dom_ui.h b/chrome/browser/extensions/extension_dom_ui.h
index 7f60e2f..7e66a4a 100644
--- a/chrome/browser/extensions/extension_dom_ui.h
+++ b/chrome/browser/extensions/extension_dom_ui.h
@@ -38,7 +38,7 @@ class ExtensionDOMUI
virtual void RenderViewCreated(RenderViewHost* render_view_host);
virtual void RenderViewReused(RenderViewHost* render_view_host);
virtual void ProcessDOMUIMessage(const std::string& message,
- const Value* content,
+ const ListValue* content,
const GURL& source_url,
int request_id,
bool has_callback);
diff --git a/chrome/browser/extensions/extension_function.cc b/chrome/browser/extensions/extension_function.cc
index 43b7033..437867f 100644
--- a/chrome/browser/extensions/extension_function.cc
+++ b/chrome/browser/extensions/extension_function.cc
@@ -16,9 +16,9 @@ Extension* ExtensionFunction::GetExtension() {
return service->GetExtensionById(extension_id_, false);
}
-void AsyncExtensionFunction::SetArgs(const Value* args) {
+void AsyncExtensionFunction::SetArgs(const ListValue* args) {
DCHECK(!args_.get()); // Should only be called once.
- args_.reset(args->DeepCopy());
+ args_.reset(static_cast<ListValue*>(args->DeepCopy()));
}
const std::string AsyncExtensionFunction::GetResult() {
@@ -40,8 +40,6 @@ void AsyncExtensionFunction::SendResponse(bool success) {
}
bool AsyncExtensionFunction::HasOptionalArgument(size_t index) {
- DCHECK(args_->IsType(Value::TYPE_LIST));
- ListValue* args_list = static_cast<ListValue*>(args_.get());
Value* value;
- return args_list->Get(index, &value) && !value->IsType(Value::TYPE_NULL);
+ return args_->Get(index, &value) && !value->IsType(Value::TYPE_NULL);
}
diff --git a/chrome/browser/extensions/extension_function.h b/chrome/browser/extensions/extension_function.h
index c715c28..d0e1d74 100644
--- a/chrome/browser/extensions/extension_function.h
+++ b/chrome/browser/extensions/extension_function.h
@@ -58,7 +58,7 @@ class ExtensionFunction : public base::RefCounted<ExtensionFunction> {
std::string extension_id() const { return extension_id_; }
// Specifies the raw arguments to the function, as a JSON value.
- virtual void SetArgs(const Value* args) = 0;
+ virtual void SetArgs(const ListValue* args) = 0;
// Retrieves the results of the function as a JSON-encoded string (may
// be empty).
@@ -165,7 +165,7 @@ class AsyncExtensionFunction : public ExtensionFunction {
public:
AsyncExtensionFunction() : args_(NULL), bad_message_(false) {}
- virtual void SetArgs(const Value* args);
+ virtual void SetArgs(const ListValue* args);
virtual const std::string GetResult();
virtual const std::string GetError() { return error_; }
virtual void Run() {
@@ -182,19 +182,12 @@ class AsyncExtensionFunction : public ExtensionFunction {
void SendResponse(bool success);
- const ListValue* args_as_list() {
- return static_cast<ListValue*>(args_.get());
- }
- const DictionaryValue* args_as_dictionary() {
- return static_cast<DictionaryValue*>(args_.get());
- }
-
// Return true if the argument to this function at |index| was provided and
// is non-null.
bool HasOptionalArgument(size_t index);
// The arguments to the API. Only non-null if argument were specified.
- scoped_ptr<Value> args_;
+ scoped_ptr<ListValue> args_;
// The result of the API. This should be populated by the derived class before
// SendResponse() is called.
diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc
index a0b846a..40dbae5 100644
--- a/chrome/browser/extensions/extension_function_dispatcher.cc
+++ b/chrome/browser/extensions/extension_function_dispatcher.cc
@@ -378,7 +378,7 @@ Browser* ExtensionFunctionDispatcher::GetCurrentBrowser(
}
void ExtensionFunctionDispatcher::HandleRequest(const std::string& name,
- const Value* args,
+ const ListValue* args,
const GURL& source_url,
int request_id,
bool has_callback) {
diff --git a/chrome/browser/extensions/extension_function_dispatcher.h b/chrome/browser/extensions/extension_function_dispatcher.h
index 6ef4d17..d9b973d 100644
--- a/chrome/browser/extensions/extension_function_dispatcher.h
+++ b/chrome/browser/extensions/extension_function_dispatcher.h
@@ -18,11 +18,11 @@ class Extension;
class ExtensionDOMUI;
class ExtensionFunction;
class ExtensionHost;
+class ListValue;
class Profile;
class RenderViewHost;
class RenderViewHostDelegate;
class TabContents;
-class Value;
// A factory function for creating new ExtensionFunction instances.
typedef ExtensionFunction* (*ExtensionFunctionFactory)();
@@ -95,7 +95,7 @@ class ExtensionFunctionDispatcher {
Delegate* delegate() { return delegate_; }
// Handle a request to execute an extension function.
- void HandleRequest(const std::string& name, const Value* args,
+ void HandleRequest(const std::string& name, const ListValue* args,
const GURL& source_url, int request_id, bool has_callback);
// Send a response to a function.
diff --git a/chrome/browser/extensions/extension_history_api.cc b/chrome/browser/extensions/extension_history_api.cc
index 400c163..db4ec49 100644
--- a/chrome/browser/extensions/extension_history_api.cc
+++ b/chrome/browser/extensions/extension_history_api.cc
@@ -206,8 +206,8 @@ void HistoryFunctionWithCallback::SendResponseToCallback() {
}
bool GetVisitsHistoryFunction::RunAsyncImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
- const DictionaryValue* json = args_as_dictionary();
+ DictionaryValue* json;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &json));
Value* value;
EXTENSION_FUNCTION_VALIDATE(json->Get(keys::kUrlKey, &value));
@@ -243,8 +243,8 @@ void GetVisitsHistoryFunction::QueryComplete(
}
bool SearchHistoryFunction::RunAsyncImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
- const DictionaryValue* json = args_as_dictionary();
+ DictionaryValue* json;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &json));
// Initialize the HistoryQuery
std::wstring search_text;
@@ -293,8 +293,8 @@ void SearchHistoryFunction::SearchComplete(
}
bool AddUrlHistoryFunction::RunImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
- const DictionaryValue* json = args_as_dictionary();
+ DictionaryValue* json;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &json));
Value* value;
EXTENSION_FUNCTION_VALIDATE(json->Get(keys::kUrlKey, &value));
@@ -311,8 +311,8 @@ bool AddUrlHistoryFunction::RunImpl() {
}
bool DeleteUrlHistoryFunction::RunImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
- const DictionaryValue* json = args_as_dictionary();
+ DictionaryValue* json;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &json));
Value* value;
EXTENSION_FUNCTION_VALIDATE(json->Get(keys::kUrlKey, &value));
@@ -329,8 +329,8 @@ bool DeleteUrlHistoryFunction::RunImpl() {
}
bool DeleteRangeHistoryFunction::RunAsyncImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
- const DictionaryValue* json = args_as_dictionary();
+ DictionaryValue* json;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &json));
Value* value = NULL;
EXTENSION_FUNCTION_VALIDATE(json->Get(keys::kStartTimeKey, &value));
diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc
index 3a6ccc3..1ae5aca 100644
--- a/chrome/browser/extensions/extension_host.cc
+++ b/chrome/browser/extensions/extension_host.cc
@@ -539,7 +539,7 @@ WebPreferences ExtensionHost::GetWebkitPrefs() {
}
void ExtensionHost::ProcessDOMUIMessage(const std::string& message,
- const Value* content,
+ const ListValue* content,
const GURL& source_url,
int request_id,
bool has_callback) {
diff --git a/chrome/browser/extensions/extension_host.h b/chrome/browser/extensions/extension_host.h
index 013cb99..8329164 100644
--- a/chrome/browser/extensions/extension_host.h
+++ b/chrome/browser/extensions/extension_host.h
@@ -130,7 +130,7 @@ class ExtensionHost : public RenderViewHostDelegate,
virtual WebPreferences GetWebkitPrefs();
virtual void ProcessDOMUIMessage(const std::string& message,
- const Value* content,
+ const ListValue* content,
const GURL& source_url,
int request_id,
bool has_callback);
diff --git a/chrome/browser/extensions/extension_idle_api.cc b/chrome/browser/extensions/extension_idle_api.cc
index da1e2b1..0a6a25f 100644
--- a/chrome/browser/extensions/extension_idle_api.cc
+++ b/chrome/browser/extensions/extension_idle_api.cc
@@ -137,7 +137,7 @@ void ExtensionIdlePollingTask::Run() {
bool ExtensionIdleQueryStateFunction::RunImpl() {
int threshold;
- EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&threshold));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &threshold));
threshold = CheckThresholdBounds(threshold);
IdleState state = ThrottledCalculateIdleState(threshold, profile());
result_.reset(CreateIdleValue(state));
diff --git a/chrome/browser/extensions/extension_infobar_module.cc b/chrome/browser/extensions/extension_infobar_module.cc
index d8cea95..d8d4950 100644
--- a/chrome/browser/extensions/extension_infobar_module.cc
+++ b/chrome/browser/extensions/extension_infobar_module.cc
@@ -20,8 +20,8 @@
namespace keys = extension_infobar_module_constants;
bool ShowInfoBarFunction::RunImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
- const DictionaryValue* args = args_as_dictionary();
+ DictionaryValue* args;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
std::string html_path;
EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kHtmlPath, &html_path));
diff --git a/chrome/browser/extensions/extension_metrics_module.cc b/chrome/browser/extensions/extension_metrics_module.cc
index 30db486..380cf0af 100644
--- a/chrome/browser/extensions/extension_metrics_module.cc
+++ b/chrome/browser/extensions/extension_metrics_module.cc
@@ -29,8 +29,7 @@ std::string BuildMetricName(const std::string& name,
bool MetricsRecordUserActionFunction::RunImpl() {
std::string name;
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_STRING));
- EXTENSION_FUNCTION_VALIDATE(args_->GetAsString(&name));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &name));
name = BuildMetricName(name, GetExtension());
UserMetrics::RecordComputedAction(name, profile());
@@ -39,11 +38,8 @@ bool MetricsRecordUserActionFunction::RunImpl() {
bool MetricsHistogramHelperFunction::GetNameAndSample(std::string* name,
int* sample) {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST));
- const ListValue* args = args_as_list();
-
- EXTENSION_FUNCTION_VALIDATE(args->GetString(0, name));
- EXTENSION_FUNCTION_VALIDATE(args->GetInteger(1, sample));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, name));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, sample));
return true;
}
@@ -74,15 +70,12 @@ bool MetricsHistogramHelperFunction::RecordValue(const std::string& name,
}
bool MetricsRecordValueFunction::RunImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST));
- const ListValue* args = args_as_list();
-
int sample;
- EXTENSION_FUNCTION_VALIDATE(args->GetInteger(1, &sample));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &sample));
// Get the histogram parameters from the metric type object.
DictionaryValue* metric_type;
- EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(0, &metric_type));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &metric_type));
std::string name;
std::string type;
diff --git a/chrome/browser/extensions/extension_page_actions_module.cc b/chrome/browser/extensions/extension_page_actions_module.cc
index a169450..f91c5ef 100644
--- a/chrome/browser/extensions/extension_page_actions_module.cc
+++ b/chrome/browser/extensions/extension_page_actions_module.cc
@@ -32,13 +32,10 @@ const char kNoIconSpecified[] = "Page action has no icons to show.";
// TODO(EXTENSIONS_DEPRECATED): obsolete API.
bool PageActionFunction::SetPageActionEnabled(bool enable) {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST));
- const ListValue* args = args_as_list();
-
std::string page_action_id;
- EXTENSION_FUNCTION_VALIDATE(args->GetString(0, &page_action_id));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &page_action_id));
DictionaryValue* action;
- EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &action));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &action));
int tab_id;
EXTENSION_FUNCTION_VALIDATE(action->GetInteger(keys::kTabIdKey, &tab_id));
@@ -117,7 +114,7 @@ bool PageActionFunction::InitCommon(int tab_id) {
bool PageActionFunction::SetVisible(bool visible) {
int tab_id;
- EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&tab_id));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id));
if (!InitCommon(tab_id))
return false;
@@ -143,8 +140,8 @@ bool PageActionHideFunction::RunImpl() {
}
bool PageActionSetIconFunction::RunImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
- const DictionaryValue* args = args_as_dictionary();
+ DictionaryValue* args;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
int tab_id;
EXTENSION_FUNCTION_VALIDATE(args->GetInteger(L"tabId", &tab_id));
@@ -179,8 +176,8 @@ bool PageActionSetIconFunction::RunImpl() {
}
bool PageActionSetTitleFunction::RunImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
- const DictionaryValue* args = args_as_dictionary();
+ DictionaryValue* args;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
int tab_id;
EXTENSION_FUNCTION_VALIDATE(args->GetInteger(L"tabId", &tab_id));
@@ -196,8 +193,8 @@ bool PageActionSetTitleFunction::RunImpl() {
}
bool PageActionSetPopupFunction::RunImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
- const DictionaryValue* args = args_as_dictionary();
+ DictionaryValue* args;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
int tab_id;
EXTENSION_FUNCTION_VALIDATE(args->GetInteger(L"tabId", &tab_id));
@@ -221,8 +218,8 @@ bool PageActionSetPopupFunction::RunImpl() {
// Not currently exposed to extensions. To re-enable, add mapping in
// extension_function_dispatcher.
bool PageActionSetBadgeBackgroundColorFunction::RunImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
- const DictionaryValue* args = args_as_dictionary();
+ DictionaryValue* args;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
int tab_id;
EXTENSION_FUNCTION_VALIDATE(args->GetInteger(L"tabId", &tab_id));
@@ -247,8 +244,8 @@ bool PageActionSetBadgeBackgroundColorFunction::RunImpl() {
// Not currently exposed to extensions. To re-enable, add mapping in
// extension_function_dispatcher.
bool PageActionSetBadgeTextColorFunction::RunImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
- const DictionaryValue* args = args_as_dictionary();
+ DictionaryValue* args;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
int tab_id;
EXTENSION_FUNCTION_VALIDATE(args->GetInteger(L"tabId", &tab_id));
@@ -273,8 +270,8 @@ bool PageActionSetBadgeTextColorFunction::RunImpl() {
// Not currently exposed to extensions. To re-enable, add mapping in
// extension_function_dispatcher.
bool PageActionSetBadgeTextFunction::RunImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
- const DictionaryValue* args = args_as_dictionary();
+ DictionaryValue* args;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
int tab_id;
EXTENSION_FUNCTION_VALIDATE(args->GetInteger(L"tabId", &tab_id));
diff --git a/chrome/browser/extensions/extension_popup_api.cc b/chrome/browser/extensions/extension_popup_api.cc
index acc47e3..c648744 100644
--- a/chrome/browser/extensions/extension_popup_api.cc
+++ b/chrome/browser/extensions/extension_popup_api.cc
@@ -329,14 +329,11 @@ bool PopupShowFunction::RunImpl() {
return false;
}
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST));
- const ListValue* args = args_as_list();
-
std::string url_string;
- EXTENSION_FUNCTION_VALIDATE(args->GetString(0, &url_string));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url_string));
DictionaryValue* show_details = NULL;
- EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &show_details));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &show_details));
DictionaryValue* dom_anchor = NULL;
EXTENSION_FUNCTION_VALIDATE(show_details->GetDictionary(kDomAnchorKey,
diff --git a/chrome/browser/extensions/extension_processes_api.cc b/chrome/browser/extensions/extension_processes_api.cc
index fda8c7f..c4895d3 100644
--- a/chrome/browser/extensions/extension_processes_api.cc
+++ b/chrome/browser/extensions/extension_processes_api.cc
@@ -20,7 +20,7 @@ DictionaryValue* CreateProcessValue(int process_id) {
bool GetProcessForTabFunction::RunImpl() {
int tab_id;
- EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&tab_id));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id));
TabContents* contents = NULL;
int tab_index = -1;
diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc
index 8de4842..047f9aa 100644
--- a/chrome/browser/extensions/extension_tabs_module.cc
+++ b/chrome/browser/extensions/extension_tabs_module.cc
@@ -220,7 +220,7 @@ bool ExtensionTabUtil::GetTabById(int tab_id, Profile* profile,
bool GetWindowFunction::RunImpl() {
int window_id;
- EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&window_id));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id));
Browser* browser = GetBrowserInProfileWithId(profile(), window_id,
include_incognito(), &error_);
@@ -254,9 +254,10 @@ bool GetLastFocusedWindowFunction::RunImpl() {
bool GetAllWindowsFunction::RunImpl() {
bool populate_tabs = false;
- if (!args_->IsType(Value::TYPE_NULL)) {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
- const DictionaryValue* args = args_as_dictionary();
+ if (HasOptionalArgument(0)) {
+ DictionaryValue* args;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
+
if (args->HasKey(keys::kPopulateKey)) {
EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kPopulateKey,
&populate_tabs));
@@ -283,9 +284,10 @@ bool CreateWindowFunction::RunImpl() {
GURL url;
// Look for optional url.
- if (!args_->IsType(Value::TYPE_NULL)) {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
- const DictionaryValue *args = args_as_dictionary();
+ if (HasOptionalArgument(0)) {
+ DictionaryValue* args;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
+
std::string url_string;
if (args->HasKey(keys::kUrlKey)) {
EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kUrlKey,
@@ -315,8 +317,9 @@ bool CreateWindowFunction::RunImpl() {
Profile* window_profile = profile();
Browser::Type window_type = Browser::TYPE_NORMAL;
- if (args_->IsType(Value::TYPE_DICTIONARY)) {
- const DictionaryValue *args = args_as_dictionary();
+ if (!args_->empty()) {
+ DictionaryValue* args;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
// Any part of the bounds can optionally be set by the caller.
int bounds_val;
@@ -386,12 +389,10 @@ bool CreateWindowFunction::RunImpl() {
}
bool UpdateWindowFunction::RunImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST));
- const ListValue* args = args_as_list();
int window_id;
- EXTENSION_FUNCTION_VALIDATE(args->GetInteger(0, &window_id));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id));
DictionaryValue* update_props;
- EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &update_props));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props));
Browser* browser = GetBrowserInProfileWithId(profile(), window_id,
include_incognito(), &error_);
@@ -438,7 +439,7 @@ bool UpdateWindowFunction::RunImpl() {
bool RemoveWindowFunction::RunImpl() {
int window_id;
- EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&window_id));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id));
Browser* browser = GetBrowserInProfileWithId(profile(), window_id,
include_incognito(), &error_);
@@ -457,8 +458,8 @@ bool GetSelectedTabFunction::RunImpl() {
// windowId defaults to "current" window.
int window_id = -1;
- if (!args_->IsType(Value::TYPE_NULL)) {
- EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&window_id));
+ if (HasOptionalArgument(0)) {
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id));
browser = GetBrowserInProfileWithId(profile(), window_id,
include_incognito(), &error_);
} else {
@@ -484,8 +485,8 @@ bool GetAllTabsInWindowFunction::RunImpl() {
Browser* browser;
// windowId defaults to "current" window.
int window_id = -1;
- if (!args_->IsType(Value::TYPE_NULL)) {
- EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&window_id));
+ if (HasOptionalArgument(0)) {
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id));
browser = GetBrowserInProfileWithId(profile(), window_id,
include_incognito(), &error_);
} else {
@@ -502,8 +503,8 @@ bool GetAllTabsInWindowFunction::RunImpl() {
}
bool CreateTabFunction::RunImpl() {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
- const DictionaryValue* args = args_as_dictionary();
+ DictionaryValue* args;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
Browser *browser;
// windowId defaults to "current" window.
@@ -589,7 +590,7 @@ bool CreateTabFunction::RunImpl() {
bool GetTabFunction::RunImpl() {
int tab_id;
- EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&tab_id));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id));
TabStripModel* tab_strip = NULL;
TabContents* contents = NULL;
@@ -615,11 +616,9 @@ bool GetCurrentTabFunction::RunImpl() {
bool UpdateTabFunction::RunImpl() {
int tab_id;
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST));
- const ListValue* args = args_as_list();
- EXTENSION_FUNCTION_VALIDATE(args->GetInteger(0, &tab_id));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id));
DictionaryValue* update_props;
- EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &update_props));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props));
TabStripModel* tab_strip = NULL;
TabContents* contents = NULL;
@@ -697,11 +696,9 @@ bool UpdateTabFunction::RunImpl() {
bool MoveTabFunction::RunImpl() {
int tab_id;
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST));
- const ListValue* args = args_as_list();
- EXTENSION_FUNCTION_VALIDATE(args->GetInteger(0, &tab_id));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id));
DictionaryValue* update_props;
- EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &update_props));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props));
int new_index;
EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(
@@ -772,7 +769,7 @@ bool MoveTabFunction::RunImpl() {
bool RemoveTabFunction::RunImpl() {
int tab_id;
- EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&tab_id));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id));
Browser* browser = NULL;
TabContents* contents = NULL;
@@ -801,11 +798,8 @@ bool CaptureVisibleTabFunction::RunImpl() {
// windowId defaults to "current" window.
int window_id = -1;
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST));
- const ListValue* args = args_as_list();
-
if (HasOptionalArgument(0)) {
- EXTENSION_FUNCTION_VALIDATE(args->GetInteger(0, &window_id));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id));
browser = GetBrowserInProfileWithId(profile(), window_id,
include_incognito(), &error_);
} else {
@@ -822,7 +816,7 @@ bool CaptureVisibleTabFunction::RunImpl() {
if (HasOptionalArgument(1)) {
DictionaryValue* options;
- EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &options));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &options));
if (options->HasKey(keys::kFormatKey)) {
std::string format;
@@ -967,8 +961,8 @@ bool DetectTabLanguageFunction::RunImpl() {
// If |tab_id| is specified, look for it. Otherwise default to selected tab
// in the current window.
- if (!args_->IsType(Value::TYPE_NULL)) {
- EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&tab_id));
+ if (HasOptionalArgument(0)) {
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id));
if (!GetTabById(tab_id, profile(), include_incognito(),
&browser, NULL, &contents, NULL, &error_)) {
return false;
diff --git a/chrome/browser/extensions/extension_test_api.cc b/chrome/browser/extensions/extension_test_api.cc
index 48323d4..e5ae650 100644
--- a/chrome/browser/extensions/extension_test_api.cc
+++ b/chrome/browser/extensions/extension_test_api.cc
@@ -20,7 +20,7 @@ bool ExtensionTestPassFunction::RunImpl() {
bool ExtensionTestFailFunction::RunImpl() {
std::string message;
- EXTENSION_FUNCTION_VALIDATE(args_->GetAsString(&message));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &message));
NotificationService::current()->Notify(
NotificationType::EXTENSION_TEST_FAILED,
Source<Profile>(dispatcher()->profile()),
@@ -30,7 +30,7 @@ bool ExtensionTestFailFunction::RunImpl() {
bool ExtensionTestLogFunction::RunImpl() {
std::string message;
- EXTENSION_FUNCTION_VALIDATE(args_->GetAsString(&message));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &message));
printf("%s\n", message.c_str());
LOG(INFO) << message;
return true;
@@ -46,7 +46,7 @@ bool ExtensionTestQuotaResetFunction::RunImpl() {
bool ExtensionTestCreateIncognitoTabFunction::RunImpl() {
std::string url;
- EXTENSION_FUNCTION_VALIDATE(args_->GetAsString(&url));
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &url));
Browser::OpenURLOffTheRecord(profile(), GURL(url));
return true;
}
diff --git a/chrome/browser/extensions/extension_toolstrip_api.cc b/chrome/browser/extensions/extension_toolstrip_api.cc
index 3732c68..26618e0 100644
--- a/chrome/browser/extensions/extension_toolstrip_api.cc
+++ b/chrome/browser/extensions/extension_toolstrip_api.cc
@@ -77,8 +77,8 @@ bool ToolstripExpandFunction::RunImpl() {
return false;
}
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
- const DictionaryValue* args = args_as_dictionary();
+ DictionaryValue* args;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
int height;
EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kHeightKey,
@@ -115,9 +115,9 @@ bool ToolstripCollapseFunction::RunImpl() {
}
GURL url;
- if (args_->GetType() != Value::TYPE_NULL) {
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
- const DictionaryValue* args = args_as_dictionary();
+ if (HasOptionalArgument(0)) {
+ DictionaryValue* args;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
if (args->HasKey(keys::kUrlKey)) {
std::string url_string;
diff --git a/chrome/browser/extensions/extensions_quota_service.cc b/chrome/browser/extensions/extensions_quota_service.cc
index 9005d8f..de5b926 100644
--- a/chrome/browser/extensions/extensions_quota_service.cc
+++ b/chrome/browser/extensions/extensions_quota_service.cc
@@ -29,7 +29,7 @@ ExtensionsQuotaService::~ExtensionsQuotaService() {
}
bool ExtensionsQuotaService::Assess(const std::string& extension_id,
- ExtensionFunction* function, const Value* args,
+ ExtensionFunction* function, const ListValue* args,
const base::TimeTicks& event_time) {
// Lookup function list for extension.
FunctionHeuristicsMap& functions = function_heuristics_[extension_id];
@@ -83,7 +83,7 @@ void QuotaLimitHeuristic::Bucket::Reset(const Config& config,
expiration_ = start + config.refill_interval;
}
-bool QuotaLimitHeuristic::ApplyToArgs(const Value* args,
+bool QuotaLimitHeuristic::ApplyToArgs(const ListValue* args,
const base::TimeTicks& event_time) {
BucketList buckets;
bucket_mapper_->GetBucketsForArgs(args, &buckets);
diff --git a/chrome/browser/extensions/extensions_quota_service.h b/chrome/browser/extensions/extensions_quota_service.h
index 700f9cc..b2999ab 100644
--- a/chrome/browser/extensions/extensions_quota_service.h
+++ b/chrome/browser/extensions/extensions_quota_service.h
@@ -43,7 +43,7 @@ class ExtensionsQuotaService {
// Returns true if the request is fine and can proceed, false if the request
// should be throttled and an error returned to the extension.
bool Assess(const std::string& extension_id, ExtensionFunction* function,
- const Value* args, const base::TimeTicks& event_time);
+ const ListValue* args, const base::TimeTicks& event_time);
private:
friend class ExtensionTestQuotaResetFunction;
typedef std::map<std::string, QuotaLimitHeuristics> FunctionHeuristicsMap;
@@ -136,7 +136,8 @@ class QuotaLimitHeuristic {
// occurs while parsing |args|, the function aborts - buckets may be non-
// empty). The expectation is that invalid args and associated errors are
// handled by the ExtensionFunction itself so we don't concern ourselves.
- virtual void GetBucketsForArgs(const Value* args, BucketList* buckets) = 0;
+ virtual void GetBucketsForArgs(const ListValue* args,
+ BucketList* buckets) = 0;
};
// Ownership of |mapper| is given to the new QuotaLimitHeuristic.
@@ -148,7 +149,7 @@ class QuotaLimitHeuristic {
// implementation of a derived class) to perform an operation with |args|,
// based on the history of similar operations with similar arguments (which
// is retrieved using the BucketMapper).
- bool ApplyToArgs(const Value* args, const base::TimeTicks& event_time);
+ bool ApplyToArgs(const ListValue* args, const base::TimeTicks& event_time);
protected:
const Config& config() { return config_; }
diff --git a/chrome/browser/extensions/extensions_quota_service_unittest.cc b/chrome/browser/extensions/extensions_quota_service_unittest.cc
index 80457eb..72958a9 100644
--- a/chrome/browser/extensions/extensions_quota_service_unittest.cc
+++ b/chrome/browser/extensions/extensions_quota_service_unittest.cc
@@ -29,11 +29,10 @@ class Mapper : public QuotaLimitHeuristic::BucketMapper {
public:
Mapper() {}
virtual ~Mapper() { STLDeleteValues(&buckets_); }
- virtual void GetBucketsForArgs(const Value* args, BucketList* buckets) {
- const ListValue* v = static_cast<const ListValue*>(args);
- for (size_t i = 0; i < v->GetSize(); i++) {
+ virtual void GetBucketsForArgs(const ListValue* args, BucketList* buckets) {
+ for (size_t i = 0; i < args->GetSize(); i++) {
int id;
- ASSERT_TRUE(v->GetInteger(i, &id));
+ ASSERT_TRUE(args->GetInteger(i, &id));
if (buckets_.find(id) == buckets_.end())
buckets_[id] = new Bucket();
buckets->push_back(buckets_[id]);
@@ -47,13 +46,13 @@ class Mapper : public QuotaLimitHeuristic::BucketMapper {
class MockMapper : public QuotaLimitHeuristic::BucketMapper {
public:
- virtual void GetBucketsForArgs(const Value* args, BucketList* buckets) {}
+ virtual void GetBucketsForArgs(const ListValue* args, BucketList* buckets) {}
};
class MockFunction : public ExtensionFunction {
public:
explicit MockFunction(const std::string& name) { set_name(name); }
- virtual void SetArgs(const Value* args) {}
+ virtual void SetArgs(const ListValue* args) {}
virtual const std::string GetError() { return std::string(); }
virtual const std::string GetResult() { return std::string(); }
virtual void Run() {}