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
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/api/commands/commands.h"
7 #include "chrome/browser/extensions/api/commands/command_service.h"
8 #include "chrome/browser/profiles/profile.h"
12 base::DictionaryValue
* CreateCommandValue(
13 const extensions::Command
& command
, bool active
) {
14 base::DictionaryValue
* result
= new base::DictionaryValue();
15 result
->SetString("name", command
.command_name());
16 result
->SetString("description", command
.description());
17 result
->SetString("shortcut",
18 active
? command
.accelerator().GetShortcutText() :
25 bool GetAllCommandsFunction::RunSync() {
26 base::ListValue
* command_list
= new base::ListValue();
28 extensions::CommandService
* command_service
=
29 extensions::CommandService::Get(GetProfile());
31 extensions::Command browser_action
;
33 if (command_service
->GetBrowserActionCommand(extension_
->id(),
34 extensions::CommandService::ALL
,
37 command_list
->Append(CreateCommandValue(browser_action
, active
));
40 extensions::Command page_action
;
41 if (command_service
->GetPageActionCommand(extension_
->id(),
42 extensions::CommandService::ALL
,
45 command_list
->Append(CreateCommandValue(page_action
, active
));
48 extensions::CommandMap named_commands
;
49 command_service
->GetNamedCommands(extension_
->id(),
50 extensions::CommandService::ALL
,
51 extensions::CommandService::ANY_SCOPE
,
54 for (extensions::CommandMap::const_iterator iter
= named_commands
.begin();
55 iter
!= named_commands
.end(); ++iter
) {
56 extensions::Command command
= command_service
->FindCommandByName(
57 extension_
->id(), iter
->second
.command_name());
58 ui::Accelerator shortcut_assigned
= command
.accelerator();
59 active
= (shortcut_assigned
.key_code() != ui::VKEY_UNKNOWN
);
61 command_list
->Append(CreateCommandValue(iter
->second
, active
));
64 SetResult(command_list
);