From 1288ba0949c899dce33fc6fcc8e212aee704bc48 Mon Sep 17 00:00:00 2001 From: "aa@chromium.org" Date: Thu, 15 Oct 2009 00:02:24 +0000 Subject: 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 --- .../extensions/extension_browser_actions_api.cc | 60 +++++++++++++--------- 1 file changed, 35 insertions(+), 25 deletions(-) (limited to '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 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(extension->browser_action()), - Details(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(args_)->GetInteger( + L"iconIndex", &icon_index)); if (icon_index < 0 || static_cast(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(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(extension->browser_action()), + Details(extension->browser_action_state())); + return true; +} + bool BrowserActionSetBadgeTextFunction::RunImpl() { + EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); + DictionaryValue* details = static_cast(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(args_); + EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); + DictionaryValue* details = static_cast(args_); + + ListValue* list = NULL; + EXTENSION_FUNCTION_VALIDATE(details->GetList(L"color", &list)); EXTENSION_FUNCTION_VALIDATE(list->GetSize() == 4); int color_array[4] = {0}; -- cgit v1.1