Commit 022a7edd authored by rafaelw@chromium.org's avatar rafaelw@chromium.org

use EXTENSION_FUNCTION_VALIDATE in extension_tabs_module.cc

BUG=11200
R=erikkay

Review URL: http://codereview.chromium.org/100213

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14976 0039d316-1c4b-4281-b951-d872f2087c98
parent d3ca3b08
...@@ -14,7 +14,7 @@ class ExtensionFunctionDispatcher; ...@@ -14,7 +14,7 @@ class ExtensionFunctionDispatcher;
class Profile; class Profile;
#define EXTENSION_FUNCTION_VALIDATE(test) do { \ #define EXTENSION_FUNCTION_VALIDATE(test) do { \
if (!test) { \ if (!(test)) { \
bad_message_ = true; \ bad_message_ = true; \
return false; \ return false; \
} \ } \
......
...@@ -44,22 +44,13 @@ bool GetWindowsFunction::RunImpl() { ...@@ -44,22 +44,13 @@ bool GetWindowsFunction::RunImpl() {
// Look for |ids| named parameter as list of id's to fetch. // Look for |ids| named parameter as list of id's to fetch.
if (args_->IsType(Value::TYPE_DICTIONARY)) { if (args_->IsType(Value::TYPE_DICTIONARY)) {
Value *ids_value; ListValue *window_id_list;
if ((!static_cast<DictionaryValue*>(args_)->Get(L"ids", &ids_value)) || const DictionaryValue *args = static_cast<const DictionaryValue*>(args_);
(!ids_value->IsType(Value::TYPE_LIST))) { EXTENSION_FUNCTION_VALIDATE(args->GetList(L"ids", &window_id_list));
DCHECK(false);
return false;
}
ListValue *window_id_list = static_cast<ListValue*>(ids_value);
for (ListValue::iterator id = window_id_list->begin(); for (ListValue::iterator id = window_id_list->begin();
id != window_id_list->end(); ++id) { id != window_id_list->end(); ++id) {
int window_id; int window_id;
if (!(*id)->GetAsInteger(&window_id)) { EXTENSION_FUNCTION_VALIDATE((*id)->GetAsInteger(&window_id));
DCHECK(false);
return false;
}
window_ids.insert(window_id); window_ids.insert(window_id);
} }
} }
...@@ -150,12 +141,8 @@ bool CreateWindowFunction::RunImpl() { ...@@ -150,12 +141,8 @@ bool CreateWindowFunction::RunImpl() {
} }
bool RemoveWindowFunction::RunImpl() { bool RemoveWindowFunction::RunImpl() {
if (!args_->IsType(Value::TYPE_INTEGER))
return false;
int window_id; int window_id;
if (!args_->GetAsInteger(&window_id)) EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&window_id));
return false;
Browser* target = NULL; Browser* target = NULL;
for (BrowserList::const_iterator browser = BrowserList::begin(); for (BrowserList::const_iterator browser = BrowserList::begin();
...@@ -181,8 +168,7 @@ bool RemoveWindowFunction::RunImpl() { ...@@ -181,8 +168,7 @@ bool RemoveWindowFunction::RunImpl() {
bool GetTabsForWindowFunction::RunImpl() { bool GetTabsForWindowFunction::RunImpl() {
if (!args_->IsType(Value::TYPE_NULL)) EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_NULL));
return false;
Browser* browser = dispatcher_->browser(); Browser* browser = dispatcher_->browser();
if (!browser) if (!browser)
...@@ -194,16 +180,14 @@ bool GetTabsForWindowFunction::RunImpl() { ...@@ -194,16 +180,14 @@ bool GetTabsForWindowFunction::RunImpl() {
} }
bool CreateTabFunction::RunImpl() { bool CreateTabFunction::RunImpl() {
// TODO(aa): Do data-driven validation in JS. EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
if (!args_->IsType(Value::TYPE_DICTIONARY)) const DictionaryValue *args = static_cast<const DictionaryValue*>(args_);
return false;
Browser* browser = BrowserList::GetLastActive(); Browser* browser = BrowserList::GetLastActive();
if (!browser) if (!browser)
return false; return false;
TabStripModel *tab_strip = browser->tabstrip_model(); TabStripModel *tab_strip = browser->tabstrip_model();
const DictionaryValue *args = static_cast<const DictionaryValue*>(args_);
// TODO(rafaelw): handle setting remaining tab properties: // TODO(rafaelw): handle setting remaining tab properties:
// -windowId // -windowId
...@@ -242,16 +226,13 @@ bool CreateTabFunction::RunImpl() { ...@@ -242,16 +226,13 @@ bool CreateTabFunction::RunImpl() {
} }
bool GetTabFunction::RunImpl() { bool GetTabFunction::RunImpl() {
if (!args_->IsType(Value::TYPE_INTEGER)) int tab_id;
return false; EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&tab_id));
Browser* browser = BrowserList::GetLastActive(); Browser* browser = BrowserList::GetLastActive();
if (!browser) if (!browser)
return false; return false;
int tab_id;
args_->GetAsInteger(&tab_id);
int tab_index; int tab_index;
TabStripModel* tab_strip = browser->tabstrip_model(); TabStripModel* tab_strip = browser->tabstrip_model();
// TODO(rafaelw): return an error if the tab is not found by |tab_id| // TODO(rafaelw): return an error if the tab is not found by |tab_id|
...@@ -263,19 +244,15 @@ bool GetTabFunction::RunImpl() { ...@@ -263,19 +244,15 @@ bool GetTabFunction::RunImpl() {
} }
bool UpdateTabFunction::RunImpl() { bool UpdateTabFunction::RunImpl() {
// TODO(aa): Do data-driven validation in JS. int tab_id;
if (!args_->IsType(Value::TYPE_DICTIONARY)) EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
return false; const DictionaryValue *args = static_cast<const DictionaryValue*>(args_);
EXTENSION_FUNCTION_VALIDATE(args->GetInteger(L"id", &tab_id));
Browser* browser = BrowserList::GetLastActive(); Browser* browser = BrowserList::GetLastActive();
if (!browser) if (!browser)
return false; 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; int tab_index;
TabStripModel* tab_strip = browser->tabstrip_model(); TabStripModel* tab_strip = browser->tabstrip_model();
// TODO(rafaelw): return an error if the tab is not found by |tab_id| // TODO(rafaelw): return an error if the tab is not found by |tab_id|
...@@ -313,18 +290,18 @@ bool UpdateTabFunction::RunImpl() { ...@@ -313,18 +290,18 @@ bool UpdateTabFunction::RunImpl() {
} }
bool MoveTabFunction::RunImpl() { bool MoveTabFunction::RunImpl() {
if (!args_->IsType(Value::TYPE_DICTIONARY)) int tab_id;
return false; 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(); Browser* browser = BrowserList::GetLastActive();
if (!browser) if (!browser)
return false; 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; int tab_index;
TabStripModel* tab_strip = browser->tabstrip_model(); TabStripModel* tab_strip = browser->tabstrip_model();
// TODO(rafaelw): return an error if the tab is not found by |tab_id| // TODO(rafaelw): return an error if the tab is not found by |tab_id|
...@@ -334,13 +311,6 @@ bool MoveTabFunction::RunImpl() { ...@@ -334,13 +311,6 @@ bool MoveTabFunction::RunImpl() {
// TODO(rafaelw): support moving tabs between windows // TODO(rafaelw): support moving tabs between windows
// -windowId // -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. // Clamp move location to the last position.
if (new_index >= tab_strip->count()) { if (new_index >= tab_strip->count()) {
new_index = tab_strip->count() - 1; new_index = tab_strip->count() - 1;
...@@ -357,19 +327,13 @@ bool MoveTabFunction::RunImpl() { ...@@ -357,19 +327,13 @@ bool MoveTabFunction::RunImpl() {
bool RemoveTabFunction::RunImpl() { bool RemoveTabFunction::RunImpl() {
// TODO(rafaelw): This should have a callback, but it can't because it could // TODO(rafaelw): This should have a callback, but it can't because it could
// close it's own tab. // close it's own tab.
int tab_id;
if (!args_->IsType(Value::TYPE_INTEGER)) EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&tab_id));
return false;
Browser* browser = BrowserList::GetLastActive(); Browser* browser = BrowserList::GetLastActive();
if (!browser) if (!browser)
return false; return false;
int tab_id;
if (!args_->GetAsInteger(&tab_id)) {
return false;
}
int tab_index; int tab_index;
TabStripModel* tab_strip = browser->tabstrip_model(); TabStripModel* tab_strip = browser->tabstrip_model();
if (GetIndexOfTabId(tab_strip, tab_id, &tab_index)) { if (GetIndexOfTabId(tab_strip, tab_id, &tab_index)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment