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

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

Issue 667833004: Fix extension command service to check if user has modified key before overwrite on update. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 <vector> 7 #include <vector>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/prefs/scoped_user_pref_update.h" 10 #include "base/prefs/scoped_user_pref_update.h"
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 const std::string& command) const { 344 const std::string& command) const {
345 const base::DictionaryValue* bindings = 345 const base::DictionaryValue* bindings =
346 profile_->GetPrefs()->GetDictionary(prefs::kExtensionCommands); 346 profile_->GetPrefs()->GetDictionary(prefs::kExtensionCommands);
347 for (base::DictionaryValue::Iterator it(*bindings); !it.IsAtEnd(); 347 for (base::DictionaryValue::Iterator it(*bindings); !it.IsAtEnd();
348 it.Advance()) { 348 it.Advance()) {
349 const base::DictionaryValue* item = NULL; 349 const base::DictionaryValue* item = NULL;
350 it.value().GetAsDictionary(&item); 350 it.value().GetAsDictionary(&item);
351 351
352 std::string extension; 352 std::string extension;
353 item->GetString(kExtension, &extension); 353 item->GetString(kExtension, &extension);
354
Finnur 2014/10/22 09:43:03 nit: This line break seems to be breaking up code
354 if (extension != extension_id) 355 if (extension != extension_id)
355 continue; 356 continue;
356 std::string command_name; 357 std::string command_name;
357 item->GetString(kCommandName, &command_name); 358 item->GetString(kCommandName, &command_name);
358 if (command != command_name) 359 if (command != command_name)
359 continue; 360 continue;
360 // Format stored in Preferences is: "Platform:Shortcut[:ExtensionId]". 361 // Format stored in Preferences is: "Platform:Shortcut[:ExtensionId]".
361 std::string shortcut = it.key(); 362 std::string shortcut = it.key();
362 if (!IsForCurrentPlatform(shortcut)) 363 if (!IsForCurrentPlatform(shortcut))
363 continue; 364 continue;
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 AddKeybindingPref(page_action_command->accelerator(), 544 AddKeybindingPref(page_action_command->accelerator(),
544 extension->id(), 545 extension->id(),
545 page_action_command->command_name(), 546 page_action_command->command_name(),
546 false, // Overwriting not allowed. 547 false, // Overwriting not allowed.
547 false); // Not global. 548 false); // Not global.
548 } 549 }
549 } 550 }
550 551
551 bool CommandService::CanAutoAssign(const Command &command, 552 bool CommandService::CanAutoAssign(const Command &command,
552 const Extension* extension) { 553 const Extension* extension) {
553 // Media Keys are non-exclusive, so allow auto-assigning them. 554
Finnur 2014/10/22 09:43:03 Don't add line breaks at the start of a function.
554 if (Command::IsMediaKey(command.accelerator())) 555 // Media Keys are non-exclusive, so allow auto-assigning them if the user
556 // has not changed them for the current extension.
557 if (Command::IsMediaKey(command.accelerator())) {
558 if (IsCommandShortcutUserModified(extension, command.command_name()))
559 return false;
555 return true; 560 return true;
Finnur 2014/10/22 09:43:03 nit: Prefer: return !foo(); over if (foo())
561 }
556 562
557 // Extensions are allowed to auto-assign updated keys if the user has not 563 // Extensions are allowed to auto-assign updated keys if the user has not
558 // changed from the previous value. 564 // changed from the previous value.
559 if (IsCommandShortcutUserModified(extension, command.command_name())) 565 if (IsCommandShortcutUserModified(extension, command.command_name()))
560 return false; 566 return false;
561 567
562 if (command.global()) { 568 if (command.global()) {
563 using namespace extensions; 569 using namespace extensions;
564 if (command.command_name() == manifest_values::kBrowserActionCommandEvent || 570 if (command.command_name() == manifest_values::kBrowserActionCommandEvent ||
565 command.command_name() == manifest_values::kPageActionCommandEvent) 571 command.command_name() == manifest_values::kPageActionCommandEvent)
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 return true; 869 return true;
864 } 870 }
865 871
866 template <> 872 template <>
867 void 873 void
868 BrowserContextKeyedAPIFactory<CommandService>::DeclareFactoryDependencies() { 874 BrowserContextKeyedAPIFactory<CommandService>::DeclareFactoryDependencies() {
869 DependsOn(ExtensionCommandsGlobalRegistry::GetFactoryInstance()); 875 DependsOn(ExtensionCommandsGlobalRegistry::GetFactoryInstance());
870 } 876 }
871 877
872 } // namespace extensions 878 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698