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

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: Fix compile Created 5 years, 11 months 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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 301
302 return true; 302 return true;
303 } 303 }
304 304
305 void CommandService::OnExtensionWillBeInstalled( 305 void CommandService::OnExtensionWillBeInstalled(
306 content::BrowserContext* browser_context, 306 content::BrowserContext* browser_context,
307 const Extension* extension, 307 const Extension* extension,
308 bool is_update, 308 bool is_update,
309 bool from_ephemeral, 309 bool from_ephemeral,
310 const std::string& old_name) { 310 const std::string& old_name) {
311 UpdateKeybindings(extension); 311 // Component extensions don't generate normal install and uninstall events so
312 // those are handled in OnExtensionLoaded.
313 if (extension->location() != Manifest::COMPONENT)
314 UpdateKeybindings(extension);
312 } 315 }
313 316
314 void CommandService::OnExtensionUninstalled( 317 void CommandService::OnExtensionUninstalled(
315 content::BrowserContext* browser_context, 318 content::BrowserContext* browser_context,
316 const Extension* extension, 319 const Extension* extension,
317 extensions::UninstallReason reason) { 320 extensions::UninstallReason reason) {
318 RemoveKeybindingPrefs(extension->id(), std::string()); 321 RemoveKeybindingPrefs(extension->id(), std::string());
319 } 322 }
320 323
324 void CommandService::OnExtensionLoaded(content::BrowserContext* browser_context,
325 const Extension* extension) {
326 if (extension->location() == Manifest::COMPONENT)
327 UpdateKeybindings(extension);
328 }
329
321 void CommandService::UpdateKeybindingPrefs(const std::string& extension_id, 330 void CommandService::UpdateKeybindingPrefs(const std::string& extension_id,
322 const std::string& command_name, 331 const std::string& command_name,
323 const std::string& keystroke) { 332 const std::string& keystroke) {
324 Command command = FindCommandByName(extension_id, command_name); 333 Command command = FindCommandByName(extension_id, command_name);
325 334
326 // The extension command might be assigned another shortcut. Remove that 335 // The extension command might be assigned another shortcut. Remove that
327 // shortcut before proceeding. 336 // shortcut before proceeding.
328 RemoveKeybindingPrefs(extension_id, command_name); 337 RemoveKeybindingPrefs(extension_id, command_name);
329 338
330 ui::Accelerator accelerator = 339 ui::Accelerator accelerator =
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 return true; 885 return true;
877 } 886 }
878 887
879 template <> 888 template <>
880 void 889 void
881 BrowserContextKeyedAPIFactory<CommandService>::DeclareFactoryDependencies() { 890 BrowserContextKeyedAPIFactory<CommandService>::DeclareFactoryDependencies() {
882 DependsOn(ExtensionCommandsGlobalRegistry::GetFactoryInstance()); 891 DependsOn(ExtensionCommandsGlobalRegistry::GetFactoryInstance());
883 } 892 }
884 893
885 } // namespace extensions 894 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/commands/command_service.h ('k') | chrome/browser/extensions/extension_keybinding_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698