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 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_COMMANDS_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_COMMANDS_H_ |
6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_COMMANDS_H_ | 6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_COMMANDS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <map> | 10 #include <map> |
11 | 11 |
12 #include "base/string16.h" | 12 #include "base/string16.h" |
13 #include "ui/base/accelerators/accelerator.h" | 13 #include "ui/base/accelerators/accelerator.h" |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 class DictionaryValue; | 16 class DictionaryValue; |
17 } | 17 } |
18 | 18 |
19 namespace extensions { | 19 namespace extensions { |
| 20 class Extension; |
| 21 } |
| 22 |
| 23 namespace extensions { |
20 | 24 |
21 class Command { | 25 class Command { |
22 public: | 26 public: |
23 // Define out of line constructor/destructor to please Clang. | 27 // Define out of line constructor/destructor to please Clang. |
24 Command(); | 28 Command(); |
25 ~Command(); | 29 ~Command(); |
26 | 30 |
27 // The platform value for the Command. | 31 // The platform value for the Command. |
28 static std::string CommandPlatform(); | 32 static std::string CommandPlatform(); |
29 | 33 |
30 // Parse the command. | 34 // Parse the command. |
31 bool Parse(base::DictionaryValue* command, | 35 bool Parse(base::DictionaryValue* command, |
32 const std::string& command_name, | 36 const std::string& command_name, |
33 int index, | 37 int index, |
34 string16* error); | 38 string16* error); |
35 | 39 |
| 40 // Convert a Command object from |extension| to a DictionaryValue. |
| 41 // |active| specifies whether the command is active or not. |
| 42 base::DictionaryValue* ToValue( |
| 43 const Extension* extension, bool active) const; |
| 44 |
36 // Accessors: | 45 // Accessors: |
37 const std::string& command_name() const { return command_name_; } | 46 const std::string& command_name() const { return command_name_; } |
38 const ui::Accelerator& accelerator() const { return accelerator_; } | 47 const ui::Accelerator& accelerator() const { return accelerator_; } |
39 const std::string& description() const { return description_; } | 48 const string16& description() const { return description_; } |
40 | 49 |
41 private: | 50 private: |
42 ui::Accelerator ParseImpl(const std::string& shortcut, | 51 ui::Accelerator ParseImpl(const std::string& shortcut, |
43 const std::string& platform_key, | 52 const std::string& platform_key, |
44 int index, | 53 int index, |
45 string16* error); | 54 string16* error); |
46 std::string command_name_; | 55 std::string command_name_; |
47 ui::Accelerator accelerator_; | 56 ui::Accelerator accelerator_; |
48 std::string description_; | 57 string16 description_; |
49 }; | 58 }; |
50 | 59 |
51 // A mapping of command name (std::string) to a command object. | 60 // A mapping of command name (std::string) to a command object. |
52 typedef std::map<std::string, Command> CommandMap; | 61 typedef std::map<std::string, Command> CommandMap; |
53 | 62 |
54 } // namespace extensions | 63 } // namespace extensions |
55 | 64 |
56 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_COMMANDS_H_ | 65 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_COMMANDS_H_ |
OLD | NEW |