OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_commands_global_registry.h" | 5 #include "chrome/browser/extensions/extension_commands_global_registry.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "chrome/browser/extensions/api/commands/command_service.h" | 8 #include "chrome/browser/extensions/api/commands/command_service.h" |
9 #include "chrome/browser/extensions/global_shortcut_listener.h" | 9 #include "chrome/browser/extensions/global_shortcut_listener.h" |
10 #include "extensions/common/extension.h" | 10 #include "extensions/common/extension.h" |
11 | 11 |
12 namespace extensions { | 12 namespace extensions { |
13 | 13 |
14 ExtensionCommandsGlobalRegistry::ExtensionCommandsGlobalRegistry( | 14 ExtensionCommandsGlobalRegistry::ExtensionCommandsGlobalRegistry( |
15 content::BrowserContext* context) | 15 content::BrowserContext* context) |
16 : ExtensionKeybindingRegistry(context, | 16 : ExtensionKeybindingRegistry(context, |
17 ExtensionKeybindingRegistry::ALL_EXTENSIONS, | 17 ExtensionKeybindingRegistry::ALL_EXTENSIONS, |
18 NULL), | 18 NULL), |
19 browser_context_(context) { | 19 browser_context_(context), |
| 20 registry_for_active_window_(NULL) { |
20 Init(); | 21 Init(); |
21 } | 22 } |
22 | 23 |
23 ExtensionCommandsGlobalRegistry::~ExtensionCommandsGlobalRegistry() { | 24 ExtensionCommandsGlobalRegistry::~ExtensionCommandsGlobalRegistry() { |
24 if (!IsEventTargetsEmpty()) { | 25 if (!IsEventTargetsEmpty()) { |
25 GlobalShortcutListener* global_shortcut_listener = | 26 GlobalShortcutListener* global_shortcut_listener = |
26 GlobalShortcutListener::GetInstance(); | 27 GlobalShortcutListener::GetInstance(); |
27 | 28 |
28 // Resume GlobalShortcutListener before we clean up if the shortcut handling | 29 // Resume GlobalShortcutListener before we clean up if the shortcut handling |
29 // is currently suspended. | 30 // is currently suspended. |
(...skipping 21 matching lines...) Expand all Loading... |
51 context); | 52 context); |
52 } | 53 } |
53 | 54 |
54 // static | 55 // static |
55 void ExtensionCommandsGlobalRegistry::SetShortcutHandlingSuspended( | 56 void ExtensionCommandsGlobalRegistry::SetShortcutHandlingSuspended( |
56 bool suspended) { | 57 bool suspended) { |
57 GlobalShortcutListener::GetInstance()->SetShortcutHandlingSuspended( | 58 GlobalShortcutListener::GetInstance()->SetShortcutHandlingSuspended( |
58 suspended); | 59 suspended); |
59 } | 60 } |
60 | 61 |
| 62 bool ExtensionCommandsGlobalRegistry::IsRegistered( |
| 63 const ui::Accelerator& accelerator) { |
| 64 return (registry_for_active_window() && |
| 65 registry_for_active_window()->IsAcceleratorRegistered(accelerator)) || |
| 66 IsAcceleratorRegistered(accelerator); |
| 67 } |
| 68 |
61 void ExtensionCommandsGlobalRegistry::AddExtensionKeybinding( | 69 void ExtensionCommandsGlobalRegistry::AddExtensionKeybinding( |
62 const extensions::Extension* extension, | 70 const extensions::Extension* extension, |
63 const std::string& command_name) { | 71 const std::string& command_name) { |
64 // This object only handles named commands, not browser/page actions. | 72 // This object only handles named commands, not browser/page actions. |
65 if (ShouldIgnoreCommand(command_name)) | 73 if (ShouldIgnoreCommand(command_name)) |
66 return; | 74 return; |
67 | 75 |
68 extensions::CommandService* command_service = | 76 extensions::CommandService* command_service = |
69 extensions::CommandService::Get(browser_context_); | 77 extensions::CommandService::Get(browser_context_); |
70 // Add all the active global keybindings, if any. | 78 // Add all the active global keybindings, if any. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 GlobalShortcutListener::GetInstance()->UnregisterAccelerator( | 112 GlobalShortcutListener::GetInstance()->UnregisterAccelerator( |
105 accelerator, this); | 113 accelerator, this); |
106 } | 114 } |
107 | 115 |
108 void ExtensionCommandsGlobalRegistry::OnKeyPressed( | 116 void ExtensionCommandsGlobalRegistry::OnKeyPressed( |
109 const ui::Accelerator& accelerator) { | 117 const ui::Accelerator& accelerator) { |
110 ExtensionKeybindingRegistry::NotifyEventTargets(accelerator); | 118 ExtensionKeybindingRegistry::NotifyEventTargets(accelerator); |
111 } | 119 } |
112 | 120 |
113 } // namespace extensions | 121 } // namespace extensions |
OLD | NEW |