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

Side by Side Diff: chrome/browser/extensions/api/commands/command_service.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
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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 293
294 return true; 294 return true;
295 } 295 }
296 296
297 void CommandService::OnExtensionWillBeInstalled( 297 void CommandService::OnExtensionWillBeInstalled(
298 content::BrowserContext* browser_context, 298 content::BrowserContext* browser_context,
299 const Extension* extension, 299 const Extension* extension,
300 bool is_update, 300 bool is_update,
301 bool from_ephemeral, 301 bool from_ephemeral,
302 const std::string& old_name) { 302 const std::string& old_name) {
303 UpdateKeybindings(extension); 303 // Component extensions don't generate normal install and uninstall events so
304 // key binding updates occur in loaded.
305 if (extension->location() != Manifest::COMPONENT)
306 UpdateKeybindings(extension);
304 } 307 }
305 308
306 void CommandService::OnExtensionUninstalled( 309 void CommandService::OnExtensionUninstalled(
307 content::BrowserContext* browser_context, 310 content::BrowserContext* browser_context,
308 const Extension* extension, 311 const Extension* extension,
309 extensions::UninstallReason reason) { 312 extensions::UninstallReason reason) {
310 RemoveKeybindingPrefs(extension->id(), std::string()); 313 if (extension->location() != Manifest::COMPONENT)
314 RemoveKeybindingPrefs(extension->id(), std::string());
315 }
316
317 void CommandService::OnExtensionLoaded(content::BrowserContext* browser_context,
318 const Extension* extension) {
319 if (extension->location() == Manifest::COMPONENT)
320 UpdateKeybindings(extension);
311 } 321 }
312 322
313 void CommandService::UpdateKeybindingPrefs(const std::string& extension_id, 323 void CommandService::UpdateKeybindingPrefs(const std::string& extension_id,
314 const std::string& command_name, 324 const std::string& command_name,
315 const std::string& keystroke) { 325 const std::string& keystroke) {
316 Command command = FindCommandByName(extension_id, command_name); 326 Command command = FindCommandByName(extension_id, command_name);
317 327
318 // The extension command might be assigned another shortcut. Remove that 328 // The extension command might be assigned another shortcut. Remove that
319 // shortcut before proceeding. 329 // shortcut before proceeding.
320 RemoveKeybindingPrefs(extension_id, command_name); 330 RemoveKeybindingPrefs(extension_id, command_name);
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 return true; 873 return true;
864 } 874 }
865 875
866 template <> 876 template <>
867 void 877 void
868 BrowserContextKeyedAPIFactory<CommandService>::DeclareFactoryDependencies() { 878 BrowserContextKeyedAPIFactory<CommandService>::DeclareFactoryDependencies() {
869 DependsOn(ExtensionCommandsGlobalRegistry::GetFactoryInstance()); 879 DependsOn(ExtensionCommandsGlobalRegistry::GetFactoryInstance());
870 } 880 }
871 881
872 } // namespace extensions 882 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698