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

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: Move the Grant/Appearance code into the switch 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::WANTS_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 GrantIfRequested(extension);
71
72 switch (mouse_button) { 70 switch (mouse_button) {
73 case 1: // left 71 case 1: // left
74 return ACTION_SHOW_SCRIPT_POPUP;
75 case 2: // middle 72 case 2: // middle
76 // TODO(yoz): Show the popup if it's available or a default if not. 73 tab_contents_->extension_tab_helper()->active_tab_permission_manager()->
74 GrantIfRequested(extension);
75
76 // Even if clicking the badge doesn't immediately cause the extension to
77 // run script on the page, we want to help users associate clicking with
78 // the extension having permission to modify the page, so we make the icon
79 // full-colored immediately.
80 if (script_badge->SetAppearance(SessionID::IdForTab(tab_contents_),
81 ExtensionAction::ACTIVE))
82 NotifyChange();
77 83
78 // Fire the scriptBadge.onClicked event. 84 // Fire the scriptBadge.onClicked event.
79 GetExtensionService()->browser_event_router()->ScriptBadgeExecuted( 85 GetExtensionService()->browser_event_router()->ScriptBadgeExecuted(
80 tab_contents_->profile(), 86 tab_contents_->profile(),
81 *script_badge, 87 *script_badge,
82 SessionID::IdForTab(tab_contents_)); 88 SessionID::IdForTab(tab_contents_));
83 return ACTION_NONE; 89
90 // TODO(jyasskin): The fallback order should be user-defined popup ->
91 // onClicked handler -> default popup.
92 return ACTION_SHOW_SCRIPT_POPUP;
84 case 3: // right 93 case 3: // right
94 // Don't grant access on right clicks, so users can investigate
95 // the extension without danger.
96
85 return extension->ShowConfigureContextMenus() ? 97 return extension->ShowConfigureContextMenus() ?
86 ACTION_SHOW_CONTEXT_MENU : ACTION_NONE; 98 ACTION_SHOW_CONTEXT_MENU : ACTION_NONE;
87 } 99 }
88 100
89 return ACTION_NONE; 101 return ACTION_NONE;
90 } 102 }
91 103
92 void ScriptBadgeController::OnExecuteScriptFinished( 104 void ScriptBadgeController::OnExecuteScriptFinished(
93 const std::string& extension_id, 105 const std::string& extension_id,
94 bool success, 106 bool success,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 current_actions_.push_back(script_badge); 191 current_actions_.push_back(script_badge);
180 return script_badge; 192 return script_badge;
181 } 193 }
182 194
183 bool ScriptBadgeController::MarkExtensionExecuting( 195 bool ScriptBadgeController::MarkExtensionExecuting(
184 const std::string& extension_id) { 196 const std::string& extension_id) {
185 ExtensionAction* script_badge = AddExtensionToCurrentActions(extension_id); 197 ExtensionAction* script_badge = AddExtensionToCurrentActions(extension_id);
186 if (!script_badge) 198 if (!script_badge)
187 return false; 199 return false;
188 200
189 script_badge->SetIsVisible(SessionID::IdForTab(tab_contents_), true); 201 script_badge->SetAppearance(SessionID::IdForTab(tab_contents_),
190 script_badge->RunIconAnimation(SessionID::IdForTab(tab_contents_)); 202 ExtensionAction::ACTIVE);
191
192 return true; 203 return true;
193 } 204 }
194 205
195 bool ScriptBadgeController::EraseExtension(const Extension* extension) { 206 bool ScriptBadgeController::EraseExtension(const Extension* extension) {
196 if (extensions_in_current_actions_.erase(extension->id()) == 0) 207 if (extensions_in_current_actions_.erase(extension->id()) == 0)
197 return false; 208 return false;
198 209
199 size_t size_before = current_actions_.size(); 210 size_t size_before = current_actions_.size();
200 211
201 for (std::vector<ExtensionAction*>::iterator it = current_actions_.begin(); 212 for (std::vector<ExtensionAction*>::iterator it = current_actions_.begin();
202 it != current_actions_.end(); ++it) { 213 it != current_actions_.end(); ++it) {
203 // Safe to -> the extension action because we still have a handle to the 214 // Safe to -> the extension action because we still have a handle to the
204 // owner Extension. 215 // owner Extension.
205 // 216 //
206 // Also note that this means that when extensions are uninstalled their 217 // Also note that this means that when extensions are uninstalled their
207 // script badges will disappear, even though they're still acting on the 218 // script badges will disappear, even though they're still acting on the
208 // page (since they would have already acted). 219 // page (since they would have already acted).
209 if ((*it)->extension_id() == extension->id()) { 220 if ((*it)->extension_id() == extension->id()) {
210 current_actions_.erase(it); 221 current_actions_.erase(it);
211 break; 222 break;
212 } 223 }
213 } 224 }
214 225
215 CHECK_EQ(size_before, current_actions_.size() + 1); 226 CHECK_EQ(size_before, current_actions_.size() + 1);
216 return true; 227 return true;
217 } 228 }
218 229
219 } // namespace extensions 230 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/extension_action/extension_page_actions_api.cc ('k') | chrome/common/extensions/extension.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698