OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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 CHROMEOS_IME_COMPONENT_EXTENSION_IME_MANAGER_H_ |
| 6 #define CHROMEOS_IME_COMPONENT_EXTENSION_IME_MANAGER_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <set> |
| 10 |
| 11 #include "base/files/file_path.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/observer_list.h" |
| 14 #include "chromeos/chromeos_export.h" |
| 15 #include "chromeos/ime/input_method_descriptor.h" |
| 16 |
| 17 class Profile; |
| 18 |
| 19 namespace chromeos { |
| 20 |
| 21 // Represents an engine in component extension IME. |
| 22 struct CHROMEOS_EXPORT ComponentExtensionEngine { |
| 23 ComponentExtensionEngine(); |
| 24 ~ComponentExtensionEngine(); |
| 25 std::string engine_id; // The engine id. |
| 26 std::string display_name; // The display name. |
| 27 std::string indicator; // The indicator text. |
| 28 std::vector<std::string> language_codes; // The engine's language(ex. "en"). |
| 29 std::string description; // The engine description. |
| 30 std::vector<std::string> layouts; // The list of keyboard layout of engine. |
| 31 GURL options_page_url; // an URL to option page. |
| 32 GURL input_view_url; // an URL to input view page. |
| 33 }; |
| 34 |
| 35 // Represents a component extension IME. |
| 36 struct CHROMEOS_EXPORT ComponentExtensionIME { |
| 37 ComponentExtensionIME(); |
| 38 ~ComponentExtensionIME(); |
| 39 std::string id; // extension id. |
| 40 std::string manifest; // the contents of manifest.json |
| 41 std::string description; // description of extension. |
| 42 GURL options_page_url; // an URL to option page. |
| 43 base::FilePath path; |
| 44 std::vector<ComponentExtensionEngine> engines; |
| 45 }; |
| 46 |
| 47 // Provides an interface to list/load/unload for component extension IME. |
| 48 class CHROMEOS_EXPORT ComponentExtensionIMEManagerDelegate { |
| 49 public: |
| 50 ComponentExtensionIMEManagerDelegate(); |
| 51 virtual ~ComponentExtensionIMEManagerDelegate(); |
| 52 |
| 53 // Lists installed component extension IMEs. |
| 54 virtual std::vector<ComponentExtensionIME> ListIME() = 0; |
| 55 |
| 56 // Loads component extension IME associated with |extension_id|. |
| 57 // Returns false if it fails, otherwise returns true. |
| 58 virtual void Load(Profile* profile, |
| 59 const std::string& extension_id, |
| 60 const std::string& manifest, |
| 61 const base::FilePath& path) = 0; |
| 62 |
| 63 // Unloads component extension IME associated with |extension_id|. |
| 64 virtual void Unload(Profile* profile, |
| 65 const std::string& extension_id, |
| 66 const base::FilePath& path) = 0; |
| 67 }; |
| 68 |
| 69 // This class manages component extension input method. |
| 70 class CHROMEOS_EXPORT ComponentExtensionIMEManager { |
| 71 public: |
| 72 ComponentExtensionIMEManager(); |
| 73 virtual ~ComponentExtensionIMEManager(); |
| 74 |
| 75 // Initializes component extension manager. This function create internal |
| 76 // mapping between input method id and engine components. This function must |
| 77 // be called before using any other function. |
| 78 void Initialize(scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate); |
| 79 |
| 80 // Loads |input_method_id| component extension IME. This function returns true |
| 81 // on success. This function is safe to call multiple times. Returns false if |
| 82 // already corresponding component extension is loaded. |
| 83 bool LoadComponentExtensionIME(Profile* profile, |
| 84 const std::string& input_method_id); |
| 85 |
| 86 // Unloads |input_method_id| component extension IME. This function returns |
| 87 // true on success. This function is safe to call multiple times. Returns |
| 88 // false if already corresponding component extension is unloaded. |
| 89 bool UnloadComponentExtensionIME(Profile* profile, |
| 90 const std::string& input_method_id); |
| 91 |
| 92 // Returns true if |input_method_id| is whitelisted component extension input |
| 93 // method. |
| 94 bool IsWhitelisted(const std::string& input_method_id); |
| 95 |
| 96 // Returns true if |extension_id| is whitelisted component extension. |
| 97 bool IsWhitelistedExtension(const std::string& extension_id); |
| 98 |
| 99 // Returns all IME as InputMethodDescriptors. |
| 100 input_method::InputMethodDescriptors GetAllIMEAsInputMethodDescriptor(); |
| 101 |
| 102 // Returns all XKB keyboard IME as InputMethodDescriptors. |
| 103 input_method::InputMethodDescriptors GetXkbIMEAsInputMethodDescriptor(); |
| 104 |
| 105 private: |
| 106 // Finds ComponentExtensionIME and EngineDescription associated with |
| 107 // |input_method_id|. This function retruns true if it is found, otherwise |
| 108 // returns false. |out_extension| and |out_engine| can be NULL. |
| 109 bool FindEngineEntry(const std::string& input_method_id, |
| 110 ComponentExtensionIME* out_extension); |
| 111 |
| 112 bool IsInLoginLayoutWhitelist(const std::vector<std::string>& layouts); |
| 113 |
| 114 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate_; |
| 115 |
| 116 // The map of extension_id to ComponentExtensionIME instance. |
| 117 // It's filled by Initialize() method and never changed during runtime. |
| 118 std::map<std::string, ComponentExtensionIME> component_extension_imes_; |
| 119 |
| 120 // For quick check the validity of a given input method id. |
| 121 // It's filled by Initialize() method and never changed during runtime. |
| 122 std::set<std::string> input_method_id_set_; |
| 123 |
| 124 std::set<std::string> login_layout_set_; |
| 125 |
| 126 DISALLOW_COPY_AND_ASSIGN(ComponentExtensionIMEManager); |
| 127 }; |
| 128 |
| 129 } // namespace chromeos |
| 130 |
| 131 #endif // CHROMEOS_IME_COMPONENT_EXTENSION_IME_MANAGER_H_ |
OLD | NEW |