Add ICU message format support
[chromium-blink-merge.git] / ui / base / ime / chromeos / component_extension_ime_manager.h
blobcdb9d757715d8d5917e6102d4d57b4fb0c4b2236
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 UI_BASE_IME_CHROMEOS_COMPONENT_EXTENSION_IME_MANAGER_H_
6 #define UI_BASE_IME_CHROMEOS_COMPONENT_EXTENSION_IME_MANAGER_H_
8 #include <map>
9 #include <set>
11 #include "base/files/file_path.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/observer_list.h"
14 #include "ui/base/ime/chromeos/input_method_descriptor.h"
15 #include "ui/base/ime/ui_base_ime_export.h"
17 class Profile;
19 namespace chromeos {
21 // Represents an engine in component extension IME.
22 struct UI_BASE_IME_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.
35 // Represents a component extension IME.
36 struct UI_BASE_IME_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;
47 // Provides an interface to list/load/unload for component extension IME.
48 class UI_BASE_IME_EXPORT ComponentExtensionIMEManagerDelegate {
49 public:
50 ComponentExtensionIMEManagerDelegate();
51 virtual ~ComponentExtensionIMEManagerDelegate();
53 // Lists installed component extension IMEs.
54 virtual std::vector<ComponentExtensionIME> ListIME() = 0;
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;
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;
69 // This class manages component extension input method.
70 class UI_BASE_IME_EXPORT ComponentExtensionIMEManager {
71 public:
72 ComponentExtensionIMEManager();
73 virtual ~ComponentExtensionIMEManager();
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);
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);
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);
92 // Returns true if |input_method_id| is whitelisted component extension input
93 // method.
94 bool IsWhitelisted(const std::string& input_method_id);
96 // Returns true if |extension_id| is whitelisted component extension.
97 bool IsWhitelistedExtension(const std::string& extension_id);
99 // Returns all IME as InputMethodDescriptors.
100 input_method::InputMethodDescriptors GetAllIMEAsInputMethodDescriptor();
102 // Returns all XKB keyboard IME as InputMethodDescriptors.
103 input_method::InputMethodDescriptors GetXkbIMEAsInputMethodDescriptor();
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);
112 bool IsInLoginLayoutWhitelist(const std::vector<std::string>& layouts);
114 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate_;
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_;
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_;
124 std::set<std::string> login_layout_set_;
126 DISALLOW_COPY_AND_ASSIGN(ComponentExtensionIMEManager);
129 } // namespace chromeos
131 #endif // UI_BASE_IME_CHROMEOS_COMPONENT_EXTENSION_IME_MANAGER_H_