diff options
author | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-06 18:56:51 +0000 |
---|---|---|
committer | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-06 18:56:51 +0000 |
commit | 3bc65248b6943fe648c996175d4f13de2f32d68b (patch) | |
tree | de2b35a5c8f6766212346d4b3ebda78fed7f7f67 /chrome/browser/extensions | |
parent | e90ed8ae06d460f74fc32207ddaca7e1d1de787d (diff) | |
download | chromium_src-3bc65248b6943fe648c996175d4f13de2f32d68b.zip chromium_src-3bc65248b6943fe648c996175d4f13de2f32d68b.tar.gz chromium_src-3bc65248b6943fe648c996175d4f13de2f32d68b.tar.bz2 |
Implement browserAction.setIcon(ImageData) for extensions.
BUG=23269
TEST=load the test_browser_action sample extension, and click the browser action. Watch it dynamically update.
Review URL: http://codereview.chromium.org/242150
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28136 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--[-rwxr-xr-x] | chrome/browser/extensions/extension_browser_actions_api.cc | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/chrome/browser/extensions/extension_browser_actions_api.cc b/chrome/browser/extensions/extension_browser_actions_api.cc index d80637d..2a3aa2e2 100755..100644 --- a/chrome/browser/extensions/extension_browser_actions_api.cc +++ b/chrome/browser/extensions/extension_browser_actions_api.cc @@ -7,6 +7,7 @@ #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" #include "chrome/common/notification_service.h" +#include "chrome/common/render_messages.h" namespace extension_browser_actions_api_constants { @@ -44,8 +45,10 @@ bool BrowserActionSetNameFunction::RunImpl() { } bool BrowserActionSetIconFunction::RunImpl() { - int icon_index = -1; - EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&icon_index)); + // 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_INTEGER)); Extension* extension = dispatcher()->GetExtension(); if (!extension->browser_action()) { @@ -53,7 +56,19 @@ bool BrowserActionSetIconFunction::RunImpl() { return false; } - extension->browser_action_state()->set_icon_index(icon_index); + if (args_->IsType(Value::TYPE_BINARY)) { + BinaryValue* binary = static_cast<BinaryValue*>(args_); + 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(args_->GetAsInteger(&icon_index)); + extension->browser_action_state()->set_icon_index(icon_index); + } NotificationService::current()->Notify( NotificationType::EXTENSION_BROWSER_ACTION_UPDATED, |