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

Side by Side Diff: chrome/browser/extensions/api/commands/command_service.cc

Issue 60353008: Mac global keybindings (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 1 month 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
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/api/commands/command_service.h" 5 #include "chrome/browser/extensions/api/commands/command_service.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/prefs/scoped_user_pref_update.h" 8 #include "base/prefs/scoped_user_pref_update.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 const ExtensionSet* extensions = extension_service->extensions(); 148 const ExtensionSet* extensions = extension_service->extensions();
149 const Extension* extension = extensions->GetByID(extension_id); 149 const Extension* extension = extensions->GetByID(extension_id);
150 CHECK(extension); 150 CHECK(extension);
151 151
152 command_map->clear(); 152 command_map->clear();
153 const extensions::CommandMap* commands = 153 const extensions::CommandMap* commands =
154 CommandsInfo::GetNamedCommands(extension); 154 CommandsInfo::GetNamedCommands(extension);
155 if (!commands) 155 if (!commands)
156 return false; 156 return false;
157 157
158 VLOG(0) << "Commands size: " << commands->size();
158 extensions::CommandMap::const_iterator iter = commands->begin(); 159 extensions::CommandMap::const_iterator iter = commands->begin();
159 for (; iter != commands->end(); ++iter) { 160 for (; iter != commands->end(); ++iter) {
160 // Look up to see if the user has overridden how the command should work. 161 // Look up to see if the user has overridden how the command should work.
161 extensions::Command saved_command = 162 extensions::Command saved_command =
162 FindCommandByName(extension_id, iter->second.command_name()); 163 FindCommandByName(extension_id, iter->second.command_name());
163 ui::Accelerator shortcut_assigned = saved_command.accelerator(); 164 ui::Accelerator shortcut_assigned = saved_command.accelerator();
164 165
165 if (type == ACTIVE_ONLY && shortcut_assigned.key_code() == ui::VKEY_UNKNOWN) 166 VLOG(0) << "Processing command: " << iter->second.command_name()
167 << ", shortcut assigned: " << shortcut_assigned.key_code()
168 << ", saved command global: " << saved_command.global();
169
170 if (type == ACTIVE_ONLY && shortcut_assigned.key_code() ==
171 ui::VKEY_UNKNOWN) {
172 VLOG(0) << "Discarded due to missing key code";
166 continue; 173 continue;
174 }
167 175
168 extensions::Command command = iter->second; 176 extensions::Command command = iter->second;
169 if (scope != ANY_SCOPE && ((scope == GLOBAL) != saved_command.global())) 177 if (scope != ANY_SCOPE &&
178 ((scope == GLOBAL) != saved_command.global())) {
179 VLOG(0) << "Discarded due to scope mismatch";
170 continue; 180 continue;
181 }
182 VLOG(0) << "HERE";
171 183
172 if (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN) 184 if (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN)
173 command.set_accelerator(shortcut_assigned); 185 command.set_accelerator(shortcut_assigned);
174 command.set_global(saved_command.global()); 186 command.set_global(saved_command.global());
175 187
188 VLOG(0) << "Adding command " << iter->second.command_name()
189 << " to command map, scope is " << scope;
190
191 VLOG(0) << "Size before: " << (*command_map).size();
176 (*command_map)[iter->second.command_name()] = command; 192 (*command_map)[iter->second.command_name()] = command;
193 VLOG(0) << "Size after: " << (*command_map).size();
177 } 194 }
178 195
179 return true; 196 return true;
180 } 197 }
181 198
182 bool CommandService::AddKeybindingPref( 199 bool CommandService::AddKeybindingPref(
183 const ui::Accelerator& accelerator, 200 const ui::Accelerator& accelerator,
184 std::string extension_id, 201 std::string extension_id,
185 std::string command_name, 202 std::string command_name,
186 bool allow_overrides, 203 bool allow_overrides,
187 bool global) { 204 bool global) {
188 if (accelerator.key_code() == ui::VKEY_UNKNOWN) 205 if (accelerator.key_code() == ui::VKEY_UNKNOWN)
189 return false; 206 return false;
190 207
208 VLOG(0) << "AddKeybindingPref, "
209 << "Global: " << global
210 << "Command name: " << command_name;
191 DictionaryPrefUpdate updater(profile_->GetPrefs(), 211 DictionaryPrefUpdate updater(profile_->GetPrefs(),
192 prefs::kExtensionCommands); 212 prefs::kExtensionCommands);
193 base::DictionaryValue* bindings = updater.Get(); 213 base::DictionaryValue* bindings = updater.Get();
194 214
195 std::string key = GetPlatformKeybindingKeyForAccelerator(accelerator); 215 std::string key = GetPlatformKeybindingKeyForAccelerator(accelerator);
196 216
197 if (!allow_overrides && bindings->HasKey(key)) 217 if (!allow_overrides && bindings->HasKey(key))
198 return false; // Already taken. 218 return false; // Already taken.
199 219
200 base::DictionaryValue* keybinding = new base::DictionaryValue(); 220 base::DictionaryValue* keybinding = new base::DictionaryValue();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 // Pre-existing shortcuts must be removed before proceeding because the 280 // Pre-existing shortcuts must be removed before proceeding because the
261 // handlers for global and non-global extensions are not one and the same. 281 // handlers for global and non-global extensions are not one and the same.
262 RemoveKeybindingPrefs(extension_id, command_name); 282 RemoveKeybindingPrefs(extension_id, command_name);
263 AddKeybindingPref(command.accelerator(), extension_id, 283 AddKeybindingPref(command.accelerator(), extension_id,
264 command_name, true, global); 284 command_name, true, global);
265 return true; 285 return true;
266 } 286 }
267 287
268 Command CommandService::FindCommandByName( 288 Command CommandService::FindCommandByName(
269 const std::string& extension_id, const std::string& command) { 289 const std::string& extension_id, const std::string& command) {
290 VLOG(0) << "FindCommandByName called.";
270 const base::DictionaryValue* bindings = 291 const base::DictionaryValue* bindings =
271 profile_->GetPrefs()->GetDictionary(prefs::kExtensionCommands); 292 profile_->GetPrefs()->GetDictionary(prefs::kExtensionCommands);
272 for (base::DictionaryValue::Iterator it(*bindings); !it.IsAtEnd(); 293 for (base::DictionaryValue::Iterator it(*bindings); !it.IsAtEnd();
273 it.Advance()) { 294 it.Advance()) {
274 const base::DictionaryValue* item = NULL; 295 const base::DictionaryValue* item = NULL;
275 it.value().GetAsDictionary(&item); 296 it.value().GetAsDictionary(&item);
276 297
277 std::string extension; 298 std::string extension;
278 item->GetString(kExtension, &extension); 299 item->GetString(kExtension, &extension);
300 VLOG(0) << "Extension: " << extension;
279 if (extension != extension_id) 301 if (extension != extension_id)
280 continue; 302 continue;
281 std::string command_name; 303 std::string command_name;
282 item->GetString(kCommandName, &command_name); 304 item->GetString(kCommandName, &command_name);
305 VLOG(0) << "Command name: " << command_name;
283 if (command != command_name) 306 if (command != command_name)
284 continue; 307 continue;
285 bool global = false; 308 bool global = false;
286 if (FeatureSwitch::global_commands()->IsEnabled()) 309 VLOG(0) << "--global-commands: "
310 << FeatureSwitch::global_commands()->IsEnabled();
311 if (FeatureSwitch::global_commands()->IsEnabled()) {
287 item->GetBoolean(kGlobal, &global); 312 item->GetBoolean(kGlobal, &global);
313 VLOG(0) << "Global: " << global;
314 }
288 315
289 std::string shortcut = it.key(); 316 std::string shortcut = it.key();
290 if (StartsWithASCII(shortcut, Command::CommandPlatform() + ":", true)) 317 if (StartsWithASCII(shortcut, Command::CommandPlatform() + ":", true))
291 shortcut = shortcut.substr(Command::CommandPlatform().length() + 1); 318 shortcut = shortcut.substr(Command::CommandPlatform().length() + 1);
292 319
293 return Command(command_name, string16(), shortcut, global); 320 return Command(command_name, string16(), shortcut, global);
294 } 321 }
295 322
296 return Command(); 323 return Command();
297 } 324 }
(...skipping 14 matching lines...) Expand all
312 extensions::CommandMap::const_iterator iter = commands->begin(); 339 extensions::CommandMap::const_iterator iter = commands->begin();
313 for (; iter != commands->end(); ++iter) { 340 for (; iter != commands->end(); ++iter) {
314 if (!chrome::IsChromeAccelerator( 341 if (!chrome::IsChromeAccelerator(
315 iter->second.accelerator(), profile_) && 342 iter->second.accelerator(), profile_) &&
316 IsWhitelistedGlobalShortcut(iter->second)) { 343 IsWhitelistedGlobalShortcut(iter->second)) {
317 AddKeybindingPref(iter->second.accelerator(), 344 AddKeybindingPref(iter->second.accelerator(),
318 extension->id(), 345 extension->id(),
319 iter->second.command_name(), 346 iter->second.command_name(),
320 false, // Overwriting not allowed. 347 false, // Overwriting not allowed.
321 iter->second.global()); 348 iter->second.global());
349 LOG(ERROR) << "CommandService::AssignInitialKeybindings. "
350 << "global: " << iter->second.global();
322 } 351 }
323 } 352 }
324 353
325 const extensions::Command* browser_action_command = 354 const extensions::Command* browser_action_command =
326 CommandsInfo::GetBrowserActionCommand(extension); 355 CommandsInfo::GetBrowserActionCommand(extension);
327 if (browser_action_command) { 356 if (browser_action_command) {
328 if (!chrome::IsChromeAccelerator( 357 if (!chrome::IsChromeAccelerator(
329 browser_action_command->accelerator(), profile_)) { 358 browser_action_command->accelerator(), profile_)) {
330 AddKeybindingPref(browser_action_command->accelerator(), 359 AddKeybindingPref(browser_action_command->accelerator(),
331 extension->id(), 360 extension->id(),
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 486
458 return true; 487 return true;
459 } 488 }
460 489
461 template <> 490 template <>
462 void ProfileKeyedAPIFactory<CommandService>::DeclareFactoryDependencies() { 491 void ProfileKeyedAPIFactory<CommandService>::DeclareFactoryDependencies() {
463 DependsOn(ExtensionCommandsGlobalRegistry::GetFactoryInstance()); 492 DependsOn(ExtensionCommandsGlobalRegistry::GetFactoryInstance());
464 } 493 }
465 494
466 } // namespace extensions 495 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698