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

Side by Side 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, 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_browser_actions_api.h" 5 #include "chrome/browser/extensions/extension_browser_actions_api.h"
6 6
7 #include "chrome/browser/browser.h" 7 #include "chrome/browser/browser.h"
8 #include "chrome/browser/browser_list.h" 8 #include "chrome/browser/browser_list.h"
9 #include "chrome/common/notification_service.h" 9 #include "chrome/common/notification_service.h"
10 10
11 namespace extension_browser_actions_api_constants { 11 namespace extension_browser_actions_api_constants {
12 12
13 const char kSetNameFunction[] = "browserAction.setName"; 13 const char kSetNameFunction[] = "browserAction.setName";
14 const char kSetIconFunction[] = "browserAction.setIcon"; 14 const char kSetIconFunction[] = "browserAction.setIcon";
15 const char kSetBadgeTextFunction[] = "browserAction.setBadgeText";
16 const char kSetBadgeBackgroundColorFunction[] =
17 "browserAction.setBadgeBackgroundColor";
15 18
16 } // namespace extension_browser_actions_api_constants 19 } // namespace extension_browser_actions_api_constants
17 20
18 namespace { 21 namespace {
19 // Errors. 22 // Errors.
20 const char kNoBrowserActionError[] = 23 const char kNoBrowserActionError[] =
21 "This extension has no browser action specified."; 24 "This extension has no browser action specified.";
22 } 25 }
23 26
24 bool BrowserActionSetNameFunction::RunImpl() { 27 bool BrowserActionSetNameFunction::RunImpl() {
(...skipping 26 matching lines...) Expand all
51 } 54 }
52 55
53 extension->browser_action_state()->set_icon_index(icon_index); 56 extension->browser_action_state()->set_icon_index(icon_index);
54 57
55 NotificationService::current()->Notify( 58 NotificationService::current()->Notify(
56 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED, 59 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
57 Source<ExtensionAction>(extension->browser_action()), 60 Source<ExtensionAction>(extension->browser_action()),
58 Details<ExtensionActionState>(extension->browser_action_state())); 61 Details<ExtensionActionState>(extension->browser_action_state()));
59 return true; 62 return true;
60 } 63 }
64
65 bool BrowserActionSetBadgeTextFunction::RunImpl() {
66 std::string badge_text;
67 EXTENSION_FUNCTION_VALIDATE(args_->GetAsString(&badge_text));
68
69 Extension* extension = dispatcher()->GetExtension();
70 if (!extension->browser_action()) {
71 error_ = kNoBrowserActionError;
72 return false;
73 }
74
75 extension->browser_action_state()->set_badge_text(badge_text);
76
77 NotificationService::current()->Notify(
78 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
79 Source<ExtensionAction>(extension->browser_action()),
80 Details<ExtensionActionState>(extension->browser_action_state()));
81 return true;
82 }
83
84 bool BrowserActionSetBadgeBackgroundColorFunction::RunImpl() {
85 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST));
86 ListValue* list = static_cast<ListValue*>(args_);
87 EXTENSION_FUNCTION_VALIDATE(list->GetSize() == 4);
88
89 int color_array[4] = {0};
90 for (size_t i = 0; i < arraysize(color_array); ++i) {
91 EXTENSION_FUNCTION_VALIDATE(list->GetInteger(i, &color_array[i]));
92 }
93
94 SkColor color = SkColorSetARGB(color_array[0], color_array[1], color_array[2],
95 color_array[3]);
96
97 Extension* extension = dispatcher()->GetExtension();
98 if (!extension->browser_action()) {
99 error_ = kNoBrowserActionError;
100 return false;
101 }
102
103 extension->browser_action_state()->set_badge_background_color(color);
104
105 NotificationService::current()->Notify(
106 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
107 Source<ExtensionAction>(extension->browser_action()),
108 Details<ExtensionActionState>(extension->browser_action_state()));
109 return true;
110 }
OLDNEW
« 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