Chromium Code Reviews| 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 "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| 11 #include "chrome/browser/extensions/api/commands/commands.h" | 11 #include "chrome/browser/extensions/api/commands/commands.h" |
| 12 #include "chrome/browser/extensions/extension_commands_global_registry.h" | |
| 12 #include "chrome/browser/extensions/extension_function_registry.h" | 13 #include "chrome/browser/extensions/extension_function_registry.h" |
| 13 #include "chrome/browser/extensions/extension_keybinding_registry.h" | 14 #include "chrome/browser/extensions/extension_keybinding_registry.h" |
| 14 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
| 15 #include "chrome/browser/extensions/extension_system.h" | 16 #include "chrome/browser/extensions/extension_system.h" |
| 16 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 17 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/accelerator_utils.h" | 19 #include "chrome/browser/ui/accelerator_utils.h" |
| 19 #include "chrome/common/extensions/api/commands/commands_handler.h" | 20 #include "chrome/common/extensions/api/commands/commands_handler.h" |
| 20 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 21 #include "components/user_prefs/pref_registry_syncable.h" | 22 #include "components/user_prefs/pref_registry_syncable.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 registry->RegisterDictionaryPref( | 68 registry->RegisterDictionaryPref( |
| 68 prefs::kExtensionCommands, | 69 prefs::kExtensionCommands, |
| 69 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 70 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| 70 } | 71 } |
| 71 | 72 |
| 72 CommandService::CommandService(Profile* profile) | 73 CommandService::CommandService(Profile* profile) |
| 73 : profile_(profile) { | 74 : profile_(profile) { |
| 74 ExtensionFunctionRegistry::GetInstance()-> | 75 ExtensionFunctionRegistry::GetInstance()-> |
| 75 RegisterFunction<GetAllCommandsFunction>(); | 76 RegisterFunction<GetAllCommandsFunction>(); |
| 76 | 77 |
| 78 ExtensionCommandsGlobalRegistry::GetFactoryInstance()->GetForProfile(profile); | |
| 79 | |
| 77 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, | 80 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, |
| 78 content::Source<Profile>(profile)); | 81 content::Source<Profile>(profile)); |
| 79 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | 82 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
| 80 content::Source<Profile>(profile)); | 83 content::Source<Profile>(profile)); |
| 81 } | 84 } |
| 82 | 85 |
| 83 CommandService::~CommandService() { | 86 CommandService::~CommandService() { |
| 84 } | 87 } |
| 85 | 88 |
| 86 static base::LazyInstance<ProfileKeyedAPIFactory<CommandService> > | 89 static base::LazyInstance<ProfileKeyedAPIFactory<CommandService> > |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 const std::string& extension_id, | 121 const std::string& extension_id, |
| 119 QueryType type, | 122 QueryType type, |
| 120 extensions::Command* command, | 123 extensions::Command* command, |
| 121 bool* active) { | 124 bool* active) { |
| 122 return GetExtensionActionCommand( | 125 return GetExtensionActionCommand( |
| 123 extension_id, type, command, active, SCRIPT_BADGE); | 126 extension_id, type, command, active, SCRIPT_BADGE); |
| 124 } | 127 } |
| 125 | 128 |
| 126 bool CommandService::GetNamedCommands(const std::string& extension_id, | 129 bool CommandService::GetNamedCommands(const std::string& extension_id, |
| 127 QueryType type, | 130 QueryType type, |
| 131 CommandScope scope, | |
| 128 extensions::CommandMap* command_map) { | 132 extensions::CommandMap* command_map) { |
| 129 const ExtensionSet* extensions = | 133 const ExtensionSet* extensions = |
| 130 ExtensionSystem::Get(profile_)->extension_service()->extensions(); | 134 ExtensionSystem::Get(profile_)->extension_service()->extensions(); |
|
zhchbin
2013/09/28 03:33:10
Because we add "ExtensionCommandsGlobalRegistry::G
| |
| 131 const Extension* extension = extensions->GetByID(extension_id); | 135 const Extension* extension = extensions->GetByID(extension_id); |
| 132 CHECK(extension); | 136 CHECK(extension); |
| 133 | 137 |
| 134 command_map->clear(); | 138 command_map->clear(); |
| 135 const extensions::CommandMap* commands = | 139 const extensions::CommandMap* commands = |
| 136 CommandsInfo::GetNamedCommands(extension); | 140 CommandsInfo::GetNamedCommands(extension); |
| 137 if (!commands) | 141 if (!commands) |
| 138 return false; | 142 return false; |
| 139 | 143 |
| 140 extensions::CommandMap::const_iterator iter = commands->begin(); | 144 extensions::CommandMap::const_iterator iter = commands->begin(); |
| 141 for (; iter != commands->end(); ++iter) { | 145 for (; iter != commands->end(); ++iter) { |
| 142 ui::Accelerator shortcut_assigned = | 146 ui::Accelerator shortcut_assigned = |
| 143 FindShortcutForCommand(extension_id, iter->second.command_name()); | 147 FindShortcutForCommand(extension_id, iter->second.command_name()); |
| 144 | 148 |
| 145 if (type == ACTIVE_ONLY && shortcut_assigned.key_code() == ui::VKEY_UNKNOWN) | 149 if (type == ACTIVE_ONLY && shortcut_assigned.key_code() == ui::VKEY_UNKNOWN) |
| 146 continue; | 150 continue; |
| 147 | 151 |
| 148 extensions::Command command = iter->second; | 152 extensions::Command command = iter->second; |
| 153 if (scope != ANY_SCOPE && ((scope == GLOBAL) != command.global())) | |
| 154 continue; | |
| 155 | |
| 149 if (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN) | 156 if (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN) |
| 150 command.set_accelerator(shortcut_assigned); | 157 command.set_accelerator(shortcut_assigned); |
| 151 | 158 |
| 152 (*command_map)[iter->second.command_name()] = command; | 159 (*command_map)[iter->second.command_name()] = command; |
| 153 } | 160 } |
| 154 | 161 |
| 155 return true; | 162 return true; |
| 156 } | 163 } |
| 157 | 164 |
| 158 bool CommandService::AddKeybindingPref( | 165 bool CommandService::AddKeybindingPref( |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 return false; | 405 return false; |
| 399 | 406 |
| 400 *command = *requested_command; | 407 *command = *requested_command; |
| 401 if (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN) | 408 if (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN) |
| 402 command->set_accelerator(shortcut_assigned); | 409 command->set_accelerator(shortcut_assigned); |
| 403 | 410 |
| 404 return true; | 411 return true; |
| 405 } | 412 } |
| 406 | 413 |
| 407 } // namespace extensions | 414 } // namespace extensions |
| OLD | NEW |