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

Side by Side Diff: chrome/browser/extensions/extension_browser_actions_api.cc

Issue 242150: Implement browserAction.setIcon(ImageData) for extensions. (Closed)
Patch Set: common function 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
« no previous file with comments | « no previous file | chrome/browser/views/browser_actions_container.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "chrome/common/render_messages.h"
10 11
11 namespace extension_browser_actions_api_constants { 12 namespace extension_browser_actions_api_constants {
12 13
13 const char kSetNameFunction[] = "browserAction.setName"; 14 const char kSetNameFunction[] = "browserAction.setName";
14 const char kSetIconFunction[] = "browserAction.setIcon"; 15 const char kSetIconFunction[] = "browserAction.setIcon";
15 const char kSetBadgeTextFunction[] = "browserAction.setBadgeText"; 16 const char kSetBadgeTextFunction[] = "browserAction.setBadgeText";
16 const char kSetBadgeBackgroundColorFunction[] = 17 const char kSetBadgeBackgroundColorFunction[] =
17 "browserAction.setBadgeBackgroundColor"; 18 "browserAction.setBadgeBackgroundColor";
18 19
19 } // namespace extension_browser_actions_api_constants 20 } // namespace extension_browser_actions_api_constants
(...skipping 17 matching lines...) Expand all
37 extension->browser_action_state()->set_title(name); 38 extension->browser_action_state()->set_title(name);
38 39
39 NotificationService::current()->Notify( 40 NotificationService::current()->Notify(
40 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED, 41 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
41 Source<ExtensionAction>(extension->browser_action()), 42 Source<ExtensionAction>(extension->browser_action()),
42 Details<ExtensionActionState>(extension->browser_action_state())); 43 Details<ExtensionActionState>(extension->browser_action_state()));
43 return true; 44 return true;
44 } 45 }
45 46
46 bool BrowserActionSetIconFunction::RunImpl() { 47 bool BrowserActionSetIconFunction::RunImpl() {
47 int icon_index = -1; 48 // setIcon can take a variant argument: either a canvas ImageData, or an
48 EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&icon_index)); 49 // icon index.
50 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_BINARY) ||
51 args_->IsType(Value::TYPE_INTEGER));
49 52
50 Extension* extension = dispatcher()->GetExtension(); 53 Extension* extension = dispatcher()->GetExtension();
51 if (!extension->browser_action()) { 54 if (!extension->browser_action()) {
52 error_ = kNoBrowserActionError; 55 error_ = kNoBrowserActionError;
53 return false; 56 return false;
54 } 57 }
55 58
56 extension->browser_action_state()->set_icon_index(icon_index); 59 if (args_->IsType(Value::TYPE_BINARY)) {
60 BinaryValue* binary = static_cast<BinaryValue*>(args_);
61 IPC::Message bitmap_pickle(binary->GetBuffer(), binary->GetSize());
62 void* iter = NULL;
63 scoped_ptr<SkBitmap> bitmap(new SkBitmap);
64 EXTENSION_FUNCTION_VALIDATE(
65 IPC::ReadParam(&bitmap_pickle, &iter, bitmap.get()));
66 extension->browser_action_state()->set_icon(bitmap.release());
67 } else {
68 int icon_index = -1;
69 EXTENSION_FUNCTION_VALIDATE(args_->GetAsInteger(&icon_index));
70 extension->browser_action_state()->set_icon_index(icon_index);
71 }
57 72
58 NotificationService::current()->Notify( 73 NotificationService::current()->Notify(
59 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED, 74 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
60 Source<ExtensionAction>(extension->browser_action()), 75 Source<ExtensionAction>(extension->browser_action()),
61 Details<ExtensionActionState>(extension->browser_action_state())); 76 Details<ExtensionActionState>(extension->browser_action_state()));
62 return true; 77 return true;
63 } 78 }
64 79
65 bool BrowserActionSetBadgeTextFunction::RunImpl() { 80 bool BrowserActionSetBadgeTextFunction::RunImpl() {
66 std::string badge_text; 81 std::string badge_text;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 } 116 }
102 117
103 extension->browser_action_state()->set_badge_background_color(color); 118 extension->browser_action_state()->set_badge_background_color(color);
104 119
105 NotificationService::current()->Notify( 120 NotificationService::current()->Notify(
106 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED, 121 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
107 Source<ExtensionAction>(extension->browser_action()), 122 Source<ExtensionAction>(extension->browser_action()),
108 Details<ExtensionActionState>(extension->browser_action_state())); 123 Details<ExtensionActionState>(extension->browser_action_state()));
109 return true; 124 return true;
110 } 125 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/views/browser_actions_container.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698