Chromium Code Reviews| Index: chrome/browser/extensions/extension_keybinding_registry.cc |
| diff --git a/chrome/browser/extensions/extension_keybinding_registry.cc b/chrome/browser/extensions/extension_keybinding_registry.cc |
| index a819ab409c17a2a842b5d4a5249afd2bce7f4be2..25161e288a7f54de12e26c0efb82513124251fb4 100644 |
| --- a/chrome/browser/extensions/extension_keybinding_registry.cc |
| +++ b/chrome/browser/extensions/extension_keybinding_registry.cc |
| @@ -7,6 +7,7 @@ |
| #include "base/values.h" |
| #include "chrome/browser/chrome_notification_types.h" |
| #include "chrome/browser/extensions/active_tab_permission_granter.h" |
| +#include "chrome/browser/extensions/api/commands/command_service.h" |
| #include "chrome/browser/extensions/event_router.h" |
| #include "chrome/browser/extensions/extension_service.h" |
| #include "chrome/browser/extensions/extension_system.h" |
| @@ -37,24 +38,25 @@ ExtensionKeybindingRegistry::~ExtensionKeybindingRegistry() { |
| void ExtensionKeybindingRegistry::RemoveExtensionKeybinding( |
| const Extension* extension, |
| const std::string& command_name) { |
| - EventTargets::iterator iter = event_targets_.begin(); |
| - while (iter != event_targets_.end()) { |
| - if (iter->second.first != extension->id() || |
| - (!command_name.empty() && (iter->second.second != command_name))) { |
| - ++iter; |
| - continue; // Not the extension or command we asked for. |
| + EventTargets::iterator it = event_targets_.begin(); |
| + while (it != event_targets_.end()) { |
| + TargetList& target_list = it->second; |
| + TargetList::iterator target = target_list.begin(); |
| + while (target != target_list.end()) { |
| + if (target->first == extension->id() && |
| + (command_name.empty() || command_name == target->second)) { |
| + target = target_list.erase(target); |
| + } else { |
| + target++; |
| + } |
| } |
| - // Let each platform-specific implementation get a chance to clean up. |
| - RemoveExtensionKeybindingImpl(iter->first, command_name); |
| - |
| - EventTargets::iterator old = iter++; |
| - event_targets_.erase(old); |
| - |
| - // If a specific command_name was requested, it has now been deleted so |
| - // no further work is required. |
| - if (!command_name.empty()) |
| - break; |
|
Finnur
2013/11/15 21:10:10
Don't we still need this?
zhchbin
2013/11/16 01:33:31
Done. I had noticed this, but seems I'm wrong at t
|
| + EventTargets::iterator old = it++; |
| + if (target_list.empty()) { |
| + // Let each platform-specific implementation get a chance to clean up. |
| + RemoveExtensionKeybindingImpl(old->first, command_name); |
| + event_targets_.erase(old); |
| + } |
| } |
| } |
| @@ -78,6 +80,18 @@ bool ExtensionKeybindingRegistry::ShouldIgnoreCommand( |
| command == manifest_values::kScriptBadgeCommandEvent; |
| } |
| +bool ExtensionKeybindingRegistry::NotifyEventTargetsByAccelerator( |
| + const ui::Accelerator& accelerator) { |
| + EventTargets::iterator targets = event_targets_.find(accelerator); |
| + if (targets == event_targets_.end() || targets->second.empty()) |
| + return false; |
| + |
| + for (TargetList::const_iterator it = targets->second.begin(); |
| + it != targets->second.end(); it++) |
| + CommandExecuted(it->first, it->second); |
| + return true; |
| +} |
| + |
| void ExtensionKeybindingRegistry::CommandExecuted( |
| const std::string& extension_id, const std::string& command) { |
| ExtensionService* service = |