Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1139)

Side by Side Diff: chrome/browser/extensions/extension_keybinding_registry.cc

Issue 788973002: Observe OnExtensionLoaded to trigger update of chrome.commands keybindings for component extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update comment. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/extensions/api/commands/command_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/commands/command_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698