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

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

Issue 264046: Update browser actions api to be like new design doc. (Closed)
Patch Set: rebase 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 e671d15e71308588b12928fb52aba1f3cfa00d06..d2cb6043abba1b30c23ea1dd32a2db3e29246de4 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};
« no previous file with comments | « chrome/browser/extensions/extension_browser_actions_api.h ('k') | chrome/browser/extensions/extension_browser_event_router.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698