| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/extension_commands_global_registry.h" | 5 #include "chrome/browser/extensions/extension_commands_global_registry.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/extensions/api/commands/command_service.h" | 9 #include "chrome/browser/extensions/api/commands/command_service.h" |
| 10 #include "chrome/browser/extensions/extension_keybinding_registry.h" | 10 #include "chrome/browser/extensions/extension_keybinding_registry.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/extensions/global_shortcut_listener.h" | 12 #include "chrome/browser/extensions/global_shortcut_listener.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
| 15 | 15 |
| 16 namespace extensions { | 16 namespace extensions { |
| 17 | 17 |
| 18 ExtensionCommandsGlobalRegistry::ExtensionCommandsGlobalRegistry( | 18 ExtensionCommandsGlobalRegistry::ExtensionCommandsGlobalRegistry( |
| 19 Profile* profile) | 19 Profile* profile) |
| 20 : ExtensionKeybindingRegistry( | 20 : ExtensionKeybindingRegistry( |
| 21 profile, ExtensionKeybindingRegistry::ALL_EXTENSIONS, NULL), | 21 profile, ExtensionKeybindingRegistry::ALL_EXTENSIONS, NULL), |
| 22 profile_(profile) { | 22 profile_(profile) { |
| 23 Init(); | 23 Init(); |
| 24 VLOG(0) << "ExtensionCommandsGlobalRegistry created"; |
| 24 } | 25 } |
| 25 | 26 |
| 26 ExtensionCommandsGlobalRegistry::~ExtensionCommandsGlobalRegistry() { | 27 ExtensionCommandsGlobalRegistry::~ExtensionCommandsGlobalRegistry() { |
| 27 EventTargets::const_iterator iter; | 28 EventTargets::const_iterator iter; |
| 28 for (iter = event_targets_.begin(); iter != event_targets_.end(); ++iter) { | 29 for (iter = event_targets_.begin(); iter != event_targets_.end(); ++iter) { |
| 29 GlobalShortcutListener::GetInstance()->UnregisterAccelerator( | 30 GlobalShortcutListener::GetInstance()->UnregisterAccelerator( |
| 30 iter->first, this); | 31 iter->first, this); |
| 31 } | 32 } |
| 32 } | 33 } |
| 33 | 34 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 53 const extensions::Extension* extension, | 54 const extensions::Extension* extension, |
| 54 const std::string& command_name) { | 55 const std::string& command_name) { |
| 55 // This object only handles named commands, not browser/page actions. | 56 // This object only handles named commands, not browser/page actions. |
| 56 if (ShouldIgnoreCommand(command_name)) | 57 if (ShouldIgnoreCommand(command_name)) |
| 57 return; | 58 return; |
| 58 | 59 |
| 59 extensions::CommandService* command_service = | 60 extensions::CommandService* command_service = |
| 60 extensions::CommandService::Get(profile_); | 61 extensions::CommandService::Get(profile_); |
| 61 // Add all the active global keybindings, if any. | 62 // Add all the active global keybindings, if any. |
| 62 extensions::CommandMap commands; | 63 extensions::CommandMap commands; |
| 64 VLOG(0) << "Calling GetNamedCommands..."; |
| 63 if (!command_service->GetNamedCommands( | 65 if (!command_service->GetNamedCommands( |
| 64 extension->id(), | 66 extension->id(), |
| 65 extensions::CommandService::ACTIVE_ONLY, | 67 extensions::CommandService::ACTIVE_ONLY, |
| 66 extensions::CommandService::GLOBAL, | 68 // TODO(smus): For now, make everything global. Sort out |
| 69 // why this is working so poorly later. |
| 70 extensions::CommandService::ANY_SCOPE, |
| 71 // extensions::CommandService::GLOBAL, |
| 67 &commands)) | 72 &commands)) |
| 68 return; | 73 return; |
| 69 | 74 |
| 75 VLOG(0) << "GetNamedCommands(...) is true. Size: " << commands.size(); |
| 70 extensions::CommandMap::const_iterator iter = commands.begin(); | 76 extensions::CommandMap::const_iterator iter = commands.begin(); |
| 71 for (; iter != commands.end(); ++iter) { | 77 for (; iter != commands.end(); ++iter) { |
| 78 VLOG(0) << "Processing command. Name: " << command_name |
| 79 << "Second name: " << iter->second.command_name(); |
| 72 if (!command_name.empty() && (iter->second.command_name() != command_name)) | 80 if (!command_name.empty() && (iter->second.command_name() != command_name)) |
| 73 continue; | 81 continue; |
| 74 | 82 |
| 75 VLOG(0) << "Adding global keybinding for " << extension->name().c_str() | 83 VLOG(0) << "Adding global keybinding for " << extension->name().c_str() |
| 76 << " " << command_name.c_str() | 84 << " " << command_name.c_str() |
| 77 << " key: " << iter->second.accelerator().GetShortcutText(); | 85 << " key: " << iter->second.accelerator().GetShortcutText(); |
| 78 | 86 |
| 79 event_targets_[iter->second.accelerator()] = | 87 event_targets_[iter->second.accelerator()] = |
| 80 std::make_pair(extension->id(), iter->second.command_name()); | 88 std::make_pair(extension->id(), iter->second.command_name()); |
| 81 | 89 |
| 82 GlobalShortcutListener::GetInstance()->RegisterAccelerator( | 90 GlobalShortcutListener::GetInstance()->RegisterAccelerator( |
| 83 iter->second.accelerator(), this); | 91 iter->second.accelerator(), this); |
| 84 } | 92 } |
| 85 } | 93 } |
| 86 | 94 |
| 87 void ExtensionCommandsGlobalRegistry::RemoveExtensionKeybindingImpl( | 95 void ExtensionCommandsGlobalRegistry::RemoveExtensionKeybindingImpl( |
| 88 const ui::Accelerator& accelerator, | 96 const ui::Accelerator& accelerator, |
| 89 const std::string& command_name) { | 97 const std::string& command_name) { |
| 90 VLOG(0) << "Removing keybinding for " << command_name.c_str(); | 98 VLOG(0) << "Removing keybinding for " << command_name.c_str(); |
| 91 | 99 |
| 92 GlobalShortcutListener::GetInstance()->UnregisterAccelerator( | 100 GlobalShortcutListener::GetInstance()->UnregisterAccelerator( |
| 93 accelerator, this); | 101 accelerator, this); |
| 94 } | 102 } |
| 95 | 103 |
| 96 void ExtensionCommandsGlobalRegistry::OnKeyPressed( | 104 void ExtensionCommandsGlobalRegistry::OnKeyPressed( |
| 97 const ui::Accelerator& accelerator) { | 105 const ui::Accelerator& accelerator) { |
| 106 VLOG(0) << "ExtensionCommandsGlobalRegistry OnKeyPressed"; |
| 98 EventTargets::iterator it = event_targets_.find(accelerator); | 107 EventTargets::iterator it = event_targets_.find(accelerator); |
| 99 if (it == event_targets_.end()) { | 108 if (it == event_targets_.end()) { |
| 100 NOTREACHED(); // Shouldn't get this event for something not registered. | 109 NOTREACHED(); // Shouldn't get this event for something not registered. |
| 101 return; | 110 return; |
| 102 } | 111 } |
| 103 | 112 |
| 104 CommandExecuted(it->second.first, it->second.second); | 113 CommandExecuted(it->second.first, it->second.second); |
| 105 } | 114 } |
| 106 | 115 |
| 107 } // namespace extensions | 116 } // namespace extensions |
| OLD | NEW |