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) { | |
21 Init(); | 20 Init(); |
22 } | 21 } |
23 | 22 |
24 ExtensionCommandsGlobalRegistry::~ExtensionCommandsGlobalRegistry() { | 23 ExtensionCommandsGlobalRegistry::~ExtensionCommandsGlobalRegistry() { |
25 if (!IsEventTargetsEmpty()) { | 24 if (!IsEventTargetsEmpty()) { |
26 GlobalShortcutListener* global_shortcut_listener = | 25 GlobalShortcutListener* global_shortcut_listener = |
27 GlobalShortcutListener::GetInstance(); | 26 GlobalShortcutListener::GetInstance(); |
28 | 27 |
29 // Resume GlobalShortcutListener before we clean up if the shortcut handling | 28 // Resume GlobalShortcutListener before we clean up if the shortcut handling |
30 // is currently suspended. | 29 // is currently suspended. |
(...skipping 21 matching lines...) Expand all Loading... |
52 context); | 51 context); |
53 } | 52 } |
54 | 53 |
55 // static | 54 // static |
56 void ExtensionCommandsGlobalRegistry::SetShortcutHandlingSuspended( | 55 void ExtensionCommandsGlobalRegistry::SetShortcutHandlingSuspended( |
57 bool suspended) { | 56 bool suspended) { |
58 GlobalShortcutListener::GetInstance()->SetShortcutHandlingSuspended( | 57 GlobalShortcutListener::GetInstance()->SetShortcutHandlingSuspended( |
59 suspended); | 58 suspended); |
60 } | 59 } |
61 | 60 |
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 | |
69 void ExtensionCommandsGlobalRegistry::AddExtensionKeybinding( | 61 void ExtensionCommandsGlobalRegistry::AddExtensionKeybinding( |
70 const extensions::Extension* extension, | 62 const extensions::Extension* extension, |
71 const std::string& command_name) { | 63 const std::string& command_name) { |
72 // This object only handles named commands, not browser/page actions. | 64 // This object only handles named commands, not browser/page actions. |
73 if (ShouldIgnoreCommand(command_name)) | 65 if (ShouldIgnoreCommand(command_name)) |
74 return; | 66 return; |
75 | 67 |
76 extensions::CommandService* command_service = | 68 extensions::CommandService* command_service = |
77 extensions::CommandService::Get(browser_context_); | 69 extensions::CommandService::Get(browser_context_); |
78 // Add all the active global keybindings, if any. | 70 // Add all the active global keybindings, if any. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 GlobalShortcutListener::GetInstance()->UnregisterAccelerator( | 104 GlobalShortcutListener::GetInstance()->UnregisterAccelerator( |
113 accelerator, this); | 105 accelerator, this); |
114 } | 106 } |
115 | 107 |
116 void ExtensionCommandsGlobalRegistry::OnKeyPressed( | 108 void ExtensionCommandsGlobalRegistry::OnKeyPressed( |
117 const ui::Accelerator& accelerator) { | 109 const ui::Accelerator& accelerator) { |
118 ExtensionKeybindingRegistry::NotifyEventTargets(accelerator); | 110 ExtensionKeybindingRegistry::NotifyEventTargets(accelerator); |
119 } | 111 } |
120 | 112 |
121 } // namespace extensions | 113 } // namespace extensions |
OLD | NEW |