Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: chrome/browser/extensions/api/input_ime/input_ime_api.cc

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

Powered by Google App Engine
This is Rietveld 408576698