| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "content/public/browser/notification_details.h" | 11 #include "content/public/browser/notification_details.h" |
| 12 #include "content/public/browser/notification_observer.h" | 12 #include "content/public/browser/notification_observer.h" |
| 13 #include "content/public/browser/notification_registrar.h" | 13 #include "content/public/browser/notification_registrar.h" |
| 14 #include "content/public/browser/notification_source.h" | 14 #include "content/public/browser/notification_source.h" |
| 15 | 15 |
| 16 class Profile; | 16 class Profile; |
| 17 | 17 |
| 18 namespace extensions { | 18 namespace extensions { |
| 19 | 19 |
| 20 class ActiveTabPermissionGranter; |
| 20 class Extension; | 21 class Extension; |
| 21 | 22 |
| 22 // The ExtensionKeybindingRegistry is a class that handles the cross-platform | 23 // The ExtensionKeybindingRegistry is a class that handles the cross-platform |
| 23 // logic for keyboard accelerators. See platform-specific implementations for | 24 // logic for keyboard accelerators. See platform-specific implementations for |
| 24 // implementation details for each platform. | 25 // implementation details for each platform. |
| 25 class ExtensionKeybindingRegistry : public content::NotificationObserver { | 26 class ExtensionKeybindingRegistry : public content::NotificationObserver { |
| 26 public: | 27 public: |
| 27 enum ExtensionFilter { | 28 enum ExtensionFilter { |
| 28 ALL_EXTENSIONS, | 29 ALL_EXTENSIONS, |
| 29 PLATFORM_APPS_ONLY | 30 PLATFORM_APPS_ONLY |
| 30 }; | 31 }; |
| 31 | 32 |
| 32 // If |extension_filter| is not ALL_EXTENSIONS, only keybindings by | 33 class Delegate { |
| 34 public: |
| 35 // Gets the ActiveTabPermissionGranter for the active tab, if any. |
| 36 // If there is no active tab then returns NULL. |
| 37 virtual ActiveTabPermissionGranter* GetActiveTabPermissionGranter() = 0; |
| 38 }; |
| 39 |
| 40 // If |extension_filter| is not ALL_EXTENSIONS, only keybindings by |
| 33 // by extensions that match the filter will be registered. | 41 // by extensions that match the filter will be registered. |
| 34 ExtensionKeybindingRegistry(Profile* profile, | 42 ExtensionKeybindingRegistry(Profile* profile, |
| 35 ExtensionFilter extension_filter); | 43 ExtensionFilter extension_filter, |
| 44 Delegate* delegate); |
| 45 |
| 36 virtual ~ExtensionKeybindingRegistry(); | 46 virtual ~ExtensionKeybindingRegistry(); |
| 37 | 47 |
| 38 // Enables/Disables general shortcut handing in Chrome. Implemented in | 48 // Enables/Disables general shortcut handing in Chrome. Implemented in |
| 39 // platform-specific ExtensionKeybindingsRegistry* files. | 49 // platform-specific ExtensionKeybindingsRegistry* files. |
| 40 static void SetShortcutHandlingSuspended(bool suspended); | 50 static void SetShortcutHandlingSuspended(bool suspended); |
| 41 | 51 |
| 42 // Overridden from content::NotificationObserver: | 52 // Overridden from content::NotificationObserver: |
| 43 virtual void Observe(int type, | 53 virtual void Observe(int type, |
| 44 const content::NotificationSource& source, | 54 const content::NotificationSource& source, |
| 45 const content::NotificationDetails& details) OVERRIDE; | 55 const content::NotificationDetails& details) OVERRIDE; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 57 const Extension* extension, | 67 const Extension* extension, |
| 58 const std::string& command_name) = 0; | 68 const std::string& command_name) = 0; |
| 59 | 69 |
| 60 // Make sure all extensions registered have keybindings added. | 70 // Make sure all extensions registered have keybindings added. |
| 61 void Init(); | 71 void Init(); |
| 62 | 72 |
| 63 // Whether to ignore this command. Only browserAction commands and pageAction | 73 // Whether to ignore this command. Only browserAction commands and pageAction |
| 64 // commands are currently ignored, since they are handled elsewhere. | 74 // commands are currently ignored, since they are handled elsewhere. |
| 65 bool ShouldIgnoreCommand(const std::string& command) const; | 75 bool ShouldIgnoreCommand(const std::string& command) const; |
| 66 | 76 |
| 77 // Notifies appropriate parties that a command has been executed. |
| 78 void CommandExecuted(const std::string& extension_id, |
| 79 const std::string& command); |
| 80 |
| 67 private: | 81 private: |
| 68 // Returns true if the |extension| matches our extension filter. | 82 // Returns true if the |extension| matches our extension filter. |
| 69 bool ExtensionMatchesFilter(const extensions::Extension* extension); | 83 bool ExtensionMatchesFilter(const extensions::Extension* extension); |
| 70 | 84 |
| 71 // The content notification registrar for listening to extension events. | 85 // The content notification registrar for listening to extension events. |
| 72 content::NotificationRegistrar registrar_; | 86 content::NotificationRegistrar registrar_; |
| 73 | 87 |
| 74 // Weak pointer to our profile. Not owned by us. | 88 // Weak pointer to our profile. Not owned by us. |
| 75 Profile* profile_; | 89 Profile* profile_; |
| 76 | 90 |
| 77 // What extensions to register keybindings for. | 91 // What extensions to register keybindings for. |
| 78 ExtensionFilter extension_filter_; | 92 ExtensionFilter extension_filter_; |
| 79 | 93 |
| 94 // Weak pointer to our delegate. Not owned by us. Must outlive this class. |
| 95 Delegate* delegate_; |
| 96 |
| 80 DISALLOW_COPY_AND_ASSIGN(ExtensionKeybindingRegistry); | 97 DISALLOW_COPY_AND_ASSIGN(ExtensionKeybindingRegistry); |
| 81 }; | 98 }; |
| 82 | 99 |
| 83 } // namespace extensions | 100 } // namespace extensions |
| 84 | 101 |
| 85 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_H_ | 102 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_H_ |
| OLD | NEW |