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

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

Issue 23445013: Parse media keys for named command in the manifest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit fix. Created 7 years, 3 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
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/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } 209 }
210 } 210 }
211 211
212 void CommandService::UpdateKeybindingPrefs(const std::string& extension_id, 212 void CommandService::UpdateKeybindingPrefs(const std::string& extension_id,
213 const std::string& command_name, 213 const std::string& command_name,
214 const std::string& keystroke) { 214 const std::string& keystroke) {
215 // The extension command might be assigned another shortcut. Remove that 215 // The extension command might be assigned another shortcut. Remove that
216 // shortcut before proceeding. 216 // shortcut before proceeding.
217 RemoveKeybindingPrefs(extension_id, command_name); 217 RemoveKeybindingPrefs(extension_id, command_name);
218 218
219 ui::Accelerator accelerator = Command::StringToAccelerator(keystroke); 219 ui::Accelerator accelerator =
220 Command::StringToAccelerator(keystroke, command_name);
220 AddKeybindingPref(accelerator, extension_id, command_name, true); 221 AddKeybindingPref(accelerator, extension_id, command_name, true);
221 } 222 }
222 223
223 ui::Accelerator CommandService::FindShortcutForCommand( 224 ui::Accelerator CommandService::FindShortcutForCommand(
224 const std::string& extension_id, const std::string& command) { 225 const std::string& extension_id, const std::string& command) {
225 const base::DictionaryValue* bindings = 226 const base::DictionaryValue* bindings =
226 profile_->GetPrefs()->GetDictionary(prefs::kExtensionCommands); 227 profile_->GetPrefs()->GetDictionary(prefs::kExtensionCommands);
227 for (base::DictionaryValue::Iterator it(*bindings); !it.IsAtEnd(); 228 for (base::DictionaryValue::Iterator it(*bindings); !it.IsAtEnd();
228 it.Advance()) { 229 it.Advance()) {
229 const base::DictionaryValue* item = NULL; 230 const base::DictionaryValue* item = NULL;
230 it.value().GetAsDictionary(&item); 231 it.value().GetAsDictionary(&item);
231 232
232 std::string extension; 233 std::string extension;
233 item->GetString(kExtension, &extension); 234 item->GetString(kExtension, &extension);
234 if (extension != extension_id) 235 if (extension != extension_id)
235 continue; 236 continue;
236 std::string command_name; 237 std::string command_name;
237 item->GetString(kCommandName, &command_name); 238 item->GetString(kCommandName, &command_name);
238 if (command != command_name) 239 if (command != command_name)
239 continue; 240 continue;
240 241
241 std::string shortcut = it.key(); 242 std::string shortcut = it.key();
242 if (StartsWithASCII(shortcut, Command::CommandPlatform() + ":", true)) 243 if (StartsWithASCII(shortcut, Command::CommandPlatform() + ":", true))
243 shortcut = shortcut.substr(Command::CommandPlatform().length() + 1); 244 shortcut = shortcut.substr(Command::CommandPlatform().length() + 1);
244 245
245 return Command::StringToAccelerator(shortcut); 246 return Command::StringToAccelerator(shortcut, command_name);
246 } 247 }
247 248
248 return ui::Accelerator(); 249 return ui::Accelerator();
249 } 250 }
250 251
251 void CommandService::AssignInitialKeybindings(const Extension* extension) { 252 void CommandService::AssignInitialKeybindings(const Extension* extension) {
252 const extensions::CommandMap* commands = 253 const extensions::CommandMap* commands =
253 CommandsInfo::GetNamedCommands(extension); 254 CommandsInfo::GetNamedCommands(extension);
254 if (!commands) 255 if (!commands)
255 return; 256 return;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 return false; 398 return false;
398 399
399 *command = *requested_command; 400 *command = *requested_command;
400 if (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN) 401 if (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN)
401 command->set_accelerator(shortcut_assigned); 402 command->set_accelerator(shortcut_assigned);
402 403
403 return true; 404 return true;
404 } 405 }
405 406
406 } // namespace extensions 407 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/commands/command_service_new.cc » ('j') | ui/base/strings/ui_strings.grd » ('J')

Powered by Google App Engine
This is Rietveld 408576698