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

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

Issue 269079: Implement new page action API. (Closed)
Patch Set: compile fixes Created 11 years, 2 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
Index: chrome/browser/extensions/extension_browser_actions_api.cc
diff --git a/chrome/browser/extensions/extension_browser_actions_api.cc b/chrome/browser/extensions/extension_browser_actions_api.cc
index e7d875e878f93d7488a881cbc8173b3177ac75eb..5cf68e8e4d1829278e7713e5f42f03c0073caa5b 100644
--- a/chrome/browser/extensions/extension_browser_actions_api.cc
+++ b/chrome/browser/extensions/extension_browser_actions_api.cc
@@ -18,10 +18,8 @@ const char kIconIndexOutOfBounds[] =
}
bool BrowserActionSetIconFunction::RunImpl() {
- // setIcon can take a variant argument: either a canvas ImageData, or an
- // icon index.
- EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_BINARY) ||
- args_->IsType(Value::TYPE_DICTIONARY));
+ EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY));
+ const DictionaryValue* args = static_cast<const DictionaryValue*>(args_);
Extension* extension = dispatcher()->GetExtension();
if (!extension->browser_action()) {
@@ -29,28 +27,28 @@ bool BrowserActionSetIconFunction::RunImpl() {
return false;
}
- if (args_->IsType(Value::TYPE_BINARY)) {
- BinaryValue* binary = static_cast<BinaryValue*>(args_);
+ // setIcon can take a variant argument: either a canvas ImageData, or an
+ // icon index.
+ BinaryValue* binary;
+ int icon_index;
+ if (args->GetBinary(L"imageData", &binary)) {
IPC::Message bitmap_pickle(binary->GetBuffer(), binary->GetSize());
void* iter = NULL;
scoped_ptr<SkBitmap> bitmap(new SkBitmap);
EXTENSION_FUNCTION_VALIDATE(
IPC::ReadParam(&bitmap_pickle, &iter, bitmap.get()));
extension->browser_action_state()->set_icon(bitmap.release());
- } else {
- int icon_index = -1;
- EXTENSION_FUNCTION_VALIDATE(
- static_cast<DictionaryValue*>(args_)->GetInteger(
- L"iconIndex", &icon_index));
+ } else if (args->GetInteger(L"iconIndex", &icon_index)) {
+ if (icon_index < 0 || static_cast<size_t>(icon_index) >=
- if (icon_index < 0 ||
- static_cast<size_t>(icon_index) >=
extension->browser_action()->icon_paths().size()) {
error_ = kIconIndexOutOfBounds;
return false;
}
extension->browser_action_state()->set_icon_index(icon_index);
extension->browser_action_state()->set_icon(NULL);
+ } else {
+ EXTENSION_FUNCTION_VALIDATE(false);
}
NotificationService::current()->Notify(
« no previous file with comments | « chrome/browser/extensions/browser_action_apitest.cc ('k') | chrome/browser/extensions/extension_function_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698