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_
10 #include "base/files/file_path.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/observer_list.h"
13 #include "chromeos/chromeos_export.h"
14 #include "chromeos/ime/input_method_descriptor.h"
18 // Represents an engine in component extension IME.
19 struct CHROMEOS_EXPORT ComponentExtensionEngine
{
20 ComponentExtensionEngine();
21 ~ComponentExtensionEngine();
22 std::string engine_id
; // The engine id.
23 std::string display_name
; // The display name.
24 std::vector
<std::string
> language_codes
; // The engine's language(ex. "en").
25 std::string description
; // The engine description.
26 std::vector
<std::string
> layouts
; // The list of keyboard layout of engine.
29 // Represents a component extension IME.
30 struct CHROMEOS_EXPORT ComponentExtensionIME
{
31 ComponentExtensionIME();
32 ~ComponentExtensionIME();
33 std::string id
; // extension id.
34 std::string manifest
; // the contents of manifest.json
35 std::string description
; // description of extension.
36 GURL options_page_url
; // an URL to option page.
37 GURL input_view_url
; // an URL to input view page.
39 std::vector
<ComponentExtensionEngine
> engines
;
42 // Provides an interface to list/load/unload for component extension IME.
43 class CHROMEOS_EXPORT ComponentExtensionIMEManagerDelegate
{
45 ComponentExtensionIMEManagerDelegate();
46 virtual ~ComponentExtensionIMEManagerDelegate();
48 // Lists installed component extension IMEs.
49 virtual std::vector
<ComponentExtensionIME
> ListIME() = 0;
51 // Loads component extension IME associated with |extension_id|.
52 // Returns false if it fails, otherwise returns true.
53 virtual bool Load(const std::string
& extension_id
,
54 const std::string
& manifest
,
55 const base::FilePath
& path
) = 0;
57 // Unloads component extension IME associated with |extension_id|.
58 virtual void Unload(const std::string
& extension_id
,
59 const base::FilePath
& path
) = 0;
62 // This class manages component extension input method.
63 class CHROMEOS_EXPORT ComponentExtensionIMEManager
{
67 // Called when the initialization is done.
68 virtual void OnImeComponentExtensionInitialized() = 0;
71 ComponentExtensionIMEManager();
72 virtual ~ComponentExtensionIMEManager();
74 // Initializes component extension manager. This function create internal
75 // mapping between input method id and engine components. This function must
76 // be called before using any other function.
77 void Initialize(scoped_ptr
<ComponentExtensionIMEManagerDelegate
> delegate
);
79 // Notifies the observers for the component extension IMEs are initialized.
80 void NotifyInitialized();
82 // Returns true if the initialization is done, otherwise returns false.
85 // Loads |input_method_id| component extension IME. This function returns true
86 // on success. This function is safe to call multiple times. Returns false if
87 // already corresponding component extension is loaded.
88 bool LoadComponentExtensionIME(const std::string
& input_method_id
);
90 // Unloads |input_method_id| component extension IME. This function returns
91 // true on success. This function is safe to call multiple times. Returns
92 // false if already corresponding component extension is unloaded.
93 bool UnloadComponentExtensionIME(const std::string
& input_method_id
);
95 // Returns true if |input_method_id| is whitelisted component extension input
97 bool IsWhitelisted(const std::string
& input_method_id
);
99 // Returns true if |extension_id| is whitelisted component extension.
100 bool IsWhitelistedExtension(const std::string
& extension_id
);
102 // Returns InputMethodId. This function returns empty string if |extension_id|
103 // and |engine_id| is not a whitelisted component extention IME.
104 std::string
GetId(const std::string
& extension_id
,
105 const std::string
& engine_id
);
107 // Returns localized name of |input_method_id|.
108 std::string
GetName(const std::string
& input_method_id
);
110 // Returns localized description of |input_method_id|.
111 std::string
GetDescription(const std::string
& input_method_id
);
113 // Returns list of input method id associated with |language|.
114 std::vector
<std::string
> ListIMEByLanguage(const std::string
& language
);
116 // Returns all IME as InputMethodDescriptors.
117 input_method::InputMethodDescriptors
GetAllIMEAsInputMethodDescriptor();
119 // Returns all XKB keyboard IME as InputMethodDescriptors.
120 input_method::InputMethodDescriptors
GetXkbIMEAsInputMethodDescriptor();
122 void AddObserver(Observer
* observer
);
123 void RemoveObserver(Observer
* observer
);
126 // Finds ComponentExtensionIME and EngineDescription associated with
127 // |input_method_id|. This function retruns true if it is found, otherwise
128 // returns false. |out_extension| and |out_engine| can be NULL.
129 bool FindEngineEntry(const std::string
& input_method_id
,
130 ComponentExtensionIME
* out_extension
,
131 ComponentExtensionEngine
* out_engine
);
133 bool IsInLoginLayoutWhitelist(const std::vector
<std::string
>& layouts
);
135 scoped_ptr
<ComponentExtensionIMEManagerDelegate
> delegate_
;
137 std::vector
<ComponentExtensionIME
> component_extension_imes_
;
139 ObserverList
<Observer
> observers_
;
141 bool is_initialized_
;
143 bool was_initialization_notified_
;
145 std::set
<std::string
> login_layout_set_
;
147 DISALLOW_COPY_AND_ASSIGN(ComponentExtensionIMEManager
);
150 } // namespace chromeos
152 #endif // CHROMEOS_IME_COMPONENT_EXTENSION_IME_MANAGER_H_