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/extension_keybinding_registry.h" | 5 #include "chrome/browser/extensions/extension_keybinding_registry.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/extensions/active_tab_permission_granter.h" | 8 #include "chrome/browser/extensions/active_tab_permission_granter.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/common/extensions/command.h" | 10 #include "chrome/common/extensions/command.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 | 123 |
124 bool ExtensionKeybindingRegistry::IsAcceleratorRegistered( | 124 bool ExtensionKeybindingRegistry::IsAcceleratorRegistered( |
125 const ui::Accelerator& accelerator) const { | 125 const ui::Accelerator& accelerator) const { |
126 return event_targets_.find(accelerator) != event_targets_.end(); | 126 return event_targets_.find(accelerator) != event_targets_.end(); |
127 } | 127 } |
128 | 128 |
129 void ExtensionKeybindingRegistry::AddEventTarget( | 129 void ExtensionKeybindingRegistry::AddEventTarget( |
130 const ui::Accelerator& accelerator, | 130 const ui::Accelerator& accelerator, |
131 const std::string& extension_id, | 131 const std::string& extension_id, |
132 const std::string& command_name) { | 132 const std::string& command_name) { |
133 // Shortcuts except media keys have only one target in the list. See comment | |
134 // about |event_targets_|. | |
135 if (!extensions::Command::IsMediaKey(accelerator) && | |
136 ((event_targets_[accelerator].size() == 1 && | |
137 !event_targets_[accelerator].begin()->second.empty() && | |
138 event_targets_[accelerator].begin()->second != command_name) || | |
139 event_targets_[accelerator].size() > 1)) | |
140 NOTREACHED(); | |
141 | |
142 // No need to add the same command again if not a media key. | |
143 if (!extensions::Command::IsMediaKey(accelerator) && | |
144 event_targets_[accelerator].size() > 0 && | |
145 event_targets_[accelerator].begin()->second == command_name) | |
146 return; | |
Finnur
2014/12/19 15:26:52
Hmm... I'm not sure I like all this. I'm sure it g
David Tseng
2014/12/19 19:41:01
I was seeing multiple event targets getting added,
Finnur
2014/12/22 15:20:08
My recommendation would be to revert back to the s
| |
147 | |
133 event_targets_[accelerator].push_back( | 148 event_targets_[accelerator].push_back( |
134 std::make_pair(extension_id, command_name)); | 149 std::make_pair(extension_id, command_name)); |
135 // Shortcuts except media keys have only one target in the list. See comment | |
136 // about |event_targets_|. | |
137 if (!extensions::Command::IsMediaKey(accelerator)) | |
138 DCHECK_EQ(1u, event_targets_[accelerator].size()); | |
139 } | 150 } |
140 | 151 |
141 bool ExtensionKeybindingRegistry::GetFirstTarget( | 152 bool ExtensionKeybindingRegistry::GetFirstTarget( |
142 const ui::Accelerator& accelerator, | 153 const ui::Accelerator& accelerator, |
143 std::string* extension_id, | 154 std::string* extension_id, |
144 std::string* command_name) const { | 155 std::string* command_name) const { |
145 EventTargets::const_iterator targets = event_targets_.find(accelerator); | 156 EventTargets::const_iterator targets = event_targets_.find(accelerator); |
146 if (targets == event_targets_.end()) | 157 if (targets == event_targets_.end()) |
147 return false; | 158 return false; |
148 | 159 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 if (extension_id.empty() || it->first == extension_id) { | 253 if (extension_id.empty() || it->first == extension_id) { |
243 CommandExecuted(it->first, it->second); | 254 CommandExecuted(it->first, it->second); |
244 executed = true; | 255 executed = true; |
245 } | 256 } |
246 } | 257 } |
247 | 258 |
248 return executed; | 259 return executed; |
249 } | 260 } |
250 | 261 |
251 } // namespace extensions | 262 } // namespace extensions |
OLD | NEW |