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

Side by Side Diff: chrome/browser/extensions/extension_input_ime_api.cc

Issue 10694106: Added support for multiple parameters to Extension API callbacks. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Synced. Created 8 years, 5 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/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/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 : next_request_id_(1) { 460 : next_request_id_(1) {
461 } 461 }
462 462
463 ExtensionInputImeEventRouter::~ExtensionInputImeEventRouter() {} 463 ExtensionInputImeEventRouter::~ExtensionInputImeEventRouter() {}
464 464
465 bool SetCompositionFunction::RunImpl() { 465 bool SetCompositionFunction::RunImpl() {
466 chromeos::InputMethodEngine* engine = 466 chromeos::InputMethodEngine* engine =
467 ExtensionInputImeEventRouter::GetInstance()-> 467 ExtensionInputImeEventRouter::GetInstance()->
468 GetActiveEngine(extension_id()); 468 GetActiveEngine(extension_id());
469 if (!engine) { 469 if (!engine) {
470 result_.reset(Value::CreateBooleanValue(false)); 470 SetResult(Value::CreateBooleanValue(false));
471 return true; 471 return true;
472 } 472 }
473 473
474 DictionaryValue* args; 474 DictionaryValue* args;
475 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); 475 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
476 int context_id; 476 int context_id;
477 std::string text; 477 std::string text;
478 int selection_start; 478 int selection_start;
479 int selection_end; 479 int selection_end;
480 int cursor; 480 int cursor;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 chromeos::InputMethodEngine::SEGMENT_STYLE_UNDERLINE; 524 chromeos::InputMethodEngine::SEGMENT_STYLE_UNDERLINE;
525 } else if (style == keys::kStyleDoubleUnderline) { 525 } else if (style == keys::kStyleDoubleUnderline) {
526 segments.back().style = 526 segments.back().style =
527 chromeos::InputMethodEngine::SEGMENT_STYLE_DOUBLE_UNDERLINE; 527 chromeos::InputMethodEngine::SEGMENT_STYLE_DOUBLE_UNDERLINE;
528 } 528 }
529 } 529 }
530 } 530 }
531 531
532 if (engine->SetComposition(context_id, text.c_str(), selection_start, 532 if (engine->SetComposition(context_id, text.c_str(), selection_start,
533 selection_end, cursor, segments, &error_)) { 533 selection_end, cursor, segments, &error_)) {
534 result_.reset(Value::CreateBooleanValue(true)); 534 SetResult(Value::CreateBooleanValue(true));
535 } else { 535 } else {
536 result_.reset(Value::CreateBooleanValue(false)); 536 SetResult(Value::CreateBooleanValue(false));
537 } 537 }
538 return true; 538 return true;
539 } 539 }
540 540
541 bool ClearCompositionFunction::RunImpl() { 541 bool ClearCompositionFunction::RunImpl() {
542 chromeos::InputMethodEngine* engine = 542 chromeos::InputMethodEngine* engine =
543 ExtensionInputImeEventRouter::GetInstance()-> 543 ExtensionInputImeEventRouter::GetInstance()->
544 GetActiveEngine(extension_id()); 544 GetActiveEngine(extension_id());
545 if (!engine) { 545 if (!engine) {
546 result_.reset(Value::CreateBooleanValue(false)); 546 SetResult(Value::CreateBooleanValue(false));
547 return true; 547 return true;
548 } 548 }
549 549
550 DictionaryValue* args; 550 DictionaryValue* args;
551 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); 551 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
552 int context_id; 552 int context_id;
553 553
554 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, 554 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey,
555 &context_id)); 555 &context_id));
556 556
557 if (engine->ClearComposition(context_id, &error_)) { 557 if (engine->ClearComposition(context_id, &error_)) {
558 result_.reset(Value::CreateBooleanValue(true)); 558 SetResult(Value::CreateBooleanValue(true));
559 } else { 559 } else {
560 result_.reset(Value::CreateBooleanValue(false)); 560 SetResult(Value::CreateBooleanValue(false));
561 } 561 }
562 return true; 562 return true;
563 } 563 }
564 564
565 bool CommitTextFunction::RunImpl() { 565 bool CommitTextFunction::RunImpl() {
566 // TODO(zork): Support committing when not active. 566 // TODO(zork): Support committing when not active.
567 chromeos::InputMethodEngine* engine = 567 chromeos::InputMethodEngine* engine =
568 ExtensionInputImeEventRouter::GetInstance()-> 568 ExtensionInputImeEventRouter::GetInstance()->
569 GetActiveEngine(extension_id()); 569 GetActiveEngine(extension_id());
570 if (!engine) { 570 if (!engine) {
571 result_.reset(Value::CreateBooleanValue(false)); 571 SetResult(Value::CreateBooleanValue(false));
572 return true; 572 return true;
573 } 573 }
574 574
575 DictionaryValue* args; 575 DictionaryValue* args;
576 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); 576 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
577 int context_id; 577 int context_id;
578 std::string text; 578 std::string text;
579 579
580 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, 580 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey,
581 &context_id)); 581 &context_id));
582 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kTextKey, &text)); 582 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kTextKey, &text));
583 583
584 if (engine->CommitText(context_id, text.c_str(), &error_)) { 584 if (engine->CommitText(context_id, text.c_str(), &error_)) {
585 result_.reset(Value::CreateBooleanValue(true)); 585 SetResult(Value::CreateBooleanValue(true));
586 } else { 586 } else {
587 result_.reset(Value::CreateBooleanValue(false)); 587 SetResult(Value::CreateBooleanValue(false));
588 } 588 }
589 return true; 589 return true;
590 } 590 }
591 591
592 bool SetCandidateWindowPropertiesFunction::RunImpl() { 592 bool SetCandidateWindowPropertiesFunction::RunImpl() {
593 DictionaryValue* args; 593 DictionaryValue* args;
594 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); 594 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
595 595
596 std::string engine_id; 596 std::string engine_id;
597 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); 597 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id));
598 598
599 chromeos::InputMethodEngine* engine = 599 chromeos::InputMethodEngine* engine =
600 ExtensionInputImeEventRouter::GetInstance()->GetEngine(extension_id(), 600 ExtensionInputImeEventRouter::GetInstance()->GetEngine(extension_id(),
601 engine_id); 601 engine_id);
602 if (!engine) { 602 if (!engine) {
603 result_.reset(Value::CreateBooleanValue(false)); 603 SetResult(Value::CreateBooleanValue(false));
604 return true; 604 return true;
605 } 605 }
606 606
607 DictionaryValue* properties; 607 DictionaryValue* properties;
608 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(keys::kPropertiesKey, 608 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(keys::kPropertiesKey,
609 &properties)); 609 &properties));
610 610
611 if (properties->HasKey(keys::kVisibleKey)) { 611 if (properties->HasKey(keys::kVisibleKey)) {
612 bool visible; 612 bool visible;
613 EXTENSION_FUNCTION_VALIDATE(properties->GetBoolean(keys::kVisibleKey, 613 EXTENSION_FUNCTION_VALIDATE(properties->GetBoolean(keys::kVisibleKey,
614 &visible)); 614 &visible));
615 if (!engine->SetCandidateWindowVisible(visible, &error_)) { 615 if (!engine->SetCandidateWindowVisible(visible, &error_)) {
616 result_.reset(Value::CreateBooleanValue(false)); 616 SetResult(Value::CreateBooleanValue(false));
617 return true; 617 return true;
618 } 618 }
619 } 619 }
620 620
621 if (properties->HasKey(keys::kCursorVisibleKey)) { 621 if (properties->HasKey(keys::kCursorVisibleKey)) {
622 bool visible; 622 bool visible;
623 EXTENSION_FUNCTION_VALIDATE(properties->GetBoolean(keys::kCursorVisibleKey, 623 EXTENSION_FUNCTION_VALIDATE(properties->GetBoolean(keys::kCursorVisibleKey,
624 &visible)); 624 &visible));
625 engine->SetCandidateWindowCursorVisible(visible); 625 engine->SetCandidateWindowCursorVisible(visible);
626 } 626 }
(...skipping 20 matching lines...) Expand all
647 } 647 }
648 648
649 if (properties->HasKey(keys::kAuxiliaryTextVisibleKey)) { 649 if (properties->HasKey(keys::kAuxiliaryTextVisibleKey)) {
650 bool visible; 650 bool visible;
651 EXTENSION_FUNCTION_VALIDATE(properties->GetBoolean( 651 EXTENSION_FUNCTION_VALIDATE(properties->GetBoolean(
652 keys::kAuxiliaryTextVisibleKey, 652 keys::kAuxiliaryTextVisibleKey,
653 &visible)); 653 &visible));
654 engine->SetCandidateWindowAuxTextVisible(visible); 654 engine->SetCandidateWindowAuxTextVisible(visible);
655 } 655 }
656 656
657 result_.reset(Value::CreateBooleanValue(true)); 657 SetResult(Value::CreateBooleanValue(true));
658 658
659 return true; 659 return true;
660 } 660 }
661 661
662 #if defined(OS_CHROMEOS) 662 #if defined(OS_CHROMEOS)
663 bool SetCandidatesFunction::ReadCandidates( 663 bool SetCandidatesFunction::ReadCandidates(
664 ListValue* candidates, 664 ListValue* candidates,
665 std::vector<chromeos::InputMethodEngine::Candidate>* output) { 665 std::vector<chromeos::InputMethodEngine::Candidate>* output) {
666 for (size_t i = 0; i < candidates->GetSize(); ++i) { 666 for (size_t i = 0; i < candidates->GetSize(); ++i) {
667 DictionaryValue* candidate_dict; 667 DictionaryValue* candidate_dict;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 } 704 }
705 705
706 return true; 706 return true;
707 } 707 }
708 708
709 bool SetCandidatesFunction::RunImpl() { 709 bool SetCandidatesFunction::RunImpl() {
710 chromeos::InputMethodEngine* engine = 710 chromeos::InputMethodEngine* engine =
711 ExtensionInputImeEventRouter::GetInstance()-> 711 ExtensionInputImeEventRouter::GetInstance()->
712 GetActiveEngine(extension_id()); 712 GetActiveEngine(extension_id());
713 if (!engine) { 713 if (!engine) {
714 result_.reset(Value::CreateBooleanValue(false)); 714 SetResult(Value::CreateBooleanValue(false));
715 return true; 715 return true;
716 } 716 }
717 717
718 DictionaryValue* args; 718 DictionaryValue* args;
719 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); 719 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
720 720
721 int context_id; 721 int context_id;
722 std::vector<chromeos::InputMethodEngine::Candidate> candidates; 722 std::vector<chromeos::InputMethodEngine::Candidate> candidates;
723 723
724 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, 724 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey,
725 &context_id)); 725 &context_id));
726 726
727 ListValue* candidate_list; 727 ListValue* candidate_list;
728 EXTENSION_FUNCTION_VALIDATE(args->GetList(keys::kCandidatesKey, 728 EXTENSION_FUNCTION_VALIDATE(args->GetList(keys::kCandidatesKey,
729 &candidate_list)); 729 &candidate_list));
730 if (!ReadCandidates(candidate_list, &candidates)) { 730 if (!ReadCandidates(candidate_list, &candidates)) {
731 error_ = kErrorBadCandidateList; 731 error_ = kErrorBadCandidateList;
732 return false; 732 return false;
733 } 733 }
734 734
735 std::string error; 735 std::string error;
736 if (engine->SetCandidates(context_id, candidates, &error_)) { 736 if (engine->SetCandidates(context_id, candidates, &error_)) {
737 result_.reset(Value::CreateBooleanValue(true)); 737 SetResult(Value::CreateBooleanValue(true));
738 } else { 738 } else {
739 result_.reset(Value::CreateBooleanValue(false)); 739 SetResult(Value::CreateBooleanValue(false));
740 } 740 }
741 return true; 741 return true;
742 } 742 }
743 743
744 bool SetCursorPositionFunction::RunImpl() { 744 bool SetCursorPositionFunction::RunImpl() {
745 chromeos::InputMethodEngine* engine = 745 chromeos::InputMethodEngine* engine =
746 ExtensionInputImeEventRouter::GetInstance()-> 746 ExtensionInputImeEventRouter::GetInstance()->
747 GetActiveEngine(extension_id()); 747 GetActiveEngine(extension_id());
748 if (!engine) { 748 if (!engine) {
749 result_.reset(Value::CreateBooleanValue(false)); 749 SetResult(Value::CreateBooleanValue(false));
750 return true; 750 return true;
751 } 751 }
752 752
753 DictionaryValue* args; 753 DictionaryValue* args;
754 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); 754 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
755 int context_id; 755 int context_id;
756 int candidate_id; 756 int candidate_id;
757 757
758 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, 758 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey,
759 &context_id)); 759 &context_id));
760 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kCandidateIdKey, 760 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kCandidateIdKey,
761 &candidate_id)); 761 &candidate_id));
762 762
763 if (engine->SetCursorPosition(context_id, candidate_id, &error_)) { 763 if (engine->SetCursorPosition(context_id, candidate_id, &error_)) {
764 result_.reset(Value::CreateBooleanValue(true)); 764 SetResult(Value::CreateBooleanValue(true));
765 } else { 765 } else {
766 result_.reset(Value::CreateBooleanValue(false)); 766 SetResult(Value::CreateBooleanValue(false));
767 } 767 }
768 return true; 768 return true;
769 } 769 }
770 770
771 bool SetMenuItemsFunction::RunImpl() { 771 bool SetMenuItemsFunction::RunImpl() {
772 DictionaryValue* args; 772 DictionaryValue* args;
773 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); 773 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
774 774
775 std::string engine_id; 775 std::string engine_id;
776 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); 776 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 828
829 bool handled = false; 829 bool handled = false;
830 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &handled)); 830 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &handled));
831 831
832 ExtensionInputImeEventRouter::GetInstance()->OnEventHandled( 832 ExtensionInputImeEventRouter::GetInstance()->OnEventHandled(
833 extension_id(), request_id_str, handled); 833 extension_id(), request_id_str, handled);
834 834
835 return true; 835 return true;
836 } 836 }
837 #endif 837 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698