| 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/ui/views/extensions/extension_keybinding_registry_views
.h" | 5 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/api/commands/command_service.h" | 7 #include "chrome/browser/extensions/api/commands/command_service.h" |
| 8 #include "chrome/browser/extensions/extension_keybinding_registry.h" | 8 #include "chrome/browser/extensions/extension_keybinding_registry.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 // This object only handles named commands, not browser/page actions. | 40 // This object only handles named commands, not browser/page actions. |
| 41 if (ShouldIgnoreCommand(command_name)) | 41 if (ShouldIgnoreCommand(command_name)) |
| 42 return; | 42 return; |
| 43 | 43 |
| 44 extensions::CommandService* command_service = | 44 extensions::CommandService* command_service = |
| 45 extensions::CommandService::Get(profile_); | 45 extensions::CommandService::Get(profile_); |
| 46 // Add all the active keybindings (except page actions and browser actions, | 46 // Add all the active keybindings (except page actions and browser actions, |
| 47 // which are handled elsewhere). | 47 // which are handled elsewhere). |
| 48 extensions::CommandMap commands; | 48 extensions::CommandMap commands; |
| 49 if (!command_service->GetNamedCommands( | 49 if (!command_service->GetNamedCommands( |
| 50 extension->id(), extensions::CommandService::ACTIVE_ONLY, &commands)) | 50 extension->id(), |
| 51 extensions::CommandService::ACTIVE_ONLY, |
| 52 extensions::CommandService::REGULAR, |
| 53 &commands)) |
| 51 return; | 54 return; |
| 52 extensions::CommandMap::const_iterator iter = commands.begin(); | 55 extensions::CommandMap::const_iterator iter = commands.begin(); |
| 53 for (; iter != commands.end(); ++iter) { | 56 for (; iter != commands.end(); ++iter) { |
| 54 if (!command_name.empty() && (iter->second.command_name() != command_name)) | 57 if (!command_name.empty() && (iter->second.command_name() != command_name)) |
| 55 continue; | 58 continue; |
| 56 | 59 |
| 57 event_targets_[iter->second.accelerator()] = | 60 event_targets_[iter->second.accelerator()] = |
| 58 std::make_pair(extension->id(), iter->second.command_name()); | 61 std::make_pair(extension->id(), iter->second.command_name()); |
| 59 focus_manager_->RegisterAccelerator( | 62 focus_manager_->RegisterAccelerator( |
| 60 iter->second.accelerator(), | 63 iter->second.accelerator(), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 74 if (iter->second.first != extension->id() || | 77 if (iter->second.first != extension->id() || |
| 75 (!command_name.empty() && (iter->second.second != command_name))) { | 78 (!command_name.empty() && (iter->second.second != command_name))) { |
| 76 ++iter; | 79 ++iter; |
| 77 continue; // Not the extension or command we asked for. | 80 continue; // Not the extension or command we asked for. |
| 78 } | 81 } |
| 79 | 82 |
| 80 focus_manager_->UnregisterAccelerator(iter->first, this); | 83 focus_manager_->UnregisterAccelerator(iter->first, this); |
| 81 | 84 |
| 82 EventTargets::iterator old = iter++; | 85 EventTargets::iterator old = iter++; |
| 83 event_targets_.erase(old); | 86 event_targets_.erase(old); |
| 87 |
| 88 // If a specific command_name was requested, it has now been deleted and |
| 89 // no further work is required. |
| 90 if (!command_name.empty()) |
| 91 break; |
| 84 } | 92 } |
| 85 } | 93 } |
| 86 | 94 |
| 87 bool ExtensionKeybindingRegistryViews::AcceleratorPressed( | 95 bool ExtensionKeybindingRegistryViews::AcceleratorPressed( |
| 88 const ui::Accelerator& accelerator) { | 96 const ui::Accelerator& accelerator) { |
| 89 EventTargets::iterator it = event_targets_.find(accelerator); | 97 EventTargets::iterator it = event_targets_.find(accelerator); |
| 90 if (it == event_targets_.end()) { | 98 if (it == event_targets_.end()) { |
| 91 NOTREACHED(); // Shouldn't get this event for something not registered. | 99 NOTREACHED(); // Shouldn't get this event for something not registered. |
| 92 return false; | 100 return false; |
| 93 } | 101 } |
| 94 | 102 |
| 95 CommandExecuted(it->second.first, it->second.second); | 103 CommandExecuted(it->second.first, it->second.second); |
| 96 | 104 |
| 97 return true; | 105 return true; |
| 98 } | 106 } |
| 99 | 107 |
| 100 bool ExtensionKeybindingRegistryViews::CanHandleAccelerators() const { | 108 bool ExtensionKeybindingRegistryViews::CanHandleAccelerators() const { |
| 101 return true; | 109 return true; |
| 102 } | 110 } |
| OLD | NEW |