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/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 const char kStyleRadio[] = "radio"; | 29 const char kStyleRadio[] = "radio"; |
30 const char kStyleSeparator[] = "separator"; | 30 const char kStyleSeparator[] = "separator"; |
31 const char kWindowPositionComposition[] = "composition"; | 31 const char kWindowPositionComposition[] = "composition"; |
32 | 32 |
33 const char kErrorEngineNotAvailable[] = "Engine is not available"; | 33 const char kErrorEngineNotAvailable[] = "Engine is not available"; |
34 const char kErrorBadCandidateList[] = "Invalid candidate list provided"; | 34 const char kErrorBadCandidateList[] = "Invalid candidate list provided"; |
35 const char kErrorSetMenuItemsFail[] = "Could not create menu Items"; | 35 const char kErrorSetMenuItemsFail[] = "Could not create menu Items"; |
36 const char kErrorUpdateMenuItemsFail[] = "Could not update menu Items"; | 36 const char kErrorUpdateMenuItemsFail[] = "Could not update menu Items"; |
37 | 37 |
38 bool ReadMenuItems( | 38 bool ReadMenuItems( |
39 ListValue* menu_items, | 39 base::ListValue* menu_items, |
40 std::vector<chromeos::InputMethodEngine::MenuItem>* output) { | 40 std::vector<chromeos::InputMethodEngine::MenuItem>* output) { |
41 for (size_t i = 0; i < menu_items->GetSize(); ++i) { | 41 for (size_t i = 0; i < menu_items->GetSize(); ++i) { |
42 DictionaryValue* item_dict; | 42 base::DictionaryValue* item_dict; |
43 if (!menu_items->GetDictionary(i, &item_dict)) { | 43 if (!menu_items->GetDictionary(i, &item_dict)) { |
44 return false; | 44 return false; |
45 } | 45 } |
46 | 46 |
47 std::string id; | 47 std::string id; |
48 std::string label; | 48 std::string label; |
49 chromeos::InputMethodEngine::MenuItemStyle style = | 49 chromeos::InputMethodEngine::MenuItemStyle style = |
50 chromeos::InputMethodEngine::MENU_ITEM_STYLE_NONE; | 50 chromeos::InputMethodEngine::MENU_ITEM_STYLE_NONE; |
51 bool visible = true; | 51 bool visible = true; |
52 bool enabled = true; | 52 bool enabled = true; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 output->back().id = id; | 111 output->back().id = id; |
112 output->back().label = label; | 112 output->back().label = label; |
113 output->back().style = style; | 113 output->back().style = style; |
114 output->back().visible = visible; | 114 output->back().visible = visible; |
115 output->back().enabled = enabled; | 115 output->back().enabled = enabled; |
116 output->back().checked = checked; | 116 output->back().checked = checked; |
117 | 117 |
118 output->back().modified = modified; | 118 output->back().modified = modified; |
119 | 119 |
120 if (item_dict->HasKey(keys::kItemsKey)) { | 120 if (item_dict->HasKey(keys::kItemsKey)) { |
121 ListValue* sub_list; | 121 base::ListValue* sub_list; |
122 if (!item_dict->GetList(keys::kItemsKey, &sub_list)) { | 122 if (!item_dict->GetList(keys::kItemsKey, &sub_list)) { |
123 return false; | 123 return false; |
124 } | 124 } |
125 | 125 |
126 if (!ReadMenuItems(sub_list, &(output->back().children))) { | 126 if (!ReadMenuItems(sub_list, &(output->back().children))) { |
127 return false; | 127 return false; |
128 } | 128 } |
129 } | 129 } |
130 } | 130 } |
131 | 131 |
132 return true; | 132 return true; |
133 } | 133 } |
134 | 134 |
135 static void DispatchEventToExtension(Profile* profile, | 135 static void DispatchEventToExtension(Profile* profile, |
136 const std::string& extension_id, | 136 const std::string& extension_id, |
137 const std::string& event_name, | 137 const std::string& event_name, |
138 scoped_ptr<ListValue> args) { | 138 scoped_ptr<base::ListValue> args) { |
139 scoped_ptr<extensions::Event> event(new extensions::Event( | 139 scoped_ptr<extensions::Event> event(new extensions::Event( |
140 event_name, args.Pass())); | 140 event_name, args.Pass())); |
141 event->restrict_to_profile = profile; | 141 event->restrict_to_profile = profile; |
142 extensions::ExtensionSystem::Get(profile)->event_router()-> | 142 extensions::ExtensionSystem::Get(profile)->event_router()-> |
143 DispatchEventToExtension(extension_id, event.Pass()); | 143 DispatchEventToExtension(extension_id, event.Pass()); |
144 } | 144 } |
145 | 145 |
146 } // namespace | 146 } // namespace |
147 | 147 |
148 namespace events { | 148 namespace events { |
(...skipping 20 matching lines...) Expand all Loading... |
169 extension_id_(extension_id), | 169 extension_id_(extension_id), |
170 engine_id_(engine_id) { | 170 engine_id_(engine_id) { |
171 } | 171 } |
172 | 172 |
173 virtual ~ImeObserver() {} | 173 virtual ~ImeObserver() {} |
174 | 174 |
175 virtual void OnActivate(const std::string& engine_id) OVERRIDE { | 175 virtual void OnActivate(const std::string& engine_id) OVERRIDE { |
176 if (profile_ == NULL || extension_id_.empty()) | 176 if (profile_ == NULL || extension_id_.empty()) |
177 return; | 177 return; |
178 | 178 |
179 scoped_ptr<base::ListValue> args(new ListValue()); | 179 scoped_ptr<base::ListValue> args(new base::ListValue()); |
180 args->Append(Value::CreateStringValue(engine_id)); | 180 args->Append(Value::CreateStringValue(engine_id)); |
181 | 181 |
182 DispatchEventToExtension(profile_, extension_id_, | 182 DispatchEventToExtension(profile_, extension_id_, |
183 events::kOnActivate, args.Pass()); | 183 events::kOnActivate, args.Pass()); |
184 } | 184 } |
185 | 185 |
186 virtual void OnDeactivated(const std::string& engine_id) OVERRIDE { | 186 virtual void OnDeactivated(const std::string& engine_id) OVERRIDE { |
187 if (profile_ == NULL || extension_id_.empty()) | 187 if (profile_ == NULL || extension_id_.empty()) |
188 return; | 188 return; |
189 | 189 |
190 scoped_ptr<base::ListValue> args(new ListValue()); | 190 scoped_ptr<base::ListValue> args(new base::ListValue()); |
191 args->Append(Value::CreateStringValue(engine_id)); | 191 args->Append(Value::CreateStringValue(engine_id)); |
192 | 192 |
193 DispatchEventToExtension(profile_, extension_id_, | 193 DispatchEventToExtension(profile_, extension_id_, |
194 events::kOnDeactivated, args.Pass()); | 194 events::kOnDeactivated, args.Pass()); |
195 } | 195 } |
196 | 196 |
197 virtual void OnFocus( | 197 virtual void OnFocus( |
198 const InputMethodEngine::InputContext& context) OVERRIDE { | 198 const InputMethodEngine::InputContext& context) OVERRIDE { |
199 if (profile_ == NULL || extension_id_.empty()) | 199 if (profile_ == NULL || extension_id_.empty()) |
200 return; | 200 return; |
201 | 201 |
202 DictionaryValue* dict = new DictionaryValue(); | 202 base::DictionaryValue* dict = new base::DictionaryValue(); |
203 dict->SetInteger("contextID", context.id); | 203 dict->SetInteger("contextID", context.id); |
204 dict->SetString("type", context.type); | 204 dict->SetString("type", context.type); |
205 | 205 |
206 scoped_ptr<base::ListValue> args(new ListValue()); | 206 scoped_ptr<base::ListValue> args(new base::ListValue()); |
207 args->Append(dict); | 207 args->Append(dict); |
208 | 208 |
209 DispatchEventToExtension(profile_, extension_id_, | 209 DispatchEventToExtension(profile_, extension_id_, |
210 events::kOnFocus, args.Pass()); | 210 events::kOnFocus, args.Pass()); |
211 } | 211 } |
212 | 212 |
213 virtual void OnBlur(int context_id) OVERRIDE { | 213 virtual void OnBlur(int context_id) OVERRIDE { |
214 if (profile_ == NULL || extension_id_.empty()) | 214 if (profile_ == NULL || extension_id_.empty()) |
215 return; | 215 return; |
216 | 216 |
217 scoped_ptr<base::ListValue> args(new ListValue()); | 217 scoped_ptr<base::ListValue> args(new base::ListValue()); |
218 args->Append(Value::CreateIntegerValue(context_id)); | 218 args->Append(Value::CreateIntegerValue(context_id)); |
219 | 219 |
220 DispatchEventToExtension(profile_, extension_id_, | 220 DispatchEventToExtension(profile_, extension_id_, |
221 events::kOnBlur, args.Pass()); | 221 events::kOnBlur, args.Pass()); |
222 } | 222 } |
223 | 223 |
224 virtual void OnInputContextUpdate( | 224 virtual void OnInputContextUpdate( |
225 const InputMethodEngine::InputContext& context) OVERRIDE { | 225 const InputMethodEngine::InputContext& context) OVERRIDE { |
226 if (profile_ == NULL || extension_id_.empty()) | 226 if (profile_ == NULL || extension_id_.empty()) |
227 return; | 227 return; |
228 | 228 |
229 DictionaryValue* dict = new DictionaryValue(); | 229 base::DictionaryValue* dict = new base::DictionaryValue(); |
230 dict->SetInteger("contextID", context.id); | 230 dict->SetInteger("contextID", context.id); |
231 dict->SetString("type", context.type); | 231 dict->SetString("type", context.type); |
232 | 232 |
233 scoped_ptr<base::ListValue> args(new ListValue()); | 233 scoped_ptr<base::ListValue> args(new base::ListValue()); |
234 args->Append(dict); | 234 args->Append(dict); |
235 | 235 |
236 DispatchEventToExtension(profile_, extension_id_, | 236 DispatchEventToExtension(profile_, extension_id_, |
237 events::kOnInputContextUpdate, args.Pass()); | 237 events::kOnInputContextUpdate, args.Pass()); |
238 } | 238 } |
239 | 239 |
240 virtual void OnKeyEvent( | 240 virtual void OnKeyEvent( |
241 const std::string& engine_id, | 241 const std::string& engine_id, |
242 const InputMethodEngine::KeyboardEvent& event, | 242 const InputMethodEngine::KeyboardEvent& event, |
243 chromeos::input_method::KeyEventHandle* key_data) OVERRIDE { | 243 chromeos::input_method::KeyEventHandle* key_data) OVERRIDE { |
244 if (profile_ == NULL || extension_id_.empty()) | 244 if (profile_ == NULL || extension_id_.empty()) |
245 return; | 245 return; |
246 | 246 |
247 std::string request_id = | 247 std::string request_id = |
248 extensions::InputImeEventRouter::GetInstance()->AddRequest(engine_id, | 248 extensions::InputImeEventRouter::GetInstance()->AddRequest(engine_id, |
249 key_data); | 249 key_data); |
250 | 250 |
251 DictionaryValue* dict = new DictionaryValue(); | 251 base::DictionaryValue* dict = new base::DictionaryValue(); |
252 dict->SetString("type", event.type); | 252 dict->SetString("type", event.type); |
253 dict->SetString("requestId", request_id); | 253 dict->SetString("requestId", request_id); |
254 dict->SetString("key", event.key); | 254 dict->SetString("key", event.key); |
255 dict->SetString("code", event.code); | 255 dict->SetString("code", event.code); |
256 dict->SetBoolean("altKey", event.alt_key); | 256 dict->SetBoolean("altKey", event.alt_key); |
257 dict->SetBoolean("ctrlKey", event.ctrl_key); | 257 dict->SetBoolean("ctrlKey", event.ctrl_key); |
258 dict->SetBoolean("shiftKey", event.shift_key); | 258 dict->SetBoolean("shiftKey", event.shift_key); |
259 dict->SetBoolean("capsLock", event.caps_lock); | 259 dict->SetBoolean("capsLock", event.caps_lock); |
260 | 260 |
261 scoped_ptr<base::ListValue> args(new ListValue()); | 261 scoped_ptr<base::ListValue> args(new base::ListValue()); |
262 args->Append(Value::CreateStringValue(engine_id)); | 262 args->Append(Value::CreateStringValue(engine_id)); |
263 args->Append(dict); | 263 args->Append(dict); |
264 | 264 |
265 DispatchEventToExtension(profile_, extension_id_, | 265 DispatchEventToExtension(profile_, extension_id_, |
266 events::kOnKeyEvent, args.Pass()); | 266 events::kOnKeyEvent, args.Pass()); |
267 } | 267 } |
268 | 268 |
269 virtual void OnCandidateClicked( | 269 virtual void OnCandidateClicked( |
270 const std::string& engine_id, | 270 const std::string& engine_id, |
271 int candidate_id, | 271 int candidate_id, |
272 chromeos::InputMethodEngine::MouseButtonEvent button) OVERRIDE { | 272 chromeos::InputMethodEngine::MouseButtonEvent button) OVERRIDE { |
273 if (profile_ == NULL || extension_id_.empty()) | 273 if (profile_ == NULL || extension_id_.empty()) |
274 return; | 274 return; |
275 | 275 |
276 scoped_ptr<base::ListValue> args(new ListValue()); | 276 scoped_ptr<base::ListValue> args(new base::ListValue()); |
277 args->Append(Value::CreateStringValue(engine_id)); | 277 args->Append(Value::CreateStringValue(engine_id)); |
278 args->Append(Value::CreateIntegerValue(candidate_id)); | 278 args->Append(Value::CreateIntegerValue(candidate_id)); |
279 switch (button) { | 279 switch (button) { |
280 case chromeos::InputMethodEngine::MOUSE_BUTTON_MIDDLE: | 280 case chromeos::InputMethodEngine::MOUSE_BUTTON_MIDDLE: |
281 args->Append(Value::CreateStringValue("middle")); | 281 args->Append(Value::CreateStringValue("middle")); |
282 break; | 282 break; |
283 | 283 |
284 case chromeos::InputMethodEngine::MOUSE_BUTTON_RIGHT: | 284 case chromeos::InputMethodEngine::MOUSE_BUTTON_RIGHT: |
285 args->Append(Value::CreateStringValue("right")); | 285 args->Append(Value::CreateStringValue("right")); |
286 break; | 286 break; |
287 | 287 |
288 case chromeos::InputMethodEngine::MOUSE_BUTTON_LEFT: | 288 case chromeos::InputMethodEngine::MOUSE_BUTTON_LEFT: |
289 // Default to left. | 289 // Default to left. |
290 default: | 290 default: |
291 args->Append(Value::CreateStringValue("left")); | 291 args->Append(Value::CreateStringValue("left")); |
292 break; | 292 break; |
293 } | 293 } |
294 | 294 |
295 DispatchEventToExtension(profile_, extension_id_, | 295 DispatchEventToExtension(profile_, extension_id_, |
296 events::kOnCandidateClicked, args.Pass()); | 296 events::kOnCandidateClicked, args.Pass()); |
297 } | 297 } |
298 | 298 |
299 virtual void OnMenuItemActivated(const std::string& engine_id, | 299 virtual void OnMenuItemActivated(const std::string& engine_id, |
300 const std::string& menu_id) OVERRIDE { | 300 const std::string& menu_id) OVERRIDE { |
301 if (profile_ == NULL || extension_id_.empty()) | 301 if (profile_ == NULL || extension_id_.empty()) |
302 return; | 302 return; |
303 | 303 |
304 scoped_ptr<base::ListValue> args(new ListValue()); | 304 scoped_ptr<base::ListValue> args(new base::ListValue()); |
305 args->Append(Value::CreateStringValue(engine_id)); | 305 args->Append(Value::CreateStringValue(engine_id)); |
306 args->Append(Value::CreateStringValue(menu_id)); | 306 args->Append(Value::CreateStringValue(menu_id)); |
307 | 307 |
308 DispatchEventToExtension(profile_, extension_id_, | 308 DispatchEventToExtension(profile_, extension_id_, |
309 events::kOnMenuItemActivated, args.Pass()); | 309 events::kOnMenuItemActivated, args.Pass()); |
310 } | 310 } |
311 | 311 |
312 virtual void OnSurroundingTextChanged(const std::string& engine_id, | 312 virtual void OnSurroundingTextChanged(const std::string& engine_id, |
313 const std::string& text, | 313 const std::string& text, |
314 int cursor_pos, | 314 int cursor_pos, |
315 int anchor_pos) OVERRIDE { | 315 int anchor_pos) OVERRIDE { |
316 if (profile_ == NULL || extension_id_.empty()) | 316 if (profile_ == NULL || extension_id_.empty()) |
317 return; | 317 return; |
318 DictionaryValue* dict = new DictionaryValue(); | 318 base::DictionaryValue* dict = new base::DictionaryValue(); |
319 dict->SetString("text", text); | 319 dict->SetString("text", text); |
320 dict->SetInteger("focus", cursor_pos); | 320 dict->SetInteger("focus", cursor_pos); |
321 dict->SetInteger("anchor", anchor_pos); | 321 dict->SetInteger("anchor", anchor_pos); |
322 | 322 |
323 scoped_ptr<ListValue> args(new ListValue); | 323 scoped_ptr<ListValue> args(new base::ListValue); |
324 args->Append(Value::CreateStringValue(engine_id)); | 324 args->Append(Value::CreateStringValue(engine_id)); |
325 args->Append(dict); | 325 args->Append(dict); |
326 | 326 |
327 DispatchEventToExtension(profile_, extension_id_, | 327 DispatchEventToExtension(profile_, extension_id_, |
328 events::kOnSurroundingTextChanged, args.Pass()); | 328 events::kOnSurroundingTextChanged, args.Pass()); |
329 } | 329 } |
330 | 330 |
331 virtual void OnReset(const std::string& engine_id) OVERRIDE { | 331 virtual void OnReset(const std::string& engine_id) OVERRIDE { |
332 if (profile_ == NULL || extension_id_.empty()) | 332 if (profile_ == NULL || extension_id_.empty()) |
333 return; | 333 return; |
334 scoped_ptr<base::ListValue> args(new ListValue()); | 334 scoped_ptr<base::ListValue> args(new base::ListValue()); |
335 args->Append(Value::CreateStringValue(engine_id)); | 335 args->Append(Value::CreateStringValue(engine_id)); |
336 | 336 |
337 DispatchEventToExtension(profile_, extension_id_, | 337 DispatchEventToExtension(profile_, extension_id_, |
338 events::kOnReset, args.Pass()); | 338 events::kOnReset, args.Pass()); |
339 } | 339 } |
340 | 340 |
341 private: | 341 private: |
342 Profile* profile_; | 342 Profile* profile_; |
343 std::string extension_id_; | 343 std::string extension_id_; |
344 std::string engine_id_; | 344 std::string engine_id_; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 InputImeEventRouter::~InputImeEventRouter() {} | 499 InputImeEventRouter::~InputImeEventRouter() {} |
500 | 500 |
501 bool SetCompositionFunction::RunImpl() { | 501 bool SetCompositionFunction::RunImpl() { |
502 chromeos::InputMethodEngine* engine = | 502 chromeos::InputMethodEngine* engine = |
503 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); | 503 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); |
504 if (!engine) { | 504 if (!engine) { |
505 SetResult(Value::CreateBooleanValue(false)); | 505 SetResult(Value::CreateBooleanValue(false)); |
506 return true; | 506 return true; |
507 } | 507 } |
508 | 508 |
509 DictionaryValue* args; | 509 base::DictionaryValue* args; |
510 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 510 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
511 int context_id; | 511 int context_id; |
512 std::string text; | 512 std::string text; |
513 int selection_start; | 513 int selection_start; |
514 int selection_end; | 514 int selection_end; |
515 int cursor; | 515 int cursor; |
516 std::vector<chromeos::InputMethodEngine::SegmentInfo> segments; | 516 std::vector<chromeos::InputMethodEngine::SegmentInfo> segments; |
517 | 517 |
518 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, | 518 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, |
519 &context_id)); | 519 &context_id)); |
520 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kTextKey, &text)); | 520 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kTextKey, &text)); |
521 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kCursorKey, &cursor)); | 521 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kCursorKey, &cursor)); |
522 if (args->HasKey(keys::kSelectionStartKey)) { | 522 if (args->HasKey(keys::kSelectionStartKey)) { |
523 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kSelectionStartKey, | 523 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kSelectionStartKey, |
524 &selection_start)); | 524 &selection_start)); |
525 } else { | 525 } else { |
526 selection_start = cursor; | 526 selection_start = cursor; |
527 } | 527 } |
528 if (args->HasKey(keys::kSelectionEndKey)) { | 528 if (args->HasKey(keys::kSelectionEndKey)) { |
529 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kSelectionEndKey, | 529 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kSelectionEndKey, |
530 &selection_end)); | 530 &selection_end)); |
531 } else { | 531 } else { |
532 selection_end = cursor; | 532 selection_end = cursor; |
533 } | 533 } |
534 | 534 |
535 if (args->HasKey(keys::kSegmentsKey)) { | 535 if (args->HasKey(keys::kSegmentsKey)) { |
536 ListValue* segment_list = NULL; | 536 base::ListValue* segment_list = NULL; |
537 EXTENSION_FUNCTION_VALIDATE(args->GetList(keys::kSegmentsKey, | 537 EXTENSION_FUNCTION_VALIDATE(args->GetList(keys::kSegmentsKey, |
538 &segment_list)); | 538 &segment_list)); |
539 | 539 |
540 for (size_t i = 0; i < segment_list->GetSize(); ++i) { | 540 for (size_t i = 0; i < segment_list->GetSize(); ++i) { |
541 DictionaryValue* segment = NULL; | 541 base::DictionaryValue* segment = NULL; |
542 if (!segment_list->GetDictionary(i, &segment)) | 542 if (!segment_list->GetDictionary(i, &segment)) |
543 continue; | 543 continue; |
544 | 544 |
545 int start; | 545 int start; |
546 int end; | 546 int end; |
547 std::string style; | 547 std::string style; |
548 | 548 |
549 EXTENSION_FUNCTION_VALIDATE(segment->GetInteger(keys::kStartKey, | 549 EXTENSION_FUNCTION_VALIDATE(segment->GetInteger(keys::kStartKey, |
550 &start)); | 550 &start)); |
551 EXTENSION_FUNCTION_VALIDATE(segment->GetInteger(keys::kEndKey, &end)); | 551 EXTENSION_FUNCTION_VALIDATE(segment->GetInteger(keys::kEndKey, &end)); |
(...skipping 22 matching lines...) Expand all Loading... |
574 } | 574 } |
575 | 575 |
576 bool ClearCompositionFunction::RunImpl() { | 576 bool ClearCompositionFunction::RunImpl() { |
577 chromeos::InputMethodEngine* engine = | 577 chromeos::InputMethodEngine* engine = |
578 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); | 578 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); |
579 if (!engine) { | 579 if (!engine) { |
580 SetResult(Value::CreateBooleanValue(false)); | 580 SetResult(Value::CreateBooleanValue(false)); |
581 return true; | 581 return true; |
582 } | 582 } |
583 | 583 |
584 DictionaryValue* args; | 584 base::DictionaryValue* args; |
585 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 585 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
586 int context_id; | 586 int context_id; |
587 | 587 |
588 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, | 588 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, |
589 &context_id)); | 589 &context_id)); |
590 | 590 |
591 if (engine->ClearComposition(context_id, &error_)) { | 591 if (engine->ClearComposition(context_id, &error_)) { |
592 SetResult(Value::CreateBooleanValue(true)); | 592 SetResult(Value::CreateBooleanValue(true)); |
593 } else { | 593 } else { |
594 SetResult(Value::CreateBooleanValue(false)); | 594 SetResult(Value::CreateBooleanValue(false)); |
595 } | 595 } |
596 return true; | 596 return true; |
597 } | 597 } |
598 | 598 |
599 bool CommitTextFunction::RunImpl() { | 599 bool CommitTextFunction::RunImpl() { |
600 // TODO(zork): Support committing when not active. | 600 // TODO(zork): Support committing when not active. |
601 chromeos::InputMethodEngine* engine = | 601 chromeos::InputMethodEngine* engine = |
602 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); | 602 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); |
603 if (!engine) { | 603 if (!engine) { |
604 SetResult(Value::CreateBooleanValue(false)); | 604 SetResult(Value::CreateBooleanValue(false)); |
605 return true; | 605 return true; |
606 } | 606 } |
607 | 607 |
608 DictionaryValue* args; | 608 base::DictionaryValue* args; |
609 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 609 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
610 int context_id; | 610 int context_id; |
611 std::string text; | 611 std::string text; |
612 | 612 |
613 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, | 613 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, |
614 &context_id)); | 614 &context_id)); |
615 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kTextKey, &text)); | 615 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kTextKey, &text)); |
616 | 616 |
617 if (engine->CommitText(context_id, text.c_str(), &error_)) { | 617 if (engine->CommitText(context_id, text.c_str(), &error_)) { |
618 SetResult(Value::CreateBooleanValue(true)); | 618 SetResult(Value::CreateBooleanValue(true)); |
619 } else { | 619 } else { |
620 SetResult(Value::CreateBooleanValue(false)); | 620 SetResult(Value::CreateBooleanValue(false)); |
621 } | 621 } |
622 return true; | 622 return true; |
623 } | 623 } |
624 | 624 |
625 bool SetCandidateWindowPropertiesFunction::RunImpl() { | 625 bool SetCandidateWindowPropertiesFunction::RunImpl() { |
626 DictionaryValue* args; | 626 base::DictionaryValue* args; |
627 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 627 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
628 | 628 |
629 std::string engine_id; | 629 std::string engine_id; |
630 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); | 630 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); |
631 | 631 |
632 chromeos::InputMethodEngine* engine = | 632 chromeos::InputMethodEngine* engine = |
633 InputImeEventRouter::GetInstance()->GetEngine(extension_id(), engine_id); | 633 InputImeEventRouter::GetInstance()->GetEngine(extension_id(), engine_id); |
634 if (!engine) { | 634 if (!engine) { |
635 SetResult(Value::CreateBooleanValue(false)); | 635 SetResult(Value::CreateBooleanValue(false)); |
636 return true; | 636 return true; |
637 } | 637 } |
638 | 638 |
639 DictionaryValue* properties; | 639 base::DictionaryValue* properties; |
640 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(keys::kPropertiesKey, | 640 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(keys::kPropertiesKey, |
641 &properties)); | 641 &properties)); |
642 | 642 |
643 if (properties->HasKey(keys::kVisibleKey)) { | 643 if (properties->HasKey(keys::kVisibleKey)) { |
644 bool visible; | 644 bool visible; |
645 EXTENSION_FUNCTION_VALIDATE(properties->GetBoolean(keys::kVisibleKey, | 645 EXTENSION_FUNCTION_VALIDATE(properties->GetBoolean(keys::kVisibleKey, |
646 &visible)); | 646 &visible)); |
647 if (!engine->SetCandidateWindowVisible(visible, &error_)) { | 647 if (!engine->SetCandidateWindowVisible(visible, &error_)) { |
648 SetResult(Value::CreateBooleanValue(false)); | 648 SetResult(Value::CreateBooleanValue(false)); |
649 return true; | 649 return true; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 engine->SetCandidateWindowPosition(window_position); | 700 engine->SetCandidateWindowPosition(window_position); |
701 } | 701 } |
702 | 702 |
703 SetResult(Value::CreateBooleanValue(true)); | 703 SetResult(Value::CreateBooleanValue(true)); |
704 | 704 |
705 return true; | 705 return true; |
706 } | 706 } |
707 | 707 |
708 #if defined(OS_CHROMEOS) | 708 #if defined(OS_CHROMEOS) |
709 bool SetCandidatesFunction::ReadCandidates( | 709 bool SetCandidatesFunction::ReadCandidates( |
710 ListValue* candidates, | 710 base::ListValue* candidates, |
711 std::vector<chromeos::InputMethodEngine::Candidate>* output) { | 711 std::vector<chromeos::InputMethodEngine::Candidate>* output) { |
712 for (size_t i = 0; i < candidates->GetSize(); ++i) { | 712 for (size_t i = 0; i < candidates->GetSize(); ++i) { |
713 DictionaryValue* candidate_dict; | 713 base::DictionaryValue* candidate_dict; |
714 EXTENSION_FUNCTION_VALIDATE(candidates->GetDictionary(i, &candidate_dict)); | 714 EXTENSION_FUNCTION_VALIDATE(candidates->GetDictionary(i, &candidate_dict)); |
715 | 715 |
716 std::string candidate; | 716 std::string candidate; |
717 int id; | 717 int id; |
718 std::string label; | 718 std::string label; |
719 std::string annotation; | 719 std::string annotation; |
720 chromeos::InputMethodEngine::UsageEntry usage_entry; | 720 chromeos::InputMethodEngine::UsageEntry usage_entry; |
721 | 721 |
722 EXTENSION_FUNCTION_VALIDATE(candidate_dict->GetString(keys::kCandidateKey, | 722 EXTENSION_FUNCTION_VALIDATE(candidate_dict->GetString(keys::kCandidateKey, |
723 &candidate)); | 723 &candidate)); |
724 EXTENSION_FUNCTION_VALIDATE(candidate_dict->GetInteger(keys::kIdKey, &id)); | 724 EXTENSION_FUNCTION_VALIDATE(candidate_dict->GetInteger(keys::kIdKey, &id)); |
725 | 725 |
726 if (candidate_dict->HasKey(keys::kLabelKey)) { | 726 if (candidate_dict->HasKey(keys::kLabelKey)) { |
727 EXTENSION_FUNCTION_VALIDATE(candidate_dict->GetString(keys::kLabelKey, | 727 EXTENSION_FUNCTION_VALIDATE(candidate_dict->GetString(keys::kLabelKey, |
728 &label)); | 728 &label)); |
729 } | 729 } |
730 if (candidate_dict->HasKey(keys::kAnnotationKey)) { | 730 if (candidate_dict->HasKey(keys::kAnnotationKey)) { |
731 EXTENSION_FUNCTION_VALIDATE(candidate_dict->GetString( | 731 EXTENSION_FUNCTION_VALIDATE(candidate_dict->GetString( |
732 keys::kAnnotationKey, | 732 keys::kAnnotationKey, |
733 &annotation)); | 733 &annotation)); |
734 } | 734 } |
735 | 735 |
736 if (candidate_dict->HasKey(keys::kUsageKey)) { | 736 if (candidate_dict->HasKey(keys::kUsageKey)) { |
737 DictionaryValue* usage_dict; | 737 base::DictionaryValue* usage_dict; |
738 EXTENSION_FUNCTION_VALIDATE(candidate_dict->GetDictionary(keys::kUsageKey, | 738 EXTENSION_FUNCTION_VALIDATE(candidate_dict->GetDictionary(keys::kUsageKey, |
739 &usage_dict)); | 739 &usage_dict)); |
740 EXTENSION_FUNCTION_VALIDATE(usage_dict->GetString(keys::kUsageTitleKey, | 740 EXTENSION_FUNCTION_VALIDATE(usage_dict->GetString(keys::kUsageTitleKey, |
741 &usage_entry.title)); | 741 &usage_entry.title)); |
742 EXTENSION_FUNCTION_VALIDATE(usage_dict->GetString(keys::kUsageBodyKey, | 742 EXTENSION_FUNCTION_VALIDATE(usage_dict->GetString(keys::kUsageBodyKey, |
743 &usage_entry.body)); | 743 &usage_entry.body)); |
744 } | 744 } |
745 | 745 |
746 output->push_back(chromeos::InputMethodEngine::Candidate()); | 746 output->push_back(chromeos::InputMethodEngine::Candidate()); |
747 output->back().value = candidate; | 747 output->back().value = candidate; |
748 output->back().id = id; | 748 output->back().id = id; |
749 output->back().label = label; | 749 output->back().label = label; |
750 output->back().annotation = annotation; | 750 output->back().annotation = annotation; |
751 output->back().usage = usage_entry; | 751 output->back().usage = usage_entry; |
752 | 752 |
753 if (candidate_dict->HasKey(keys::kCandidatesKey)) { | 753 if (candidate_dict->HasKey(keys::kCandidatesKey)) { |
754 ListValue* sub_list; | 754 base::ListValue* sub_list; |
755 EXTENSION_FUNCTION_VALIDATE(candidate_dict->GetList(keys::kCandidatesKey, | 755 EXTENSION_FUNCTION_VALIDATE(candidate_dict->GetList(keys::kCandidatesKey, |
756 &sub_list)); | 756 &sub_list)); |
757 if (!ReadCandidates(sub_list, &(output->back().candidates))) { | 757 if (!ReadCandidates(sub_list, &(output->back().candidates))) { |
758 error_ = kErrorBadCandidateList; | 758 error_ = kErrorBadCandidateList; |
759 return false; | 759 return false; |
760 } | 760 } |
761 } | 761 } |
762 } | 762 } |
763 | 763 |
764 return true; | 764 return true; |
765 } | 765 } |
766 | 766 |
767 bool SetCandidatesFunction::RunImpl() { | 767 bool SetCandidatesFunction::RunImpl() { |
768 chromeos::InputMethodEngine* engine = | 768 chromeos::InputMethodEngine* engine = |
769 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); | 769 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); |
770 if (!engine) { | 770 if (!engine) { |
771 SetResult(Value::CreateBooleanValue(false)); | 771 SetResult(Value::CreateBooleanValue(false)); |
772 return true; | 772 return true; |
773 } | 773 } |
774 | 774 |
775 DictionaryValue* args; | 775 base::DictionaryValue* args; |
776 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 776 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
777 | 777 |
778 int context_id; | 778 int context_id; |
779 std::vector<chromeos::InputMethodEngine::Candidate> candidates; | 779 std::vector<chromeos::InputMethodEngine::Candidate> candidates; |
780 | 780 |
781 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, | 781 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, |
782 &context_id)); | 782 &context_id)); |
783 | 783 |
784 ListValue* candidate_list; | 784 base::ListValue* candidate_list; |
785 EXTENSION_FUNCTION_VALIDATE(args->GetList(keys::kCandidatesKey, | 785 EXTENSION_FUNCTION_VALIDATE(args->GetList(keys::kCandidatesKey, |
786 &candidate_list)); | 786 &candidate_list)); |
787 if (!ReadCandidates(candidate_list, &candidates)) { | 787 if (!ReadCandidates(candidate_list, &candidates)) { |
788 error_ = kErrorBadCandidateList; | 788 error_ = kErrorBadCandidateList; |
789 return false; | 789 return false; |
790 } | 790 } |
791 | 791 |
792 std::string error; | 792 std::string error; |
793 if (engine->SetCandidates(context_id, candidates, &error_)) { | 793 if (engine->SetCandidates(context_id, candidates, &error_)) { |
794 SetResult(Value::CreateBooleanValue(true)); | 794 SetResult(Value::CreateBooleanValue(true)); |
795 } else { | 795 } else { |
796 SetResult(Value::CreateBooleanValue(false)); | 796 SetResult(Value::CreateBooleanValue(false)); |
797 } | 797 } |
798 return true; | 798 return true; |
799 } | 799 } |
800 | 800 |
801 bool SetCursorPositionFunction::RunImpl() { | 801 bool SetCursorPositionFunction::RunImpl() { |
802 chromeos::InputMethodEngine* engine = | 802 chromeos::InputMethodEngine* engine = |
803 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); | 803 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); |
804 if (!engine) { | 804 if (!engine) { |
805 SetResult(Value::CreateBooleanValue(false)); | 805 SetResult(Value::CreateBooleanValue(false)); |
806 return true; | 806 return true; |
807 } | 807 } |
808 | 808 |
809 DictionaryValue* args; | 809 base::DictionaryValue* args; |
810 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 810 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
811 int context_id; | 811 int context_id; |
812 int candidate_id; | 812 int candidate_id; |
813 | 813 |
814 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, | 814 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, |
815 &context_id)); | 815 &context_id)); |
816 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kCandidateIdKey, | 816 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kCandidateIdKey, |
817 &candidate_id)); | 817 &candidate_id)); |
818 | 818 |
819 if (engine->SetCursorPosition(context_id, candidate_id, &error_)) { | 819 if (engine->SetCursorPosition(context_id, candidate_id, &error_)) { |
820 SetResult(Value::CreateBooleanValue(true)); | 820 SetResult(Value::CreateBooleanValue(true)); |
821 } else { | 821 } else { |
822 SetResult(Value::CreateBooleanValue(false)); | 822 SetResult(Value::CreateBooleanValue(false)); |
823 } | 823 } |
824 return true; | 824 return true; |
825 } | 825 } |
826 | 826 |
827 bool SetMenuItemsFunction::RunImpl() { | 827 bool SetMenuItemsFunction::RunImpl() { |
828 DictionaryValue* args; | 828 base::DictionaryValue* args; |
829 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 829 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
830 | 830 |
831 std::string engine_id; | 831 std::string engine_id; |
832 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); | 832 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); |
833 | 833 |
834 chromeos::InputMethodEngine* engine = | 834 chromeos::InputMethodEngine* engine = |
835 InputImeEventRouter::GetInstance()->GetEngine(extension_id(), engine_id); | 835 InputImeEventRouter::GetInstance()->GetEngine(extension_id(), engine_id); |
836 if (!engine) { | 836 if (!engine) { |
837 error_ = kErrorEngineNotAvailable; | 837 error_ = kErrorEngineNotAvailable; |
838 return false; | 838 return false; |
839 } | 839 } |
840 | 840 |
841 ListValue* items; | 841 base::ListValue* items; |
842 EXTENSION_FUNCTION_VALIDATE(args->GetList(keys::kItemsKey, &items)); | 842 EXTENSION_FUNCTION_VALIDATE(args->GetList(keys::kItemsKey, &items)); |
843 | 843 |
844 std::vector<chromeos::InputMethodEngine::MenuItem> menu_items; | 844 std::vector<chromeos::InputMethodEngine::MenuItem> menu_items; |
845 EXTENSION_FUNCTION_VALIDATE(ReadMenuItems(items, &menu_items)); | 845 EXTENSION_FUNCTION_VALIDATE(ReadMenuItems(items, &menu_items)); |
846 | 846 |
847 if (!engine->SetMenuItems(menu_items)) { | 847 if (!engine->SetMenuItems(menu_items)) { |
848 error_ = kErrorSetMenuItemsFail; | 848 error_ = kErrorSetMenuItemsFail; |
849 } | 849 } |
850 return true; | 850 return true; |
851 } | 851 } |
852 | 852 |
853 bool UpdateMenuItemsFunction::RunImpl() { | 853 bool UpdateMenuItemsFunction::RunImpl() { |
854 DictionaryValue* args; | 854 base::DictionaryValue* args; |
855 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 855 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
856 | 856 |
857 std::string engine_id; | 857 std::string engine_id; |
858 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); | 858 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); |
859 | 859 |
860 chromeos::InputMethodEngine* engine = | 860 chromeos::InputMethodEngine* engine = |
861 InputImeEventRouter::GetInstance()->GetEngine(extension_id(), engine_id); | 861 InputImeEventRouter::GetInstance()->GetEngine(extension_id(), engine_id); |
862 if (!engine) { | 862 if (!engine) { |
863 error_ = kErrorEngineNotAvailable; | 863 error_ = kErrorEngineNotAvailable; |
864 return false; | 864 return false; |
865 } | 865 } |
866 | 866 |
867 ListValue* items; | 867 base::ListValue* items; |
868 EXTENSION_FUNCTION_VALIDATE(args->GetList(keys::kItemsKey, &items)); | 868 EXTENSION_FUNCTION_VALIDATE(args->GetList(keys::kItemsKey, &items)); |
869 | 869 |
870 std::vector<chromeos::InputMethodEngine::MenuItem> menu_items; | 870 std::vector<chromeos::InputMethodEngine::MenuItem> menu_items; |
871 EXTENSION_FUNCTION_VALIDATE(ReadMenuItems(items, &menu_items)); | 871 EXTENSION_FUNCTION_VALIDATE(ReadMenuItems(items, &menu_items)); |
872 | 872 |
873 if (!engine->UpdateMenuItems(menu_items)) { | 873 if (!engine->UpdateMenuItems(menu_items)) { |
874 error_ = kErrorUpdateMenuItemsFail; | 874 error_ = kErrorUpdateMenuItemsFail; |
875 } | 875 } |
876 return true; | 876 return true; |
877 } | 877 } |
878 | 878 |
879 bool DeleteSurroundingTextFunction::RunImpl() { | 879 bool DeleteSurroundingTextFunction::RunImpl() { |
880 DictionaryValue* args; | 880 base::DictionaryValue* args; |
881 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 881 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
882 | 882 |
883 std::string engine_id; | 883 std::string engine_id; |
884 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); | 884 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); |
885 | 885 |
886 chromeos::InputMethodEngine* engine = | 886 chromeos::InputMethodEngine* engine = |
887 InputImeEventRouter::GetInstance()->GetEngine(extension_id(), engine_id); | 887 InputImeEventRouter::GetInstance()->GetEngine(extension_id(), engine_id); |
888 if (!engine) { | 888 if (!engine) { |
889 error_ = kErrorEngineNotAvailable; | 889 error_ = kErrorEngineNotAvailable; |
890 return false; | 890 return false; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 input_ime_event_router()->UnregisterAllImes(profile_, extension->id()); | 977 input_ime_event_router()->UnregisterAllImes(profile_, extension->id()); |
978 } | 978 } |
979 } | 979 } |
980 } | 980 } |
981 | 981 |
982 InputImeEventRouter* InputImeAPI::input_ime_event_router() { | 982 InputImeEventRouter* InputImeAPI::input_ime_event_router() { |
983 return InputImeEventRouter::GetInstance(); | 983 return InputImeEventRouter::GetInstance(); |
984 } | 984 } |
985 | 985 |
986 } // namespace extensions | 986 } // namespace extensions |
OLD | NEW |