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

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

Issue 256032: Add an API to manipulate the browser action badge. (Closed)
Patch Set: meet halfway Created 11 years, 3 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 6087d14ce416be036f8bb3b256218081671d364d..d80637d918023f798b927fe8358fca8acdd598df 100755
--- a/chrome/browser/extensions/extension_browser_actions_api.cc
+++ b/chrome/browser/extensions/extension_browser_actions_api.cc
@@ -12,6 +12,9 @@ namespace extension_browser_actions_api_constants {
const char kSetNameFunction[] = "browserAction.setName";
const char kSetIconFunction[] = "browserAction.setIcon";
+const char kSetBadgeTextFunction[] = "browserAction.setBadgeText";
+const char kSetBadgeBackgroundColorFunction[] =
+ "browserAction.setBadgeBackgroundColor";
} // namespace extension_browser_actions_api_constants
@@ -58,3 +61,50 @@ bool BrowserActionSetIconFunction::RunImpl() {
Details<ExtensionActionState>(extension->browser_action_state()));
return true;
}
+
+bool BrowserActionSetBadgeTextFunction::RunImpl() {
+ std::string badge_text;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetAsString(&badge_text));
+
+ Extension* extension = dispatcher()->GetExtension();
+ if (!extension->browser_action()) {
+ error_ = kNoBrowserActionError;
+ return false;
+ }
+
+ extension->browser_action_state()->set_badge_text(badge_text);
+
+ NotificationService::current()->Notify(
+ NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
+ Source<ExtensionAction>(extension->browser_action()),
+ Details<ExtensionActionState>(extension->browser_action_state()));
+ return true;
+}
+
+bool BrowserActionSetBadgeBackgroundColorFunction::RunImpl() {
+ EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST));
+ ListValue* list = static_cast<ListValue*>(args_);
+ EXTENSION_FUNCTION_VALIDATE(list->GetSize() == 4);
+
+ int color_array[4] = {0};
+ for (size_t i = 0; i < arraysize(color_array); ++i) {
+ EXTENSION_FUNCTION_VALIDATE(list->GetInteger(i, &color_array[i]));
+ }
+
+ SkColor color = SkColorSetARGB(color_array[0], color_array[1], color_array[2],
+ color_array[3]);
+
+ Extension* extension = dispatcher()->GetExtension();
+ if (!extension->browser_action()) {
+ error_ = kNoBrowserActionError;
+ return false;
+ }
+
+ extension->browser_action_state()->set_badge_background_color(color);
+
+ NotificationService::current()->Notify(
+ NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
+ Source<ExtensionAction>(extension->browser_action()),
+ Details<ExtensionActionState>(extension->browser_action_state()));
+ return true;
+}
« no previous file with comments | « chrome/browser/extensions/extension_browser_actions_api.h ('k') | chrome/browser/extensions/extension_function_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698