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

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

Issue 10559054: Animate the script badges. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase, fix thing i accidentally deleted in the last rebase Created 8 years, 5 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) 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/extension_browser_event_router.h" 7 #include "chrome/browser/extensions/extension_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/extension_tab_helper.h" 10 #include "chrome/browser/extensions/extension_tab_helper.h"
11 #include "chrome/browser/ui/tab_contents/tab_contents.h" 11 #include "chrome/browser/ui/tab_contents/tab_contents.h"
12 #include "chrome/common/extensions/extension.h" 12 #include "chrome/common/extensions/extension.h"
13 #include "chrome/common/extensions/extension_action.h" 13 #include "chrome/common/extensions/extension_action.h"
14 #include "chrome/common/extensions/extension_messages.h" 14 #include "chrome/common/extensions/extension_messages.h"
15 #include "chrome/common/extensions/extension_set.h" 15 #include "chrome/common/extensions/extension_set.h"
16 #include "chrome/common/extensions/extension_switch_utils.h"
17 #include "chrome/common/chrome_notification_types.h" 16 #include "chrome/common/chrome_notification_types.h"
18 #include "content/public/browser/navigation_controller.h" 17 #include "content/public/browser/navigation_controller.h"
19 #include "content/public/browser/navigation_entry.h" 18 #include "content/public/browser/navigation_entry.h"
20 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
21 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
22 #include "ipc/ipc_message.h" 21 #include "ipc/ipc_message.h"
23 #include "ipc/ipc_message_macros.h" 22 #include "ipc/ipc_message_macros.h"
24 23
25 namespace extensions { 24 namespace extensions {
26 25
27 ScriptBadgeController::ScriptBadgeController(TabContents* tab_contents) 26 ScriptBadgeController::ScriptBadgeController(TabContents* tab_contents)
28 : content::WebContentsObserver(tab_contents->web_contents()), 27 : content::WebContentsObserver(tab_contents->web_contents()),
29 script_executor_(tab_contents->web_contents()), 28 script_executor_(tab_contents->web_contents()),
30 tab_contents_(tab_contents) { 29 tab_contents_(tab_contents) {
31 registrar_.Add(this, 30 registrar_.Add(this,
32 chrome::NOTIFICATION_EXTENSION_UNLOADED, 31 chrome::NOTIFICATION_EXTENSION_UNLOADED,
33 content::Source<Profile>(tab_contents->profile())); 32 content::Source<Profile>(tab_contents->profile()));
34 } 33 }
35 34
36 ScriptBadgeController::~ScriptBadgeController() {} 35 ScriptBadgeController::~ScriptBadgeController() {}
37 36
38 std::vector<ExtensionAction*> ScriptBadgeController::GetCurrentActions() { 37 std::vector<ExtensionAction*> ScriptBadgeController::GetCurrentActions() const {
39 return current_actions_; 38 return current_actions_;
40 } 39 }
41 40
42 LocationBarController::Action ScriptBadgeController::OnClicked( 41 LocationBarController::Action ScriptBadgeController::OnClicked(
43 const std::string& extension_id, int mouse_button) { 42 const std::string& extension_id, int mouse_button) {
44 ExtensionService* service = GetExtensionService(); 43 ExtensionService* service = GetExtensionService();
45 if (!service) 44 if (!service)
46 return ACTION_NONE; 45 return ACTION_NONE;
47 46
48 const Extension* extension = service->extensions()->GetByID(extension_id); 47 const Extension* extension = service->extensions()->GetByID(extension_id);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 return false; 169 return false;
171 170
172 ExtensionService* service = GetExtensionService(); 171 ExtensionService* service = GetExtensionService();
173 if (!service) 172 if (!service)
174 return false; 173 return false;
175 174
176 const Extension* extension = service->extensions()->GetByID(extension_id); 175 const Extension* extension = service->extensions()->GetByID(extension_id);
177 if (!extension) 176 if (!extension)
178 return false; 177 return false;
179 178
180 current_actions_.push_back(extension->script_badge()); 179 ExtensionAction* script_badge = extension->script_badge();
180 current_actions_.push_back(script_badge);
181 script_badge->RunIconAnimation(
182 tab_contents_->extension_tab_helper()->tab_id());
183
181 return true; 184 return true;
182 } 185 }
183 186
184
185 bool ScriptBadgeController::EraseExtension(const Extension* extension) { 187 bool ScriptBadgeController::EraseExtension(const Extension* extension) {
186 if (extensions_executing_scripts_.erase(extension->id()) == 0) 188 if (extensions_executing_scripts_.erase(extension->id()) == 0)
187 return false; 189 return false;
188 190
189 size_t size_before = current_actions_.size(); 191 size_t size_before = current_actions_.size();
190 192
191 for (std::vector<ExtensionAction*>::iterator it = current_actions_.begin(); 193 for (std::vector<ExtensionAction*>::iterator it = current_actions_.begin();
192 it != current_actions_.end(); ++it) { 194 it != current_actions_.end(); ++it) {
193 // Safe to -> the extension action because we still have a handle to the 195 // Safe to -> the extension action because we still have a handle to the
194 // owner Extension. 196 // owner Extension.
195 // 197 //
196 // Also note that this means that when extensions are uninstalled their 198 // Also note that this means that when extensions are uninstalled their
197 // script badges will disappear, even though they're still acting on the 199 // script badges will disappear, even though they're still acting on the
198 // page (since they would have already acted). 200 // page (since they would have already acted).
199 if ((*it)->extension_id() == extension->id()) { 201 if ((*it)->extension_id() == extension->id()) {
200 current_actions_.erase(it); 202 current_actions_.erase(it);
201 break; 203 break;
202 } 204 }
203 } 205 }
204 206
205 CHECK_EQ(size_before, current_actions_.size() + 1); 207 CHECK_EQ(size_before, current_actions_.size() + 1);
206 return true; 208 return true;
207 } 209 }
208 210
209 } // namespace extensions 211 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/script_badge_controller.h ('k') | chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698