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/commands.h" | 5 #include "chrome/browser/extensions/api/commands/commands.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "chrome/browser/extensions/api/commands/command_service.h" | 10 #include "chrome/browser/extensions/api/commands/command_service.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 base::DictionaryValue* CreateCommandValue( | 15 base::DictionaryValue* CreateCommandValue( |
16 const extensions::Command& command, bool active) { | 16 const extensions::Command& command, bool active) { |
17 base::DictionaryValue* result = new base::DictionaryValue(); | 17 base::DictionaryValue* result = new base::DictionaryValue(); |
18 result->SetString("name", command.command_name()); | 18 result->SetString("name", command.command_name()); |
19 result->SetString("description", command.description()); | 19 result->SetString("description", command.description()); |
20 result->SetString("shortcut", | 20 result->SetString("shortcut", |
21 active ? command.accelerator().GetShortcutText() : | 21 active ? command.accelerator().GetShortcutText() : |
22 base::string16()); | 22 base::string16()); |
23 return result; | 23 return result; |
24 } | 24 } |
25 | 25 |
26 } // namespace | 26 } // namespace |
27 | 27 |
28 bool GetAllCommandsFunction::RunSync() { | 28 ExtensionFunction::ResponseAction GetAllCommandsFunction::Run() { |
29 std::unique_ptr<base::ListValue> command_list(new base::ListValue()); | 29 std::unique_ptr<base::ListValue> command_list(new base::ListValue()); |
30 | 30 |
31 extensions::CommandService* command_service = | 31 extensions::CommandService* command_service = |
32 extensions::CommandService::Get(GetProfile()); | 32 extensions::CommandService::Get(browser_context()); |
33 | 33 |
34 extensions::Command browser_action; | 34 extensions::Command browser_action; |
35 bool active = false; | 35 bool active = false; |
36 if (command_service->GetBrowserActionCommand(extension_->id(), | 36 if (command_service->GetBrowserActionCommand(extension_->id(), |
37 extensions::CommandService::ALL, | 37 extensions::CommandService::ALL, |
38 &browser_action, | 38 &browser_action, |
39 &active)) { | 39 &active)) { |
40 command_list->Append(CreateCommandValue(browser_action, active)); | 40 command_list->Append(CreateCommandValue(browser_action, active)); |
41 } | 41 } |
42 | 42 |
(...skipping 14 matching lines...) Expand all Loading... |
57 for (extensions::CommandMap::const_iterator iter = named_commands.begin(); | 57 for (extensions::CommandMap::const_iterator iter = named_commands.begin(); |
58 iter != named_commands.end(); ++iter) { | 58 iter != named_commands.end(); ++iter) { |
59 extensions::Command command = command_service->FindCommandByName( | 59 extensions::Command command = command_service->FindCommandByName( |
60 extension_->id(), iter->second.command_name()); | 60 extension_->id(), iter->second.command_name()); |
61 ui::Accelerator shortcut_assigned = command.accelerator(); | 61 ui::Accelerator shortcut_assigned = command.accelerator(); |
62 active = (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN); | 62 active = (shortcut_assigned.key_code() != ui::VKEY_UNKNOWN); |
63 | 63 |
64 command_list->Append(CreateCommandValue(iter->second, active)); | 64 command_list->Append(CreateCommandValue(iter->second, active)); |
65 } | 65 } |
66 | 66 |
67 SetResult(std::move(command_list)); | 67 return RespondNow(OneArgument(std::move(command_list))); |
68 return true; | |
69 } | 68 } |
OLD | NEW |