Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Side by Side Diff: chrome/browser/extensions/extension_keybinding_registry.h

Issue 23812010: Implement first part of supporting global extension commands. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: gclient sync Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <map>
8 #include <string> 9 #include <string>
9 10
10 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
11 #include "content/public/browser/notification_details.h" 12 #include "content/public/browser/notification_details.h"
12 #include "content/public/browser/notification_observer.h" 13 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h" 14 #include "content/public/browser/notification_registrar.h"
14 #include "content/public/browser/notification_source.h" 15 #include "content/public/browser/notification_source.h"
15 16
16 class Profile; 17 class Profile;
17 18
19 namespace ui {
20 class Accelerator;
21 }
22
18 namespace extensions { 23 namespace extensions {
19 24
20 class ActiveTabPermissionGranter; 25 class ActiveTabPermissionGranter;
21 class Extension; 26 class Extension;
22 27
23 // The ExtensionKeybindingRegistry is a class that handles the cross-platform 28 // The ExtensionKeybindingRegistry is a class that handles the cross-platform
24 // logic for keyboard accelerators. See platform-specific implementations for 29 // logic for keyboard accelerators. See platform-specific implementations for
25 // implementation details for each platform. 30 // implementation details for each platform.
26 class ExtensionKeybindingRegistry : public content::NotificationObserver { 31 class ExtensionKeybindingRegistry : public content::NotificationObserver {
27 public: 32 public:
(...skipping 28 matching lines...) Expand all
56 61
57 protected: 62 protected:
58 // Add extension keybinding for the events defined by the |extension|. 63 // Add extension keybinding for the events defined by the |extension|.
59 // |command_name| is optional, but if not blank then only the command 64 // |command_name| is optional, but if not blank then only the command
60 // specified will be added. 65 // specified will be added.
61 virtual void AddExtensionKeybinding( 66 virtual void AddExtensionKeybinding(
62 const Extension* extension, 67 const Extension* extension,
63 const std::string& command_name) = 0; 68 const std::string& command_name) = 0;
64 // Remove extension bindings for |extension|. |command_name| is optional, 69 // Remove extension bindings for |extension|. |command_name| is optional,
65 // but if not blank then only the command specified will be removed. 70 // but if not blank then only the command specified will be removed.
66 virtual void RemoveExtensionKeybinding( 71 void RemoveExtensionKeybinding(
67 const Extension* extension, 72 const Extension* extension,
73 const std::string& command_name);
74 // Overridden by platform specific implementations to provide additional
75 // unregistration (which varies between platforms).
76 virtual void RemoveExtensionKeybindingImpl(
77 const ui::Accelerator& accelerator,
68 const std::string& command_name) = 0; 78 const std::string& command_name) = 0;
69 79
70 // Make sure all extensions registered have keybindings added. 80 // Make sure all extensions registered have keybindings added.
71 void Init(); 81 void Init();
72 82
73 // Whether to ignore this command. Only browserAction commands and pageAction 83 // Whether to ignore this command. Only browserAction commands and pageAction
74 // commands are currently ignored, since they are handled elsewhere. 84 // commands are currently ignored, since they are handled elsewhere.
75 bool ShouldIgnoreCommand(const std::string& command) const; 85 bool ShouldIgnoreCommand(const std::string& command) const;
76 86
77 // Notifies appropriate parties that a command has been executed. 87 // Notifies appropriate parties that a command has been executed.
78 void CommandExecuted(const std::string& extension_id, 88 void CommandExecuted(const std::string& extension_id,
79 const std::string& command); 89 const std::string& command);
80 90
91 // Maps an accelerator to a string pair (extension id, command name) for
92 // commands that have been registered. This keeps track of the targets for the
93 // keybinding event (which named command to call in which extension). On GTK,
94 // this map contains registration for pageAction and browserAction commands,
95 // whereas on other platforms it does not.
96 typedef std::map< ui::Accelerator,
97 std::pair<std::string, std::string> > EventTargets;
98 EventTargets event_targets_;
99
81 private: 100 private:
82 // Returns true if the |extension| matches our extension filter. 101 // Returns true if the |extension| matches our extension filter.
83 bool ExtensionMatchesFilter(const extensions::Extension* extension); 102 bool ExtensionMatchesFilter(const extensions::Extension* extension);
84 103
85 // The content notification registrar for listening to extension events. 104 // The content notification registrar for listening to extension events.
86 content::NotificationRegistrar registrar_; 105 content::NotificationRegistrar registrar_;
87 106
88 // Weak pointer to our profile. Not owned by us. 107 // Weak pointer to our profile. Not owned by us.
89 Profile* profile_; 108 Profile* profile_;
90 109
91 // What extensions to register keybindings for. 110 // What extensions to register keybindings for.
92 ExtensionFilter extension_filter_; 111 ExtensionFilter extension_filter_;
93 112
94 // Weak pointer to our delegate. Not owned by us. Must outlive this class. 113 // Weak pointer to our delegate. Not owned by us. Must outlive this class.
95 Delegate* delegate_; 114 Delegate* delegate_;
96 115
97 DISALLOW_COPY_AND_ASSIGN(ExtensionKeybindingRegistry); 116 DISALLOW_COPY_AND_ASSIGN(ExtensionKeybindingRegistry);
98 }; 117 };
99 118
100 } // namespace extensions 119 } // namespace extensions
101 120
102 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_H_ 121 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698