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

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
27 // This service keeps track of preferences related to extension commands 31 // This service keeps track of preferences related to extension commands
28 // (assigning initial keybindings on install and removing them on deletion 32 // (assigning initial keybindings on install and removing them on deletion
29 // and answers questions related to which commands are active. 33 // and answers questions related to which commands are active.
30 class ExtensionCommandService : public ProfileKeyedService, 34 class ExtensionCommandService : public ProfileKeyedService,
Aaron Boodman 2012/05/19 05:33:26 I may have already mentioned this, and it's a low
Finnur 2012/05/21 21:28:43 How about a separate changelist, so as to not mess
31 public content::NotificationObserver { 35 public content::NotificationObserver {
32 public: 36 public:
37 // An enum specifying whether to fetch all extension commands or only active
38 // ones.
39 enum ExtensionCommandQueryType {
Aaron Boodman 2012/05/19 05:33:26 Seems like QueryType is sufficient.
Finnur 2012/05/21 21:28:43 Done.
40 ALL,
41 ACTIVE_ONLY,
42 };
43
33 // Register prefs for keybinding. 44 // Register prefs for keybinding.
34 static void RegisterUserPrefs(PrefService* user_prefs); 45 static void RegisterUserPrefs(PrefService* user_prefs);
35 46
36 // Constructs an ExtensionCommandService object for the given profile. 47 // Constructs an ExtensionCommandService object for the given profile.
37 explicit ExtensionCommandService(Profile* profile); 48 explicit ExtensionCommandService(Profile* profile);
38 virtual ~ExtensionCommandService(); 49 virtual ~ExtensionCommandService();
39 50
40 // Gets the active keybinding (if any) for the browser action of an extension 51 // 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 52 // 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 53 // the keybinding is active. Returns NULL if the extension has no browser
43 // action or no active keybinding for it. 54 // action. Returns NULL if the keybinding is not active and |type| requested
44 const extensions::Command* GetActiveBrowserActionCommand( 55 // is ACTIVE_ONLY.
45 const std::string& extension_id); 56 const extensions::Command* GetBrowserActionCommand(
57 const std::string& extension_id, ExtensionCommandQueryType type);
46 58
47 // Gets the active keybinding (if any) for the page action of an extension 59 // Gets the keybinding (if any) for the browser action of an extension given
Aaron Boodman 2012/05/19 05:33:26 Did you mean to change this? Also, we're killing p
Finnur 2012/05/21 21:28:43 Did not mean to change it. I'm hesitant to remove
48 // given its |extension_id|. The function consults the master list to see if 60 // 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 61 // the keybinding is active. Returns NULL if the extension has no page
50 // or no active keybinding for it. 62 // action. Returns NULL if the keybinding is not active and |type| requested
51 const extensions::Command* GetActivePageActionCommand( 63 // is ACTIVE_ONLY.
52 const std::string& extension_id); 64 const extensions::Command* GetPageActionCommand(
65 const std::string& extension_id, ExtensionCommandQueryType type);
53 66
54 // Gets the active keybinding (if any) for the named commands of an extension 67 // 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 68 // 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 69 // the keybinding is active. Returns an empty map if the extension has no
57 // named commands or no active keybinding for the commands. 70 // named commands or no active named commands when |type| requested is
58 extensions::CommandMap GetActiveNamedCommands( 71 // ACTIVE_ONLY.
59 const std::string& extension_id); 72 extensions::CommandMap GetNamedCommands(
73 const std::string& extension_id, ExtensionCommandQueryType type);
74
75 // Fetches all known commands, active and inactive and returns them through
76 // |commands|.
77 void GetAllCommands(base::DictionaryValue* commands);
Aaron Boodman 2012/05/19 05:33:26 Weird to have an interface that deals in Values he
Finnur 2012/05/21 21:28:43 Done.
60 78
61 // Checks to see if a keybinding |accelerator| for a given |command_name| in 79 // 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 80 // an extension with id |extension_id| is registered as active (by consulting
63 // the master list in |user_prefs|). 81 // the master list in |user_prefs|).
64 bool IsKeybindingActive(const ui::Accelerator& accelerator, 82 bool IsKeybindingActive(const ui::Accelerator& accelerator,
65 std::string extension_id, 83 std::string extension_id,
66 std::string command_name); 84 std::string command_name);
67 85
68 // Records a keybinding |accelerator| as active for an extension with id 86 // Records a keybinding |accelerator| as active for an extension with id
69 // |extension_id| and command with the name |command_name|. If 87 // |extension_id| and command with the name |command_name|. If
(...skipping 16 matching lines...) Expand all
86 // Assigns initial keybinding for a given |extension|'s page action, browser 104 // Assigns initial keybinding for a given |extension|'s page action, browser
87 // action and named commands. In each case, if the suggested keybinding is 105 // action and named commands. In each case, if the suggested keybinding is
88 // free, it will be taken by this extension. If not, that keybinding request 106 // free, it will be taken by this extension. If not, that keybinding request
89 // is ignored. |user_pref| is the PrefService used to record the new 107 // is ignored. |user_pref| is the PrefService used to record the new
90 // keybinding assignment. 108 // keybinding assignment.
91 void AssignInitialKeybindings(const Extension* extension); 109 void AssignInitialKeybindings(const Extension* extension);
92 110
93 // Removes all keybindings for a given extension by its |extension_id|. 111 // Removes all keybindings for a given extension by its |extension_id|.
94 void RemoveKeybindingPrefs(std::string extension_id); 112 void RemoveKeybindingPrefs(std::string extension_id);
95 113
114 // Creates a DictionaryValue containing the details of the extension and
115 // its commands. |extension| and |command| are pointers to the objects this
116 // function should describe.
117 base::DictionaryValue* CreateExtensionDetailValue(
Aaron Boodman 2012/05/19 05:33:26 Seems like this should be Command::ToValue().
Finnur 2012/05/21 21:28:43 Done.
118 const Extension* extension,
119 const extensions::Command* command);
120
96 // The content notification registrar for listening to extension events. 121 // The content notification registrar for listening to extension events.
97 content::NotificationRegistrar registrar_; 122 content::NotificationRegistrar registrar_;
98 123
99 // A weak pointer to the profile we are associated with. Not owned by us. 124 // A weak pointer to the profile we are associated with. Not owned by us.
100 Profile* profile_; 125 Profile* profile_;
101 126
102 DISALLOW_COPY_AND_ASSIGN(ExtensionCommandService); 127 DISALLOW_COPY_AND_ASSIGN(ExtensionCommandService);
103 }; 128 };
104 129
105 #endif // CHROME_BROWSER_EXTENSIONS_API_COMMANDS_EXTENSION_COMMAND_SERVICE_H_ 130 #endif // CHROME_BROWSER_EXTENSIONS_API_COMMANDS_EXTENSION_COMMAND_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698