command.h revision a93a17c8d99d686bd4a1511e5504e5e6cc9fcadf
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. 4 5#ifndef CHROME_COMMON_EXTENSIONS_COMMAND_H_ 6#define CHROME_COMMON_EXTENSIONS_COMMAND_H_ 7 8#include <string> 9#include <map> 10 11#include "base/string16.h" 12#include "ui/base/accelerators/accelerator.h" 13 14namespace base { 15class DictionaryValue; 16} 17 18namespace extensions { 19class Extension; 20} 21 22namespace extensions { 23 24class Command { 25 public: 26 Command(); 27 Command(const std::string& command_name, 28 const string16& description, 29 const std::string& accelerator); 30 ~Command(); 31 32 // The platform value for the Command. 33 static std::string CommandPlatform(); 34 35 // Parse a string as an accelerator. If the accelerator is unparsable then 36 // a generic ui::Accelerator object will be returns (with key_code Unknown). 37 static ui::Accelerator StringToAccelerator(const std::string& accelerator); 38 39 // Returns the string representation of an accelerator without localizing the 40 // shortcut text (like accelerator::GetShortcutText() does). 41 static std::string AcceleratorToString(const ui::Accelerator& accelerator); 42 43 // Parse the command. 44 bool Parse(const base::DictionaryValue* command, 45 const std::string& command_name, 46 int index, 47 string16* error); 48 49 // Convert a Command object from |extension| to a DictionaryValue. 50 // |active| specifies whether the command is active or not. 51 base::DictionaryValue* ToValue( 52 const Extension* extension, bool active) const; 53 54 // Accessors: 55 const std::string& command_name() const { return command_name_; } 56 const ui::Accelerator& accelerator() const { return accelerator_; } 57 const string16& description() const { return description_; } 58 59 // Setter: 60 void set_accelerator(ui::Accelerator accelerator) { 61 accelerator_ = accelerator; 62 } 63 64 private: 65 std::string command_name_; 66 ui::Accelerator accelerator_; 67 string16 description_; 68}; 69 70// A mapping of command name (std::string) to a command object. 71typedef std::map<std::string, Command> CommandMap; 72 73} // namespace extensions 74 75#endif // CHROME_COMMON_EXTENSIONS_COMMAND_H_ 76