summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/command.h
blob: f2186474c67ef99009ba4dba5a4a0b39468a690f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_COMMON_EXTENSIONS_COMMAND_H_
#define CHROME_COMMON_EXTENSIONS_COMMAND_H_
#pragma once

#include <string>
#include <map>

#include "base/string16.h"
#include "ui/base/accelerators/accelerator.h"

namespace base {
class DictionaryValue;
}

namespace extensions {
class Extension;
}

namespace extensions {

class Command {
 public:
  // Define out of line constructor/destructor to please Clang.
  Command();
  ~Command();

  // The platform value for the Command.
  static std::string CommandPlatform();

  // Parse the command.
  bool Parse(base::DictionaryValue* command,
             const std::string& command_name,
             int index,
             string16* error);

  // Convert a Command object from |extension| to a DictionaryValue.
  // |active| specifies whether the command is active or not.
  base::DictionaryValue* ToValue(
      const Extension* extension, bool active) const;

  // Accessors:
  const std::string& command_name() const { return command_name_; }
  const ui::Accelerator& accelerator() const { return accelerator_; }
  const string16& description() const { return description_; }

 private:
  ui::Accelerator ParseImpl(const std::string& shortcut,
                            const std::string& platform_key,
                            int index,
                            string16* error);
  std::string command_name_;
  ui::Accelerator accelerator_;
  string16 description_;
};

// A mapping of command name (std::string) to a command object.
typedef std::map<std::string, Command> CommandMap;

}  // namespace extensions

#endif  // CHROME_COMMON_EXTENSIONS_COMMAND_H_