Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / chromeos / ime / component_extension_ime_manager.h
blob98e0bbc26a62779d5a0f0ff19c963bec95fa7134
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 <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 "chromeos/chromeos_export.h"
15 #include "chromeos/ime/input_method_descriptor.h"
17 class Profile;
19 namespace chromeos {
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::vector<std::string> language_codes; // The engine's language(ex. "en").
28 std::string description; // The engine description.
29 std::vector<std::string> layouts; // The list of keyboard layout of engine.
30 GURL options_page_url; // an URL to option page.
31 GURL input_view_url; // an URL to input view page.
34 // Represents a component extension IME.
35 struct CHROMEOS_EXPORT ComponentExtensionIME {
36 ComponentExtensionIME();
37 ~ComponentExtensionIME();
38 std::string id; // extension id.
39 std::string manifest; // the contents of manifest.json
40 std::string description; // description of extension.
41 GURL options_page_url; // an URL to option page.
42 base::FilePath path;
43 std::vector<ComponentExtensionEngine> engines;
46 // Provides an interface to list/load/unload for component extension IME.
47 class CHROMEOS_EXPORT ComponentExtensionIMEManagerDelegate {
48 public:
49 ComponentExtensionIMEManagerDelegate();
50 virtual ~ComponentExtensionIMEManagerDelegate();
52 // Lists installed component extension IMEs.
53 virtual std::vector<ComponentExtensionIME> ListIME() = 0;
55 // Loads component extension IME associated with |extension_id|.
56 // Returns false if it fails, otherwise returns true.
57 virtual void Load(Profile* profile,
58 const std::string& extension_id,
59 const std::string& manifest,
60 const base::FilePath& path) = 0;
62 // Unloads component extension IME associated with |extension_id|.
63 virtual void Unload(Profile* profile,
64 const std::string& extension_id,
65 const base::FilePath& path) = 0;
68 // This class manages component extension input method.
69 class CHROMEOS_EXPORT ComponentExtensionIMEManager {
70 public:
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 // Loads |input_method_id| component extension IME. This function returns true
80 // on success. This function is safe to call multiple times. Returns false if
81 // already corresponding component extension is loaded.
82 bool LoadComponentExtensionIME(Profile* profile,
83 const std::string& input_method_id);
85 // Unloads |input_method_id| component extension IME. This function returns
86 // true on success. This function is safe to call multiple times. Returns
87 // false if already corresponding component extension is unloaded.
88 bool UnloadComponentExtensionIME(Profile* profile,
89 const std::string& input_method_id);
91 // Returns true if |input_method_id| is whitelisted component extension input
92 // method.
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 all IME as InputMethodDescriptors.
99 input_method::InputMethodDescriptors GetAllIMEAsInputMethodDescriptor();
101 // Returns all XKB keyboard IME as InputMethodDescriptors.
102 input_method::InputMethodDescriptors GetXkbIMEAsInputMethodDescriptor();
104 private:
105 // Finds ComponentExtensionIME and EngineDescription associated with
106 // |input_method_id|. This function retruns true if it is found, otherwise
107 // returns false. |out_extension| and |out_engine| can be NULL.
108 bool FindEngineEntry(const std::string& input_method_id,
109 ComponentExtensionIME* out_extension);
111 bool IsInLoginLayoutWhitelist(const std::vector<std::string>& layouts);
113 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate_;
115 // The map of extension_id to ComponentExtensionIME instance.
116 // It's filled by Initialize() method and never changed during runtime.
117 std::map<std::string, ComponentExtensionIME> component_extension_imes_;
119 // For quick check the validity of a given input method id.
120 // It's filled by Initialize() method and never changed during runtime.
121 std::set<std::string> input_method_id_set_;
123 std::set<std::string> login_layout_set_;
125 DISALLOW_COPY_AND_ASSIGN(ComponentExtensionIMEManager);
128 } // namespace chromeos
130 #endif // CHROMEOS_IME_COMPONENT_EXTENSION_IME_MANAGER_H_