| 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/extension_keybinding_registry.h" | 5 #include "chrome/browser/extensions/extension_keybinding_registry.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/extensions/active_tab_permission_granter.h" | 8 #include "chrome/browser/extensions/active_tab_permission_granter.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/extensions/command.h" | 10 #include "chrome/common/extensions/command.h" |
| 11 #include "content/public/browser/browser_context.h" | 11 #include "content/public/browser/browser_context.h" |
| 12 #include "extensions/browser/event_router.h" | 12 #include "extensions/browser/event_router.h" |
| 13 #include "extensions/browser/extension_registry.h" | 13 #include "extensions/browser/extension_registry.h" |
| 14 #include "extensions/browser/notification_types.h" | 14 #include "extensions/browser/notification_types.h" |
| 15 #include "extensions/common/extension_set.h" | 15 #include "extensions/common/extension_set.h" |
| 16 #include "extensions/common/manifest_constants.h" | 16 #include "extensions/common/manifest_constants.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 const char kOnCommandEventName[] = "commands.onCommand"; | 19 const char kOnCommandEventName[] = "commands.onCommand"; |
| 20 } // namespace | 20 } // namespace |
| 21 | 21 |
| 22 namespace extensions { | 22 namespace extensions { |
| 23 | 23 |
| 24 bool ExtensionKeybindingRegistry::shortcut_handling_suspended_ = false; |
| 25 |
| 24 ExtensionKeybindingRegistry::ExtensionKeybindingRegistry( | 26 ExtensionKeybindingRegistry::ExtensionKeybindingRegistry( |
| 25 content::BrowserContext* context, | 27 content::BrowserContext* context, |
| 26 ExtensionFilter extension_filter, | 28 ExtensionFilter extension_filter, |
| 27 Delegate* delegate) | 29 Delegate* delegate) |
| 28 : browser_context_(context), | 30 : browser_context_(context), |
| 29 extension_filter_(extension_filter), | 31 extension_filter_(extension_filter), |
| 30 delegate_(delegate), | 32 delegate_(delegate), |
| 31 extension_registry_observer_(this) { | 33 extension_registry_observer_(this) { |
| 32 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); | 34 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); |
| 33 | 35 |
| 34 Profile* profile = Profile::FromBrowserContext(browser_context_); | 36 Profile* profile = Profile::FromBrowserContext(browser_context_); |
| 35 registrar_.Add(this, | 37 registrar_.Add(this, |
| 36 extensions::NOTIFICATION_EXTENSION_COMMAND_ADDED, | 38 extensions::NOTIFICATION_EXTENSION_COMMAND_ADDED, |
| 37 content::Source<Profile>(profile->GetOriginalProfile())); | 39 content::Source<Profile>(profile->GetOriginalProfile())); |
| 38 registrar_.Add(this, | 40 registrar_.Add(this, |
| 39 extensions::NOTIFICATION_EXTENSION_COMMAND_REMOVED, | 41 extensions::NOTIFICATION_EXTENSION_COMMAND_REMOVED, |
| 40 content::Source<Profile>(profile->GetOriginalProfile())); | 42 content::Source<Profile>(profile->GetOriginalProfile())); |
| 41 } | 43 } |
| 42 | 44 |
| 43 ExtensionKeybindingRegistry::~ExtensionKeybindingRegistry() { | 45 ExtensionKeybindingRegistry::~ExtensionKeybindingRegistry() { |
| 44 } | 46 } |
| 45 | 47 |
| 48 // static |
| 49 void ExtensionKeybindingRegistry::SetShortcutHandlingSuspended(bool suspended) { |
| 50 shortcut_handling_suspended_ = suspended; |
| 51 } |
| 52 |
| 53 // static |
| 54 bool ExtensionKeybindingRegistry::IsShortcutHandlingSuspended() { |
| 55 return shortcut_handling_suspended_; |
| 56 } |
| 57 |
| 46 void ExtensionKeybindingRegistry::RemoveExtensionKeybinding( | 58 void ExtensionKeybindingRegistry::RemoveExtensionKeybinding( |
| 47 const Extension* extension, | 59 const Extension* extension, |
| 48 const std::string& command_name) { | 60 const std::string& command_name) { |
| 49 EventTargets::iterator it = event_targets_.begin(); | 61 EventTargets::iterator it = event_targets_.begin(); |
| 50 while (it != event_targets_.end()) { | 62 while (it != event_targets_.end()) { |
| 51 TargetList& target_list = it->second; | 63 TargetList& target_list = it->second; |
| 52 TargetList::iterator target = target_list.begin(); | 64 TargetList::iterator target = target_list.begin(); |
| 53 while (target != target_list.end()) { | 65 while (target != target_list.end()) { |
| 54 if (target->first == extension->id() && | 66 if (target->first == extension->id() && |
| 55 (command_name.empty() || command_name == target->second)) | 67 (command_name.empty() || command_name == target->second)) |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 if (extension_id.empty() || it->first == extension_id) { | 254 if (extension_id.empty() || it->first == extension_id) { |
| 243 CommandExecuted(it->first, it->second); | 255 CommandExecuted(it->first, it->second); |
| 244 executed = true; | 256 executed = true; |
| 245 } | 257 } |
| 246 } | 258 } |
| 247 | 259 |
| 248 return executed; | 260 return executed; |
| 249 } | 261 } |
| 250 | 262 |
| 251 } // namespace extensions | 263 } // namespace extensions |
| OLD | NEW |