Enable Enterprise enrollment on desktop builds.
[chromium-blink-merge.git] / chrome / common / extensions / command.h
blob41ec35aa503dae6a57d5139112a2759e6a845291
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 #ifndef CHROME_COMMON_EXTENSIONS_COMMAND_H_
6 #define CHROME_COMMON_EXTENSIONS_COMMAND_H_
8 #include <map>
9 #include <string>
11 #include "base/strings/string16.h"
12 #include "ui/base/accelerators/accelerator.h"
14 namespace base {
15 class DictionaryValue;
18 namespace extensions {
19 class Extension;
22 namespace extensions {
24 class Command {
25 public:
26 Command();
27 Command(const std::string& command_name,
28 const base::string16& description,
29 const std::string& accelerator,
30 bool global);
31 ~Command();
33 // The platform value for the Command.
34 static std::string CommandPlatform();
36 // Parse a string as an accelerator. If the accelerator is unparsable then
37 // a generic ui::Accelerator object will be returns (with key_code Unknown).
38 static ui::Accelerator StringToAccelerator(const std::string& accelerator,
39 const std::string& command_name);
41 // Returns the string representation of an accelerator without localizing the
42 // shortcut text (like accelerator::GetShortcutText() does).
43 static std::string AcceleratorToString(const ui::Accelerator& accelerator);
45 // Return true if the specified accelerator is one of the following multimedia
46 // keys: Next Track key, Previous Track key, Stop Media key, Play/Pause Media
47 // key, without any modifiers.
48 static bool IsMediaKey(const ui::Accelerator& accelerator);
50 // Parse the command.
51 bool Parse(const base::DictionaryValue* command,
52 const std::string& command_name,
53 int index,
54 base::string16* error);
56 // Convert a Command object from |extension| to a DictionaryValue.
57 // |active| specifies whether the command is active or not.
58 base::DictionaryValue* ToValue(
59 const Extension* extension, bool active) const;
61 // Accessors:
62 const std::string& command_name() const { return command_name_; }
63 const ui::Accelerator& accelerator() const { return accelerator_; }
64 const base::string16& description() const { return description_; }
65 bool global() const { return global_; }
67 // Setter:
68 void set_accelerator(ui::Accelerator accelerator) {
69 accelerator_ = accelerator;
71 void set_global(bool global) {
72 global_ = global;
75 private:
76 std::string command_name_;
77 ui::Accelerator accelerator_;
78 base::string16 description_;
79 bool global_;
82 // A mapping of command name (std::string) to a command object.
83 typedef std::map<std::string, Command> CommandMap;
85 } // namespace extensions
87 #endif // CHROME_COMMON_EXTENSIONS_COMMAND_H_