| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "chrome/browser/extensions/browser_event_router.h" | 10 #include "chrome/browser/extensions/browser_event_router.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/extensions/extension_system.h" | 12 #include "chrome/browser/extensions/extension_system.h" |
| 13 #include "chrome/browser/extensions/tab_helper.h" | 13 #include "chrome/browser/extensions/tab_helper.h" |
| 14 #include "chrome/browser/sessions/session_id.h" | 14 #include "chrome/browser/sessions/session_id.h" |
| 15 #include "chrome/browser/sessions/session_tab_helper.h" | 15 #include "chrome/browser/sessions/session_tab_helper.h" |
| 16 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 16 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 17 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
| 18 #include "chrome/common/extensions/extension_action.h" | 18 #include "chrome/browser/extensions/extension_action.h" |
| 19 #include "chrome/common/extensions/extension_messages.h" | 19 #include "chrome/common/extensions/extension_messages.h" |
| 20 #include "chrome/common/extensions/extension_set.h" | 20 #include "chrome/common/extensions/extension_set.h" |
| 21 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
| 22 #include "content/public/browser/navigation_controller.h" | 22 #include "content/public/browser/navigation_controller.h" |
| 23 #include "content/public/browser/navigation_details.h" | 23 #include "content/public/browser/navigation_details.h" |
| 24 #include "content/public/browser/navigation_entry.h" | 24 #include "content/public/browser/navigation_entry.h" |
| 25 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
| 26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 27 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
| 28 #include "ipc/ipc_message.h" | 28 #include "ipc/ipc_message.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 } | 66 } |
| 67 | 67 |
| 68 LocationBarController::Action ScriptBadgeController::OnClicked( | 68 LocationBarController::Action ScriptBadgeController::OnClicked( |
| 69 const std::string& extension_id, int mouse_button) { | 69 const std::string& extension_id, int mouse_button) { |
| 70 ExtensionService* service = GetExtensionService(); | 70 ExtensionService* service = GetExtensionService(); |
| 71 if (!service) | 71 if (!service) |
| 72 return ACTION_NONE; | 72 return ACTION_NONE; |
| 73 | 73 |
| 74 const Extension* extension = service->extensions()->GetByID(extension_id); | 74 const Extension* extension = service->extensions()->GetByID(extension_id); |
| 75 CHECK(extension); | 75 CHECK(extension); |
| 76 ExtensionAction* script_badge = extension->script_badge(); | 76 ExtensionAction* script_badge = service->GetScriptBadge(*extension); |
| 77 CHECK(script_badge); | 77 CHECK(script_badge); |
| 78 | 78 |
| 79 switch (mouse_button) { | 79 switch (mouse_button) { |
| 80 case 1: // left | 80 case 1: // left |
| 81 case 2: { // middle | 81 case 2: { // middle |
| 82 TabContents* tab_contents = TabContents::FromWebContents(web_contents()); | 82 TabContents* tab_contents = TabContents::FromWebContents(web_contents()); |
| 83 tab_contents->extension_tab_helper()->active_tab_permission_manager()-> | 83 tab_contents->extension_tab_helper()->active_tab_permission_manager()-> |
| 84 GrantIfRequested(extension); | 84 GrantIfRequested(extension); |
| 85 | 85 |
| 86 // Even if clicking the badge doesn't immediately cause the extension to | 86 // Even if clicking the badge doesn't immediately cause the extension to |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 return NULL; | 233 return NULL; |
| 234 | 234 |
| 235 ExtensionService* service = GetExtensionService(); | 235 ExtensionService* service = GetExtensionService(); |
| 236 if (!service) | 236 if (!service) |
| 237 return NULL; | 237 return NULL; |
| 238 | 238 |
| 239 const Extension* extension = service->extensions()->GetByID(extension_id); | 239 const Extension* extension = service->extensions()->GetByID(extension_id); |
| 240 if (!extension) | 240 if (!extension) |
| 241 return NULL; | 241 return NULL; |
| 242 | 242 |
| 243 ExtensionAction* script_badge = extension->script_badge(); | 243 ExtensionAction* script_badge = service->GetScriptBadge(*extension); |
| 244 current_actions_.push_back(script_badge); | 244 current_actions_.push_back(script_badge); |
| 245 return script_badge; | 245 return script_badge; |
| 246 } | 246 } |
| 247 | 247 |
| 248 bool ScriptBadgeController::MarkExtensionExecuting( | 248 bool ScriptBadgeController::MarkExtensionExecuting( |
| 249 const std::string& extension_id) { | 249 const std::string& extension_id) { |
| 250 ExtensionAction* script_badge = AddExtensionToCurrentActions(extension_id); | 250 ExtensionAction* script_badge = AddExtensionToCurrentActions(extension_id); |
| 251 if (!script_badge) | 251 if (!script_badge) |
| 252 return false; | 252 return false; |
| 253 | 253 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 277 current_actions_.erase(it); | 277 current_actions_.erase(it); |
| 278 break; | 278 break; |
| 279 } | 279 } |
| 280 } | 280 } |
| 281 | 281 |
| 282 CHECK_EQ(size_before, current_actions_.size() + 1); | 282 CHECK_EQ(size_before, current_actions_.size() + 1); |
| 283 return true; | 283 return true; |
| 284 } | 284 } |
| 285 | 285 |
| 286 } // namespace extensions | 286 } // namespace extensions |
| OLD | NEW |