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

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

Issue 10833071: Renaming the 'keybinding' permission to 'commands'. (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 #include "chrome/browser/extensions/api/commands/command_service.h" 5 #include "chrome/browser/extensions/api/commands/command_service.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/extensions/extension_keybinding_registry.h" 9 #include "chrome/browser/extensions/extension_keybinding_registry.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
(...skipping 19 matching lines...) Expand all
30 UTF16ToUTF8(accelerator.GetShortcutText()); 30 UTF16ToUTF8(accelerator.GetShortcutText());
31 } 31 }
32 32
33 } // namespace 33 } // namespace
34 34
35 namespace extensions { 35 namespace extensions {
36 36
37 // static 37 // static
38 void CommandService::RegisterUserPrefs( 38 void CommandService::RegisterUserPrefs(
39 PrefService* user_prefs) { 39 PrefService* user_prefs) {
40 user_prefs->RegisterDictionaryPref(prefs::kExtensionKeybindings, 40 user_prefs->RegisterDictionaryPref(prefs::kExtensionCommands,
41 PrefService::SYNCABLE_PREF); 41 PrefService::SYNCABLE_PREF);
42 } 42 }
43 43
44 CommandService::CommandService(Profile* profile) 44 CommandService::CommandService(Profile* profile)
45 : profile_(profile) { 45 : profile_(profile) {
46 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, 46 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED,
47 content::Source<Profile>(profile)); 47 content::Source<Profile>(profile));
48 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, 48 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
49 content::Source<Profile>(profile)); 49 content::Source<Profile>(profile));
50 } 50 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 101
102 bool CommandService::AddKeybindingPref( 102 bool CommandService::AddKeybindingPref(
103 const ui::Accelerator& accelerator, 103 const ui::Accelerator& accelerator,
104 std::string extension_id, 104 std::string extension_id,
105 std::string command_name, 105 std::string command_name,
106 bool allow_overrides) { 106 bool allow_overrides) {
107 if (accelerator.key_code() == ui::VKEY_UNKNOWN) 107 if (accelerator.key_code() == ui::VKEY_UNKNOWN)
108 return false; 108 return false;
109 109
110 DictionaryPrefUpdate updater(profile_->GetPrefs(), 110 DictionaryPrefUpdate updater(profile_->GetPrefs(),
111 prefs::kExtensionKeybindings); 111 prefs::kExtensionCommands);
112 DictionaryValue* bindings = updater.Get(); 112 DictionaryValue* bindings = updater.Get();
113 113
114 std::string key = GetPlatformKeybindingKeyForAccelerator(accelerator); 114 std::string key = GetPlatformKeybindingKeyForAccelerator(accelerator);
115 115
116 if (!allow_overrides && bindings->HasKey(key)) 116 if (!allow_overrides && bindings->HasKey(key))
117 return false; // Already taken. 117 return false; // Already taken.
118 118
119 DictionaryValue* keybinding = new DictionaryValue(); 119 DictionaryValue* keybinding = new DictionaryValue();
120 keybinding->SetString(kExtension, extension_id); 120 keybinding->SetString(kExtension, extension_id);
121 keybinding->SetString(kCommandName, command_name); 121 keybinding->SetString(kCommandName, command_name);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 // shortcut before proceeding. 160 // shortcut before proceeding.
161 RemoveKeybindingPrefs(extension_id, command_name); 161 RemoveKeybindingPrefs(extension_id, command_name);
162 162
163 ui::Accelerator accelerator = Command::StringToAccelerator(keystroke); 163 ui::Accelerator accelerator = Command::StringToAccelerator(keystroke);
164 AddKeybindingPref(accelerator, extension_id, command_name, true); 164 AddKeybindingPref(accelerator, extension_id, command_name, true);
165 } 165 }
166 166
167 ui::Accelerator CommandService::FindShortcutForCommand( 167 ui::Accelerator CommandService::FindShortcutForCommand(
168 const std::string& extension_id, const std::string& command) { 168 const std::string& extension_id, const std::string& command) {
169 const DictionaryValue* bindings = 169 const DictionaryValue* bindings =
170 profile_->GetPrefs()->GetDictionary(prefs::kExtensionKeybindings); 170 profile_->GetPrefs()->GetDictionary(prefs::kExtensionCommands);
171 for (DictionaryValue::key_iterator it = bindings->begin_keys(); 171 for (DictionaryValue::key_iterator it = bindings->begin_keys();
172 it != bindings->end_keys(); ++it) { 172 it != bindings->end_keys(); ++it) {
173 const DictionaryValue* item = NULL; 173 const DictionaryValue* item = NULL;
174 bindings->GetDictionary(*it, &item); 174 bindings->GetDictionary(*it, &item);
175 175
176 std::string extension; 176 std::string extension;
177 item->GetString(kExtension, &extension); 177 item->GetString(kExtension, &extension);
178 if (extension != extension_id) 178 if (extension != extension_id)
179 continue; 179 continue;
180 std::string command_name; 180 std::string command_name;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 AddKeybindingPref(page_action_command->accelerator(), 217 AddKeybindingPref(page_action_command->accelerator(),
218 extension->id(), 218 extension->id(),
219 page_action_command->command_name(), 219 page_action_command->command_name(),
220 false); // Overwriting not allowed. 220 false); // Overwriting not allowed.
221 } 221 }
222 } 222 }
223 223
224 void CommandService::RemoveKeybindingPrefs(const std::string& extension_id, 224 void CommandService::RemoveKeybindingPrefs(const std::string& extension_id,
225 const std::string& command_name) { 225 const std::string& command_name) {
226 DictionaryPrefUpdate updater(profile_->GetPrefs(), 226 DictionaryPrefUpdate updater(profile_->GetPrefs(),
227 prefs::kExtensionKeybindings); 227 prefs::kExtensionCommands);
228 DictionaryValue* bindings = updater.Get(); 228 DictionaryValue* bindings = updater.Get();
229 229
230 typedef std::vector<std::string> KeysToRemove; 230 typedef std::vector<std::string> KeysToRemove;
231 KeysToRemove keys_to_remove; 231 KeysToRemove keys_to_remove;
232 for (DictionaryValue::key_iterator it = bindings->begin_keys(); 232 for (DictionaryValue::key_iterator it = bindings->begin_keys();
233 it != bindings->end_keys(); ++it) { 233 it != bindings->end_keys(); ++it) {
234 std::string key = *it; 234 std::string key = *it;
235 DictionaryValue* item = NULL; 235 DictionaryValue* item = NULL;
236 bindings->GetDictionary(key, &item); 236 bindings->GetDictionary(key, &item);
237 237
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 return false; 296 return false;
297 297
298 *command = *requested_command; 298 *command = *requested_command;
299 if (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN) 299 if (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN)
300 command->set_accelerator(shortcut_assigned); 300 command->set_accelerator(shortcut_assigned);
301 301
302 return true; 302 return true;
303 } 303 }
304 304
305 } // namespace extensions 305 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/browser_event_router.cc » ('j') | chrome/common/pref_names.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698