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 284 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 |