OLD | NEW |
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/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/extensions/api/commands/commands.h" | 10 #include "chrome/browser/extensions/api/commands/commands.h" |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 } | 225 } |
226 | 226 |
227 void CommandService::AssignInitialKeybindings(const Extension* extension) { | 227 void CommandService::AssignInitialKeybindings(const Extension* extension) { |
228 const extensions::CommandMap* commands = | 228 const extensions::CommandMap* commands = |
229 CommandsInfo::GetNamedCommands(extension); | 229 CommandsInfo::GetNamedCommands(extension); |
230 if (!commands) | 230 if (!commands) |
231 return; | 231 return; |
232 | 232 |
233 extensions::CommandMap::const_iterator iter = commands->begin(); | 233 extensions::CommandMap::const_iterator iter = commands->begin(); |
234 for (; iter != commands->end(); ++iter) { | 234 for (; iter != commands->end(); ++iter) { |
235 AddKeybindingPref(iter->second.accelerator(), | 235 if (!ExtensionKeybindingRegistry::IsChromeAccelerator( |
236 extension->id(), | 236 iter->second.accelerator())) { |
237 iter->second.command_name(), | 237 AddKeybindingPref(iter->second.accelerator(), |
238 false); // Overwriting not allowed. | 238 extension->id(), |
| 239 iter->second.command_name(), |
| 240 false); // Overwriting not allowed. |
| 241 } |
239 } | 242 } |
240 | 243 |
241 const extensions::Command* browser_action_command = | 244 const extensions::Command* browser_action_command = |
242 CommandsInfo::GetBrowserActionCommand(extension); | 245 CommandsInfo::GetBrowserActionCommand(extension); |
243 if (browser_action_command) { | 246 if (browser_action_command) { |
244 AddKeybindingPref(browser_action_command->accelerator(), | 247 if (!ExtensionKeybindingRegistry::IsChromeAccelerator( |
245 extension->id(), | 248 browser_action_command->accelerator())) { |
246 browser_action_command->command_name(), | 249 AddKeybindingPref(browser_action_command->accelerator(), |
247 false); // Overwriting not allowed. | 250 extension->id(), |
| 251 browser_action_command->command_name(), |
| 252 false); // Overwriting not allowed. |
| 253 } |
248 } | 254 } |
249 | 255 |
250 const extensions::Command* page_action_command = | 256 const extensions::Command* page_action_command = |
251 CommandsInfo::GetPageActionCommand(extension); | 257 CommandsInfo::GetPageActionCommand(extension); |
252 if (page_action_command) { | 258 if (page_action_command) { |
253 AddKeybindingPref(page_action_command->accelerator(), | 259 if (!ExtensionKeybindingRegistry::IsChromeAccelerator( |
254 extension->id(), | 260 page_action_command->accelerator())) { |
255 page_action_command->command_name(), | 261 AddKeybindingPref(page_action_command->accelerator(), |
256 false); // Overwriting not allowed. | 262 extension->id(), |
| 263 page_action_command->command_name(), |
| 264 false); // Overwriting not allowed. |
| 265 } |
257 } | 266 } |
258 | 267 |
259 const extensions::Command* script_badge_command = | 268 const extensions::Command* script_badge_command = |
260 CommandsInfo::GetScriptBadgeCommand(extension); | 269 CommandsInfo::GetScriptBadgeCommand(extension); |
261 if (script_badge_command) { | 270 if (script_badge_command) { |
262 AddKeybindingPref(script_badge_command->accelerator(), | 271 if (!ExtensionKeybindingRegistry::IsChromeAccelerator( |
263 extension->id(), | 272 script_badge_command->accelerator())) { |
264 script_badge_command->command_name(), | 273 AddKeybindingPref(script_badge_command->accelerator(), |
265 false); // Overwriting not allowed. | 274 extension->id(), |
| 275 script_badge_command->command_name(), |
| 276 false); // Overwriting not allowed. |
| 277 } |
266 } | 278 } |
267 } | 279 } |
268 | 280 |
269 void CommandService::RemoveKeybindingPrefs(const std::string& extension_id, | 281 void CommandService::RemoveKeybindingPrefs(const std::string& extension_id, |
270 const std::string& command_name) { | 282 const std::string& command_name) { |
271 DictionaryPrefUpdate updater(profile_->GetPrefs(), | 283 DictionaryPrefUpdate updater(profile_->GetPrefs(), |
272 prefs::kExtensionCommands); | 284 prefs::kExtensionCommands); |
273 DictionaryValue* bindings = updater.Get(); | 285 DictionaryValue* bindings = updater.Get(); |
274 | 286 |
275 typedef std::vector<std::string> KeysToRemove; | 287 typedef std::vector<std::string> KeysToRemove; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 return false; | 365 return false; |
354 | 366 |
355 *command = *requested_command; | 367 *command = *requested_command; |
356 if (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN) | 368 if (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN) |
357 command->set_accelerator(shortcut_assigned); | 369 command->set_accelerator(shortcut_assigned); |
358 | 370 |
359 return true; | 371 return true; |
360 } | 372 } |
361 | 373 |
362 } // namespace extensions | 374 } // namespace extensions |
OLD | NEW |