NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / extensions / extension_commands_global_registry.h
blob04e8bd839c867701016cac9bd5320df775deb8bc
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_
8 #include <map>
9 #include <string>
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"
17 class Profile;
19 namespace extensions {
20 class Extension;
23 namespace extensions {
25 // ExtensionCommandsGlobalRegistry is a class that handles the cross-platform
26 // implementation of the global shortcut registration for the Extension Commands
27 // API).
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 {
36 public:
37 // ProfileKeyedAPI implementation.
38 static ProfileKeyedAPIFactory<
39 ExtensionCommandsGlobalRegistry>* GetFactoryInstance();
41 // Convenience method to get the ExtensionCommandsGlobalRegistry for a
42 // profile.
43 static ExtensionCommandsGlobalRegistry* Get(Profile* profile);
45 explicit ExtensionCommandsGlobalRegistry(Profile* profile);
46 virtual ~ExtensionCommandsGlobalRegistry();
48 private:
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.
69 Profile* profile_;
71 DISALLOW_COPY_AND_ASSIGN(ExtensionCommandsGlobalRegistry);
74 } // namespace extensions
76 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_COMMANDS_GLOBAL_REGISTRY_H_