diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-15 00:02:24 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-15 00:02:24 +0000 |
commit | 1288ba0949c899dce33fc6fcc8e212aee704bc48 (patch) | |
tree | bc9c5b2a1c969670e1b8a32bc5736b6dc1bb7f63 /chrome/browser/extensions/extension_browser_actions_api.cc | |
parent | be1c57d6ca0e4661760202621db55b536c189041 (diff) | |
download | chromium_src-1288ba0949c899dce33fc6fcc8e212aee704bc48.zip chromium_src-1288ba0949c899dce33fc6fcc8e212aee704bc48.tar.gz chromium_src-1288ba0949c899dce33fc6fcc8e212aee704bc48.tar.bz2 |
Update browser actions api to be like new design doc.
BUG=23879
TEST=Install sample gmail browser action sample.
Review URL: http://codereview.chromium.org/264046
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29068 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_browser_actions_api.cc')
-rw-r--r-- | chrome/browser/extensions/extension_browser_actions_api.cc | 60 |
1 files changed, 35 insertions, 25 deletions
diff --git a/chrome/browser/extensions/extension_browser_actions_api.cc b/chrome/browser/extensions/extension_browser_actions_api.cc index e671d15..d2cb604 100644 --- a/chrome/browser/extensions/extension_browser_actions_api.cc +++ b/chrome/browser/extensions/extension_browser_actions_api.cc @@ -17,30 +17,11 @@ const char kIconIndexOutOfBounds[] = "Browser action icon index out of bounds."; } -bool BrowserActionSetNameFunction::RunImpl() { - std::string title; - EXTENSION_FUNCTION_VALIDATE(args_->GetAsString(&title)); - - Extension* extension = dispatcher()->GetExtension(); - if (!extension->browser_action()) { - error_ = kNoBrowserActionError; - return false; - } - - extension->browser_action_state()->set_title(title); - - NotificationService::current()->Notify( - NotificationType::EXTENSION_BROWSER_ACTION_UPDATED, - Source<ExtensionAction>(extension->browser_action()), - Details<ExtensionActionState>(extension->browser_action_state())); - return true; -} - 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_INTEGER)); + args_->IsType(Value::TYPE_DICTIONARY)); Extension* extension = dispatcher()->GetExtension(); if (!extension->browser_action()) { @@ -58,8 +39,9 @@ bool BrowserActionSetIconFunction::RunImpl() { extension->browser_action_state()->set_icon(bitmap.release()); } else { int icon_index = -1; - EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&icon_index)); - + EXTENSION_FUNCTION_VALIDATE( + static_cast<DictionaryValue*>(args_)->GetInteger( + L"iconIndex", &icon_index)); if (icon_index < 0 || static_cast<size_t>(icon_index) >= extension->browser_action()->icon_paths().size()) { @@ -77,9 +59,34 @@ bool BrowserActionSetIconFunction::RunImpl() { return true; } +bool BrowserActionSetTitleFunction::RunImpl() { + EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); + DictionaryValue* details = static_cast<DictionaryValue*>(args_); + + std::string title; + EXTENSION_FUNCTION_VALIDATE(details->GetString(L"title", &title)); + + Extension* extension = dispatcher()->GetExtension(); + if (!extension->browser_action()) { + error_ = kNoBrowserActionError; + return false; + } + + extension->browser_action_state()->set_title(title); + + NotificationService::current()->Notify( + NotificationType::EXTENSION_BROWSER_ACTION_UPDATED, + Source<ExtensionAction>(extension->browser_action()), + Details<ExtensionActionState>(extension->browser_action_state())); + return true; +} + bool BrowserActionSetBadgeTextFunction::RunImpl() { + EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); + DictionaryValue* details = static_cast<DictionaryValue*>(args_); + std::string badge_text; - EXTENSION_FUNCTION_VALIDATE(args_->GetAsString(&badge_text)); + EXTENSION_FUNCTION_VALIDATE(details->GetString(L"text", &badge_text)); Extension* extension = dispatcher()->GetExtension(); if (!extension->browser_action()) { @@ -97,8 +104,11 @@ bool BrowserActionSetBadgeTextFunction::RunImpl() { } bool BrowserActionSetBadgeBackgroundColorFunction::RunImpl() { - EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST)); - ListValue* list = static_cast<ListValue*>(args_); + EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); + DictionaryValue* details = static_cast<DictionaryValue*>(args_); + + ListValue* list = NULL; + EXTENSION_FUNCTION_VALIDATE(details->GetList(L"color", &list)); EXTENSION_FUNCTION_VALIDATE(list->GetSize() == 4); int color_array[4] = {0}; |