Add a comment to the Browser Blacklist List
[chromium-blink-merge.git] / chromeos / ime / component_extension_ime_manager.h
blob11f113f9e0b1750d83e1b258579504bd64936e69
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 <set>
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"
16 namespace chromeos {
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.
27 GURL options_page_url; // an URL to option page.
28 GURL input_view_url; // an URL to input view page.
31 // Represents a component extension IME.
32 struct CHROMEOS_EXPORT ComponentExtensionIME {
33 ComponentExtensionIME();
34 ~ComponentExtensionIME();
35 std::string id; // extension id.
36 std::string manifest; // the contents of manifest.json
37 std::string description; // description of extension.
38 GURL options_page_url; // an URL to option page.
39 base::FilePath path;
40 std::vector<ComponentExtensionEngine> engines;
43 // Provides an interface to list/load/unload for component extension IME.
44 class CHROMEOS_EXPORT ComponentExtensionIMEManagerDelegate {
45 public:
46 ComponentExtensionIMEManagerDelegate();
47 virtual ~ComponentExtensionIMEManagerDelegate();
49 // Lists installed component extension IMEs.
50 virtual std::vector<ComponentExtensionIME> ListIME() = 0;
52 // Loads component extension IME associated with |extension_id|.
53 // Returns false if it fails, otherwise returns true.
54 virtual bool Load(const std::string& extension_id,
55 const std::string& manifest,
56 const base::FilePath& path) = 0;
58 // Unloads component extension IME associated with |extension_id|.
59 virtual void Unload(const std::string& extension_id,
60 const base::FilePath& path) = 0;
63 // This class manages component extension input method.
64 class CHROMEOS_EXPORT ComponentExtensionIMEManager {
65 public:
66 class Observer {
67 public:
68 // Called when the initialization is done.
69 virtual void OnImeComponentExtensionInitialized() = 0;
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 // Notifies the observers for the component extension IMEs are initialized.
81 void NotifyInitialized();
83 // Returns true if the initialization is done, otherwise returns false.
84 bool IsInitialized();
86 // Loads |input_method_id| component extension IME. This function returns true
87 // on success. This function is safe to call multiple times. Returns false if
88 // already corresponding component extension is loaded.
89 bool LoadComponentExtensionIME(const std::string& input_method_id);
91 // Unloads |input_method_id| component extension IME. This function returns
92 // true on success. This function is safe to call multiple times. Returns
93 // false if already corresponding component extension is unloaded.
94 bool UnloadComponentExtensionIME(const std::string& input_method_id);
96 // Returns true if |input_method_id| is whitelisted component extension input
97 // method.
98 bool IsWhitelisted(const std::string& input_method_id);
100 // Returns true if |extension_id| is whitelisted component extension.
101 bool IsWhitelistedExtension(const std::string& extension_id);
103 // Returns InputMethodId. This function returns empty string if |extension_id|
104 // and |engine_id| is not a whitelisted component extention IME.
105 std::string GetId(const std::string& extension_id,
106 const std::string& engine_id);
108 // Returns localized name of |input_method_id|.
109 std::string GetName(const std::string& input_method_id);
111 // Returns localized description of |input_method_id|.
112 std::string GetDescription(const std::string& input_method_id);
114 // Returns list of input method id associated with |language|.
115 std::vector<std::string> ListIMEByLanguage(const std::string& language);
117 // Returns all IME as InputMethodDescriptors.
118 input_method::InputMethodDescriptors GetAllIMEAsInputMethodDescriptor();
120 // Returns all XKB keyboard IME as InputMethodDescriptors.
121 input_method::InputMethodDescriptors GetXkbIMEAsInputMethodDescriptor();
123 void AddObserver(Observer* observer);
124 void RemoveObserver(Observer* observer);
126 private:
127 // Finds ComponentExtensionIME and EngineDescription associated with
128 // |input_method_id|. This function retruns true if it is found, otherwise
129 // returns false. |out_extension| and |out_engine| can be NULL.
130 bool FindEngineEntry(const std::string& input_method_id,
131 ComponentExtensionIME* out_extension,
132 ComponentExtensionEngine* out_engine);
134 bool IsInLoginLayoutWhitelist(const std::vector<std::string>& layouts);
136 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate_;
138 std::vector<ComponentExtensionIME> component_extension_imes_;
140 ObserverList<Observer> observers_;
142 bool is_initialized_;
144 bool was_initialization_notified_;
146 std::set<std::string> login_layout_set_;
148 DISALLOW_COPY_AND_ASSIGN(ComponentExtensionIMEManager);
151 } // namespace chromeos
153 #endif // CHROMEOS_IME_COMPONENT_EXTENSION_IME_MANAGER_H_