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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_COMMANDS_GLOBAL_REGISTRY_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_COMMANDS_GLOBAL_REGISTRY_H_
11 #include "base/compiler_specific.h"
12 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
13 #include "chrome/browser/extensions/extension_keybinding_registry.h"
14 #include "chrome/browser/extensions/global_shortcut_listener.h"
15 #include "ui/base/accelerators/accelerator.h"
19 namespace extensions
{
23 namespace extensions
{
25 // ExtensionCommandsGlobalRegistry is a class that handles the cross-platform
26 // implementation of the global shortcut registration for the Extension Commands
28 // Note: It handles regular extension commands (not browserAction and pageAction
29 // popups, which are not bindable to global shortcuts). This class registers the
30 // accelerators on behalf of the extensions and routes the commands to them via
31 // the BrowserEventRouter.
32 class ExtensionCommandsGlobalRegistry
33 : public ProfileKeyedAPI
,
34 public ExtensionKeybindingRegistry
,
35 public GlobalShortcutListener::Observer
{
37 // ProfileKeyedAPI implementation.
38 static ProfileKeyedAPIFactory
<
39 ExtensionCommandsGlobalRegistry
>* GetFactoryInstance();
41 // Convenience method to get the ExtensionCommandsGlobalRegistry for a
43 static ExtensionCommandsGlobalRegistry
* Get(Profile
* profile
);
45 explicit ExtensionCommandsGlobalRegistry(Profile
* profile
);
46 virtual ~ExtensionCommandsGlobalRegistry();
49 friend class ProfileKeyedAPIFactory
<ExtensionCommandsGlobalRegistry
>;
51 // ProfileKeyedAPI implementation.
52 static const char* service_name() {
53 return "ExtensionCommandsGlobalRegistry";
56 // Overridden from ExtensionKeybindingRegistry:
57 virtual void AddExtensionKeybinding(
58 const Extension
* extension
,
59 const std::string
& command_name
) OVERRIDE
;
60 virtual void RemoveExtensionKeybindingImpl(
61 const ui::Accelerator
& accelerator
,
62 const std::string
& command_name
) OVERRIDE
;
64 // Called by the GlobalShortcutListener object when a shortcut this class has
65 // registered for has been pressed.
66 virtual void OnKeyPressed(const ui::Accelerator
& accelerator
) OVERRIDE
;
68 // Weak pointer to our profile. Not owned by us.
71 DISALLOW_COPY_AND_ASSIGN(ExtensionCommandsGlobalRegistry
);
74 } // namespace extensions
76 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_COMMANDS_GLOBAL_REGISTRY_H_