Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / extensions / api / commands / commands.cc
blob2cc997b1ae9f70711874a1f7b66771e951ce5a8e
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"
10 namespace {
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() :
19 base::string16());
20 return result;
23 } // namespace
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;
32 bool active = false;
33 if (command_service->GetBrowserActionCommand(extension_->id(),
34 extensions::CommandService::ALL,
35 &browser_action,
36 &active)) {
37 command_list->Append(CreateCommandValue(browser_action, active));
40 extensions::Command page_action;
41 if (command_service->GetPageActionCommand(extension_->id(),
42 extensions::CommandService::ALL,
43 &page_action,
44 &active)) {
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,
52 &named_commands);
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);
65 return true;