OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/api/input_ime/input_ime_api.h" | 5 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/chromeos/input_method/input_method_engine.h" | 9 #include "chrome/browser/chromeos/input_method/input_method_engine.h" |
10 #include "chrome/browser/chromeos/login/lock/screen_locker.h" | 10 #include "chrome/browser/chromeos/login/lock/screen_locker.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 71 |
72 if (input.checked) | 72 if (input.checked) |
73 out->modified |= InputMethodEngineInterface::MENU_ITEM_MODIFIED_CHECKED; | 73 out->modified |= InputMethodEngineInterface::MENU_ITEM_MODIFIED_CHECKED; |
74 out->checked = input.checked ? *input.checked : false; | 74 out->checked = input.checked ? *input.checked : false; |
75 | 75 |
76 if (input.enabled) | 76 if (input.enabled) |
77 out->modified |= InputMethodEngineInterface::MENU_ITEM_MODIFIED_ENABLED; | 77 out->modified |= InputMethodEngineInterface::MENU_ITEM_MODIFIED_ENABLED; |
78 out->enabled = input.enabled ? *input.enabled : true; | 78 out->enabled = input.enabled ? *input.enabled : true; |
79 } | 79 } |
80 | 80 |
81 static void DispatchEventToExtension(const std::string& extension_id, | |
82 const std::string& event_name, | |
83 scoped_ptr<base::ListValue> args) { | |
84 Profile* profile = ProfileManager::GetActiveUserProfile(); | |
85 if (event_name != input_ime::OnActivate::kEventName) { | |
86 // For suspended IME extension (e.g. XKB extension), don't awake it by IME | |
87 // events except onActivate. The IME extension should be awake by other | |
88 // events (e.g. runtime.onMessage) from its other pages. | |
89 // This is to save memory for steady state Chrome OS on which the users | |
90 // don't want any IME features. | |
91 extensions::ExtensionSystem* extension_system = | |
92 extensions::ExtensionSystem::Get(profile); | |
93 if (extension_system) { | |
94 const extensions::Extension* extension = | |
95 extension_system->extension_service()->GetExtensionById( | |
96 extension_id, false /* include_disabled */); | |
97 if (!extension) | |
98 return; | |
99 extensions::ProcessManager* process_manager = | |
100 extensions::ProcessManager::Get(profile); | |
101 if (extensions::BackgroundInfo::HasBackgroundPage(extension) && | |
102 !process_manager->GetBackgroundHostForExtension(extension_id)) { | |
103 return; | |
104 } | |
105 } | |
106 } | |
107 | |
108 scoped_ptr<extensions::Event> event(new extensions::Event( | |
109 event_name, args.Pass())); | |
110 event->restrict_to_browser_context = profile; | |
111 extensions::EventRouter::Get(profile) | |
112 ->DispatchEventToExtension(extension_id, event.Pass()); | |
113 } | |
114 | |
115 void CallbackKeyEventHandle(chromeos::input_method::KeyEventHandle* key_data, | 81 void CallbackKeyEventHandle(chromeos::input_method::KeyEventHandle* key_data, |
116 bool handled) { | 82 bool handled) { |
117 base::Callback<void(bool consumed)>* callback = | 83 base::Callback<void(bool consumed)>* callback = |
118 reinterpret_cast<base::Callback<void(bool consumed)>*>(key_data); | 84 reinterpret_cast<base::Callback<void(bool consumed)>*>(key_data); |
119 callback->Run(handled); | 85 callback->Run(handled); |
120 delete callback; | 86 delete callback; |
121 } | 87 } |
122 | 88 |
| 89 extensions::InputImeEventRouter* GetInputImeEventRouter(Profile* profile) { |
| 90 if (profile->HasOffTheRecordProfile()) |
| 91 profile = profile->GetOffTheRecordProfile(); |
| 92 return extensions::InputImeEventRouterFactory::GetInstance()->GetRouter( |
| 93 profile); |
| 94 } |
| 95 |
123 } // namespace | 96 } // namespace |
124 | 97 |
125 namespace chromeos { | 98 namespace chromeos { |
126 class ImeObserver : public InputMethodEngineInterface::Observer { | 99 class ImeObserver : public InputMethodEngineInterface::Observer { |
127 public: | 100 public: |
128 explicit ImeObserver(const std::string& extension_id) | 101 explicit ImeObserver(const std::string& extension_id, Profile* profile) |
129 : extension_id_(extension_id) {} | 102 : extension_id_(extension_id), profile_(profile) {} |
130 | 103 |
131 ~ImeObserver() override {} | 104 ~ImeObserver() override {} |
132 | 105 |
133 void OnActivate(const std::string& component_id) override { | 106 void OnActivate(const std::string& component_id) override { |
134 if (extension_id_.empty() || | 107 if (extension_id_.empty() || |
135 !HasListener(input_ime::OnActivate::kEventName)) | 108 !HasListener(input_ime::OnActivate::kEventName)) |
136 return; | 109 return; |
137 | 110 |
138 scoped_ptr<base::ListValue> args(input_ime::OnActivate::Create( | 111 scoped_ptr<base::ListValue> args(input_ime::OnActivate::Create( |
139 component_id, | 112 component_id, |
140 input_ime::ParseScreenType(GetCurrentScreenType()))); | 113 input_ime::ParseScreenType(GetCurrentScreenType()))); |
141 | 114 |
142 DispatchEventToExtension( | 115 DispatchEventToExtension(input_ime::OnActivate::kEventName, args.Pass()); |
143 extension_id_, input_ime::OnActivate::kEventName, args.Pass()); | |
144 } | 116 } |
145 | 117 |
146 void OnDeactivated(const std::string& component_id) override { | 118 void OnDeactivated(const std::string& component_id) override { |
147 if (extension_id_.empty() || | 119 if (extension_id_.empty() || |
148 !HasListener(input_ime::OnDeactivated::kEventName)) | 120 !HasListener(input_ime::OnDeactivated::kEventName)) |
149 return; | 121 return; |
150 | 122 |
151 scoped_ptr<base::ListValue> args( | 123 scoped_ptr<base::ListValue> args( |
152 input_ime::OnDeactivated::Create(component_id)); | 124 input_ime::OnDeactivated::Create(component_id)); |
153 | 125 |
154 DispatchEventToExtension( | 126 DispatchEventToExtension(input_ime::OnDeactivated::kEventName, args.Pass()); |
155 extension_id_, input_ime::OnDeactivated::kEventName, args.Pass()); | |
156 } | 127 } |
157 | 128 |
158 void OnFocus( | 129 void OnFocus( |
159 const InputMethodEngineInterface::InputContext& context) override { | 130 const InputMethodEngineInterface::InputContext& context) override { |
160 if (extension_id_.empty() || !HasListener(input_ime::OnFocus::kEventName)) | 131 if (extension_id_.empty() || !HasListener(input_ime::OnFocus::kEventName)) |
161 return; | 132 return; |
162 | 133 |
163 input_ime::InputContext context_value; | 134 input_ime::InputContext context_value; |
164 context_value.context_id = context.id; | 135 context_value.context_id = context.id; |
165 context_value.type = input_ime::ParseInputContextType(context.type); | 136 context_value.type = input_ime::ParseInputContextType(context.type); |
166 context_value.auto_correct = context.auto_correct; | 137 context_value.auto_correct = context.auto_correct; |
167 context_value.auto_complete = context.auto_complete; | 138 context_value.auto_complete = context.auto_complete; |
168 context_value.spell_check = context.spell_check; | 139 context_value.spell_check = context.spell_check; |
169 | 140 |
170 scoped_ptr<base::ListValue> args(input_ime::OnFocus::Create(context_value)); | 141 scoped_ptr<base::ListValue> args(input_ime::OnFocus::Create(context_value)); |
171 | 142 |
172 DispatchEventToExtension( | 143 DispatchEventToExtension(input_ime::OnFocus::kEventName, args.Pass()); |
173 extension_id_, input_ime::OnFocus::kEventName, args.Pass()); | |
174 } | 144 } |
175 | 145 |
176 void OnBlur(int context_id) override { | 146 void OnBlur(int context_id) override { |
177 if (extension_id_.empty() || !HasListener(input_ime::OnBlur::kEventName)) | 147 if (extension_id_.empty() || !HasListener(input_ime::OnBlur::kEventName)) |
178 return; | 148 return; |
179 | 149 |
180 scoped_ptr<base::ListValue> args(input_ime::OnBlur::Create(context_id)); | 150 scoped_ptr<base::ListValue> args(input_ime::OnBlur::Create(context_id)); |
181 | 151 |
182 DispatchEventToExtension( | 152 DispatchEventToExtension(input_ime::OnBlur::kEventName, args.Pass()); |
183 extension_id_, input_ime::OnBlur::kEventName, args.Pass()); | |
184 } | 153 } |
185 | 154 |
186 void OnInputContextUpdate( | 155 void OnInputContextUpdate( |
187 const InputMethodEngineInterface::InputContext& context) override { | 156 const InputMethodEngineInterface::InputContext& context) override { |
188 if (extension_id_.empty() || | 157 if (extension_id_.empty() || |
189 !HasListener(input_ime::OnInputContextUpdate::kEventName)) | 158 !HasListener(input_ime::OnInputContextUpdate::kEventName)) |
190 return; | 159 return; |
191 | 160 |
192 input_ime::InputContext context_value; | 161 input_ime::InputContext context_value; |
193 context_value.context_id = context.id; | 162 context_value.context_id = context.id; |
194 context_value.type = input_ime::ParseInputContextType(context.type); | 163 context_value.type = input_ime::ParseInputContextType(context.type); |
195 | 164 |
196 scoped_ptr<base::ListValue> args( | 165 scoped_ptr<base::ListValue> args( |
197 input_ime::OnInputContextUpdate::Create(context_value)); | 166 input_ime::OnInputContextUpdate::Create(context_value)); |
198 | 167 |
199 DispatchEventToExtension(extension_id_, | 168 DispatchEventToExtension(input_ime::OnInputContextUpdate::kEventName, |
200 input_ime::OnInputContextUpdate::kEventName, | |
201 args.Pass()); | 169 args.Pass()); |
202 } | 170 } |
203 | 171 |
204 bool IsInterestedInKeyEvent() const override { | 172 bool IsInterestedInKeyEvent() const override { |
205 return ShouldForwardKeyEvent(); | 173 return ShouldForwardKeyEvent(); |
206 } | 174 } |
207 | 175 |
208 void OnKeyEvent(const std::string& component_id, | 176 void OnKeyEvent(const std::string& component_id, |
209 const InputMethodEngineInterface::KeyboardEvent& event, | 177 const InputMethodEngineInterface::KeyboardEvent& event, |
210 chromeos::input_method::KeyEventHandle* key_data) override { | 178 chromeos::input_method::KeyEventHandle* key_data) override { |
211 if (extension_id_.empty()) | 179 if (extension_id_.empty()) |
212 return; | 180 return; |
213 | 181 |
214 // If there is no listener for the event, no need to dispatch the event to | 182 // If there is no listener for the event, no need to dispatch the event to |
215 // extension. Instead, releases the key event for default system behavior. | 183 // extension. Instead, releases the key event for default system behavior. |
216 if (!ShouldForwardKeyEvent()) { | 184 if (!ShouldForwardKeyEvent()) { |
217 // Continue processing the key event so that the physical keyboard can | 185 // Continue processing the key event so that the physical keyboard can |
218 // still work. | 186 // still work. |
219 CallbackKeyEventHandle(key_data, false); | 187 CallbackKeyEventHandle(key_data, false); |
220 return; | 188 return; |
221 } | 189 } |
222 | 190 |
223 extensions::InputImeEventRouter* ime_event_router = | |
224 extensions::InputImeEventRouter::GetInstance(); | |
225 | |
226 const std::string request_id = | 191 const std::string request_id = |
227 ime_event_router->AddRequest(component_id, key_data); | 192 GetInputImeEventRouter(profile_)->AddRequest(component_id, key_data); |
228 | 193 |
229 input_ime::KeyboardEvent key_data_value; | 194 input_ime::KeyboardEvent key_data_value; |
230 key_data_value.type = input_ime::ParseKeyboardEventType(event.type); | 195 key_data_value.type = input_ime::ParseKeyboardEventType(event.type); |
231 key_data_value.request_id = request_id; | 196 key_data_value.request_id = request_id; |
232 if (!event.extension_id.empty()) | 197 if (!event.extension_id.empty()) |
233 key_data_value.extension_id.reset(new std::string(event.extension_id)); | 198 key_data_value.extension_id.reset(new std::string(event.extension_id)); |
234 key_data_value.key = event.key; | 199 key_data_value.key = event.key; |
235 key_data_value.code = event.code; | 200 key_data_value.code = event.code; |
236 key_data_value.alt_key.reset(new bool(event.alt_key)); | 201 key_data_value.alt_key.reset(new bool(event.alt_key)); |
237 key_data_value.ctrl_key.reset(new bool(event.ctrl_key)); | 202 key_data_value.ctrl_key.reset(new bool(event.ctrl_key)); |
238 key_data_value.shift_key.reset(new bool(event.shift_key)); | 203 key_data_value.shift_key.reset(new bool(event.shift_key)); |
239 key_data_value.caps_lock.reset(new bool(event.caps_lock)); | 204 key_data_value.caps_lock.reset(new bool(event.caps_lock)); |
240 | 205 |
241 scoped_ptr<base::ListValue> args( | 206 scoped_ptr<base::ListValue> args( |
242 input_ime::OnKeyEvent::Create(component_id, key_data_value)); | 207 input_ime::OnKeyEvent::Create(component_id, key_data_value)); |
243 | 208 |
244 DispatchEventToExtension( | 209 DispatchEventToExtension(input_ime::OnKeyEvent::kEventName, args.Pass()); |
245 extension_id_, input_ime::OnKeyEvent::kEventName, args.Pass()); | |
246 } | 210 } |
247 | 211 |
248 void OnCandidateClicked( | 212 void OnCandidateClicked( |
249 const std::string& component_id, | 213 const std::string& component_id, |
250 int candidate_id, | 214 int candidate_id, |
251 InputMethodEngineInterface::MouseButtonEvent button) override { | 215 InputMethodEngineInterface::MouseButtonEvent button) override { |
252 if (extension_id_.empty() || | 216 if (extension_id_.empty() || |
253 !HasListener(input_ime::OnCandidateClicked::kEventName)) | 217 !HasListener(input_ime::OnCandidateClicked::kEventName)) |
254 return; | 218 return; |
255 | 219 |
(...skipping 10 matching lines...) Expand all Loading... |
266 case InputMethodEngineInterface::MOUSE_BUTTON_LEFT: | 230 case InputMethodEngineInterface::MOUSE_BUTTON_LEFT: |
267 // Default to left. | 231 // Default to left. |
268 default: | 232 default: |
269 button_enum = input_ime::MOUSE_BUTTON_LEFT; | 233 button_enum = input_ime::MOUSE_BUTTON_LEFT; |
270 break; | 234 break; |
271 } | 235 } |
272 | 236 |
273 scoped_ptr<base::ListValue> args(input_ime::OnCandidateClicked::Create( | 237 scoped_ptr<base::ListValue> args(input_ime::OnCandidateClicked::Create( |
274 component_id, candidate_id, button_enum)); | 238 component_id, candidate_id, button_enum)); |
275 | 239 |
276 DispatchEventToExtension( | 240 DispatchEventToExtension(input_ime::OnCandidateClicked::kEventName, |
277 extension_id_, input_ime::OnCandidateClicked::kEventName, args.Pass()); | 241 args.Pass()); |
278 } | 242 } |
279 | 243 |
280 void OnMenuItemActivated(const std::string& component_id, | 244 void OnMenuItemActivated(const std::string& component_id, |
281 const std::string& menu_id) override { | 245 const std::string& menu_id) override { |
282 if (extension_id_.empty() || | 246 if (extension_id_.empty() || |
283 !HasListener(input_ime::OnMenuItemActivated::kEventName)) | 247 !HasListener(input_ime::OnMenuItemActivated::kEventName)) |
284 return; | 248 return; |
285 | 249 |
286 scoped_ptr<base::ListValue> args( | 250 scoped_ptr<base::ListValue> args( |
287 input_ime::OnMenuItemActivated::Create(component_id, menu_id)); | 251 input_ime::OnMenuItemActivated::Create(component_id, menu_id)); |
288 | 252 |
289 DispatchEventToExtension( | 253 DispatchEventToExtension(input_ime::OnMenuItemActivated::kEventName, |
290 extension_id_, input_ime::OnMenuItemActivated::kEventName, args.Pass()); | 254 args.Pass()); |
291 } | 255 } |
292 | 256 |
293 void OnSurroundingTextChanged(const std::string& component_id, | 257 void OnSurroundingTextChanged(const std::string& component_id, |
294 const std::string& text, | 258 const std::string& text, |
295 int cursor_pos, | 259 int cursor_pos, |
296 int anchor_pos) override { | 260 int anchor_pos) override { |
297 if (extension_id_.empty() || | 261 if (extension_id_.empty() || |
298 !HasListener(input_ime::OnSurroundingTextChanged::kEventName)) | 262 !HasListener(input_ime::OnSurroundingTextChanged::kEventName)) |
299 return; | 263 return; |
300 | 264 |
301 input_ime::OnSurroundingTextChanged::SurroundingInfo info; | 265 input_ime::OnSurroundingTextChanged::SurroundingInfo info; |
302 info.text = text; | 266 info.text = text; |
303 info.focus = cursor_pos; | 267 info.focus = cursor_pos; |
304 info.anchor = anchor_pos; | 268 info.anchor = anchor_pos; |
305 scoped_ptr<base::ListValue> args( | 269 scoped_ptr<base::ListValue> args( |
306 input_ime::OnSurroundingTextChanged::Create(component_id, info)); | 270 input_ime::OnSurroundingTextChanged::Create(component_id, info)); |
307 | 271 |
308 DispatchEventToExtension(extension_id_, | 272 DispatchEventToExtension(input_ime::OnSurroundingTextChanged::kEventName, |
309 input_ime::OnSurroundingTextChanged::kEventName, | |
310 args.Pass()); | 273 args.Pass()); |
311 } | 274 } |
312 | 275 |
313 void OnCompositionBoundsChanged( | 276 void OnCompositionBoundsChanged( |
314 const std::vector<gfx::Rect>& bounds) override { | 277 const std::vector<gfx::Rect>& bounds) override { |
315 if (extension_id_.empty() || | 278 if (extension_id_.empty() || |
316 !HasListener(kOnCompositionBoundsChangedEventName)) | 279 !HasListener(kOnCompositionBoundsChangedEventName)) |
317 return; | 280 return; |
318 | 281 |
319 // Note: this is a private API event. | 282 // Note: this is a private API event. |
(...skipping 11 matching lines...) Expand all Loading... |
331 return; | 294 return; |
332 scoped_ptr<base::ListValue> args(new base::ListValue()); | 295 scoped_ptr<base::ListValue> args(new base::ListValue()); |
333 | 296 |
334 // The old extension code uses the first parameter to get the bounds of the | 297 // The old extension code uses the first parameter to get the bounds of the |
335 // first composition character, so for backward compatibility, add it here. | 298 // first composition character, so for backward compatibility, add it here. |
336 base::Value* first_value = NULL; | 299 base::Value* first_value = NULL; |
337 if (bounds_list->Get(0, &first_value)) | 300 if (bounds_list->Get(0, &first_value)) |
338 args->Append(first_value->DeepCopy()); | 301 args->Append(first_value->DeepCopy()); |
339 args->Append(bounds_list); | 302 args->Append(bounds_list); |
340 | 303 |
341 DispatchEventToExtension(extension_id_, | 304 DispatchEventToExtension(kOnCompositionBoundsChangedEventName, args.Pass()); |
342 kOnCompositionBoundsChangedEventName, | |
343 args.Pass()); | |
344 } | 305 } |
345 | 306 |
346 void OnReset(const std::string& component_id) override { | 307 void OnReset(const std::string& component_id) override { |
347 if (extension_id_.empty() || !HasListener(input_ime::OnReset::kEventName)) | 308 if (extension_id_.empty() || !HasListener(input_ime::OnReset::kEventName)) |
348 return; | 309 return; |
349 | 310 |
350 scoped_ptr<base::ListValue> args(input_ime::OnReset::Create(component_id)); | 311 scoped_ptr<base::ListValue> args(input_ime::OnReset::Create(component_id)); |
351 | 312 |
352 DispatchEventToExtension( | 313 DispatchEventToExtension(input_ime::OnReset::kEventName, args.Pass()); |
353 extension_id_, input_ime::OnReset::kEventName, args.Pass()); | |
354 } | 314 } |
355 | 315 |
356 private: | 316 private: |
| 317 void DispatchEventToExtension(const std::string& event_name, |
| 318 scoped_ptr<base::ListValue> args) { |
| 319 if (event_name != input_ime::OnActivate::kEventName) { |
| 320 // For suspended IME extension (e.g. XKB extension), don't awake it by IME |
| 321 // events except onActivate. The IME extension should be awake by other |
| 322 // events (e.g. runtime.onMessage) from its other pages. |
| 323 // This is to save memory for steady state Chrome OS on which the users |
| 324 // don't want any IME features. |
| 325 extensions::ExtensionSystem* extension_system = |
| 326 extensions::ExtensionSystem::Get(profile_); |
| 327 if (extension_system) { |
| 328 const extensions::Extension* extension = |
| 329 extension_system->extension_service()->GetExtensionById( |
| 330 extension_id_, false /* include_disabled */); |
| 331 if (!extension) |
| 332 return; |
| 333 extensions::ProcessManager* process_manager = |
| 334 extensions::ProcessManager::Get(profile_); |
| 335 if (extensions::BackgroundInfo::HasBackgroundPage(extension) && |
| 336 !process_manager->GetBackgroundHostForExtension(extension_id_)) { |
| 337 return; |
| 338 } |
| 339 } |
| 340 } |
| 341 |
| 342 scoped_ptr<extensions::Event> event( |
| 343 new extensions::Event(event_name, args.Pass())); |
| 344 event->restrict_to_browser_context = profile_; |
| 345 extensions::EventRouter::Get(profile_) |
| 346 ->DispatchEventToExtension(extension_id_, event.Pass()); |
| 347 } |
| 348 |
357 // Returns true if the extension is ready to accept key event, otherwise | 349 // Returns true if the extension is ready to accept key event, otherwise |
358 // returns false. | 350 // returns false. |
359 bool ShouldForwardKeyEvent() const { | 351 bool ShouldForwardKeyEvent() const { |
360 // Only forward key events to extension if there are non-lazy listeners | 352 // Only forward key events to extension if there are non-lazy listeners |
361 // for onKeyEvent. Because if something wrong with the lazy background | 353 // for onKeyEvent. Because if something wrong with the lazy background |
362 // page which doesn't register listener for onKeyEvent, it will not handle | 354 // page which doesn't register listener for onKeyEvent, it will not handle |
363 // the key events, and therefore, all key events will be eaten. | 355 // the key events, and therefore, all key events will be eaten. |
364 // This is for error-tolerance, and it means that onKeyEvent will never wake | 356 // This is for error-tolerance, and it means that onKeyEvent will never wake |
365 // up lazy background page. | 357 // up lazy background page. |
366 const extensions::EventListenerMap::ListenerList& listener_list = | 358 const extensions::EventListenerMap::ListenerList& listener_list = |
367 extensions::EventRouter::Get(ProfileManager::GetActiveUserProfile()) | 359 extensions::EventRouter::Get(profile_) |
368 ->listeners().GetEventListenersByName( | 360 ->listeners() |
369 input_ime::OnKeyEvent::kEventName); | 361 .GetEventListenersByName(input_ime::OnKeyEvent::kEventName); |
370 for (extensions::EventListenerMap::ListenerList::const_iterator it = | 362 for (extensions::EventListenerMap::ListenerList::const_iterator it = |
371 listener_list.begin(); | 363 listener_list.begin(); |
372 it != listener_list.end(); ++it) { | 364 it != listener_list.end(); ++it) { |
373 if ((*it)->extension_id() == extension_id_ && !(*it)->IsLazy()) | 365 if ((*it)->extension_id() == extension_id_ && !(*it)->IsLazy()) |
374 return true; | 366 return true; |
375 } | 367 } |
376 return false; | 368 return false; |
377 } | 369 } |
378 | 370 |
379 bool HasListener(const std::string& event_name) const { | 371 bool HasListener(const std::string& event_name) const { |
380 return extensions::EventRouter::Get( | 372 return extensions::EventRouter::Get(profile_)->HasEventListener(event_name); |
381 ProfileManager::GetActiveUserProfile())->HasEventListener(event_name); | |
382 } | 373 } |
383 | 374 |
384 // The component IME extensions need to know the current screen type (e.g. | 375 // The component IME extensions need to know the current screen type (e.g. |
385 // lock screen, login screen, etc.) so that its on-screen keyboard page | 376 // lock screen, login screen, etc.) so that its on-screen keyboard page |
386 // won't open new windows/pages. See crbug.com/395621. | 377 // won't open new windows/pages. See crbug.com/395621. |
387 std::string GetCurrentScreenType() { | 378 std::string GetCurrentScreenType() { |
388 switch (chromeos::input_method::InputMethodManager::Get() | 379 switch (chromeos::input_method::InputMethodManager::Get() |
389 ->GetUISessionState()) { | 380 ->GetUISessionState()) { |
390 case chromeos::input_method::InputMethodManager::STATE_LOGIN_SCREEN: | 381 case chromeos::input_method::InputMethodManager::STATE_LOGIN_SCREEN: |
391 return "login"; | 382 return "login"; |
392 case chromeos::input_method::InputMethodManager::STATE_LOCK_SCREEN: | 383 case chromeos::input_method::InputMethodManager::STATE_LOCK_SCREEN: |
393 return "lock"; | 384 return "lock"; |
394 case chromeos::input_method::InputMethodManager::STATE_BROWSER_SCREEN: | 385 case chromeos::input_method::InputMethodManager::STATE_BROWSER_SCREEN: |
395 return UserAddingScreen::Get()->IsRunning() ? "secondary-login" | 386 return UserAddingScreen::Get()->IsRunning() ? "secondary-login" |
396 : "normal"; | 387 : "normal"; |
397 case chromeos::input_method::InputMethodManager::STATE_TERMINATING: | 388 case chromeos::input_method::InputMethodManager::STATE_TERMINATING: |
398 return "normal"; | 389 return "normal"; |
399 } | 390 } |
400 NOTREACHED() << "New screen type is added. Please add new entry above."; | 391 NOTREACHED() << "New screen type is added. Please add new entry above."; |
401 return "normal"; | 392 return "normal"; |
402 } | 393 } |
403 | 394 |
404 std::string extension_id_; | 395 std::string extension_id_; |
| 396 Profile* profile_; |
405 | 397 |
406 DISALLOW_COPY_AND_ASSIGN(ImeObserver); | 398 DISALLOW_COPY_AND_ASSIGN(ImeObserver); |
407 }; | 399 }; |
408 | 400 |
409 } // namespace chromeos | 401 } // namespace chromeos |
410 | 402 |
411 namespace extensions { | 403 namespace extensions { |
412 | 404 |
413 InputImeEventRouter* | 405 InputImeEventRouterFactory* InputImeEventRouterFactory::GetInstance() { |
414 InputImeEventRouter::GetInstance() { | 406 return Singleton<InputImeEventRouterFactory>::get(); |
415 return Singleton<InputImeEventRouter>::get(); | 407 } |
| 408 |
| 409 InputImeEventRouterFactory::InputImeEventRouterFactory() { |
| 410 } |
| 411 |
| 412 InputImeEventRouterFactory::~InputImeEventRouterFactory() { |
| 413 } |
| 414 |
| 415 InputImeEventRouter* InputImeEventRouterFactory::GetRouter(Profile* profile) { |
| 416 InputImeEventRouter* router = router_map_[profile]; |
| 417 if (!router) { |
| 418 router = new InputImeEventRouter(profile); |
| 419 router_map_[profile] = router; |
| 420 } |
| 421 return router; |
| 422 } |
| 423 |
| 424 InputImeEventRouter::InputImeEventRouter(Profile* profile) |
| 425 : next_request_id_(1), profile_(profile) { |
| 426 } |
| 427 |
| 428 InputImeEventRouter::~InputImeEventRouter() { |
416 } | 429 } |
417 | 430 |
418 bool InputImeEventRouter::RegisterImeExtension( | 431 bool InputImeEventRouter::RegisterImeExtension( |
419 Profile* profile, | |
420 const std::string& extension_id, | 432 const std::string& extension_id, |
421 const std::vector<extensions::InputComponentInfo>& input_components) { | 433 const std::vector<extensions::InputComponentInfo>& input_components) { |
422 VLOG(1) << "RegisterImeExtension: " << extension_id; | 434 VLOG(1) << "RegisterImeExtension: " << extension_id; |
423 | 435 |
424 if (engine_map_[extension_id]) | 436 if (engine_map_[extension_id]) |
425 return false; | 437 return false; |
426 | 438 |
427 chromeos::input_method::InputMethodManager* manager = | 439 chromeos::input_method::InputMethodManager* manager = |
428 chromeos::input_method::InputMethodManager::Get(); | 440 chromeos::input_method::InputMethodManager::Get(); |
429 chromeos::ComponentExtensionIMEManager* comp_ext_ime_manager = | 441 chromeos::ComponentExtensionIMEManager* comp_ext_ime_manager = |
(...skipping 24 matching lines...) Expand all Loading... |
454 std::string(), // TODO(uekawa): Set short name. | 466 std::string(), // TODO(uekawa): Set short name. |
455 layouts, | 467 layouts, |
456 languages, | 468 languages, |
457 false, // 3rd party IMEs are always not for login. | 469 false, // 3rd party IMEs are always not for login. |
458 component.options_page_url, | 470 component.options_page_url, |
459 component.input_view_url)); | 471 component.input_view_url)); |
460 } | 472 } |
461 } | 473 } |
462 | 474 |
463 scoped_ptr<chromeos::InputMethodEngineInterface::Observer> observer( | 475 scoped_ptr<chromeos::InputMethodEngineInterface::Observer> observer( |
464 new chromeos::ImeObserver(extension_id)); | 476 new chromeos::ImeObserver(extension_id, profile_)); |
465 chromeos::InputMethodEngine* engine = new chromeos::InputMethodEngine(); | 477 chromeos::InputMethodEngine* engine = new chromeos::InputMethodEngine(); |
466 engine->Initialize(observer.Pass(), extension_id.c_str()); | 478 engine->Initialize(observer.Pass(), extension_id.c_str(), profile_); |
467 engine_map_[extension_id] = engine; | 479 engine_map_[extension_id] = engine; |
468 chromeos::UserSessionManager::GetInstance() | 480 chromeos::UserSessionManager::GetInstance() |
469 ->GetDefaultIMEState(profile) | 481 ->GetDefaultIMEState(profile_) |
470 ->AddInputMethodExtension(extension_id, descriptors, engine); | 482 ->AddInputMethodExtension(extension_id, descriptors, engine); |
471 | 483 |
472 return true; | 484 return true; |
473 } | 485 } |
474 | 486 |
475 void InputImeEventRouter::UnregisterAllImes(const std::string& extension_id) { | 487 void InputImeEventRouter::UnregisterAllImes(const std::string& extension_id) { |
476 std::map<std::string, InputMethodEngineInterface*>::iterator it = | 488 std::map<std::string, InputMethodEngineInterface*>::iterator it = |
477 engine_map_.find(extension_id); | 489 engine_map_.find(extension_id); |
478 if (it != engine_map_.end()) { | 490 if (it != engine_map_.end()) { |
479 chromeos::input_method::InputMethodManager::Get() | 491 chromeos::input_method::InputMethodManager::Get() |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 const std::string& component_id, | 536 const std::string& component_id, |
525 chromeos::input_method::KeyEventHandle* key_data) { | 537 chromeos::input_method::KeyEventHandle* key_data) { |
526 std::string request_id = base::IntToString(next_request_id_); | 538 std::string request_id = base::IntToString(next_request_id_); |
527 ++next_request_id_; | 539 ++next_request_id_; |
528 | 540 |
529 request_map_[request_id] = std::make_pair(component_id, key_data); | 541 request_map_[request_id] = std::make_pair(component_id, key_data); |
530 | 542 |
531 return request_id; | 543 return request_id; |
532 } | 544 } |
533 | 545 |
534 InputImeEventRouter::InputImeEventRouter() | |
535 : next_request_id_(1) { | |
536 } | |
537 | |
538 InputImeEventRouter::~InputImeEventRouter() {} | |
539 | |
540 bool InputImeSetCompositionFunction::RunSync() { | 546 bool InputImeSetCompositionFunction::RunSync() { |
541 InputMethodEngineInterface* engine = | 547 InputMethodEngineInterface* engine = |
542 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); | 548 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
| 549 ->GetActiveEngine(extension_id()); |
543 if (!engine) { | 550 if (!engine) { |
544 SetResult(new base::FundamentalValue(false)); | 551 SetResult(new base::FundamentalValue(false)); |
545 return true; | 552 return true; |
546 } | 553 } |
547 | 554 |
548 scoped_ptr<SetComposition::Params> parent_params( | 555 scoped_ptr<SetComposition::Params> parent_params( |
549 SetComposition::Params::Create(*args_)); | 556 SetComposition::Params::Create(*args_)); |
550 const SetComposition::Params::Parameters& params = parent_params->parameters; | 557 const SetComposition::Params::Parameters& params = parent_params->parameters; |
551 std::vector<InputMethodEngineInterface::SegmentInfo> segments; | 558 std::vector<InputMethodEngineInterface::SegmentInfo> segments; |
552 if (params.segments) { | 559 if (params.segments) { |
(...skipping 29 matching lines...) Expand all Loading... |
582 | 589 |
583 SetResult(new base::FundamentalValue( | 590 SetResult(new base::FundamentalValue( |
584 engine->SetComposition(params.context_id, params.text.c_str(), | 591 engine->SetComposition(params.context_id, params.text.c_str(), |
585 selection_start, selection_end, params.cursor, | 592 selection_start, selection_end, params.cursor, |
586 segments, &error_))); | 593 segments, &error_))); |
587 return true; | 594 return true; |
588 } | 595 } |
589 | 596 |
590 bool InputImeClearCompositionFunction::RunSync() { | 597 bool InputImeClearCompositionFunction::RunSync() { |
591 InputMethodEngineInterface* engine = | 598 InputMethodEngineInterface* engine = |
592 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); | 599 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
| 600 ->GetActiveEngine(extension_id()); |
593 if (!engine) { | 601 if (!engine) { |
594 SetResult(new base::FundamentalValue(false)); | 602 SetResult(new base::FundamentalValue(false)); |
595 return true; | 603 return true; |
596 } | 604 } |
597 | 605 |
598 scoped_ptr<ClearComposition::Params> parent_params( | 606 scoped_ptr<ClearComposition::Params> parent_params( |
599 ClearComposition::Params::Create(*args_)); | 607 ClearComposition::Params::Create(*args_)); |
600 const ClearComposition::Params::Parameters& params = | 608 const ClearComposition::Params::Parameters& params = |
601 parent_params->parameters; | 609 parent_params->parameters; |
602 | 610 |
603 SetResult(new base::FundamentalValue( | 611 SetResult(new base::FundamentalValue( |
604 engine->ClearComposition(params.context_id, &error_))); | 612 engine->ClearComposition(params.context_id, &error_))); |
605 return true; | 613 return true; |
606 } | 614 } |
607 | 615 |
608 bool InputImeCommitTextFunction::RunSync() { | 616 bool InputImeCommitTextFunction::RunSync() { |
609 // TODO(zork): Support committing when not active. | |
610 InputMethodEngineInterface* engine = | 617 InputMethodEngineInterface* engine = |
611 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); | 618 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
| 619 ->GetActiveEngine(extension_id()); |
612 if (!engine) { | 620 if (!engine) { |
613 SetResult(new base::FundamentalValue(false)); | 621 SetResult(new base::FundamentalValue(false)); |
614 return true; | 622 return true; |
615 } | 623 } |
616 | 624 |
617 scoped_ptr<CommitText::Params> parent_params( | 625 scoped_ptr<CommitText::Params> parent_params( |
618 CommitText::Params::Create(*args_)); | 626 CommitText::Params::Create(*args_)); |
619 const CommitText::Params::Parameters& params = | 627 const CommitText::Params::Parameters& params = |
620 parent_params->parameters; | 628 parent_params->parameters; |
621 | 629 |
622 SetResult(new base::FundamentalValue( | 630 SetResult(new base::FundamentalValue( |
623 engine->CommitText(params.context_id, params.text.c_str(), &error_))); | 631 engine->CommitText(params.context_id, params.text.c_str(), &error_))); |
624 return true; | 632 return true; |
625 } | 633 } |
626 | 634 |
627 bool InputImeHideInputViewFunction::RunAsync() { | 635 bool InputImeHideInputViewFunction::RunAsync() { |
628 InputMethodEngineInterface* engine = | 636 InputMethodEngineInterface* engine = |
629 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); | 637 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
| 638 ->GetActiveEngine(extension_id()); |
630 if (!engine) { | 639 if (!engine) { |
631 return true; | 640 return true; |
632 } | 641 } |
633 engine->HideInputView(); | 642 engine->HideInputView(); |
634 return true; | 643 return true; |
635 } | 644 } |
636 | 645 |
637 bool InputImeSendKeyEventsFunction::RunAsync() { | 646 bool InputImeSendKeyEventsFunction::RunAsync() { |
638 scoped_ptr<SendKeyEvents::Params> parent_params( | 647 scoped_ptr<SendKeyEvents::Params> parent_params( |
639 SendKeyEvents::Params::Create(*args_)); | 648 SendKeyEvents::Params::Create(*args_)); |
640 const SendKeyEvents::Params::Parameters& params = | 649 const SendKeyEvents::Params::Parameters& params = |
641 parent_params->parameters; | 650 parent_params->parameters; |
642 chromeos::InputMethodEngineInterface* engine = | 651 InputMethodEngineInterface* engine = |
643 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); | 652 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
| 653 ->GetActiveEngine(extension_id()); |
644 if (!engine) { | 654 if (!engine) { |
645 error_ = kErrorEngineNotAvailable; | 655 error_ = kErrorEngineNotAvailable; |
646 return false; | 656 return false; |
647 } | 657 } |
648 | 658 |
649 const std::vector<linked_ptr<input_ime::KeyboardEvent> >& key_data = | 659 const std::vector<linked_ptr<input_ime::KeyboardEvent> >& key_data = |
650 params.key_data; | 660 params.key_data; |
651 std::vector<chromeos::InputMethodEngineInterface::KeyboardEvent> key_data_out; | 661 std::vector<chromeos::InputMethodEngineInterface::KeyboardEvent> key_data_out; |
652 | 662 |
653 for (size_t i = 0; i < key_data.size(); ++i) { | 663 for (size_t i = 0; i < key_data.size(); ++i) { |
(...skipping 17 matching lines...) Expand all Loading... |
671 return true; | 681 return true; |
672 } | 682 } |
673 | 683 |
674 bool InputImeSetCandidateWindowPropertiesFunction::RunSync() { | 684 bool InputImeSetCandidateWindowPropertiesFunction::RunSync() { |
675 scoped_ptr<SetCandidateWindowProperties::Params> parent_params( | 685 scoped_ptr<SetCandidateWindowProperties::Params> parent_params( |
676 SetCandidateWindowProperties::Params::Create(*args_)); | 686 SetCandidateWindowProperties::Params::Create(*args_)); |
677 const SetCandidateWindowProperties::Params::Parameters& | 687 const SetCandidateWindowProperties::Params::Parameters& |
678 params = parent_params->parameters; | 688 params = parent_params->parameters; |
679 | 689 |
680 InputMethodEngineInterface* engine = | 690 InputMethodEngineInterface* engine = |
681 InputImeEventRouter::GetInstance()->GetEngine(extension_id(), | 691 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
682 params.engine_id); | 692 ->GetEngine(extension_id(), params.engine_id); |
683 | |
684 if (!engine) { | 693 if (!engine) { |
685 SetResult(new base::FundamentalValue(false)); | 694 SetResult(new base::FundamentalValue(false)); |
686 return true; | 695 return true; |
687 } | 696 } |
688 | 697 |
689 const SetCandidateWindowProperties::Params::Parameters::Properties& | 698 const SetCandidateWindowProperties::Params::Parameters::Properties& |
690 properties = params.properties; | 699 properties = params.properties; |
691 | 700 |
692 if (properties.visible && | 701 if (properties.visible && |
693 !engine->SetCandidateWindowVisible(*properties.visible, &error_)) { | 702 !engine->SetCandidateWindowVisible(*properties.visible, &error_)) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 engine->SetCandidateWindowProperty(properties_out); | 746 engine->SetCandidateWindowProperty(properties_out); |
738 } | 747 } |
739 | 748 |
740 SetResult(new base::FundamentalValue(true)); | 749 SetResult(new base::FundamentalValue(true)); |
741 | 750 |
742 return true; | 751 return true; |
743 } | 752 } |
744 | 753 |
745 bool InputImeSetCandidatesFunction::RunSync() { | 754 bool InputImeSetCandidatesFunction::RunSync() { |
746 InputMethodEngineInterface* engine = | 755 InputMethodEngineInterface* engine = |
747 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); | 756 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
| 757 ->GetActiveEngine(extension_id()); |
748 if (!engine) { | 758 if (!engine) { |
749 SetResult(new base::FundamentalValue(false)); | 759 SetResult(new base::FundamentalValue(false)); |
750 return true; | 760 return true; |
751 } | 761 } |
752 | 762 |
753 scoped_ptr<SetCandidates::Params> parent_params( | 763 scoped_ptr<SetCandidates::Params> parent_params( |
754 SetCandidates::Params::Create(*args_)); | 764 SetCandidates::Params::Create(*args_)); |
755 const SetCandidates::Params::Parameters& params = | 765 const SetCandidates::Params::Parameters& params = |
756 parent_params->parameters; | 766 parent_params->parameters; |
757 | 767 |
(...skipping 15 matching lines...) Expand all Loading... |
773 } | 783 } |
774 } | 784 } |
775 | 785 |
776 SetResult(new base::FundamentalValue( | 786 SetResult(new base::FundamentalValue( |
777 engine->SetCandidates(params.context_id, candidates_out, &error_))); | 787 engine->SetCandidates(params.context_id, candidates_out, &error_))); |
778 return true; | 788 return true; |
779 } | 789 } |
780 | 790 |
781 bool InputImeSetCursorPositionFunction::RunSync() { | 791 bool InputImeSetCursorPositionFunction::RunSync() { |
782 InputMethodEngineInterface* engine = | 792 InputMethodEngineInterface* engine = |
783 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); | 793 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
| 794 ->GetActiveEngine(extension_id()); |
784 if (!engine) { | 795 if (!engine) { |
785 SetResult(new base::FundamentalValue(false)); | 796 SetResult(new base::FundamentalValue(false)); |
786 return true; | 797 return true; |
787 } | 798 } |
788 | 799 |
789 scoped_ptr<SetCursorPosition::Params> parent_params( | 800 scoped_ptr<SetCursorPosition::Params> parent_params( |
790 SetCursorPosition::Params::Create(*args_)); | 801 SetCursorPosition::Params::Create(*args_)); |
791 const SetCursorPosition::Params::Parameters& params = | 802 const SetCursorPosition::Params::Parameters& params = |
792 parent_params->parameters; | 803 parent_params->parameters; |
793 | 804 |
794 SetResult(new base::FundamentalValue( | 805 SetResult(new base::FundamentalValue( |
795 engine->SetCursorPosition(params.context_id, params.candidate_id, | 806 engine->SetCursorPosition(params.context_id, params.candidate_id, |
796 &error_))); | 807 &error_))); |
797 return true; | 808 return true; |
798 } | 809 } |
799 | 810 |
800 bool InputImeSetMenuItemsFunction::RunSync() { | 811 bool InputImeSetMenuItemsFunction::RunSync() { |
801 scoped_ptr<SetMenuItems::Params> parent_params( | 812 scoped_ptr<SetMenuItems::Params> parent_params( |
802 SetMenuItems::Params::Create(*args_)); | 813 SetMenuItems::Params::Create(*args_)); |
803 const SetMenuItems::Params::Parameters& params = | 814 const SetMenuItems::Params::Parameters& params = |
804 parent_params->parameters; | 815 parent_params->parameters; |
805 | 816 |
806 InputMethodEngineInterface* engine = | 817 InputMethodEngineInterface* engine = |
807 InputImeEventRouter::GetInstance()->GetEngine(extension_id(), | 818 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
808 params.engine_id); | 819 ->GetEngine(extension_id(), params.engine_id); |
809 if (!engine) { | 820 if (!engine) { |
810 error_ = kErrorEngineNotAvailable; | 821 error_ = kErrorEngineNotAvailable; |
811 return false; | 822 return false; |
812 } | 823 } |
813 | 824 |
814 const std::vector<linked_ptr<input_ime::MenuItem> >& items = params.items; | 825 const std::vector<linked_ptr<input_ime::MenuItem> >& items = params.items; |
815 std::vector<InputMethodEngineInterface::MenuItem> items_out; | 826 std::vector<InputMethodEngineInterface::MenuItem> items_out; |
816 | 827 |
817 for (size_t i = 0; i < items.size(); ++i) { | 828 for (size_t i = 0; i < items.size(); ++i) { |
818 items_out.push_back(InputMethodEngineInterface::MenuItem()); | 829 items_out.push_back(InputMethodEngineInterface::MenuItem()); |
819 SetMenuItemToMenu(*items[i], &items_out.back()); | 830 SetMenuItemToMenu(*items[i], &items_out.back()); |
820 } | 831 } |
821 | 832 |
822 if (!engine->SetMenuItems(items_out)) | 833 if (!engine->SetMenuItems(items_out)) |
823 error_ = kErrorSetMenuItemsFail; | 834 error_ = kErrorSetMenuItemsFail; |
824 return true; | 835 return true; |
825 } | 836 } |
826 | 837 |
827 bool InputImeUpdateMenuItemsFunction::RunSync() { | 838 bool InputImeUpdateMenuItemsFunction::RunSync() { |
828 scoped_ptr<UpdateMenuItems::Params> parent_params( | 839 scoped_ptr<UpdateMenuItems::Params> parent_params( |
829 UpdateMenuItems::Params::Create(*args_)); | 840 UpdateMenuItems::Params::Create(*args_)); |
830 const UpdateMenuItems::Params::Parameters& params = | 841 const UpdateMenuItems::Params::Parameters& params = |
831 parent_params->parameters; | 842 parent_params->parameters; |
832 | 843 |
833 InputMethodEngineInterface* engine = | 844 InputMethodEngineInterface* engine = |
834 InputImeEventRouter::GetInstance()->GetEngine(extension_id(), | 845 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
835 params.engine_id); | 846 ->GetEngine(extension_id(), params.engine_id); |
836 if (!engine) { | 847 if (!engine) { |
837 error_ = kErrorEngineNotAvailable; | 848 error_ = kErrorEngineNotAvailable; |
838 return false; | 849 return false; |
839 } | 850 } |
840 | 851 |
841 const std::vector<linked_ptr<input_ime::MenuItem> >& items = params.items; | 852 const std::vector<linked_ptr<input_ime::MenuItem> >& items = params.items; |
842 std::vector<InputMethodEngineInterface::MenuItem> items_out; | 853 std::vector<InputMethodEngineInterface::MenuItem> items_out; |
843 | 854 |
844 for (size_t i = 0; i < items.size(); ++i) { | 855 for (size_t i = 0; i < items.size(); ++i) { |
845 items_out.push_back(InputMethodEngineInterface::MenuItem()); | 856 items_out.push_back(InputMethodEngineInterface::MenuItem()); |
846 SetMenuItemToMenu(*items[i], &items_out.back()); | 857 SetMenuItemToMenu(*items[i], &items_out.back()); |
847 } | 858 } |
848 | 859 |
849 if (!engine->UpdateMenuItems(items_out)) | 860 if (!engine->UpdateMenuItems(items_out)) |
850 error_ = kErrorUpdateMenuItemsFail; | 861 error_ = kErrorUpdateMenuItemsFail; |
851 return true; | 862 return true; |
852 } | 863 } |
853 | 864 |
854 bool InputImeDeleteSurroundingTextFunction::RunSync() { | 865 bool InputImeDeleteSurroundingTextFunction::RunSync() { |
855 scoped_ptr<DeleteSurroundingText::Params> parent_params( | 866 scoped_ptr<DeleteSurroundingText::Params> parent_params( |
856 DeleteSurroundingText::Params::Create(*args_)); | 867 DeleteSurroundingText::Params::Create(*args_)); |
857 const DeleteSurroundingText::Params::Parameters& params = | 868 const DeleteSurroundingText::Params::Parameters& params = |
858 parent_params->parameters; | 869 parent_params->parameters; |
859 | 870 |
860 InputMethodEngineInterface* engine = | 871 InputMethodEngineInterface* engine = |
861 InputImeEventRouter::GetInstance()->GetEngine(extension_id(), | 872 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
862 params.engine_id); | 873 ->GetEngine(extension_id(), params.engine_id); |
863 if (!engine) { | 874 if (!engine) { |
864 error_ = kErrorEngineNotAvailable; | 875 error_ = kErrorEngineNotAvailable; |
865 return false; | 876 return false; |
866 } | 877 } |
867 | 878 |
868 engine->DeleteSurroundingText(params.context_id, params.offset, params.length, | 879 engine->DeleteSurroundingText(params.context_id, params.offset, params.length, |
869 &error_); | 880 &error_); |
870 return true; | 881 return true; |
871 } | 882 } |
872 | 883 |
873 bool InputImeKeyEventHandledFunction::RunAsync() { | 884 bool InputImeKeyEventHandledFunction::RunAsync() { |
874 scoped_ptr<KeyEventHandled::Params> params( | 885 scoped_ptr<KeyEventHandled::Params> params( |
875 KeyEventHandled::Params::Create(*args_)); | 886 KeyEventHandled::Params::Create(*args_)); |
876 InputImeEventRouter::GetInstance()->OnKeyEventHandled( | 887 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
877 extension_id(), params->request_id, params->response); | 888 ->OnKeyEventHandled(extension_id(), params->request_id, params->response); |
878 return true; | 889 return true; |
879 } | 890 } |
880 | 891 |
881 InputImeAPI::InputImeAPI(content::BrowserContext* context) | 892 InputImeAPI::InputImeAPI(content::BrowserContext* context) |
882 : browser_context_(context), extension_registry_observer_(this) { | 893 : browser_context_(context), extension_registry_observer_(this) { |
883 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); | 894 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); |
884 | 895 |
885 EventRouter* event_router = EventRouter::Get(browser_context_); | 896 EventRouter* event_router = EventRouter::Get(browser_context_); |
886 event_router->RegisterObserver(this, input_ime::OnFocus::kEventName); | 897 event_router->RegisterObserver(this, input_ime::OnFocus::kEventName); |
887 } | 898 } |
888 | 899 |
889 InputImeAPI::~InputImeAPI() { | 900 InputImeAPI::~InputImeAPI() { |
890 EventRouter::Get(browser_context_)->UnregisterObserver(this); | 901 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
891 } | 902 } |
892 | 903 |
893 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputImeAPI> > | 904 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputImeAPI> > |
894 g_factory = LAZY_INSTANCE_INITIALIZER; | 905 g_factory = LAZY_INSTANCE_INITIALIZER; |
895 | 906 |
896 // static | 907 // static |
897 BrowserContextKeyedAPIFactory<InputImeAPI>* InputImeAPI::GetFactoryInstance() { | 908 BrowserContextKeyedAPIFactory<InputImeAPI>* InputImeAPI::GetFactoryInstance() { |
898 return g_factory.Pointer(); | 909 return g_factory.Pointer(); |
899 } | 910 } |
900 | 911 |
901 void InputImeAPI::OnExtensionLoaded(content::BrowserContext* browser_context, | 912 void InputImeAPI::OnExtensionLoaded(content::BrowserContext* browser_context, |
902 const Extension* extension) { | 913 const Extension* extension) { |
903 const std::vector<InputComponentInfo>* input_components = | 914 const std::vector<InputComponentInfo>* input_components = |
904 extensions::InputComponents::GetInputComponents(extension); | 915 extensions::InputComponents::GetInputComponents(extension); |
905 if (input_components) | 916 if (input_components) |
906 input_ime_event_router()->RegisterImeExtension( | 917 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context)) |
907 Profile::FromBrowserContext(browser_context), | 918 ->RegisterImeExtension(extension->id(), *input_components); |
908 extension->id(), | |
909 *input_components); | |
910 } | 919 } |
911 | 920 |
912 void InputImeAPI::OnExtensionUnloaded(content::BrowserContext* browser_context, | 921 void InputImeAPI::OnExtensionUnloaded(content::BrowserContext* browser_context, |
913 const Extension* extension, | 922 const Extension* extension, |
914 UnloadedExtensionInfo::Reason reason) { | 923 UnloadedExtensionInfo::Reason reason) { |
915 const std::vector<InputComponentInfo>* input_components = | 924 const std::vector<InputComponentInfo>* input_components = |
916 extensions::InputComponents::GetInputComponents(extension); | 925 extensions::InputComponents::GetInputComponents(extension); |
917 if (!input_components) | 926 if (!input_components) |
918 return; | 927 return; |
919 if (input_components->size() > 0) | 928 if (input_components->size() > 0) { |
920 input_ime_event_router()->UnregisterAllImes(extension->id()); | 929 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context)) |
| 930 ->UnregisterAllImes(extension->id()); |
| 931 } |
921 } | 932 } |
922 | 933 |
923 void InputImeAPI::OnListenerAdded(const EventListenerInfo& details) { | 934 void InputImeAPI::OnListenerAdded(const EventListenerInfo& details) { |
| 935 if (!details.browser_context) |
| 936 return; |
924 InputMethodEngineInterface* engine = | 937 InputMethodEngineInterface* engine = |
925 input_ime_event_router()->GetActiveEngine(details.extension_id); | 938 GetInputImeEventRouter( |
| 939 Profile::FromBrowserContext(details.browser_context)) |
| 940 ->GetActiveEngine(details.extension_id); |
926 // Notifies the IME extension for IME ready with onActivate/onFocus events. | 941 // Notifies the IME extension for IME ready with onActivate/onFocus events. |
927 if (engine) | 942 if (engine) |
928 engine->Enable(engine->GetActiveComponentId()); | 943 engine->Enable(engine->GetActiveComponentId()); |
929 } | 944 } |
930 | 945 |
931 InputImeEventRouter* InputImeAPI::input_ime_event_router() { | |
932 return InputImeEventRouter::GetInstance(); | |
933 } | |
934 | |
935 } // namespace extensions | 946 } // namespace extensions |
OLD | NEW |