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