OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromeos/ime/component_extension_ime_manager.h" | 5 #include "chromeos/ime/component_extension_ime_manager.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "chromeos/ime/extension_ime_util.h" | 9 #include "chromeos/ime/extension_ime_util.h" |
10 | 10 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 68 |
69 ComponentExtensionIME::~ComponentExtensionIME() { | 69 ComponentExtensionIME::~ComponentExtensionIME() { |
70 } | 70 } |
71 | 71 |
72 ComponentExtensionIMEManagerDelegate::ComponentExtensionIMEManagerDelegate() { | 72 ComponentExtensionIMEManagerDelegate::ComponentExtensionIMEManagerDelegate() { |
73 } | 73 } |
74 | 74 |
75 ComponentExtensionIMEManagerDelegate::~ComponentExtensionIMEManagerDelegate() { | 75 ComponentExtensionIMEManagerDelegate::~ComponentExtensionIMEManagerDelegate() { |
76 } | 76 } |
77 | 77 |
78 ComponentExtensionIMEManager::ComponentExtensionIMEManager() | 78 ComponentExtensionIMEManager::ComponentExtensionIMEManager() { |
79 : is_initialized_(false), was_initialization_notified_(false) { | |
80 for (size_t i = 0; i < arraysize(kLoginLayoutWhitelist); ++i) { | 79 for (size_t i = 0; i < arraysize(kLoginLayoutWhitelist); ++i) { |
81 login_layout_set_.insert(kLoginLayoutWhitelist[i]); | 80 login_layout_set_.insert(kLoginLayoutWhitelist[i]); |
82 } | 81 } |
83 } | 82 } |
84 | 83 |
85 ComponentExtensionIMEManager::~ComponentExtensionIMEManager() { | 84 ComponentExtensionIMEManager::~ComponentExtensionIMEManager() { |
86 } | 85 } |
87 | 86 |
88 void ComponentExtensionIMEManager::Initialize( | 87 void ComponentExtensionIMEManager::Initialize( |
89 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate) { | 88 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate) { |
90 delegate_ = delegate.Pass(); | 89 delegate_ = delegate.Pass(); |
91 component_extension_imes_ = delegate_->ListIME(); | 90 component_extension_imes_ = delegate_->ListIME(); |
92 is_initialized_ = true; | |
93 } | |
94 | |
95 void ComponentExtensionIMEManager::NotifyInitialized() { | |
96 if (is_initialized_ && !was_initialization_notified_) { | |
97 FOR_EACH_OBSERVER( | |
98 Observer, observers_, OnImeComponentExtensionInitialized()); | |
99 was_initialization_notified_ = true; | |
100 } | |
101 } | |
102 | |
103 bool ComponentExtensionIMEManager::IsInitialized() { | |
104 return is_initialized_; | |
105 } | 91 } |
106 | 92 |
107 bool ComponentExtensionIMEManager::LoadComponentExtensionIME( | 93 bool ComponentExtensionIMEManager::LoadComponentExtensionIME( |
108 const std::string& input_method_id) { | 94 const std::string& input_method_id) { |
109 ComponentExtensionIME ime; | 95 ComponentExtensionIME ime; |
110 if (FindEngineEntry(input_method_id, &ime, NULL)) | 96 if (FindEngineEntry(input_method_id, &ime, NULL)) |
111 return delegate_->Load(ime.id, ime.manifest, ime.path); | 97 return delegate_->Load(ime.id, ime.manifest, ime.path); |
112 else | 98 else |
113 return false; | 99 return false; |
114 } | 100 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 input_method::InputMethodDescriptors result; | 201 input_method::InputMethodDescriptors result; |
216 const input_method::InputMethodDescriptors& descriptors = | 202 const input_method::InputMethodDescriptors& descriptors = |
217 GetAllIMEAsInputMethodDescriptor(); | 203 GetAllIMEAsInputMethodDescriptor(); |
218 for (size_t i = 0; i < descriptors.size(); ++i) { | 204 for (size_t i = 0; i < descriptors.size(); ++i) { |
219 if (extension_ime_util::IsKeyboardLayoutExtension(descriptors[i].id())) | 205 if (extension_ime_util::IsKeyboardLayoutExtension(descriptors[i].id())) |
220 result.push_back(descriptors[i]); | 206 result.push_back(descriptors[i]); |
221 } | 207 } |
222 return result; | 208 return result; |
223 } | 209 } |
224 | 210 |
225 void ComponentExtensionIMEManager::AddObserver(Observer* observer) { | |
226 observers_.AddObserver(observer); | |
227 } | |
228 | |
229 void ComponentExtensionIMEManager::RemoveObserver(Observer* observer) { | |
230 observers_.RemoveObserver(observer); | |
231 } | |
232 | |
233 bool ComponentExtensionIMEManager::FindEngineEntry( | 211 bool ComponentExtensionIMEManager::FindEngineEntry( |
234 const std::string& input_method_id, | 212 const std::string& input_method_id, |
235 ComponentExtensionIME* out_extension, | 213 ComponentExtensionIME* out_extension, |
236 ComponentExtensionEngine* out_engine) { | 214 ComponentExtensionEngine* out_engine) { |
237 if (!extension_ime_util::IsComponentExtensionIME(input_method_id)) | 215 if (!extension_ime_util::IsComponentExtensionIME(input_method_id)) |
238 return false; | 216 return false; |
239 for (size_t i = 0; i < component_extension_imes_.size(); ++i) { | 217 for (size_t i = 0; i < component_extension_imes_.size(); ++i) { |
240 const std::string extension_id = component_extension_imes_[i].id; | 218 const std::string extension_id = component_extension_imes_[i].id; |
241 const std::vector<ComponentExtensionEngine>& engines = | 219 const std::vector<ComponentExtensionEngine>& engines = |
242 component_extension_imes_[i].engines; | 220 component_extension_imes_[i].engines; |
(...skipping 18 matching lines...) Expand all Loading... |
261 bool ComponentExtensionIMEManager::IsInLoginLayoutWhitelist( | 239 bool ComponentExtensionIMEManager::IsInLoginLayoutWhitelist( |
262 const std::vector<std::string>& layouts) { | 240 const std::vector<std::string>& layouts) { |
263 for (size_t i = 0; i < layouts.size(); ++i) { | 241 for (size_t i = 0; i < layouts.size(); ++i) { |
264 if (login_layout_set_.find(layouts[i]) != login_layout_set_.end()) | 242 if (login_layout_set_.find(layouts[i]) != login_layout_set_.end()) |
265 return true; | 243 return true; |
266 } | 244 } |
267 return false; | 245 return false; |
268 } | 246 } |
269 | 247 |
270 } // namespace chromeos | 248 } // namespace chromeos |
OLD | NEW |