| OLD | NEW |
| 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_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
| 8 #include "chrome/browser/extensions/extension_system.h" | 8 #include "chrome/browser/extensions/extension_system.h" |
| 9 #include "chrome/browser/extensions/extension_tab_helper.h" |
| 9 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 10 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 10 #include "chrome/common/extensions/extension.h" | 11 #include "chrome/common/extensions/extension.h" |
| 11 #include "chrome/common/extensions/extension_action.h" | 12 #include "chrome/common/extensions/extension_action.h" |
| 12 #include "chrome/common/extensions/extension_messages.h" | 13 #include "chrome/common/extensions/extension_messages.h" |
| 13 #include "chrome/common/extensions/extension_set.h" | 14 #include "chrome/common/extensions/extension_set.h" |
| 14 #include "chrome/common/extensions/extension_switch_utils.h" | |
| 15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "content/public/browser/navigation_controller.h" | 16 #include "content/public/browser/navigation_controller.h" |
| 17 #include "content/public/browser/navigation_entry.h" | 17 #include "content/public/browser/navigation_entry.h" |
| 18 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 20 #include "ipc/ipc_message.h" | 20 #include "ipc/ipc_message.h" |
| 21 #include "ipc/ipc_message_macros.h" | 21 #include "ipc/ipc_message_macros.h" |
| 22 | 22 |
| 23 namespace extensions { | 23 namespace extensions { |
| 24 | 24 |
| 25 ScriptBadgeController::ScriptBadgeController(TabContents* tab_contents) | 25 ScriptBadgeController::ScriptBadgeController(TabContents* tab_contents) |
| 26 : content::WebContentsObserver(tab_contents->web_contents()), | 26 : content::WebContentsObserver(tab_contents->web_contents()), |
| 27 script_executor_(tab_contents->web_contents()), | 27 script_executor_(tab_contents->web_contents()), |
| 28 tab_contents_(tab_contents) { | 28 tab_contents_(tab_contents) { |
| 29 registrar_.Add(this, | 29 registrar_.Add(this, |
| 30 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 30 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 31 content::Source<Profile>(tab_contents->profile())); | 31 content::Source<Profile>(tab_contents->profile())); |
| 32 } | 32 } |
| 33 | 33 |
| 34 ScriptBadgeController::~ScriptBadgeController() {} | 34 ScriptBadgeController::~ScriptBadgeController() {} |
| 35 | 35 |
| 36 std::vector<ExtensionAction*> ScriptBadgeController::GetCurrentActions() { | 36 std::vector<ExtensionAction*> ScriptBadgeController::GetCurrentActions() const { |
| 37 return current_actions_; | 37 return current_actions_; |
| 38 } | 38 } |
| 39 | 39 |
| 40 LocationBarController::Action ScriptBadgeController::OnClicked( | 40 LocationBarController::Action ScriptBadgeController::OnClicked( |
| 41 const std::string& extension_id, int mouse_button) { | 41 const std::string& extension_id, int mouse_button) { |
| 42 ExtensionService* service = GetExtensionService(); | 42 ExtensionService* service = GetExtensionService(); |
| 43 if (!service) | 43 if (!service) |
| 44 return ACTION_NONE; | 44 return ACTION_NONE; |
| 45 | 45 |
| 46 const Extension* extension = service->extensions()->GetByID(extension_id); | 46 const Extension* extension = service->extensions()->GetByID(extension_id); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 return false; | 161 return false; |
| 162 | 162 |
| 163 ExtensionService* service = GetExtensionService(); | 163 ExtensionService* service = GetExtensionService(); |
| 164 if (!service) | 164 if (!service) |
| 165 return false; | 165 return false; |
| 166 | 166 |
| 167 const Extension* extension = service->extensions()->GetByID(extension_id); | 167 const Extension* extension = service->extensions()->GetByID(extension_id); |
| 168 if (!extension) | 168 if (!extension) |
| 169 return false; | 169 return false; |
| 170 | 170 |
| 171 current_actions_.push_back(extension->script_badge()); | 171 ExtensionAction* script_badge = extension->script_badge(); |
| 172 current_actions_.push_back(script_badge); |
| 173 script_badge->RunIconAnimation( |
| 174 tab_contents_->extension_tab_helper()->tab_id()); |
| 175 |
| 172 return true; | 176 return true; |
| 173 } | 177 } |
| 174 | 178 |
| 175 | |
| 176 bool ScriptBadgeController::EraseExtension(const Extension* extension) { | 179 bool ScriptBadgeController::EraseExtension(const Extension* extension) { |
| 177 if (extensions_executing_scripts_.erase(extension->id()) == 0) | 180 if (extensions_executing_scripts_.erase(extension->id()) == 0) |
| 178 return false; | 181 return false; |
| 179 | 182 |
| 180 size_t size_before = current_actions_.size(); | 183 size_t size_before = current_actions_.size(); |
| 181 | 184 |
| 182 for (std::vector<ExtensionAction*>::iterator it = current_actions_.begin(); | 185 for (std::vector<ExtensionAction*>::iterator it = current_actions_.begin(); |
| 183 it != current_actions_.end(); ++it) { | 186 it != current_actions_.end(); ++it) { |
| 184 // Safe to -> the extension action because we still have a handle to the | 187 // Safe to -> the extension action because we still have a handle to the |
| 185 // owner Extension. | 188 // owner Extension. |
| 186 // | 189 // |
| 187 // Also note that this means that when extensions are uninstalled their | 190 // Also note that this means that when extensions are uninstalled their |
| 188 // script badges will disappear, even though they're still acting on the | 191 // script badges will disappear, even though they're still acting on the |
| 189 // page (since they would have already acted). | 192 // page (since they would have already acted). |
| 190 if ((*it)->extension_id() == extension->id()) { | 193 if ((*it)->extension_id() == extension->id()) { |
| 191 current_actions_.erase(it); | 194 current_actions_.erase(it); |
| 192 break; | 195 break; |
| 193 } | 196 } |
| 194 } | 197 } |
| 195 | 198 |
| 196 CHECK_EQ(size_before, current_actions_.size() + 1); | 199 CHECK_EQ(size_before, current_actions_.size() + 1); |
| 197 return true; | 200 return true; |
| 198 } | 201 } |
| 199 | 202 |
| 200 } // namespace extensions | 203 } // namespace extensions |
| OLD | NEW |