| 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/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/profiles/profile_helper.h" | 9 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 10 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 | 426 |
| 427 return request_id; | 427 return request_id; |
| 428 } | 428 } |
| 429 | 429 |
| 430 InputImeEventRouter::InputImeEventRouter() | 430 InputImeEventRouter::InputImeEventRouter() |
| 431 : next_request_id_(1) { | 431 : next_request_id_(1) { |
| 432 } | 432 } |
| 433 | 433 |
| 434 InputImeEventRouter::~InputImeEventRouter() {} | 434 InputImeEventRouter::~InputImeEventRouter() {} |
| 435 | 435 |
| 436 bool InputImeSetCompositionFunction::RunImpl() { | 436 bool InputImeSetCompositionFunction::RunSync() { |
| 437 InputMethodEngineInterface* engine = | 437 InputMethodEngineInterface* engine = |
| 438 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); | 438 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); |
| 439 if (!engine) { | 439 if (!engine) { |
| 440 SetResult(new base::FundamentalValue(false)); | 440 SetResult(new base::FundamentalValue(false)); |
| 441 return true; | 441 return true; |
| 442 } | 442 } |
| 443 | 443 |
| 444 scoped_ptr<SetComposition::Params> parent_params( | 444 scoped_ptr<SetComposition::Params> parent_params( |
| 445 SetComposition::Params::Create(*args_)); | 445 SetComposition::Params::Create(*args_)); |
| 446 const SetComposition::Params::Parameters& params = parent_params->parameters; | 446 const SetComposition::Params::Parameters& params = parent_params->parameters; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 472 int selection_end = | 472 int selection_end = |
| 473 params.selection_end ? *params.selection_end : params.cursor; | 473 params.selection_end ? *params.selection_end : params.cursor; |
| 474 | 474 |
| 475 SetResult(new base::FundamentalValue( | 475 SetResult(new base::FundamentalValue( |
| 476 engine->SetComposition(params.context_id, params.text.c_str(), | 476 engine->SetComposition(params.context_id, params.text.c_str(), |
| 477 selection_start, selection_end, params.cursor, | 477 selection_start, selection_end, params.cursor, |
| 478 segments, &error_))); | 478 segments, &error_))); |
| 479 return true; | 479 return true; |
| 480 } | 480 } |
| 481 | 481 |
| 482 bool InputImeClearCompositionFunction::RunImpl() { | 482 bool InputImeClearCompositionFunction::RunSync() { |
| 483 InputMethodEngineInterface* engine = | 483 InputMethodEngineInterface* engine = |
| 484 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); | 484 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); |
| 485 if (!engine) { | 485 if (!engine) { |
| 486 SetResult(new base::FundamentalValue(false)); | 486 SetResult(new base::FundamentalValue(false)); |
| 487 return true; | 487 return true; |
| 488 } | 488 } |
| 489 | 489 |
| 490 scoped_ptr<ClearComposition::Params> parent_params( | 490 scoped_ptr<ClearComposition::Params> parent_params( |
| 491 ClearComposition::Params::Create(*args_)); | 491 ClearComposition::Params::Create(*args_)); |
| 492 const ClearComposition::Params::Parameters& params = | 492 const ClearComposition::Params::Parameters& params = |
| 493 parent_params->parameters; | 493 parent_params->parameters; |
| 494 | 494 |
| 495 SetResult(new base::FundamentalValue( | 495 SetResult(new base::FundamentalValue( |
| 496 engine->ClearComposition(params.context_id, &error_))); | 496 engine->ClearComposition(params.context_id, &error_))); |
| 497 return true; | 497 return true; |
| 498 } | 498 } |
| 499 | 499 |
| 500 bool InputImeCommitTextFunction::RunImpl() { | 500 bool InputImeCommitTextFunction::RunSync() { |
| 501 // TODO(zork): Support committing when not active. | 501 // TODO(zork): Support committing when not active. |
| 502 InputMethodEngineInterface* engine = | 502 InputMethodEngineInterface* engine = |
| 503 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); | 503 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); |
| 504 if (!engine) { | 504 if (!engine) { |
| 505 SetResult(new base::FundamentalValue(false)); | 505 SetResult(new base::FundamentalValue(false)); |
| 506 return true; | 506 return true; |
| 507 } | 507 } |
| 508 | 508 |
| 509 scoped_ptr<CommitText::Params> parent_params( | 509 scoped_ptr<CommitText::Params> parent_params( |
| 510 CommitText::Params::Create(*args_)); | 510 CommitText::Params::Create(*args_)); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 event.shift_key = *(key_data[i]->shift_key); | 555 event.shift_key = *(key_data[i]->shift_key); |
| 556 if (key_data[i]->caps_lock) | 556 if (key_data[i]->caps_lock) |
| 557 event.caps_lock = *(key_data[i]->caps_lock); | 557 event.caps_lock = *(key_data[i]->caps_lock); |
| 558 key_data_out.push_back(event); | 558 key_data_out.push_back(event); |
| 559 } | 559 } |
| 560 | 560 |
| 561 engine->SendKeyEvents(params.context_id, key_data_out); | 561 engine->SendKeyEvents(params.context_id, key_data_out); |
| 562 return true; | 562 return true; |
| 563 } | 563 } |
| 564 | 564 |
| 565 bool InputImeSetCandidateWindowPropertiesFunction::RunImpl() { | 565 bool InputImeSetCandidateWindowPropertiesFunction::RunSync() { |
| 566 scoped_ptr<SetCandidateWindowProperties::Params> parent_params( | 566 scoped_ptr<SetCandidateWindowProperties::Params> parent_params( |
| 567 SetCandidateWindowProperties::Params::Create(*args_)); | 567 SetCandidateWindowProperties::Params::Create(*args_)); |
| 568 const SetCandidateWindowProperties::Params::Parameters& | 568 const SetCandidateWindowProperties::Params::Parameters& |
| 569 params = parent_params->parameters; | 569 params = parent_params->parameters; |
| 570 | 570 |
| 571 InputMethodEngineInterface* engine = | 571 InputMethodEngineInterface* engine = |
| 572 InputImeEventRouter::GetInstance()->GetEngine(extension_id(), | 572 InputImeEventRouter::GetInstance()->GetEngine(extension_id(), |
| 573 params.engine_id); | 573 params.engine_id); |
| 574 | 574 |
| 575 if (!engine) { | 575 if (!engine) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 | 630 |
| 631 if (modified) { | 631 if (modified) { |
| 632 engine->SetCandidateWindowProperty(properties_out); | 632 engine->SetCandidateWindowProperty(properties_out); |
| 633 } | 633 } |
| 634 | 634 |
| 635 SetResult(new base::FundamentalValue(true)); | 635 SetResult(new base::FundamentalValue(true)); |
| 636 | 636 |
| 637 return true; | 637 return true; |
| 638 } | 638 } |
| 639 | 639 |
| 640 bool InputImeSetCandidatesFunction::RunImpl() { | 640 bool InputImeSetCandidatesFunction::RunSync() { |
| 641 InputMethodEngineInterface* engine = | 641 InputMethodEngineInterface* engine = |
| 642 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); | 642 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); |
| 643 if (!engine) { | 643 if (!engine) { |
| 644 SetResult(new base::FundamentalValue(false)); | 644 SetResult(new base::FundamentalValue(false)); |
| 645 return true; | 645 return true; |
| 646 } | 646 } |
| 647 | 647 |
| 648 scoped_ptr<SetCandidates::Params> parent_params( | 648 scoped_ptr<SetCandidates::Params> parent_params( |
| 649 SetCandidates::Params::Create(*args_)); | 649 SetCandidates::Params::Create(*args_)); |
| 650 const SetCandidates::Params::Parameters& params = | 650 const SetCandidates::Params::Parameters& params = |
| (...skipping 15 matching lines...) Expand all Loading... |
| 666 candidates_out.back().usage.title = candidates_in[i]->usage->title; | 666 candidates_out.back().usage.title = candidates_in[i]->usage->title; |
| 667 candidates_out.back().usage.body = candidates_in[i]->usage->body; | 667 candidates_out.back().usage.body = candidates_in[i]->usage->body; |
| 668 } | 668 } |
| 669 } | 669 } |
| 670 | 670 |
| 671 SetResult(new base::FundamentalValue( | 671 SetResult(new base::FundamentalValue( |
| 672 engine->SetCandidates(params.context_id, candidates_out, &error_))); | 672 engine->SetCandidates(params.context_id, candidates_out, &error_))); |
| 673 return true; | 673 return true; |
| 674 } | 674 } |
| 675 | 675 |
| 676 bool InputImeSetCursorPositionFunction::RunImpl() { | 676 bool InputImeSetCursorPositionFunction::RunSync() { |
| 677 InputMethodEngineInterface* engine = | 677 InputMethodEngineInterface* engine = |
| 678 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); | 678 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); |
| 679 if (!engine) { | 679 if (!engine) { |
| 680 SetResult(new base::FundamentalValue(false)); | 680 SetResult(new base::FundamentalValue(false)); |
| 681 return true; | 681 return true; |
| 682 } | 682 } |
| 683 | 683 |
| 684 scoped_ptr<SetCursorPosition::Params> parent_params( | 684 scoped_ptr<SetCursorPosition::Params> parent_params( |
| 685 SetCursorPosition::Params::Create(*args_)); | 685 SetCursorPosition::Params::Create(*args_)); |
| 686 const SetCursorPosition::Params::Parameters& params = | 686 const SetCursorPosition::Params::Parameters& params = |
| 687 parent_params->parameters; | 687 parent_params->parameters; |
| 688 | 688 |
| 689 SetResult(new base::FundamentalValue( | 689 SetResult(new base::FundamentalValue( |
| 690 engine->SetCursorPosition(params.context_id, params.candidate_id, | 690 engine->SetCursorPosition(params.context_id, params.candidate_id, |
| 691 &error_))); | 691 &error_))); |
| 692 return true; | 692 return true; |
| 693 } | 693 } |
| 694 | 694 |
| 695 bool InputImeSetMenuItemsFunction::RunImpl() { | 695 bool InputImeSetMenuItemsFunction::RunSync() { |
| 696 scoped_ptr<SetMenuItems::Params> parent_params( | 696 scoped_ptr<SetMenuItems::Params> parent_params( |
| 697 SetMenuItems::Params::Create(*args_)); | 697 SetMenuItems::Params::Create(*args_)); |
| 698 const SetMenuItems::Params::Parameters& params = | 698 const SetMenuItems::Params::Parameters& params = |
| 699 parent_params->parameters; | 699 parent_params->parameters; |
| 700 | 700 |
| 701 InputMethodEngineInterface* engine = | 701 InputMethodEngineInterface* engine = |
| 702 InputImeEventRouter::GetInstance()->GetEngine(extension_id(), | 702 InputImeEventRouter::GetInstance()->GetEngine(extension_id(), |
| 703 params.engine_id); | 703 params.engine_id); |
| 704 if (!engine) { | 704 if (!engine) { |
| 705 error_ = kErrorEngineNotAvailable; | 705 error_ = kErrorEngineNotAvailable; |
| 706 return false; | 706 return false; |
| 707 } | 707 } |
| 708 | 708 |
| 709 const std::vector<linked_ptr<input_ime::MenuItem> >& items = params.items; | 709 const std::vector<linked_ptr<input_ime::MenuItem> >& items = params.items; |
| 710 std::vector<InputMethodEngineInterface::MenuItem> items_out; | 710 std::vector<InputMethodEngineInterface::MenuItem> items_out; |
| 711 | 711 |
| 712 for (size_t i = 0; i < items.size(); ++i) { | 712 for (size_t i = 0; i < items.size(); ++i) { |
| 713 items_out.push_back(InputMethodEngineInterface::MenuItem()); | 713 items_out.push_back(InputMethodEngineInterface::MenuItem()); |
| 714 SetMenuItemToMenu(*items[i], &items_out.back()); | 714 SetMenuItemToMenu(*items[i], &items_out.back()); |
| 715 } | 715 } |
| 716 | 716 |
| 717 if (!engine->SetMenuItems(items_out)) | 717 if (!engine->SetMenuItems(items_out)) |
| 718 error_ = kErrorSetMenuItemsFail; | 718 error_ = kErrorSetMenuItemsFail; |
| 719 return true; | 719 return true; |
| 720 } | 720 } |
| 721 | 721 |
| 722 bool InputImeUpdateMenuItemsFunction::RunImpl() { | 722 bool InputImeUpdateMenuItemsFunction::RunSync() { |
| 723 scoped_ptr<UpdateMenuItems::Params> parent_params( | 723 scoped_ptr<UpdateMenuItems::Params> parent_params( |
| 724 UpdateMenuItems::Params::Create(*args_)); | 724 UpdateMenuItems::Params::Create(*args_)); |
| 725 const UpdateMenuItems::Params::Parameters& params = | 725 const UpdateMenuItems::Params::Parameters& params = |
| 726 parent_params->parameters; | 726 parent_params->parameters; |
| 727 | 727 |
| 728 InputMethodEngineInterface* engine = | 728 InputMethodEngineInterface* engine = |
| 729 InputImeEventRouter::GetInstance()->GetEngine(extension_id(), | 729 InputImeEventRouter::GetInstance()->GetEngine(extension_id(), |
| 730 params.engine_id); | 730 params.engine_id); |
| 731 if (!engine) { | 731 if (!engine) { |
| 732 error_ = kErrorEngineNotAvailable; | 732 error_ = kErrorEngineNotAvailable; |
| 733 return false; | 733 return false; |
| 734 } | 734 } |
| 735 | 735 |
| 736 const std::vector<linked_ptr<input_ime::MenuItem> >& items = params.items; | 736 const std::vector<linked_ptr<input_ime::MenuItem> >& items = params.items; |
| 737 std::vector<InputMethodEngineInterface::MenuItem> items_out; | 737 std::vector<InputMethodEngineInterface::MenuItem> items_out; |
| 738 | 738 |
| 739 for (size_t i = 0; i < items.size(); ++i) { | 739 for (size_t i = 0; i < items.size(); ++i) { |
| 740 items_out.push_back(InputMethodEngineInterface::MenuItem()); | 740 items_out.push_back(InputMethodEngineInterface::MenuItem()); |
| 741 SetMenuItemToMenu(*items[i], &items_out.back()); | 741 SetMenuItemToMenu(*items[i], &items_out.back()); |
| 742 } | 742 } |
| 743 | 743 |
| 744 if (!engine->UpdateMenuItems(items_out)) | 744 if (!engine->UpdateMenuItems(items_out)) |
| 745 error_ = kErrorUpdateMenuItemsFail; | 745 error_ = kErrorUpdateMenuItemsFail; |
| 746 return true; | 746 return true; |
| 747 } | 747 } |
| 748 | 748 |
| 749 bool InputImeDeleteSurroundingTextFunction::RunImpl() { | 749 bool InputImeDeleteSurroundingTextFunction::RunSync() { |
| 750 scoped_ptr<DeleteSurroundingText::Params> parent_params( | 750 scoped_ptr<DeleteSurroundingText::Params> parent_params( |
| 751 DeleteSurroundingText::Params::Create(*args_)); | 751 DeleteSurroundingText::Params::Create(*args_)); |
| 752 const DeleteSurroundingText::Params::Parameters& params = | 752 const DeleteSurroundingText::Params::Parameters& params = |
| 753 parent_params->parameters; | 753 parent_params->parameters; |
| 754 | 754 |
| 755 InputMethodEngineInterface* engine = | 755 InputMethodEngineInterface* engine = |
| 756 InputImeEventRouter::GetInstance()->GetEngine(extension_id(), | 756 InputImeEventRouter::GetInstance()->GetEngine(extension_id(), |
| 757 params.engine_id); | 757 params.engine_id); |
| 758 if (!engine) { | 758 if (!engine) { |
| 759 error_ = kErrorEngineNotAvailable; | 759 error_ = kErrorEngineNotAvailable; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 input_ime_event_router()->GetActiveEngine(details.extension_id); | 833 input_ime_event_router()->GetActiveEngine(details.extension_id); |
| 834 if (engine) | 834 if (engine) |
| 835 engine->NotifyImeReady(); | 835 engine->NotifyImeReady(); |
| 836 } | 836 } |
| 837 | 837 |
| 838 InputImeEventRouter* InputImeAPI::input_ime_event_router() { | 838 InputImeEventRouter* InputImeAPI::input_ime_event_router() { |
| 839 return InputImeEventRouter::GetInstance(); | 839 return InputImeEventRouter::GetInstance(); |
| 840 } | 840 } |
| 841 | 841 |
| 842 } // namespace extensions | 842 } // namespace extensions |
| OLD | NEW |