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/cocoa/extensions/extension_keybinding_registry_cocoa .h" | 5 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa .h" |
6 | 6 |
7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
8 #include "chrome/browser/extensions/api/commands/command_service.h" | 8 #include "chrome/browser/extensions/api/commands/command_service.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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 | 77 |
78 void ExtensionKeybindingRegistryCocoa::AddExtensionKeybinding( | 78 void ExtensionKeybindingRegistryCocoa::AddExtensionKeybinding( |
79 const extensions::Extension* extension, | 79 const extensions::Extension* extension, |
80 const std::string& command_name) { | 80 const std::string& command_name) { |
81 extensions::CommandService* command_service = | 81 extensions::CommandService* command_service = |
82 extensions::CommandService::Get(profile_); | 82 extensions::CommandService::Get(profile_); |
83 extensions::CommandMap commands; | 83 extensions::CommandMap commands; |
84 command_service->GetNamedCommands( | 84 command_service->GetNamedCommands( |
85 extension->id(), | 85 extension->id(), |
86 extensions::CommandService::ACTIVE_ONLY, | 86 extensions::CommandService::ACTIVE_ONLY, |
87 extensions::CommandService::REGULAR, | |
87 &commands); | 88 &commands); |
88 | 89 |
89 for (extensions::CommandMap::const_iterator iter = commands.begin(); | 90 for (extensions::CommandMap::const_iterator iter = commands.begin(); |
90 iter != commands.end(); ++iter) { | 91 iter != commands.end(); ++iter) { |
91 if (!command_name.empty() && (iter->second.command_name() != command_name)) | 92 if (!command_name.empty() && (iter->second.command_name() != command_name)) |
92 continue; | 93 continue; |
93 | 94 |
94 ui::Accelerator accelerator(iter->second.accelerator()); | 95 ui::Accelerator accelerator(iter->second.accelerator()); |
95 event_targets_[accelerator] = | 96 event_targets_[accelerator] = |
96 std::make_pair(extension->id(), iter->second.command_name()); | 97 std::make_pair(extension->id(), iter->second.command_name()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 } | 136 } |
136 } | 137 } |
137 | 138 |
138 void ExtensionKeybindingRegistryCocoa::RemoveExtensionKeybinding( | 139 void ExtensionKeybindingRegistryCocoa::RemoveExtensionKeybinding( |
139 const extensions::Extension* extension, | 140 const extensions::Extension* extension, |
140 const std::string& command_name) { | 141 const std::string& command_name) { |
141 EventTargets::iterator iter = event_targets_.begin(); | 142 EventTargets::iterator iter = event_targets_.begin(); |
142 while (iter != event_targets_.end()) { | 143 while (iter != event_targets_.end()) { |
143 EventTargets::iterator old = iter++; | 144 EventTargets::iterator old = iter++; |
144 if (old->second.first == extension->id() && | 145 if (old->second.first == extension->id() && |
145 (command_name.empty() || (old->second.second == command_name))) | 146 (command_name.empty() || (old->second.second == command_name))) { |
146 event_targets_.erase(old); | 147 event_targets_.erase(old); |
148 | |
149 // If a specific command_name was requested, it has now been deleted so | |
150 // no further work is required. | |
Nico
2013/10/03 16:48:53
This seems to be in every UI implementation. Is th
Finnur
2013/10/03 21:57:58
I'll take a closer look tomorrow morning.
Finnur
2013/10/04 17:57:02
I opted for moving this into the base class, which
Yoyo Zhou
2013/10/04 18:12:07
Looks fine to me.
| |
151 if (!command_name.empty()) | |
152 break; | |
153 } | |
147 } | 154 } |
148 } | 155 } |
OLD | NEW |