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" |
11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/app/chrome_command_ids.h" | 14 #include "chrome/app/chrome_command_ids.h" |
15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
16 #include "chrome/browser/extensions/api/commands/commands.h" | 16 #include "chrome/browser/extensions/api/commands/commands.h" |
17 #include "chrome/browser/extensions/extension_commands_global_registry.h" | 17 #include "chrome/browser/extensions/extension_commands_global_registry.h" |
18 #include "chrome/browser/extensions/extension_function_registry.h" | 18 #include "chrome/browser/extensions/extension_function_registry.h" |
19 #include "chrome/browser/extensions/extension_keybinding_registry.h" | 19 #include "chrome/browser/extensions/extension_keybinding_registry.h" |
20 #include "chrome/browser/extensions/extension_service.h" | |
21 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/browser/ui/accelerator_utils.h" | 21 #include "chrome/browser/ui/accelerator_utils.h" |
23 #include "chrome/common/extensions/api/commands/commands_handler.h" | 22 #include "chrome/common/extensions/api/commands/commands_handler.h" |
24 #include "chrome/common/extensions/manifest_handlers/settings_overrides_handler.
h" | 23 #include "chrome/common/extensions/manifest_handlers/settings_overrides_handler.
h" |
25 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
26 #include "components/user_prefs/pref_registry_syncable.h" | 25 #include "components/user_prefs/pref_registry_syncable.h" |
27 #include "content/public/browser/notification_details.h" | 26 #include "content/public/browser/notification_details.h" |
28 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
| 28 #include "extensions/browser/extension_prefs.h" |
| 29 #include "extensions/browser/extension_registry.h" |
29 #include "extensions/browser/extension_system.h" | 30 #include "extensions/browser/extension_system.h" |
30 #include "extensions/common/feature_switch.h" | 31 #include "extensions/common/feature_switch.h" |
31 #include "extensions/common/manifest_constants.h" | 32 #include "extensions/common/manifest_constants.h" |
32 #include "extensions/common/permissions/permissions_data.h" | 33 #include "extensions/common/permissions/permissions_data.h" |
33 | 34 |
34 using extensions::Extension; | 35 using extensions::Extension; |
35 using extensions::ExtensionPrefs; | 36 using extensions::ExtensionPrefs; |
36 | 37 |
37 namespace { | 38 namespace { |
38 | 39 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 extensions::Command* command, | 202 extensions::Command* command, |
202 bool* active) { | 203 bool* active) { |
203 return GetExtensionActionCommand( | 204 return GetExtensionActionCommand( |
204 extension_id, type, command, active, PAGE_ACTION); | 205 extension_id, type, command, active, PAGE_ACTION); |
205 } | 206 } |
206 | 207 |
207 bool CommandService::GetNamedCommands(const std::string& extension_id, | 208 bool CommandService::GetNamedCommands(const std::string& extension_id, |
208 QueryType type, | 209 QueryType type, |
209 CommandScope scope, | 210 CommandScope scope, |
210 extensions::CommandMap* command_map) { | 211 extensions::CommandMap* command_map) { |
211 ExtensionService* extension_service = | 212 const ExtensionSet& extensions = |
212 ExtensionSystem::Get(profile_)->extension_service(); | 213 ExtensionRegistry::Get(profile_)->enabled_extensions(); |
213 if (!extension_service) | 214 const Extension* extension = extensions.GetByID(extension_id); |
214 return false; // Can occur during testing. | |
215 const ExtensionSet* extensions = extension_service->extensions(); | |
216 const Extension* extension = extensions->GetByID(extension_id); | |
217 CHECK(extension); | 215 CHECK(extension); |
218 | 216 |
219 command_map->clear(); | 217 command_map->clear(); |
220 const extensions::CommandMap* commands = | 218 const extensions::CommandMap* commands = |
221 CommandsInfo::GetNamedCommands(extension); | 219 CommandsInfo::GetNamedCommands(extension); |
222 if (!commands) | 220 if (!commands) |
223 return false; | 221 return false; |
224 | 222 |
225 extensions::CommandMap::const_iterator iter = commands->begin(); | 223 extensions::CommandMap::const_iterator iter = commands->begin(); |
226 for (; iter != commands->end(); ++iter) { | 224 for (; iter != commands->end(); ++iter) { |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 | 384 |
387 return Command(); | 385 return Command(); |
388 } | 386 } |
389 | 387 |
390 void CommandService::AssignInitialKeybindings(const Extension* extension) { | 388 void CommandService::AssignInitialKeybindings(const Extension* extension) { |
391 const extensions::CommandMap* commands = | 389 const extensions::CommandMap* commands = |
392 CommandsInfo::GetNamedCommands(extension); | 390 CommandsInfo::GetNamedCommands(extension); |
393 if (!commands) | 391 if (!commands) |
394 return; | 392 return; |
395 | 393 |
396 ExtensionService* extension_service = | 394 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile_); |
397 ExtensionSystem::Get(profile_)->extension_service(); | |
398 ExtensionPrefs* extension_prefs = extension_service->extension_prefs(); | |
399 if (InitialBindingsHaveBeenAssigned(extension_prefs, extension->id())) | 395 if (InitialBindingsHaveBeenAssigned(extension_prefs, extension->id())) |
400 return; | 396 return; |
401 SetInitialBindingsHaveBeenAssigned(extension_prefs, extension->id()); | 397 SetInitialBindingsHaveBeenAssigned(extension_prefs, extension->id()); |
402 | 398 |
403 extensions::CommandMap::const_iterator iter = commands->begin(); | 399 extensions::CommandMap::const_iterator iter = commands->begin(); |
404 for (; iter != commands->end(); ++iter) { | 400 for (; iter != commands->end(); ++iter) { |
405 const extensions::Command command = iter->second; | 401 const extensions::Command command = iter->second; |
406 if (CanAutoAssign(command.accelerator(), | 402 if (CanAutoAssign(command.accelerator(), |
407 extension, | 403 extension, |
408 profile_, | 404 profile_, |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 std::pair<const std::string, const std::string> >(&details)); | 491 std::pair<const std::string, const std::string> >(&details)); |
496 } | 492 } |
497 } | 493 } |
498 | 494 |
499 bool CommandService::GetExtensionActionCommand( | 495 bool CommandService::GetExtensionActionCommand( |
500 const std::string& extension_id, | 496 const std::string& extension_id, |
501 QueryType query_type, | 497 QueryType query_type, |
502 extensions::Command* command, | 498 extensions::Command* command, |
503 bool* active, | 499 bool* active, |
504 ExtensionActionType action_type) { | 500 ExtensionActionType action_type) { |
505 ExtensionService* service = | 501 const ExtensionSet& extensions = |
506 ExtensionSystem::Get(profile_)->extension_service(); | 502 ExtensionRegistry::Get(profile_)->enabled_extensions(); |
507 if (!service) | 503 const Extension* extension = extensions.GetByID(extension_id); |
508 return false; // Can happen in tests. | |
509 const ExtensionSet* extensions = service->extensions(); | |
510 const Extension* extension = extensions->GetByID(extension_id); | |
511 CHECK(extension); | 504 CHECK(extension); |
512 | 505 |
513 if (active) | 506 if (active) |
514 *active = false; | 507 *active = false; |
515 | 508 |
516 const extensions::Command* requested_command = NULL; | 509 const extensions::Command* requested_command = NULL; |
517 switch (action_type) { | 510 switch (action_type) { |
518 case BROWSER_ACTION: | 511 case BROWSER_ACTION: |
519 requested_command = CommandsInfo::GetBrowserActionCommand(extension); | 512 requested_command = CommandsInfo::GetBrowserActionCommand(extension); |
520 break; | 513 break; |
(...skipping 22 matching lines...) Expand all Loading... |
543 | 536 |
544 return true; | 537 return true; |
545 } | 538 } |
546 | 539 |
547 template <> | 540 template <> |
548 void ProfileKeyedAPIFactory<CommandService>::DeclareFactoryDependencies() { | 541 void ProfileKeyedAPIFactory<CommandService>::DeclareFactoryDependencies() { |
549 DependsOn(ExtensionCommandsGlobalRegistry::GetFactoryInstance()); | 542 DependsOn(ExtensionCommandsGlobalRegistry::GetFactoryInstance()); |
550 } | 543 } |
551 | 544 |
552 } // namespace extensions | 545 } // namespace extensions |
OLD | NEW |