OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_COMMANDS_GLOBAL_REGISTRY_VI
EWS_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_COMMANDS_GLOBAL_REGISTRY_VI
EWS_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 |
| 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" |
| 16 |
| 17 class Profile; |
| 18 |
| 19 namespace extensions { |
| 20 class Extension; |
| 21 } |
| 22 |
| 23 namespace extensions { |
| 24 |
| 25 // ExtensionCommandsGlobalRegistryViews is a class that handles the |
| 26 // Views-specific implementation of the global shortcut registration for the |
| 27 // Extension Commands 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 ExtensionCommandsGlobalRegistryViews |
| 33 : public ProfileKeyedAPI, |
| 34 public ExtensionKeybindingRegistry, |
| 35 public GlobalShortcutListener::Observer { |
| 36 public: |
| 37 // ProfileKeyedAPI implementation. |
| 38 static ProfileKeyedAPIFactory< |
| 39 ExtensionCommandsGlobalRegistryViews>* GetFactoryInstance(); |
| 40 |
| 41 // Convenience method to get the ExtensionCommandsGlobalRegistryViews for a |
| 42 // profile. |
| 43 static ExtensionCommandsGlobalRegistryViews* Get(Profile* profile); |
| 44 |
| 45 explicit ExtensionCommandsGlobalRegistryViews(Profile* profile); |
| 46 virtual ~ExtensionCommandsGlobalRegistryViews(); |
| 47 |
| 48 private: |
| 49 friend class ProfileKeyedAPIFactory<ExtensionCommandsGlobalRegistryViews>; |
| 50 |
| 51 // ProfileKeyedAPI implementation. |
| 52 static const char* service_name() { |
| 53 return "ExtensionCommandsGlobalRegistryViews"; |
| 54 } |
| 55 |
| 56 // Overridden from ExtensionKeybindingRegistry: |
| 57 virtual void AddExtensionKeybinding( |
| 58 const Extension* extension, |
| 59 const std::string& command_name) OVERRIDE; |
| 60 virtual void RemoveExtensionKeybinding( |
| 61 const Extension* extension, |
| 62 const std::string& command_name) OVERRIDE; |
| 63 |
| 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; |
| 67 |
| 68 // Weak pointer to our profile. Not owned by us. |
| 69 Profile* profile_; |
| 70 |
| 71 // Maps an accelerator to a string pair (extension id, command name) for |
| 72 // commands that have been registered. |
| 73 typedef std::map< ui::Accelerator, |
| 74 std::pair<std::string, std::string> > EventTargets; |
| 75 EventTargets event_targets_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(ExtensionCommandsGlobalRegistryViews); |
| 78 }; |
| 79 |
| 80 } // namespace extensions |
| 81 |
| 82 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_COMMANDS_GLOBAL_REGISTRY
_VIEWS_H_ |
OLD | NEW |