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.
5 #ifndef CHROMEOS_IME_COMPONENT_EXTENSION_IME_MANAGER_H_
6 #define CHROMEOS_IME_COMPONENT_EXTENSION_IME_MANAGER_H_
8 #include "base/files/file_path.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/observer_list.h"
11 #include "chromeos/chromeos_export.h"
12 #include "chromeos/ime/input_method_descriptor.h"
16 // Represents an engine in component extension IME.
17 struct CHROMEOS_EXPORT ComponentExtensionEngine {
18 ComponentExtensionEngine();
19 ~ComponentExtensionEngine();
20 std::string engine_id; // The engine id.
21 std::string display_name; // The display name.
22 std::vector<std::string> language_codes; // The engine's language(ex. "en").
23 std::string description; // The engine description.
24 std::vector<std::string> layouts; // The list of keyboard layout of engine.
27 // Represents a component extension IME.
28 struct CHROMEOS_EXPORT ComponentExtensionIME {
29 ComponentExtensionIME();
30 ~ComponentExtensionIME();
31 std::string id; // extension id.
32 std::string manifest; // the contents of manifest.json
33 std::string description; // description of extension.
34 GURL options_page_url; // an URL to option page.
35 GURL input_view_url; // an URL to input view page.
37 std::vector<ComponentExtensionEngine> engines;
40 // Provides an interface to list/load/unload for component extension IME.
41 class CHROMEOS_EXPORT ComponentExtensionIMEManagerDelegate {
43 ComponentExtensionIMEManagerDelegate();
44 virtual ~ComponentExtensionIMEManagerDelegate();
46 // Lists installed component extension IMEs.
47 virtual std::vector<ComponentExtensionIME> ListIME() = 0;
49 // Loads component extension IME associated with |extension_id|.
50 // Returns false if it fails, otherwise returns true.
51 virtual bool Load(const std::string& extension_id,
52 const std::string& manifest,
53 const base::FilePath& path) = 0;
55 // Unloads component extension IME associated with |extension_id|.
56 // Returns false if it fails, otherwise returns true;
57 virtual bool Unload(const std::string& extension_id,
58 const base::FilePath& path) = 0;
61 // This class manages component extension input method.
62 class CHROMEOS_EXPORT ComponentExtensionIMEManager {
66 // Called when the initialization is done.
67 virtual void OnInitialized() = 0;
70 ComponentExtensionIMEManager();
71 virtual ~ComponentExtensionIMEManager();
73 // Initializes component extension manager. This function create internal
74 // mapping between input method id and engine components. This function must
75 // be called before using any other function.
76 void Initialize(scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate);
78 // Returns true if the initialization is done, otherwise returns false.
81 // Loads |input_method_id| component extension IME. This function returns true
82 // on success. This function is safe to call multiple times. Returns false if
83 // already corresponding component extension is loaded.
84 bool LoadComponentExtensionIME(const std::string& input_method_id);
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(const std::string& input_method_id);
91 // Returns true if |input_method_id| is whitelisted component extension input
93 bool IsWhitelisted(const std::string& input_method_id);
95 // Returns true if |extension_id| is whitelisted component extension.
96 bool IsWhitelistedExtension(const std::string& extension_id);
98 // Returns InputMethodId. This function returns empty string if |extension_id|
99 // and |engine_id| is not a whitelisted component extention IME.
100 std::string GetId(const std::string& extension_id,
101 const std::string& engine_id);
103 // Returns localized name of |input_method_id|.
104 std::string GetName(const std::string& input_method_id);
106 // Returns localized description of |input_method_id|.
107 std::string GetDescription(const std::string& input_method_id);
109 // Returns list of input method id associated with |language|.
110 std::vector<std::string> ListIMEByLanguage(const std::string& language);
112 // Returns all IME as InputMethodDescriptors.
113 input_method::InputMethodDescriptors GetAllIMEAsInputMethodDescriptor();
115 void AddObserver(Observer* observer);
116 void RemoveObserver(Observer* observer);
119 // Finds ComponentExtensionIME and EngineDescription associated with
120 // |input_method_id|. This function retruns true if it is found, otherwise
121 // returns false. |out_extension| and |out_engine| can be NULL.
122 bool FindEngineEntry(const std::string& input_method_id,
123 ComponentExtensionIME* out_extension,
124 ComponentExtensionEngine* out_engine);
125 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate_;
127 std::vector<ComponentExtensionIME> component_extension_imes_;
129 ObserverList<Observer> observers_;
131 bool is_initialized_;
133 DISALLOW_COPY_AND_ASSIGN(ComponentExtensionIMEManager);
136 } // namespace chromeos
138 #endif // CHROMEOS_IME_COMPONENT_EXTENSION_IME_MANAGER_H_