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

Side by Side Diff: chrome/browser/extensions/api/commands/extension_command_service.h

Issue 10383240: This adds a webui overlay on the extensions page for showing what Extension keybindings are active.… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 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_API_COMMANDS_EXTENSION_COMMAND_SERVICE_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_COMMANDS_EXTENSION_COMMAND_SERVICE_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_COMMANDS_EXTENSION_COMMAND_SERVICE_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_COMMANDS_EXTENSION_COMMAND_SERVICE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "chrome/browser/profiles/profile_keyed_service.h" 12 #include "chrome/browser/profiles/profile_keyed_service.h"
13 #include "chrome/common/extensions/extension.h" 13 #include "chrome/common/extensions/extension.h"
14 #include "chrome/common/extensions/extension_commands.h" 14 #include "chrome/common/extensions/extension_commands.h"
15 #include "content/public/browser/notification_details.h" 15 #include "content/public/browser/notification_details.h"
16 #include "content/public/browser/notification_observer.h" 16 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h" 17 #include "content/public/browser/notification_registrar.h"
18 #include "content/public/browser/notification_source.h" 18 #include "content/public/browser/notification_source.h"
19 19
20 class PrefService; 20 class PrefService;
21 class Profile; 21 class Profile;
22 22
23 namespace base {
24 class DictionaryValue;
25 }
26
23 namespace ui { 27 namespace ui {
24 class Accelerator; 28 class Accelerator;
25 } 29 }
26 30
31 namespace extensions {
32
27 // This service keeps track of preferences related to extension commands 33 // This service keeps track of preferences related to extension commands
28 // (assigning initial keybindings on install and removing them on deletion 34 // (assigning initial keybindings on install and removing them on deletion
29 // and answers questions related to which commands are active. 35 // and answers questions related to which commands are active.
30 class ExtensionCommandService : public ProfileKeyedService, 36 class ExtensionCommandService : public ProfileKeyedService,
31 public content::NotificationObserver { 37 public content::NotificationObserver {
32 public: 38 public:
39 // An enum specifying whether to fetch all extension commands or only active
40 // ones.
41 enum QueryType {
42 ALL,
43 ACTIVE_ONLY,
44 };
45
33 // Register prefs for keybinding. 46 // Register prefs for keybinding.
34 static void RegisterUserPrefs(PrefService* user_prefs); 47 static void RegisterUserPrefs(PrefService* user_prefs);
35 48
36 // Constructs an ExtensionCommandService object for the given profile. 49 // Constructs an ExtensionCommandService object for the given profile.
37 explicit ExtensionCommandService(Profile* profile); 50 explicit ExtensionCommandService(Profile* profile);
38 virtual ~ExtensionCommandService(); 51 virtual ~ExtensionCommandService();
39 52
40 // Gets the active keybinding (if any) for the browser action of an extension 53 // Gets the keybinding (if any) for the browser action of an extension given
41 // given its |extension_id|. The function consults the master list to see if 54 // its |extension_id|. The function consults the master list to see if
42 // the keybinding is active. Returns NULL if the extension has no browser 55 // the keybinding is active. Returns NULL if the extension has no browser
43 // action or no active keybinding for it. 56 // action. Returns NULL if the keybinding is not active and |type| requested
44 const extensions::Command* GetActiveBrowserActionCommand( 57 // is ACTIVE_ONLY.
45 const std::string& extension_id); 58 const extensions::Command* GetBrowserActionCommand(
59 const std::string& extension_id, QueryType type);
46 60
47 // Gets the active keybinding (if any) for the page action of an extension 61 // Gets the keybinding (if any) for the page action of an extension given
48 // given its |extension_id|. The function consults the master list to see if 62 // its |extension_id|. The function consults the master list to see if
49 // the keybinding is active. Returns NULL if the extension has no page action 63 // the keybinding is active. Returns NULL if the extension has no page
50 // or no active keybinding for it. 64 // action. Returns NULL if the keybinding is not active and |type| requested
51 const extensions::Command* GetActivePageActionCommand( 65 // is ACTIVE_ONLY.
52 const std::string& extension_id); 66 const extensions::Command* GetPageActionCommand(
67 const std::string& extension_id, QueryType type);
53 68
54 // Gets the active keybinding (if any) for the named commands of an extension 69 // Gets the active keybinding (if any) for the named commands of an extension
55 // given its |extension_id|. The function consults the master list to see if 70 // given its |extension_id|. The function consults the master list to see if
56 // the keybinding is active. Returns an empty map if the extension has no 71 // the keybinding is active. Returns an empty map if the extension has no
57 // named commands or no active keybinding for the commands. 72 // named commands or no active named commands when |type| requested is
58 extensions::CommandMap GetActiveNamedCommands( 73 // ACTIVE_ONLY.
59 const std::string& extension_id); 74 extensions::CommandMap GetNamedCommands(
75 const std::string& extension_id, QueryType type);
60 76
61 // Checks to see if a keybinding |accelerator| for a given |command_name| in 77 // Checks to see if a keybinding |accelerator| for a given |command_name| in
62 // an extension with id |extension_id| is registered as active (by consulting 78 // an extension with id |extension_id| is registered as active (by consulting
63 // the master list in |user_prefs|). 79 // the master list in |user_prefs|).
64 bool IsKeybindingActive(const ui::Accelerator& accelerator, 80 bool IsKeybindingActive(const ui::Accelerator& accelerator,
65 std::string extension_id, 81 const std::string& extension_id,
66 std::string command_name); 82 const std::string& command_name) const;
67 83
68 // Records a keybinding |accelerator| as active for an extension with id 84 // Records a keybinding |accelerator| as active for an extension with id
69 // |extension_id| and command with the name |command_name|. If 85 // |extension_id| and command with the name |command_name|. If
70 // |allow_overrides| is false, the keybinding must be free for the change to 86 // |allow_overrides| is false, the keybinding must be free for the change to
71 // be recorded (as determined by the master list in |user_prefs|). If 87 // be recorded (as determined by the master list in |user_prefs|). If
72 // |allow_overwrites| is true, any previously recorded keybinding for this 88 // |allow_overwrites| is true, any previously recorded keybinding for this
73 // |accelerator| will be overwritten. Returns true if the change was 89 // |accelerator| will be overwritten. Returns true if the change was
74 // successfully recorded. 90 // successfully recorded.
75 bool AddKeybindingPref(const ui::Accelerator& accelerator, 91 bool AddKeybindingPref(const ui::Accelerator& accelerator,
76 std::string extension_id, 92 std::string extension_id,
(...skipping 18 matching lines...) Expand all
95 111
96 // The content notification registrar for listening to extension events. 112 // The content notification registrar for listening to extension events.
97 content::NotificationRegistrar registrar_; 113 content::NotificationRegistrar registrar_;
98 114
99 // A weak pointer to the profile we are associated with. Not owned by us. 115 // A weak pointer to the profile we are associated with. Not owned by us.
100 Profile* profile_; 116 Profile* profile_;
101 117
102 DISALLOW_COPY_AND_ASSIGN(ExtensionCommandService); 118 DISALLOW_COPY_AND_ASSIGN(ExtensionCommandService);
103 }; 119 };
104 120
121 } // namespace extensions
122
105 #endif // CHROME_BROWSER_EXTENSIONS_API_COMMANDS_EXTENSION_COMMAND_SERVICE_H_ 123 #endif // CHROME_BROWSER_EXTENSIONS_API_COMMANDS_EXTENSION_COMMAND_SERVICE_H_
OLDNEW
« no previous file with comments | « chrome/browser/browser_resources.grd ('k') | chrome/browser/extensions/api/commands/extension_command_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698