OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_H_ | |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_H_ | |
7 #pragma once | |
8 | |
9 #include <map> | |
10 #include <string> | |
11 #include <utility> | |
12 | |
13 #include "base/compiler_specific.h" | |
14 #include "content/public/browser/notification_details.h" | |
15 #include "content/public/browser/notification_observer.h" | |
16 #include "content/public/browser/notification_registrar.h" | |
17 #include "content/public/browser/notification_source.h" | |
18 #include "ui/base/accelerators/accelerator.h" | |
19 | |
20 class Extension; | |
21 class Profile; | |
22 | |
23 namespace views { | |
24 class FocusManager; | |
25 } | |
26 | |
27 // The ExtensionKeybindingRegistry is a class that handles keyboard accelerators | |
28 // for regular extension commands (other than displaying browserAction and | |
29 // pageAction popups). It registers all those accelerators on behalf of the | |
30 // extensions and routes the commands to them via the BrowserEventRouter. | |
31 class ExtensionKeybindingRegistry : ui::AcceleratorTarget, | |
32 public content::NotificationObserver { | |
33 public: | |
34 ExtensionKeybindingRegistry(Profile* profile, | |
35 views::FocusManager* focus_manager); | |
36 virtual ~ExtensionKeybindingRegistry(); | |
37 | |
38 // Overridden from ui::AcceleratorTarget. | |
39 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | |
40 virtual bool CanHandleAccelerators() const OVERRIDE; | |
41 | |
42 // Overridden from content::NotificationObserver: | |
43 virtual void Observe(int type, | |
44 const content::NotificationSource& source, | |
45 const content::NotificationDetails& details) OVERRIDE; | |
46 | |
47 private: | |
48 void AddExtensionKeybinding(const Extension* extension); | |
49 void RemoveExtensionKeybinding(const Extension* extension); | |
50 | |
51 // Whether to ignore this command. | |
52 bool ShouldIgnoreCommand(const std::string& command) const; | |
53 | |
54 // Weak pointer back to parent profile. | |
55 Profile* profile_; | |
56 | |
57 // Weak pointer back to the focus manager to use to register and unregister | |
58 // accelerators with. | |
59 views::FocusManager* focus_manager_; | |
60 | |
61 // Maps an accelerator to a string pair (extension id, command name). | |
62 typedef std::map< ui::Accelerator, | |
63 std::pair<std::string, std::string> > EventTargets; | |
64 EventTargets event_targets_; | |
65 | |
66 // The content notification registrar for listening to extension events. | |
67 content::NotificationRegistrar registrar_; | |
68 | |
69 DISALLOW_COPY_AND_ASSIGN(ExtensionKeybindingRegistry); | |
70 }; | |
71 | |
72 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_KEYBINDING_REGISTRY_H_ | |
OLD | NEW |