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

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

Issue 10823143: Make the getAttention badge grey. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/script_badge_controller.h" 5 #include "chrome/browser/extensions/script_badge_controller.h"
6 6
7 #include "chrome/browser/extensions/browser_event_router.h" 7 #include "chrome/browser/extensions/browser_event_router.h"
8 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/extensions/extension_system.h" 9 #include "chrome/browser/extensions/extension_system.h"
10 #include "chrome/browser/extensions/tab_helper.h" 10 #include "chrome/browser/extensions/tab_helper.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 void ScriptBadgeController::GetAttentionFor( 44 void ScriptBadgeController::GetAttentionFor(
45 const std::string& extension_id) { 45 const std::string& extension_id) {
46 ExtensionAction* script_badge = AddExtensionToCurrentActions(extension_id); 46 ExtensionAction* script_badge = AddExtensionToCurrentActions(extension_id);
47 if (!script_badge) 47 if (!script_badge)
48 return; 48 return;
49 49
50 // TODO(jyasskin): Modify the icon's appearance to indicate that the 50 // TODO(jyasskin): Modify the icon's appearance to indicate that the
51 // extension is merely asking for permission to run: 51 // extension is merely asking for permission to run:
52 // http://crbug.com/133142 52 // http://crbug.com/133142
53 script_badge->SetIsVisible(SessionID::IdForTab(tab_contents_), true); 53 script_badge->SetAppearance(SessionID::IdForTab(tab_contents_),
54 ExtensionAction::GETTING_ATTENTION);
54 55
55 NotifyChange(); 56 NotifyChange();
56 } 57 }
57 58
58 LocationBarController::Action ScriptBadgeController::OnClicked( 59 LocationBarController::Action ScriptBadgeController::OnClicked(
59 const std::string& extension_id, int mouse_button) { 60 const std::string& extension_id, int mouse_button) {
60 ExtensionService* service = GetExtensionService(); 61 ExtensionService* service = GetExtensionService();
61 if (!service) 62 if (!service)
62 return ACTION_NONE; 63 return ACTION_NONE;
63 64
64 const Extension* extension = service->extensions()->GetByID(extension_id); 65 const Extension* extension = service->extensions()->GetByID(extension_id);
65 CHECK(extension); 66 CHECK(extension);
66 ExtensionAction* script_badge = extension->script_badge(); 67 ExtensionAction* script_badge = extension->script_badge();
67 CHECK(script_badge); 68 CHECK(script_badge);
68 69
69 tab_contents_->extension_tab_helper()->active_tab_permission_manager()-> 70 if (mouse_button != 3) {
70 GrantIfRequested(extension); 71 // Don't grant access on right clicks, so users can investigate
not at google - send to devlin 2012/08/02 15:38:09 can you move this inside the switch below? That wa
Jeffrey Yasskin 2012/08/02 15:55:56 I would have done that, except it conflicts with t
Jeffrey Yasskin 2012/08/03 11:11:30 Done now, by having both mouse buttons send the on
72 // the extension without danger.
73
74 tab_contents_->extension_tab_helper()->active_tab_permission_manager()->
75 GrantIfRequested(extension);
76
77 // Even if clicking the badge doesn't immediately cause the extension to run
78 // script on the page, we want to help users associate clicking with the
79 // extension having permission to modify the page, so we make the icon
80 // full-colored immediately.
81 if (script_badge->SetAppearance(SessionID::IdForTab(tab_contents_),
82 ExtensionAction::ACTIVE))
83 NotifyChange();
84 }
71 85
72 switch (mouse_button) { 86 switch (mouse_button) {
73 case 1: // left 87 case 1: // left
74 return ACTION_SHOW_SCRIPT_POPUP; 88 return ACTION_SHOW_SCRIPT_POPUP;
75 case 2: // middle 89 case 2: // middle
76 // TODO(yoz): Show the popup if it's available or a default if not. 90 // TODO(yoz): Show the popup if it's available or a default if not.
77 91
78 // Fire the scriptBadge.onClicked event. 92 // Fire the scriptBadge.onClicked event.
79 GetExtensionService()->browser_event_router()->ScriptBadgeExecuted( 93 GetExtensionService()->browser_event_router()->ScriptBadgeExecuted(
80 tab_contents_->profile(), 94 tab_contents_->profile(),
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 current_actions_.push_back(script_badge); 193 current_actions_.push_back(script_badge);
180 return script_badge; 194 return script_badge;
181 } 195 }
182 196
183 bool ScriptBadgeController::MarkExtensionExecuting( 197 bool ScriptBadgeController::MarkExtensionExecuting(
184 const std::string& extension_id) { 198 const std::string& extension_id) {
185 ExtensionAction* script_badge = AddExtensionToCurrentActions(extension_id); 199 ExtensionAction* script_badge = AddExtensionToCurrentActions(extension_id);
186 if (!script_badge) 200 if (!script_badge)
187 return false; 201 return false;
188 202
189 script_badge->SetIsVisible(SessionID::IdForTab(tab_contents_), true); 203 script_badge->SetAppearance(SessionID::IdForTab(tab_contents_),
190 script_badge->RunIconAnimation(SessionID::IdForTab(tab_contents_)); 204 ExtensionAction::ACTIVE);
191 205
not at google - send to devlin 2012/08/02 15:38:09 nit: 1 less \n (not yours I know)
Jeffrey Yasskin 2012/08/02 15:55:56 Done.
192 return true; 206 return true;
193 } 207 }
194 208
195 bool ScriptBadgeController::EraseExtension(const Extension* extension) { 209 bool ScriptBadgeController::EraseExtension(const Extension* extension) {
196 if (extensions_in_current_actions_.erase(extension->id()) == 0) 210 if (extensions_in_current_actions_.erase(extension->id()) == 0)
197 return false; 211 return false;
198 212
199 size_t size_before = current_actions_.size(); 213 size_t size_before = current_actions_.size();
200 214
201 for (std::vector<ExtensionAction*>::iterator it = current_actions_.begin(); 215 for (std::vector<ExtensionAction*>::iterator it = current_actions_.begin();
202 it != current_actions_.end(); ++it) { 216 it != current_actions_.end(); ++it) {
203 // Safe to -> the extension action because we still have a handle to the 217 // Safe to -> the extension action because we still have a handle to the
204 // owner Extension. 218 // owner Extension.
205 // 219 //
206 // Also note that this means that when extensions are uninstalled their 220 // Also note that this means that when extensions are uninstalled their
207 // script badges will disappear, even though they're still acting on the 221 // script badges will disappear, even though they're still acting on the
208 // page (since they would have already acted). 222 // page (since they would have already acted).
209 if ((*it)->extension_id() == extension->id()) { 223 if ((*it)->extension_id() == extension->id()) {
210 current_actions_.erase(it); 224 current_actions_.erase(it);
211 break; 225 break;
212 } 226 }
213 } 227 }
214 228
215 CHECK_EQ(size_before, current_actions_.size() + 1); 229 CHECK_EQ(size_before, current_actions_.size() + 1);
216 return true; 230 return true;
217 } 231 }
218 232
219 } // namespace extensions 233 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698