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_EXTENSIONS_EXTENSION_COMMANDS_GLOBAL_REGISTRY_H_ | |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_COMMANDS_GLOBAL_REGISTRY_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 // 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(); | |
40 | |
41 // Convenience method to get the ExtensionCommandsGlobalRegistry for a | |
42 // profile. | |
43 static ExtensionCommandsGlobalRegistry* Get(Profile* profile); | |
44 | |
45 explicit ExtensionCommandsGlobalRegistry(Profile* profile); | |
46 virtual ~ExtensionCommandsGlobalRegistry(); | |
47 | |
48 private: | |
49 friend class ProfileKeyedAPIFactory<ExtensionCommandsGlobalRegistry>; | |
50 | |
51 // ProfileKeyedAPI implementation. | |
52 static const char* service_name() { | |
53 return "ExtensionCommandsGlobalRegistry"; | |
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; | |
Yoyo Zhou
2013/10/03 22:08:50
Why is this called EventTargets? I don't see eithe
Finnur
2013/10/04 17:57:02
Moved to base class (and added a bit more comments
| |
75 EventTargets event_targets_; | |
76 | |
77 DISALLOW_COPY_AND_ASSIGN(ExtensionCommandsGlobalRegistry); | |
78 }; | |
79 | |
80 } // namespace extensions | |
81 | |
82 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_COMMANDS_GLOBAL_REGISTRY_H_ | |
OLD | NEW |