| Index: chrome/browser/extensions/api/commands/extension_command_service.cc
|
| ===================================================================
|
| --- chrome/browser/extensions/api/commands/extension_command_service.cc (revision 137495)
|
| +++ chrome/browser/extensions/api/commands/extension_command_service.cc (working copy)
|
| @@ -11,9 +11,14 @@
|
| #include "chrome/browser/prefs/scoped_user_pref_update.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/common/chrome_notification_types.h"
|
| +#include "chrome/common/extensions/extension_manifest_constants.h"
|
| #include "chrome/common/pref_names.h"
|
| #include "content/public/browser/notification_service.h"
|
| +#include "grit/generated_resources.h"
|
| +#include "ui/base/l10n/l10n_util.h"
|
|
|
| +namespace values = extension_manifest_values;
|
| +
|
| namespace {
|
|
|
| const char kExtension[] = "extension";
|
| @@ -47,8 +52,8 @@
|
| }
|
|
|
| const extensions::Command*
|
| - ExtensionCommandService::GetActiveBrowserActionCommand(
|
| - const std::string& extension_id) {
|
| + ExtensionCommandService::GetBrowserActionCommand(
|
| + const std::string& extension_id, ExtensionCommandQueryType type) {
|
| const ExtensionSet* extensions =
|
| ExtensionSystem::Get(profile_)->extension_service()->extensions();
|
| const Extension* extension = extensions->GetByID(extension_id);
|
| @@ -57,7 +62,8 @@
|
| const extensions::Command* command = extension->browser_action_command();
|
| if (!command)
|
| return NULL;
|
| - if (!IsKeybindingActive(command->accelerator(),
|
| + if (type == ACTIVE_ONLY &&
|
| + !IsKeybindingActive(command->accelerator(),
|
| extension_id,
|
| command->command_name())) {
|
| return NULL;
|
| @@ -66,8 +72,8 @@
|
| return command;
|
| }
|
|
|
| -const extensions::Command* ExtensionCommandService::GetActivePageActionCommand(
|
| - const std::string& extension_id) {
|
| +const extensions::Command* ExtensionCommandService::GetPageActionCommand(
|
| + const std::string& extension_id, ExtensionCommandQueryType type) {
|
| const ExtensionSet* extensions =
|
| ExtensionSystem::Get(profile_)->extension_service()->extensions();
|
| const Extension* extension = extensions->GetByID(extension_id);
|
| @@ -76,7 +82,8 @@
|
| const extensions::Command* command = extension->page_action_command();
|
| if (!command)
|
| return NULL;
|
| - if (!IsKeybindingActive(command->accelerator(),
|
| + if (type == ACTIVE_ONLY &&
|
| + !IsKeybindingActive(command->accelerator(),
|
| extension_id,
|
| command->command_name())) {
|
| return NULL;
|
| @@ -85,8 +92,8 @@
|
| return command;
|
| }
|
|
|
| -extensions::CommandMap ExtensionCommandService::GetActiveNamedCommands(
|
| - const std::string& extension_id) {
|
| +extensions::CommandMap ExtensionCommandService::GetNamedCommands(
|
| + const std::string& extension_id, ExtensionCommandQueryType type) {
|
| const ExtensionSet* extensions =
|
| ExtensionSystem::Get(profile_)->extension_service()->extensions();
|
| const Extension* extension = extensions->GetByID(extension_id);
|
| @@ -99,7 +106,8 @@
|
|
|
| extensions::CommandMap::const_iterator iter = commands.begin();
|
| for (; iter != commands.end(); ++iter) {
|
| - if (!IsKeybindingActive(iter->second.accelerator(),
|
| + if (type == ACTIVE_ONLY &&
|
| + !IsKeybindingActive(iter->second.accelerator(),
|
| extension_id,
|
| iter->second.command_name())) {
|
| continue;
|
| @@ -111,6 +119,51 @@
|
| return result;
|
| }
|
|
|
| +void ExtensionCommandService::GetAllCommands(DictionaryValue* commands) {
|
| + ListValue* results = new ListValue;
|
| +
|
| + const ExtensionSet* extensions =
|
| + ExtensionSystem::Get(profile_)->extension_service()->extensions();
|
| + for (ExtensionSet::const_iterator extension = extensions->begin();
|
| + extension != extensions->end(); ++extension) {
|
| + scoped_ptr<DictionaryValue> extension_dict(new DictionaryValue);
|
| + extension_dict->SetString("name", (*extension)->name());
|
| + extension_dict->SetString("id", (*extension)->id());
|
| +
|
| + // Add the keybindings to a list structure.
|
| + scoped_ptr<ListValue> extensions_list(new ListValue());
|
| +
|
| + const extensions::Command* browser_action =
|
| + GetBrowserActionCommand((*extension)->id(), ALL);
|
| + if (browser_action) {
|
| + extensions_list->Append(CreateExtensionDetailValue(*extension,
|
| + browser_action));
|
| + }
|
| +
|
| + const extensions::Command* page_action =
|
| + GetPageActionCommand((*extension)->id(), ALL);
|
| + if (page_action) {
|
| + extensions_list->Append(CreateExtensionDetailValue(*extension,
|
| + page_action));
|
| + }
|
| +
|
| + extensions::CommandMap named_commands =
|
| + GetNamedCommands((*extension)->id(), ALL);
|
| + extensions::CommandMap::const_iterator iter = named_commands.begin();
|
| + for (; iter != named_commands.end(); ++iter) {
|
| + extensions_list->Append(
|
| + CreateExtensionDetailValue(*extension, &iter->second));
|
| + }
|
| +
|
| + if (!extensions_list->empty()) {
|
| + extension_dict->Set("commands", extensions_list.release());
|
| + results->Append(extension_dict.release());
|
| + }
|
| + }
|
| +
|
| + commands->Set("commands", results);
|
| +}
|
| +
|
| bool ExtensionCommandService::IsKeybindingActive(
|
| const ui::Accelerator& accelerator,
|
| std::string extension_id,
|
| @@ -232,3 +285,27 @@
|
| bindings->Remove(*it, NULL);
|
| }
|
| }
|
| +
|
| +DictionaryValue* ExtensionCommandService::CreateExtensionDetailValue(
|
| + const Extension* extension,
|
| + const extensions::Command* command) {
|
| + DictionaryValue* extension_data = new DictionaryValue();
|
| +
|
| + string16 description;
|
| + if (command->command_name() == values::kBrowserActionKeybindingEvent ||
|
| + command->command_name() == values::kPageActionKeybindingEvent) {
|
| + description =
|
| + l10n_util::GetStringUTF16(IDS_EXTENSION_COMMANDS_GENERIC_ACTIVATE);
|
| + } else {
|
| + description = command->description();
|
| + }
|
| + extension_data->SetString("description", description);
|
| + extension_data->SetBoolean(
|
| + "active", IsKeybindingActive(command->accelerator(),
|
| + extension->id(),
|
| + command->command_name()));
|
| + extension_data->SetString("keybinding",
|
| + command->accelerator().GetShortcutText());
|
| +
|
| + return extension_data;
|
| +}
|
|
|