OLD | NEW |
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 Loading... |
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 // Component extensions don't generate normal install and uninstall events so | 311 UpdateKeybindings(extension); |
312 // those are handled in OnExtensionLoaded. | |
313 if (extension->location() != Manifest::COMPONENT) | |
314 UpdateKeybindings(extension); | |
315 } | 312 } |
316 | 313 |
317 void CommandService::OnExtensionUninstalled( | 314 void CommandService::OnExtensionUninstalled( |
318 content::BrowserContext* browser_context, | 315 content::BrowserContext* browser_context, |
319 const Extension* extension, | 316 const Extension* extension, |
320 extensions::UninstallReason reason) { | 317 extensions::UninstallReason reason) { |
| 318 // Adding a component extensions will only trigger install the first time on a |
| 319 // clean profile or on a version increase (see |
| 320 // ComponentLoader::AddComponentExtension). It will, however, always trigger |
| 321 // an uninstall on removal. See http://crbug.com/458612. Isolate this case and |
| 322 // ignore it. |
| 323 if (reason == extensions::UNINSTALL_REASON_COMPONENT_REMOVED) |
| 324 return; |
| 325 |
321 RemoveKeybindingPrefs(extension->id(), std::string()); | 326 RemoveKeybindingPrefs(extension->id(), std::string()); |
322 } | 327 } |
323 | 328 |
324 void CommandService::OnExtensionLoaded(content::BrowserContext* browser_context, | |
325 const Extension* extension) { | |
326 if (extension->location() == Manifest::COMPONENT) | |
327 UpdateKeybindings(extension); | |
328 } | |
329 | |
330 void CommandService::UpdateKeybindingPrefs(const std::string& extension_id, | 329 void CommandService::UpdateKeybindingPrefs(const std::string& extension_id, |
331 const std::string& command_name, | 330 const std::string& command_name, |
332 const std::string& keystroke) { | 331 const std::string& keystroke) { |
333 Command command = FindCommandByName(extension_id, command_name); | 332 Command command = FindCommandByName(extension_id, command_name); |
334 | 333 |
335 // The extension command might be assigned another shortcut. Remove that | 334 // The extension command might be assigned another shortcut. Remove that |
336 // shortcut before proceeding. | 335 // shortcut before proceeding. |
337 RemoveKeybindingPrefs(extension_id, command_name); | 336 RemoveKeybindingPrefs(extension_id, command_name); |
338 | 337 |
339 ui::Accelerator accelerator = | 338 ui::Accelerator accelerator = |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 return true; | 884 return true; |
886 } | 885 } |
887 | 886 |
888 template <> | 887 template <> |
889 void | 888 void |
890 BrowserContextKeyedAPIFactory<CommandService>::DeclareFactoryDependencies() { | 889 BrowserContextKeyedAPIFactory<CommandService>::DeclareFactoryDependencies() { |
891 DependsOn(ExtensionCommandsGlobalRegistry::GetFactoryInstance()); | 890 DependsOn(ExtensionCommandsGlobalRegistry::GetFactoryInstance()); |
892 } | 891 } |
893 | 892 |
894 } // namespace extensions | 893 } // namespace extensions |
OLD | NEW |