OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extension_input_ime_api.h" | 5 #include "chrome/browser/extensions/extension_input_ime_api.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.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/extensions/extension_event_router.h" | 10 #include "chrome/browser/extensions/extension_event_router.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 } | 37 } |
38 | 38 |
39 virtual ~ImeObserver() { | 39 virtual ~ImeObserver() { |
40 } | 40 } |
41 | 41 |
42 virtual void OnActivate(const std::string& engine_id) { | 42 virtual void OnActivate(const std::string& engine_id) { |
43 if (profile_ == NULL || extension_id_.empty()) | 43 if (profile_ == NULL || extension_id_.empty()) |
44 return; | 44 return; |
45 | 45 |
46 ListValue args; | 46 ListValue args; |
47 args.Append(Value::CreateStringValue(engine_id)); | 47 args.Append(base::StringValue::New(engine_id)); |
48 | 48 |
49 std::string json_args; | 49 std::string json_args; |
50 base::JSONWriter::Write(&args, false, &json_args); | 50 base::JSONWriter::Write(&args, false, &json_args); |
51 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 51 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
52 extension_id_, events::kOnActivate, json_args, profile_, GURL()); | 52 extension_id_, events::kOnActivate, json_args, profile_, GURL()); |
53 } | 53 } |
54 | 54 |
55 virtual void OnDeactivated(const std::string& engine_id) { | 55 virtual void OnDeactivated(const std::string& engine_id) { |
56 if (profile_ == NULL || extension_id_.empty()) | 56 if (profile_ == NULL || extension_id_.empty()) |
57 return; | 57 return; |
58 | 58 |
59 ListValue args; | 59 ListValue args; |
60 args.Append(Value::CreateStringValue(engine_id)); | 60 args.Append(base::StringValue::New(engine_id)); |
61 | 61 |
62 std::string json_args; | 62 std::string json_args; |
63 base::JSONWriter::Write(&args, false, &json_args); | 63 base::JSONWriter::Write(&args, false, &json_args); |
64 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 64 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
65 extension_id_, events::kOnDeactivated, json_args, profile_, GURL()); | 65 extension_id_, events::kOnDeactivated, json_args, profile_, GURL()); |
66 } | 66 } |
67 | 67 |
68 virtual void OnFocus(const InputMethodEngine::InputContext& context) { | 68 virtual void OnFocus(const InputMethodEngine::InputContext& context) { |
69 if (profile_ == NULL || extension_id_.empty()) | 69 if (profile_ == NULL || extension_id_.empty()) |
70 return; | 70 return; |
71 | 71 |
72 DictionaryValue* dict = new DictionaryValue(); | 72 DictionaryValue* dict = new DictionaryValue(); |
73 dict->SetInteger("contextID", context.id); | 73 dict->SetInteger("contextID", context.id); |
74 dict->SetString("type", context.type); | 74 dict->SetString("type", context.type); |
75 | 75 |
76 ListValue args; | 76 ListValue args; |
77 args.Append(dict); | 77 args.Append(dict); |
78 | 78 |
79 std::string json_args; | 79 std::string json_args; |
80 base::JSONWriter::Write(&args, false, &json_args); | 80 base::JSONWriter::Write(&args, false, &json_args); |
81 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 81 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
82 extension_id_, events::kOnFocus, json_args, profile_, GURL()); | 82 extension_id_, events::kOnFocus, json_args, profile_, GURL()); |
83 } | 83 } |
84 | 84 |
85 virtual void OnBlur(int context_id) { | 85 virtual void OnBlur(int context_id) { |
86 if (profile_ == NULL || extension_id_.empty()) | 86 if (profile_ == NULL || extension_id_.empty()) |
87 return; | 87 return; |
88 | 88 |
89 ListValue args; | 89 ListValue args; |
90 args.Append(Value::CreateIntegerValue(context_id)); | 90 args.Append(base::NumberValue::New(context_id)); |
91 | 91 |
92 std::string json_args; | 92 std::string json_args; |
93 base::JSONWriter::Write(&args, false, &json_args); | 93 base::JSONWriter::Write(&args, false, &json_args); |
94 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 94 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
95 extension_id_, events::kOnBlur, json_args, profile_, GURL()); | 95 extension_id_, events::kOnBlur, json_args, profile_, GURL()); |
96 } | 96 } |
97 | 97 |
98 virtual void OnInputContextUpdate( | 98 virtual void OnInputContextUpdate( |
99 const InputMethodEngine::InputContext& context) { | 99 const InputMethodEngine::InputContext& context) { |
100 if (profile_ == NULL || extension_id_.empty()) | 100 if (profile_ == NULL || extension_id_.empty()) |
(...skipping 20 matching lines...) Expand all Loading... |
121 | 121 |
122 DictionaryValue* dict = new DictionaryValue(); | 122 DictionaryValue* dict = new DictionaryValue(); |
123 dict->SetString("type", event.type); | 123 dict->SetString("type", event.type); |
124 dict->SetString("key", event.key); | 124 dict->SetString("key", event.key); |
125 dict->SetString("keyCode", event.key_code); | 125 dict->SetString("keyCode", event.key_code); |
126 dict->SetBoolean("altKey", event.alt_key); | 126 dict->SetBoolean("altKey", event.alt_key); |
127 dict->SetBoolean("ctrlKey", event.ctrl_key); | 127 dict->SetBoolean("ctrlKey", event.ctrl_key); |
128 dict->SetBoolean("shiftKey", event.shift_key); | 128 dict->SetBoolean("shiftKey", event.shift_key); |
129 | 129 |
130 ListValue args; | 130 ListValue args; |
131 args.Append(Value::CreateStringValue(engine_id)); | 131 args.Append(base::StringValue::New(engine_id)); |
132 args.Append(dict); | 132 args.Append(dict); |
133 | 133 |
134 std::string json_args; | 134 std::string json_args; |
135 base::JSONWriter::Write(&args, false, &json_args); | 135 base::JSONWriter::Write(&args, false, &json_args); |
136 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 136 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
137 extension_id_, events::kOnKeyEvent, json_args, profile_, GURL()); | 137 extension_id_, events::kOnKeyEvent, json_args, profile_, GURL()); |
138 } | 138 } |
139 | 139 |
140 virtual void OnCandidateClicked(const std::string& engine_id, | 140 virtual void OnCandidateClicked(const std::string& engine_id, |
141 int candidate_id, | 141 int candidate_id, |
142 int button) { | 142 int button) { |
143 if (profile_ == NULL || extension_id_.empty()) | 143 if (profile_ == NULL || extension_id_.empty()) |
144 return; | 144 return; |
145 | 145 |
146 ListValue args; | 146 ListValue args; |
147 args.Append(Value::CreateStringValue(engine_id)); | 147 args.Append(base::StringValue::New(engine_id)); |
148 args.Append(Value::CreateIntegerValue(candidate_id)); | 148 args.Append(base::NumberValue::New(candidate_id)); |
149 switch (button) { | 149 switch (button) { |
150 case chromeos::InputMethodEngine::MOUSE_BUTTON_MIDDLE: | 150 case chromeos::InputMethodEngine::MOUSE_BUTTON_MIDDLE: |
151 args.Append(Value::CreateStringValue("middle")); | 151 args.Append(base::StringValue::New("middle")); |
152 break; | 152 break; |
153 | 153 |
154 case chromeos::InputMethodEngine::MOUSE_BUTTON_RIGHT: | 154 case chromeos::InputMethodEngine::MOUSE_BUTTON_RIGHT: |
155 args.Append(Value::CreateStringValue("right")); | 155 args.Append(base::StringValue::New("right")); |
156 break; | 156 break; |
157 | 157 |
158 case chromeos::InputMethodEngine::MOUSE_BUTTON_LEFT: | 158 case chromeos::InputMethodEngine::MOUSE_BUTTON_LEFT: |
159 // Default to left. | 159 // Default to left. |
160 default: | 160 default: |
161 args.Append(Value::CreateStringValue("left")); | 161 args.Append(base::StringValue::New("left")); |
162 break; | 162 break; |
163 } | 163 } |
164 | 164 |
165 std::string json_args; | 165 std::string json_args; |
166 base::JSONWriter::Write(&args, false, &json_args); | 166 base::JSONWriter::Write(&args, false, &json_args); |
167 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 167 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
168 extension_id_, events::kOnCandidateClicked, json_args, profile_, | 168 extension_id_, events::kOnCandidateClicked, json_args, profile_, |
169 GURL()); | 169 GURL()); |
170 } | 170 } |
171 | 171 |
172 virtual void OnMenuItemActivated(const std::string& engine_id, | 172 virtual void OnMenuItemActivated(const std::string& engine_id, |
173 const std::string& menu_id) { | 173 const std::string& menu_id) { |
174 if (profile_ == NULL || extension_id_.empty()) | 174 if (profile_ == NULL || extension_id_.empty()) |
175 return; | 175 return; |
176 | 176 |
177 ListValue args; | 177 ListValue args; |
178 args.Append(Value::CreateStringValue(engine_id)); | 178 args.Append(base::StringValue::New(engine_id)); |
179 args.Append(Value::CreateStringValue(menu_id)); | 179 args.Append(base::StringValue::New(menu_id)); |
180 | 180 |
181 std::string json_args; | 181 std::string json_args; |
182 base::JSONWriter::Write(&args, false, &json_args); | 182 base::JSONWriter::Write(&args, false, &json_args); |
183 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 183 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
184 extension_id_, events::kOnMenuItemActivated, json_args, profile_, | 184 extension_id_, events::kOnMenuItemActivated, json_args, profile_, |
185 GURL()); | 185 GURL()); |
186 } | 186 } |
187 | 187 |
188 private: | 188 private: |
189 Profile* profile_; | 189 Profile* profile_; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 } | 295 } |
296 return NULL; | 296 return NULL; |
297 } | 297 } |
298 | 298 |
299 bool SetCompositionFunction::RunImpl() { | 299 bool SetCompositionFunction::RunImpl() { |
300 chromeos::InputMethodEngine* engine = | 300 chromeos::InputMethodEngine* engine = |
301 ExtensionInputImeEventRouter::GetInstance()-> | 301 ExtensionInputImeEventRouter::GetInstance()-> |
302 GetActiveEngine(extension_id()); | 302 GetActiveEngine(extension_id()); |
303 if (!engine) { | 303 if (!engine) { |
304 if (has_callback()) { | 304 if (has_callback()) { |
305 result_.reset(Value::CreateBooleanValue(false)); | 305 result_.reset(base::FalseValue()); |
306 } | 306 } |
307 return true; | 307 return true; |
308 } | 308 } |
309 | 309 |
310 DictionaryValue* args; | 310 DictionaryValue* args; |
311 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 311 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
312 int context_id; | 312 int context_id; |
313 std::string text; | 313 std::string text; |
314 int selection_start; | 314 int selection_start; |
315 int selection_end; | 315 int selection_end; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 segments.back().style = | 354 segments.back().style = |
355 chromeos::InputMethodEngine::SEGMENT_STYLE_DOUBLE_UNDERLINE; | 355 chromeos::InputMethodEngine::SEGMENT_STYLE_DOUBLE_UNDERLINE; |
356 } | 356 } |
357 } | 357 } |
358 | 358 |
359 std::string error; | 359 std::string error; |
360 | 360 |
361 if (engine->SetComposition(context_id, text.c_str(), selection_start, | 361 if (engine->SetComposition(context_id, text.c_str(), selection_start, |
362 selection_end, segments, &error)) { | 362 selection_end, segments, &error)) { |
363 if (has_callback()) { | 363 if (has_callback()) { |
364 result_.reset(Value::CreateBooleanValue(true)); | 364 result_.reset(base::TrueValue()); |
365 } | 365 } |
366 return true; | 366 return true; |
367 } else { | 367 } else { |
368 if (has_callback()) { | 368 if (has_callback()) { |
369 result_.reset(Value::CreateBooleanValue(false)); | 369 result_.reset(base::FalseValue()); |
370 } | 370 } |
371 return false; | 371 return false; |
372 } | 372 } |
373 } | 373 } |
374 | 374 |
375 bool ClearCompositionFunction::RunImpl() { | 375 bool ClearCompositionFunction::RunImpl() { |
376 chromeos::InputMethodEngine* engine = | 376 chromeos::InputMethodEngine* engine = |
377 ExtensionInputImeEventRouter::GetInstance()-> | 377 ExtensionInputImeEventRouter::GetInstance()-> |
378 GetActiveEngine(extension_id()); | 378 GetActiveEngine(extension_id()); |
379 if (!engine) { | 379 if (!engine) { |
380 return false; | 380 return false; |
381 } | 381 } |
382 | 382 |
383 DictionaryValue* args; | 383 DictionaryValue* args; |
384 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 384 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
385 int context_id; | 385 int context_id; |
386 | 386 |
387 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, | 387 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, |
388 &context_id)); | 388 &context_id)); |
389 | 389 |
390 std::string error; | 390 std::string error; |
391 if (engine->ClearComposition(context_id, &error)) { | 391 if (engine->ClearComposition(context_id, &error)) { |
392 if (has_callback()) { | 392 if (has_callback()) { |
393 result_.reset(Value::CreateBooleanValue(true)); | 393 result_.reset(base::TrueValue()); |
394 } | 394 } |
395 return true; | 395 return true; |
396 } else { | 396 } else { |
397 if (has_callback()) { | 397 if (has_callback()) { |
398 result_.reset(Value::CreateBooleanValue(false)); | 398 result_.reset(base::FalseValue()); |
399 } | 399 } |
400 return false; | 400 return false; |
401 } | 401 } |
402 } | 402 } |
403 | 403 |
404 bool CommitTextFunction::RunImpl() { | 404 bool CommitTextFunction::RunImpl() { |
405 // TODO(zork): Support committing when not active. | 405 // TODO(zork): Support committing when not active. |
406 chromeos::InputMethodEngine* engine = | 406 chromeos::InputMethodEngine* engine = |
407 ExtensionInputImeEventRouter::GetInstance()-> | 407 ExtensionInputImeEventRouter::GetInstance()-> |
408 GetActiveEngine(extension_id()); | 408 GetActiveEngine(extension_id()); |
409 if (!engine) { | 409 if (!engine) { |
410 return false; | 410 return false; |
411 } | 411 } |
412 | 412 |
413 DictionaryValue* args; | 413 DictionaryValue* args; |
414 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 414 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
415 int context_id; | 415 int context_id; |
416 std::string text; | 416 std::string text; |
417 | 417 |
418 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, | 418 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, |
419 &context_id)); | 419 &context_id)); |
420 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kTextKey, &text)); | 420 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kTextKey, &text)); |
421 | 421 |
422 std::string error; | 422 std::string error; |
423 if (engine->CommitText(context_id, text.c_str(), &error)) { | 423 if (engine->CommitText(context_id, text.c_str(), &error)) { |
424 if (has_callback()) { | 424 if (has_callback()) { |
425 result_.reset(Value::CreateBooleanValue(true)); | 425 result_.reset(base::TrueValue()); |
426 } | 426 } |
427 return true; | 427 return true; |
428 } else { | 428 } else { |
429 if (has_callback()) { | 429 if (has_callback()) { |
430 result_.reset(Value::CreateBooleanValue(false)); | 430 result_.reset(base::FalseValue()); |
431 } | 431 } |
432 return false; | 432 return false; |
433 } | 433 } |
434 } | 434 } |
435 | 435 |
436 bool SetCandidateWindowPropertiesFunction::RunImpl() { | 436 bool SetCandidateWindowPropertiesFunction::RunImpl() { |
437 DictionaryValue* args; | 437 DictionaryValue* args; |
438 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 438 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
439 | 439 |
440 std::string engine_id; | 440 std::string engine_id; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 | 492 |
493 if (properties->HasKey(keys::kAuxiliaryTextVisibleKey)) { | 493 if (properties->HasKey(keys::kAuxiliaryTextVisibleKey)) { |
494 bool visible; | 494 bool visible; |
495 EXTENSION_FUNCTION_VALIDATE(properties->GetBoolean( | 495 EXTENSION_FUNCTION_VALIDATE(properties->GetBoolean( |
496 keys::kAuxiliaryTextVisibleKey, | 496 keys::kAuxiliaryTextVisibleKey, |
497 &visible)); | 497 &visible)); |
498 engine->SetCandidateWindowAuxTextVisible(visible); | 498 engine->SetCandidateWindowAuxTextVisible(visible); |
499 } | 499 } |
500 | 500 |
501 if (has_callback()) { | 501 if (has_callback()) { |
502 result_.reset(Value::CreateBooleanValue(true)); | 502 result_.reset(base::TrueValue()); |
503 } | 503 } |
504 | 504 |
505 return true; | 505 return true; |
506 } | 506 } |
507 | 507 |
508 #if defined(OS_CHROMEOS) | 508 #if defined(OS_CHROMEOS) |
509 bool SetCandidatesFunction::ReadCandidates( | 509 bool SetCandidatesFunction::ReadCandidates( |
510 ListValue* candidates, | 510 ListValue* candidates, |
511 std::vector<chromeos::InputMethodEngine::Candidate>* output) { | 511 std::vector<chromeos::InputMethodEngine::Candidate>* output) { |
512 for (size_t i = 0; i < candidates->GetSize(); ++i) { | 512 for (size_t i = 0; i < candidates->GetSize(); ++i) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 ListValue* candidate_list; | 571 ListValue* candidate_list; |
572 EXTENSION_FUNCTION_VALIDATE(args->GetList(keys::kCandidatesKey, | 572 EXTENSION_FUNCTION_VALIDATE(args->GetList(keys::kCandidatesKey, |
573 &candidate_list)); | 573 &candidate_list)); |
574 if (!ReadCandidates(candidate_list, &candidates)) { | 574 if (!ReadCandidates(candidate_list, &candidates)) { |
575 return false; | 575 return false; |
576 } | 576 } |
577 | 577 |
578 std::string error; | 578 std::string error; |
579 if (engine->SetCandidates(context_id, candidates, &error)) { | 579 if (engine->SetCandidates(context_id, candidates, &error)) { |
580 if (has_callback()) { | 580 if (has_callback()) { |
581 result_.reset(Value::CreateBooleanValue(true)); | 581 result_.reset(base::TrueValue()); |
582 } | 582 } |
583 return true; | 583 return true; |
584 } else { | 584 } else { |
585 if (has_callback()) { | 585 if (has_callback()) { |
586 result_.reset(Value::CreateBooleanValue(false)); | 586 result_.reset(base::FalseValue()); |
587 } | 587 } |
588 return false; | 588 return false; |
589 } | 589 } |
590 } | 590 } |
591 | 591 |
592 bool SetCursorPositionFunction::RunImpl() { | 592 bool SetCursorPositionFunction::RunImpl() { |
593 chromeos::InputMethodEngine* engine = | 593 chromeos::InputMethodEngine* engine = |
594 ExtensionInputImeEventRouter::GetInstance()-> | 594 ExtensionInputImeEventRouter::GetInstance()-> |
595 GetActiveEngine(extension_id()); | 595 GetActiveEngine(extension_id()); |
596 if (!engine) { | 596 if (!engine) { |
597 return false; | 597 return false; |
598 } | 598 } |
599 | 599 |
600 DictionaryValue* args; | 600 DictionaryValue* args; |
601 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 601 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
602 int context_id; | 602 int context_id; |
603 int candidate_id; | 603 int candidate_id; |
604 | 604 |
605 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, | 605 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, |
606 &context_id)); | 606 &context_id)); |
607 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kCandidateIdKey, | 607 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kCandidateIdKey, |
608 &candidate_id)); | 608 &candidate_id)); |
609 | 609 |
610 std::string error; | 610 std::string error; |
611 if (engine->SetCursorPosition(context_id, candidate_id, &error)) { | 611 if (engine->SetCursorPosition(context_id, candidate_id, &error)) { |
612 if (has_callback()) { | 612 if (has_callback()) { |
613 result_.reset(Value::CreateBooleanValue(true)); | 613 result_.reset(base::TrueValue()); |
614 } | 614 } |
615 return true; | 615 return true; |
616 } else { | 616 } else { |
617 if (has_callback()) { | 617 if (has_callback()) { |
618 result_.reset(Value::CreateBooleanValue(false)); | 618 result_.reset(base::FalseValue()); |
619 } | 619 } |
620 return false; | 620 return false; |
621 } | 621 } |
622 return true; | 622 return true; |
623 } | 623 } |
624 | 624 |
625 bool SetMenuItemsFunction::RunImpl() { | 625 bool SetMenuItemsFunction::RunImpl() { |
626 // TODO | 626 // TODO |
627 return true; | 627 return true; |
628 } | 628 } |
629 | 629 |
630 bool UpdateMenuItemsFunction::RunImpl() { | 630 bool UpdateMenuItemsFunction::RunImpl() { |
631 // TODO | 631 // TODO |
632 return true; | 632 return true; |
633 } | 633 } |
634 #endif | 634 #endif |
OLD | NEW |