| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 // If |extension_filter| is not ALL_EXTENSIONS, only keybindings by | 52 // If |extension_filter| is not ALL_EXTENSIONS, only keybindings by |
| 53 // by extensions that match the filter will be registered. | 53 // by extensions that match the filter will be registered. |
| 54 ExtensionKeybindingRegistry(content::BrowserContext* context, | 54 ExtensionKeybindingRegistry(content::BrowserContext* context, |
| 55 ExtensionFilter extension_filter, | 55 ExtensionFilter extension_filter, |
| 56 Delegate* delegate); | 56 Delegate* delegate); |
| 57 | 57 |
| 58 ~ExtensionKeybindingRegistry() override; | 58 ~ExtensionKeybindingRegistry() override; |
| 59 | 59 |
| 60 // Enables/Disables general shortcut handling in Chrome. Implemented in | 60 // Enables/Disables general shortcut handling in Chrome. |
| 61 // platform-specific ExtensionKeybindingsRegistry* files. | 61 void set_shortcut_handling_suspended(bool suspended); |
| 62 static void SetShortcutHandlingSuspended(bool suspended); | 62 bool shortcut_handling_suspended() const; |
| 63 | 63 |
| 64 // Execute the command bound to |accelerator| and provided by the extension | 64 // Execute the command bound to |accelerator| and provided by the extension |
| 65 // with |extension_id|, if it exists. | 65 // with |extension_id|, if it exists. |
| 66 void ExecuteCommand(const std::string& extension_id, | 66 void ExecuteCommand(const std::string& extension_id, |
| 67 const ui::Accelerator& accelerator); | 67 const ui::Accelerator& accelerator); |
| 68 | 68 |
| 69 // Check whether the specified |accelerator| has been registered. | 69 // Check whether the specified |accelerator| has been registered. |
| 70 bool IsAcceleratorRegistered(const ui::Accelerator& accelerator) const; | 70 bool IsAcceleratorRegistered(const ui::Accelerator& accelerator) const; |
| 71 | 71 |
| 72 protected: | 72 protected: |
| 73 // Add extension keybindings for the events defined by the |extension|. | 73 // Add extension keybindings for the events defined by the |extension|. |
| 74 // |command_name| is optional, but if not blank then only the command | 74 // |command_name| is optional, but if not blank then only the command |
| 75 // specified will be added. | 75 // specified will be added. |
| 76 virtual void AddExtensionKeybindings( | 76 virtual void AddExtensionKeybindings( |
| 77 const Extension* extension, | 77 const Extension* extension, |
| 78 const std::string& command_name) = 0; | 78 const std::string& command_name) = 0; |
| 79 // Remove extension bindings for |extension|. |command_name| is optional, | 79 // Remove extension bindings for |extension|. |command_name| is optional, |
| 80 // but if not blank then only the command specified will be removed. | 80 // but if not blank then only the command specified will be removed. |
| 81 void RemoveExtensionKeybinding( | 81 void RemoveExtensionKeybinding( |
| 82 const Extension* extension, | 82 const Extension* extension, |
| 83 const std::string& command_name); | 83 const std::string& command_name); |
| 84 // Overridden by platform specific implementations to provide additional | 84 // Overridden by platform specific implementations to provide additional |
| 85 // unregistration (which varies between platforms). | 85 // unregistration (which varies between platforms). |
| 86 virtual void RemoveExtensionKeybindingImpl( | 86 virtual void RemoveExtensionKeybindingImpl( |
| 87 const ui::Accelerator& accelerator, | 87 const ui::Accelerator& accelerator, |
| 88 const std::string& command_name) = 0; | 88 const std::string& command_name) = 0; |
| 89 | 89 |
| 90 // Called when shortcut handling is suspended or resumed. |
| 91 virtual void OnShortcutHandlingSuspended(bool suspended) {} |
| 92 |
| 90 // Make sure all extensions registered have keybindings added. | 93 // Make sure all extensions registered have keybindings added. |
| 91 void Init(); | 94 void Init(); |
| 92 | 95 |
| 93 // Whether to ignore this command. Only browserAction commands and pageAction | 96 // Whether to ignore this command. Only browserAction commands and pageAction |
| 94 // commands are currently ignored, since they are handled elsewhere. | 97 // commands are currently ignored, since they are handled elsewhere. |
| 95 bool ShouldIgnoreCommand(const std::string& command) const; | 98 bool ShouldIgnoreCommand(const std::string& command) const; |
| 96 | 99 |
| 97 // Fire event targets which the specified |accelerator| is binding with. | 100 // Fire event targets which the specified |accelerator| is binding with. |
| 98 // Returns true if we can find the appropriate event targets. | 101 // Returns true if we can find the appropriate event targets. |
| 99 bool NotifyEventTargets(const ui::Accelerator& accelerator); | 102 bool NotifyEventTargets(const ui::Accelerator& accelerator); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 // accelerator (which isn't media keys) has only one target, while the media | 169 // accelerator (which isn't media keys) has only one target, while the media |
| 167 // keys can have more than one. | 170 // keys can have more than one. |
| 168 typedef std::list<std::pair<std::string, std::string> > TargetList; | 171 typedef std::list<std::pair<std::string, std::string> > TargetList; |
| 169 typedef std::map<ui::Accelerator, TargetList> EventTargets; | 172 typedef std::map<ui::Accelerator, TargetList> EventTargets; |
| 170 EventTargets event_targets_; | 173 EventTargets event_targets_; |
| 171 | 174 |
| 172 // Listen to extension load, unloaded notifications. | 175 // Listen to extension load, unloaded notifications. |
| 173 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 176 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 174 extension_registry_observer_; | 177 extension_registry_observer_; |
| 175 | 178 |
| 179 // Keeps track of whether shortcut handling is currently suspended. Shortcuts |
| 180 // are suspended briefly while capturing which shortcut to assign to an |
| 181 // extension command in the Config UI. If handling isn't suspended while |
| 182 // capturing then trying to assign Ctrl+F to a command would instead result |
| 183 // in the Find box opening. |
| 184 bool shortcut_handling_suspended_; |
| 185 |
| 176 DISALLOW_COPY_AND_ASSIGN(ExtensionKeybindingRegistry); | 186 DISALLOW_COPY_AND_ASSIGN(ExtensionKeybindingRegistry); |
| 177 }; | 187 }; |
| 178 | 188 |
| 179 } // namespace extensions | 189 } // namespace extensions |
| 180 | 190 |
| 181 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_H_ | 191 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_H_ |
| OLD | NEW |