Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
|
Finnur
2013/08/28 15:46:34
This whole file should be deleted. I think it is d
zhchbin
2013/08/29 06:20:14
Done.
| |
| 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" |
| 11 #include "chrome/browser/extensions/api/commands/commands.h" | 11 #include "chrome/browser/extensions/api/commands/commands.h" |
| 12 #include "chrome/browser/extensions/extension_function_registry.h" | 12 #include "chrome/browser/extensions/extension_function_registry.h" |
| 13 #include "chrome/browser/extensions/extension_keybinding_registry.h" | 13 #include "chrome/browser/extensions/extension_keybinding_registry.h" |
| 14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
| 15 #include "chrome/browser/extensions/extension_system.h" | 15 #include "chrome/browser/extensions/extension_system.h" |
| 16 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 16 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/common/extensions/api/commands/commands_handler.h" | |
| 18 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 19 #include "components/user_prefs/pref_registry_syncable.h" | 20 #include "components/user_prefs/pref_registry_syncable.h" |
| 20 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
| 21 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
| 22 | 23 |
| 23 using extensions::Extension; | 24 using extensions::Extension; |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 const char kExtension[] = "extension"; | 28 const char kExtension[] = "extension"; |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 } | 186 } |
| 186 } | 187 } |
| 187 | 188 |
| 188 void CommandService::UpdateKeybindingPrefs(const std::string& extension_id, | 189 void CommandService::UpdateKeybindingPrefs(const std::string& extension_id, |
| 189 const std::string& command_name, | 190 const std::string& command_name, |
| 190 const std::string& keystroke) { | 191 const std::string& keystroke) { |
| 191 // The extension command might be assigned another shortcut. Remove that | 192 // The extension command might be assigned another shortcut. Remove that |
| 192 // shortcut before proceeding. | 193 // shortcut before proceeding. |
| 193 RemoveKeybindingPrefs(extension_id, command_name); | 194 RemoveKeybindingPrefs(extension_id, command_name); |
| 194 | 195 |
| 195 ui::Accelerator accelerator = Command::StringToAccelerator(keystroke); | 196 ui::Accelerator accelerator = |
| 197 Command::StringToAccelerator(keystroke, command_name); | |
| 196 AddKeybindingPref(accelerator, extension_id, command_name, true); | 198 AddKeybindingPref(accelerator, extension_id, command_name, true); |
| 197 } | 199 } |
| 198 | 200 |
| 199 ui::Accelerator CommandService::FindShortcutForCommand( | 201 ui::Accelerator CommandService::FindShortcutForCommand( |
| 200 const std::string& extension_id, const std::string& command) { | 202 const std::string& extension_id, const std::string& command) { |
| 201 const base::DictionaryValue* bindings = | 203 const base::DictionaryValue* bindings = |
| 202 profile_->GetPrefs()->GetDictionary(prefs::kExtensionCommands); | 204 profile_->GetPrefs()->GetDictionary(prefs::kExtensionCommands); |
| 203 for (base::DictionaryValue::Iterator it(*bindings); !it.IsAtEnd(); | 205 for (base::DictionaryValue::Iterator it(*bindings); !it.IsAtEnd(); |
| 204 it.Advance()) { | 206 it.Advance()) { |
| 205 const base::DictionaryValue* item = NULL; | 207 const base::DictionaryValue* item = NULL; |
| 206 it.value().GetAsDictionary(&item); | 208 it.value().GetAsDictionary(&item); |
| 207 | 209 |
| 208 std::string extension; | 210 std::string extension; |
| 209 item->GetString(kExtension, &extension); | 211 item->GetString(kExtension, &extension); |
| 210 if (extension != extension_id) | 212 if (extension != extension_id) |
| 211 continue; | 213 continue; |
| 212 std::string command_name; | 214 std::string command_name; |
| 213 item->GetString(kCommandName, &command_name); | 215 item->GetString(kCommandName, &command_name); |
| 214 if (command != command_name) | 216 if (command != command_name) |
| 215 continue; | 217 continue; |
| 216 | 218 |
| 217 std::string shortcut = it.key(); | 219 std::string shortcut = it.key(); |
| 218 if (StartsWithASCII(shortcut, Command::CommandPlatform() + ":", true)) | 220 if (StartsWithASCII(shortcut, Command::CommandPlatform() + ":", true)) |
| 219 shortcut = shortcut.substr(Command::CommandPlatform().length() + 1); | 221 shortcut = shortcut.substr(Command::CommandPlatform().length() + 1); |
| 220 | 222 |
| 221 return Command::StringToAccelerator(shortcut); | 223 return Command::StringToAccelerator(shortcut, command_name); |
| 222 } | 224 } |
| 223 | 225 |
| 224 return ui::Accelerator(); | 226 return ui::Accelerator(); |
| 225 } | 227 } |
| 226 | 228 |
| 227 void CommandService::AssignInitialKeybindings(const Extension* extension) { | 229 void CommandService::AssignInitialKeybindings(const Extension* extension) { |
| 228 const extensions::CommandMap* commands = | 230 const extensions::CommandMap* commands = |
| 229 CommandsInfo::GetNamedCommands(extension); | 231 CommandsInfo::GetNamedCommands(extension); |
| 230 if (!commands) | 232 if (!commands) |
| 231 return; | 233 return; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 shortcut_assigned.key_code() == ui::VKEY_UNKNOWN) | 355 shortcut_assigned.key_code() == ui::VKEY_UNKNOWN) |
| 354 return false; | 356 return false; |
| 355 | 357 |
| 356 *command = *requested_command; | 358 *command = *requested_command; |
| 357 if (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN) | 359 if (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN) |
| 358 command->set_accelerator(shortcut_assigned); | 360 command->set_accelerator(shortcut_assigned); |
| 359 | 361 |
| 360 return true; | 362 return true; |
| 361 } | 363 } |
| 362 | 364 |
| 363 } // namespace extensions | 365 } // namespace extensions |
|
Finnur
2013/08/29 11:20:52
Wait, does the file still exist but is now empty?
zhchbin
2013/08/29 14:27:11
Not, I have deleted the file...Maybe just a wrong
| |
| OLD | NEW |