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" |
11 #include "chrome/browser/extensions/extension_function_registry.h" | 11 #include "chrome/browser/extensions/extension_function_registry.h" |
12 #include "chrome/browser/extensions/extension_keybinding_registry.h" | 12 #include "chrome/browser/extensions/extension_keybinding_registry.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/extensions/extension_system.h" | 14 #include "chrome/browser/extensions/extension_system.h" |
15 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 15 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/accelerator_utils.h" |
17 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
18 #include "chrome/common/extensions/api/commands/commands_handler.h" | 19 #include "chrome/common/extensions/api/commands/commands_handler.h" |
19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
20 #include "components/user_prefs/pref_registry_syncable.h" | 21 #include "components/user_prefs/pref_registry_syncable.h" |
21 #include "content/public/browser/notification_details.h" | 22 #include "content/public/browser/notification_details.h" |
22 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
23 | 24 |
24 using extensions::Extension; | 25 using extensions::Extension; |
25 | 26 |
26 namespace { | 27 namespace { |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 } | 226 } |
226 | 227 |
227 void CommandService::AssignInitialKeybindings(const Extension* extension) { | 228 void CommandService::AssignInitialKeybindings(const Extension* extension) { |
228 const extensions::CommandMap* commands = | 229 const extensions::CommandMap* commands = |
229 CommandsInfo::GetNamedCommands(extension); | 230 CommandsInfo::GetNamedCommands(extension); |
230 if (!commands) | 231 if (!commands) |
231 return; | 232 return; |
232 | 233 |
233 extensions::CommandMap::const_iterator iter = commands->begin(); | 234 extensions::CommandMap::const_iterator iter = commands->begin(); |
234 for (; iter != commands->end(); ++iter) { | 235 for (; iter != commands->end(); ++iter) { |
235 AddKeybindingPref(iter->second.accelerator(), | 236 if (!chrome::IsChromeAccelerator( |
236 extension->id(), | 237 iter->second.accelerator(), profile_)) { |
237 iter->second.command_name(), | 238 AddKeybindingPref(iter->second.accelerator(), |
238 false); // Overwriting not allowed. | 239 extension->id(), |
| 240 iter->second.command_name(), |
| 241 false); // Overwriting not allowed. |
| 242 } |
239 } | 243 } |
240 | 244 |
241 const extensions::Command* browser_action_command = | 245 const extensions::Command* browser_action_command = |
242 CommandsInfo::GetBrowserActionCommand(extension); | 246 CommandsInfo::GetBrowserActionCommand(extension); |
243 if (browser_action_command) { | 247 if (browser_action_command) { |
244 AddKeybindingPref(browser_action_command->accelerator(), | 248 if (!chrome::IsChromeAccelerator( |
245 extension->id(), | 249 browser_action_command->accelerator(), profile_)) { |
246 browser_action_command->command_name(), | 250 AddKeybindingPref(browser_action_command->accelerator(), |
247 false); // Overwriting not allowed. | 251 extension->id(), |
| 252 browser_action_command->command_name(), |
| 253 false); // Overwriting not allowed. |
| 254 } |
248 } | 255 } |
249 | 256 |
250 const extensions::Command* page_action_command = | 257 const extensions::Command* page_action_command = |
251 CommandsInfo::GetPageActionCommand(extension); | 258 CommandsInfo::GetPageActionCommand(extension); |
252 if (page_action_command) { | 259 if (page_action_command) { |
253 AddKeybindingPref(page_action_command->accelerator(), | 260 if (!chrome::IsChromeAccelerator( |
254 extension->id(), | 261 page_action_command->accelerator(), profile_)) { |
255 page_action_command->command_name(), | 262 AddKeybindingPref(page_action_command->accelerator(), |
256 false); // Overwriting not allowed. | 263 extension->id(), |
| 264 page_action_command->command_name(), |
| 265 false); // Overwriting not allowed. |
| 266 } |
257 } | 267 } |
258 | 268 |
259 const extensions::Command* script_badge_command = | 269 const extensions::Command* script_badge_command = |
260 CommandsInfo::GetScriptBadgeCommand(extension); | 270 CommandsInfo::GetScriptBadgeCommand(extension); |
261 if (script_badge_command) { | 271 if (script_badge_command) { |
262 AddKeybindingPref(script_badge_command->accelerator(), | 272 if (!chrome::IsChromeAccelerator( |
263 extension->id(), | 273 script_badge_command->accelerator(), profile_)) { |
264 script_badge_command->command_name(), | 274 AddKeybindingPref(script_badge_command->accelerator(), |
265 false); // Overwriting not allowed. | 275 extension->id(), |
| 276 script_badge_command->command_name(), |
| 277 false); // Overwriting not allowed. |
| 278 } |
266 } | 279 } |
267 } | 280 } |
268 | 281 |
269 void CommandService::RemoveKeybindingPrefs(const std::string& extension_id, | 282 void CommandService::RemoveKeybindingPrefs(const std::string& extension_id, |
270 const std::string& command_name) { | 283 const std::string& command_name) { |
271 DictionaryPrefUpdate updater(profile_->GetPrefs(), | 284 DictionaryPrefUpdate updater(profile_->GetPrefs(), |
272 prefs::kExtensionCommands); | 285 prefs::kExtensionCommands); |
273 DictionaryValue* bindings = updater.Get(); | 286 DictionaryValue* bindings = updater.Get(); |
274 | 287 |
275 typedef std::vector<std::string> KeysToRemove; | 288 typedef std::vector<std::string> KeysToRemove; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 return false; | 366 return false; |
354 | 367 |
355 *command = *requested_command; | 368 *command = *requested_command; |
356 if (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN) | 369 if (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN) |
357 command->set_accelerator(shortcut_assigned); | 370 command->set_accelerator(shortcut_assigned); |
358 | 371 |
359 return true; | 372 return true; |
360 } | 373 } |
361 | 374 |
362 } // namespace extensions | 375 } // namespace extensions |
OLD | NEW |