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

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

Issue 10834106: Implement Keybinding for script badges. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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_COMMAND_SERVICE_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_COMMANDS_COMMAND_SERVICE_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_COMMANDS_COMMAND_SERVICE_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_COMMANDS_COMMAND_SERVICE_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 ACTIVE_ONLY, 42 ACTIVE_ONLY,
43 }; 43 };
44 44
45 // Register prefs for keybinding. 45 // Register prefs for keybinding.
46 static void RegisterUserPrefs(PrefService* user_prefs); 46 static void RegisterUserPrefs(PrefService* user_prefs);
47 47
48 // Constructs a CommandService object for the given profile. 48 // Constructs a CommandService object for the given profile.
49 explicit CommandService(Profile* profile); 49 explicit CommandService(Profile* profile);
50 virtual ~CommandService(); 50 virtual ~CommandService();
51 51
52 // Gets the keybinding (if any) for the browser action of an extension given 52 // Gets the command (if any) for the browser action of an extension given
53 // its |extension_id|. The function consults the master list to see if 53 // its |extension_id|. The function consults the master list to see if
54 // the keybinding is active. Returns false if the extension has no browser 54 // the command is active. Returns false if the extension has no browser
55 // action. Returns false if the keybinding is not active and |type| requested 55 // action. Returns false if the command is not active and |type| requested
56 // is ACTIVE_ONLY. |command| contains the command found and |active| (if not 56 // is ACTIVE_ONLY. |command| contains the command found and |active| (if not
57 // NULL) contains whether |command| is active. 57 // NULL) contains whether |command| is active.
58 bool GetBrowserActionCommand(const std::string& extension_id, 58 bool GetBrowserActionCommand(const std::string& extension_id,
59 QueryType type, 59 QueryType type,
60 extensions::Command* command, 60 extensions::Command* command,
61 bool* active); 61 bool* active);
62 62
63 // Gets the keybinding (if any) for the page action of an extension given 63 // Gets the command (if any) for the page action of an extension given
64 // its |extension_id|. The function consults the master list to see if 64 // its |extension_id|. The function consults the master list to see if
65 // the keybinding is active. Returns false if the extension has no page 65 // the command is active. Returns false if the extension has no page
66 // action. Returns false if the keybinding is not active and |type| requested 66 // action. Returns false if the command is not active and |type| requested
67 // is ACTIVE_ONLY. |command| contains the command found and |active| (if not 67 // is ACTIVE_ONLY. |command| contains the command found and |active| (if not
68 // NULL) contains whether |command| is active. 68 // NULL) contains whether |command| is active.
69 bool GetPageActionCommand(const std::string& extension_id, 69 bool GetPageActionCommand(const std::string& extension_id,
70 QueryType type, 70 QueryType type,
71 extensions::Command* command, 71 extensions::Command* command,
72 bool* active); 72 bool* active);
73 73
74 // Gets the active keybinding (if any) for the named commands of an extension 74 // Gets the command (if any) for the script badge of an extension given
75 // its |extension_id|. The function consults the master list to see if
76 // the command is active. Returns false if the extension has no script
77 // badge. Returns false if the command is not active and |type| requested
78 // is ACTIVE_ONLY. |command| contains the command found and |active| (if not
79 // NULL) contains whether |command| is active.
80 bool GetScriptBadgeCommand(const std::string& extension_id,
81 QueryType type,
82 extensions::Command* command,
83 bool* active);
84
85 // Gets the active command (if any) for the named commands of an extension
75 // given its |extension_id|. The function consults the master list to see if 86 // given its |extension_id|. The function consults the master list to see if
76 // the keybinding is active. Returns an empty map if the extension has no 87 // the command is active. Returns an empty map if the extension has no
77 // named commands or no active named commands when |type| requested is 88 // named commands or no active named commands when |type| requested is
78 // ACTIVE_ONLY. 89 // ACTIVE_ONLY.
79 bool GetNamedCommands(const std::string& extension_id, 90 bool GetNamedCommands(const std::string& extension_id,
80 QueryType type, 91 QueryType type,
81 extensions::CommandMap* command_map); 92 extensions::CommandMap* command_map);
82 93
83 // Records a keybinding |accelerator| as active for an extension with id 94 // Records a keybinding |accelerator| as active for an extension with id
84 // |extension_id| and command with the name |command_name|. If 95 // |extension_id| and command with the name |command_name|. If
85 // |allow_overrides| is false, the keybinding must be free for the change to 96 // |allow_overrides| is false, the keybinding must be free for the change to
86 // be recorded (as determined by the master list in |user_prefs|). If 97 // be recorded (as determined by the master list in |user_prefs|). If
(...skipping 18 matching lines...) Expand all
105 // command is not found. 116 // command is not found.
106 ui::Accelerator FindShortcutForCommand(const std::string& extension_id, 117 ui::Accelerator FindShortcutForCommand(const std::string& extension_id,
107 const std::string& command); 118 const std::string& command);
108 119
109 // Overridden from content::NotificationObserver. 120 // Overridden from content::NotificationObserver.
110 virtual void Observe(int type, 121 virtual void Observe(int type,
111 const content::NotificationSource& source, 122 const content::NotificationSource& source,
112 const content::NotificationDetails& details) OVERRIDE; 123 const content::NotificationDetails& details) OVERRIDE;
113 124
114 private: 125 private:
126 // An enum specifying the types of icons that can have a command.
127 enum ExtensionActionType {
128 BROWSER_ACTION,
129 PAGE_ACTION,
130 SCRIPT_BADGE,
131 };
132
115 // Assigns initial keybinding for a given |extension|'s page action, browser 133 // Assigns initial keybinding for a given |extension|'s page action, browser
116 // action and named commands. In each case, if the suggested keybinding is 134 // action and named commands. In each case, if the suggested keybinding is
117 // free, it will be taken by this extension. If not, that keybinding request 135 // free, it will be taken by this extension. If not, that keybinding request
118 // is ignored. |user_pref| is the PrefService used to record the new 136 // is ignored. |user_pref| is the PrefService used to record the new
119 // keybinding assignment. 137 // keybinding assignment.
120 void AssignInitialKeybindings(const extensions::Extension* extension); 138 void AssignInitialKeybindings(const extensions::Extension* extension);
121 139
122 // Removes all keybindings for a given extension by its |extension_id|. 140 // Removes all keybindings for a given extension by its |extension_id|.
123 // |command_name| is optional and if specified, causes only the command with 141 // |command_name| is optional and if specified, causes only the command with
124 // the name |command_name| to be removed. 142 // the name |command_name| to be removed.
125 void RemoveKeybindingPrefs(const std::string& extension_id, 143 void RemoveKeybindingPrefs(const std::string& extension_id,
126 const std::string& command_name); 144 const std::string& command_name);
127 145
128 bool GetExtensionActionCommand(const std::string& extension_id, 146 bool GetExtensionActionCommand(const std::string& extension_id,
129 QueryType type, 147 QueryType query_type,
130 extensions::Command* command, 148 extensions::Command* command,
131 bool* active, 149 bool* active,
132 bool browser_action); 150 ExtensionActionType action_type);
133 151
134 // The content notification registrar for listening to extension events. 152 // The content notification registrar for listening to extension events.
135 content::NotificationRegistrar registrar_; 153 content::NotificationRegistrar registrar_;
136 154
137 // A weak pointer to the profile we are associated with. Not owned by us. 155 // A weak pointer to the profile we are associated with. Not owned by us.
138 Profile* profile_; 156 Profile* profile_;
139 157
140 DISALLOW_COPY_AND_ASSIGN(CommandService); 158 DISALLOW_COPY_AND_ASSIGN(CommandService);
141 }; 159 };
142 160
143 } // namespace extensions 161 } // namespace extensions
144 162
145 #endif // CHROME_BROWSER_EXTENSIONS_API_COMMANDS_COMMAND_SERVICE_H_ 163 #endif // CHROME_BROWSER_EXTENSIONS_API_COMMANDS_COMMAND_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698