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

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

Issue 100213: use EXTENSION_FUNCTION_VALIDATE (Closed)
Patch Set: final CR change Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/extension_function.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_tabs_module.cc
diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc
index 269ffcebc23a35b6267a41ecf7a7dfc98ef9c562..069110e8bf28f8dfd727dc8fddb777299327d0ee 100644
--- a/chrome/browser/extensions/extension_tabs_module.cc
+++ b/chrome/browser/extensions/extension_tabs_module.cc
@@ -44,22 +44,13 @@ bool GetWindowsFunction::RunImpl() {
// Look for |ids| named parameter as list of id's to fetch.
if (args_->IsType(Value::TYPE_DICTIONARY)) {
- Value *ids_value;
- if ((!static_cast<DictionaryValue*>(args_)->Get(L"ids", &ids_value)) ||
- (!ids_value->IsType(Value::TYPE_LIST))) {
- DCHECK(false);
- return false;
- }
-
- ListValue *window_id_list = static_cast<ListValue*>(ids_value);
+ ListValue *window_id_list;
+ const DictionaryValue *args = static_cast<const DictionaryValue*>(args_);
+ EXTENSION_FUNCTION_VALIDATE(args->GetList(L"ids", &window_id_list));
for (ListValue::iterator id = window_id_list->begin();
id != window_id_list->end(); ++id) {
int window_id;
- if (!(*id)->GetAsInteger(&window_id)) {
- DCHECK(false);
- return false;
- }
-
+ EXTENSION_FUNCTION_VALIDATE((*id)->GetAsInteger(&window_id));
window_ids.insert(window_id);
}
}
@@ -150,12 +141,8 @@ bool CreateWindowFunction::RunImpl() {
}
bool RemoveWindowFunction::RunImpl() {
- if (!args_->IsType(Value::TYPE_INTEGER))
- return false;
-
int window_id;
- if (!args_->GetAsInteger(&window_id))
- return false;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&window_id));
Browser* target = NULL;
for (BrowserList::const_iterator browser = BrowserList::begin();
@@ -181,8 +168,7 @@ bool RemoveWindowFunction::RunImpl() {
bool GetTabsForWindowFunction::RunImpl() {
- if (!args_->IsType(Value::TYPE_NULL))
- return false;
+ EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_NULL));
Browser* browser = dispatcher_->browser();
if (!browser)
@@ -194,16 +180,14 @@ bool GetTabsForWindowFunction::RunImpl() {
}
bool CreateTabFunction::RunImpl() {
- // TODO(aa): Do data-driven validation in JS.
- if (!args_->IsType(Value::TYPE_DICTIONARY))
- return false;
+ EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
+ const DictionaryValue *args = static_cast<const DictionaryValue*>(args_);
Browser* browser = BrowserList::GetLastActive();
if (!browser)
return false;
TabStripModel *tab_strip = browser->tabstrip_model();
- const DictionaryValue *args = static_cast<const DictionaryValue*>(args_);
// TODO(rafaelw): handle setting remaining tab properties:
// -windowId
@@ -242,16 +226,13 @@ bool CreateTabFunction::RunImpl() {
}
bool GetTabFunction::RunImpl() {
- if (!args_->IsType(Value::TYPE_INTEGER))
- return false;
+ int tab_id;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&tab_id));
Browser* browser = BrowserList::GetLastActive();
if (!browser)
return false;
- int tab_id;
- args_->GetAsInteger(&tab_id);
-
int tab_index;
TabStripModel* tab_strip = browser->tabstrip_model();
// TODO(rafaelw): return an error if the tab is not found by |tab_id|
@@ -263,19 +244,15 @@ bool GetTabFunction::RunImpl() {
}
bool UpdateTabFunction::RunImpl() {
- // TODO(aa): Do data-driven validation in JS.
- if (!args_->IsType(Value::TYPE_DICTIONARY))
- return false;
+ int tab_id;
+ EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
+ const DictionaryValue *args = static_cast<const DictionaryValue*>(args_);
+ EXTENSION_FUNCTION_VALIDATE(args->GetInteger(L"id", &tab_id));
Browser* browser = BrowserList::GetLastActive();
if (!browser)
return false;
- int tab_id;
- const DictionaryValue *args = static_cast<const DictionaryValue*>(args_);
- if (!args->GetInteger(L"id", &tab_id))
- return false;
-
int tab_index;
TabStripModel* tab_strip = browser->tabstrip_model();
// TODO(rafaelw): return an error if the tab is not found by |tab_id|
@@ -313,18 +290,18 @@ bool UpdateTabFunction::RunImpl() {
}
bool MoveTabFunction::RunImpl() {
- if (!args_->IsType(Value::TYPE_DICTIONARY))
- return false;
+ int tab_id;
+ int new_index;
+ EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
+ const DictionaryValue *args = static_cast<const DictionaryValue*>(args_);
+ EXTENSION_FUNCTION_VALIDATE(args->GetInteger(L"id", &tab_id));
+ EXTENSION_FUNCTION_VALIDATE(args->GetInteger(L"index", &new_index));
+ EXTENSION_FUNCTION_VALIDATE(new_index >= 0);
Browser* browser = BrowserList::GetLastActive();
if (!browser)
return false;
- int tab_id;
- const DictionaryValue *args = static_cast<const DictionaryValue*>(args_);
- if (!args->GetInteger(L"id", &tab_id))
- return false;
-
int tab_index;
TabStripModel* tab_strip = browser->tabstrip_model();
// TODO(rafaelw): return an error if the tab is not found by |tab_id|
@@ -334,13 +311,6 @@ bool MoveTabFunction::RunImpl() {
// TODO(rafaelw): support moving tabs between windows
// -windowId
- int new_index;
- bool found_index = args->GetInteger(L"index", &new_index);
- if (!found_index || new_index < 0) {
- DCHECK(false);
- return false;
- }
-
// Clamp move location to the last position.
if (new_index >= tab_strip->count()) {
new_index = tab_strip->count() - 1;
@@ -357,19 +327,13 @@ bool MoveTabFunction::RunImpl() {
bool RemoveTabFunction::RunImpl() {
// TODO(rafaelw): This should have a callback, but it can't because it could
// close it's own tab.
-
- if (!args_->IsType(Value::TYPE_INTEGER))
- return false;
+ int tab_id;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&tab_id));
Browser* browser = BrowserList::GetLastActive();
if (!browser)
return false;
- int tab_id;
- if (!args_->GetAsInteger(&tab_id)) {
- return false;
- }
-
int tab_index;
TabStripModel* tab_strip = browser->tabstrip_model();
if (GetIndexOfTabId(tab_strip, tab_id, &tab_index)) {
« no previous file with comments | « chrome/browser/extensions/extension_function.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698