| 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 Init(); | 20 Init(); |
| 21 } | 21 } |
| 22 | 22 |
| 23 ExtensionCommandsGlobalRegistry::~ExtensionCommandsGlobalRegistry() { | 23 ExtensionCommandsGlobalRegistry::~ExtensionCommandsGlobalRegistry() { |
| 24 if (!IsEventTargetsEmpty()) | 24 if (!IsEventTargetsEmpty()) |
| 25 GlobalShortcutListener::GetInstance()->UnregisterAccelerators(this); | 25 GlobalShortcutListener::GetInstance()->UnregisterAccelerators(this); |
| 26 } | 26 } |
| 27 | 27 |
| 28 static base::LazyInstance< | 28 static base::LazyInstance< |
| 29 ProfileKeyedAPIFactory<ExtensionCommandsGlobalRegistry> > | 29 BrowserContextKeyedAPIFactory<ExtensionCommandsGlobalRegistry> > g_factory = |
| 30 g_factory = LAZY_INSTANCE_INITIALIZER; | 30 LAZY_INSTANCE_INITIALIZER; |
| 31 | 31 |
| 32 // static | 32 // static |
| 33 ProfileKeyedAPIFactory<ExtensionCommandsGlobalRegistry>* | 33 BrowserContextKeyedAPIFactory<ExtensionCommandsGlobalRegistry>* |
| 34 ExtensionCommandsGlobalRegistry::GetFactoryInstance() { | 34 ExtensionCommandsGlobalRegistry::GetFactoryInstance() { |
| 35 return g_factory.Pointer(); | 35 return g_factory.Pointer(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 // static | 38 // static |
| 39 ExtensionCommandsGlobalRegistry* ExtensionCommandsGlobalRegistry::Get( | 39 ExtensionCommandsGlobalRegistry* ExtensionCommandsGlobalRegistry::Get( |
| 40 content::BrowserContext* context) { | 40 content::BrowserContext* context) { |
| 41 return ProfileKeyedAPIFactory<ExtensionCommandsGlobalRegistry>::GetForProfile( | 41 return BrowserContextKeyedAPIFactory<ExtensionCommandsGlobalRegistry>::Get( |
| 42 context); | 42 context); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void ExtensionCommandsGlobalRegistry::AddExtensionKeybinding( | 45 void ExtensionCommandsGlobalRegistry::AddExtensionKeybinding( |
| 46 const extensions::Extension* extension, | 46 const extensions::Extension* extension, |
| 47 const std::string& command_name) { | 47 const std::string& command_name) { |
| 48 // This object only handles named commands, not browser/page actions. | 48 // This object only handles named commands, not browser/page actions. |
| 49 if (ShouldIgnoreCommand(command_name)) | 49 if (ShouldIgnoreCommand(command_name)) |
| 50 return; | 50 return; |
| 51 | 51 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 GlobalShortcutListener::GetInstance()->UnregisterAccelerator( | 88 GlobalShortcutListener::GetInstance()->UnregisterAccelerator( |
| 89 accelerator, this); | 89 accelerator, this); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void ExtensionCommandsGlobalRegistry::OnKeyPressed( | 92 void ExtensionCommandsGlobalRegistry::OnKeyPressed( |
| 93 const ui::Accelerator& accelerator) { | 93 const ui::Accelerator& accelerator) { |
| 94 ExtensionKeybindingRegistry::NotifyEventTargets(accelerator); | 94 ExtensionKeybindingRegistry::NotifyEventTargets(accelerator); |
| 95 } | 95 } |
| 96 | 96 |
| 97 } // namespace extensions | 97 } // namespace extensions |
| OLD | NEW |