OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 if (!engine) { | 363 if (!engine) { |
364 return RespondNow( | 364 return RespondNow( |
365 OneArgument(base::MakeUnique<base::FundamentalValue>(false))); | 365 OneArgument(base::MakeUnique<base::FundamentalValue>(false))); |
366 } | 366 } |
367 | 367 |
368 std::unique_ptr<ClearComposition::Params> parent_params( | 368 std::unique_ptr<ClearComposition::Params> parent_params( |
369 ClearComposition::Params::Create(*args_)); | 369 ClearComposition::Params::Create(*args_)); |
370 const ClearComposition::Params::Parameters& params = | 370 const ClearComposition::Params::Parameters& params = |
371 parent_params->parameters; | 371 parent_params->parameters; |
372 | 372 |
373 return RespondNow(OneArgument(base::MakeUnique<base::FundamentalValue>( | 373 std::string error; |
374 engine->ClearComposition(params.context_id, &error_)))); | 374 bool success = engine->ClearComposition(params.context_id, &error); |
| 375 if (!success) |
| 376 SetError(error); |
| 377 return RespondNow( |
| 378 OneArgument(base::MakeUnique<base::FundamentalValue>(success))); |
375 } | 379 } |
376 | 380 |
377 bool InputImeHideInputViewFunction::RunAsync() { | 381 bool InputImeHideInputViewFunction::RunAsync() { |
378 InputMethodEngine* engine = GetActiveEngine( | 382 InputMethodEngine* engine = GetActiveEngine( |
379 Profile::FromBrowserContext(browser_context()), extension_id()); | 383 Profile::FromBrowserContext(browser_context()), extension_id()); |
380 if (!engine) { | 384 if (!engine) { |
381 return true; | 385 return true; |
382 } | 386 } |
383 engine->HideInputView(); | 387 engine->HideInputView(); |
384 return true; | 388 return true; |
(...skipping 12 matching lines...) Expand all Loading... |
397 event_router ? event_router->GetEngine(extension_id(), params.engine_id) | 401 event_router ? event_router->GetEngine(extension_id(), params.engine_id) |
398 : nullptr; | 402 : nullptr; |
399 if (!engine) { | 403 if (!engine) { |
400 return RespondNow( | 404 return RespondNow( |
401 OneArgument(base::MakeUnique<base::FundamentalValue>(false))); | 405 OneArgument(base::MakeUnique<base::FundamentalValue>(false))); |
402 } | 406 } |
403 | 407 |
404 const SetCandidateWindowProperties::Params::Parameters::Properties& | 408 const SetCandidateWindowProperties::Params::Parameters::Properties& |
405 properties = params.properties; | 409 properties = params.properties; |
406 | 410 |
| 411 std::string error; |
407 if (properties.visible && | 412 if (properties.visible && |
408 !engine->SetCandidateWindowVisible(*properties.visible, &error_)) { | 413 !engine->SetCandidateWindowVisible(*properties.visible, &error)) { |
| 414 SetError(error); |
409 return RespondNow( | 415 return RespondNow( |
410 OneArgument(base::MakeUnique<base::FundamentalValue>(false))); | 416 OneArgument(base::MakeUnique<base::FundamentalValue>(false))); |
411 } | 417 } |
412 | 418 |
413 InputMethodEngine::CandidateWindowProperty properties_out = | 419 InputMethodEngine::CandidateWindowProperty properties_out = |
414 engine->GetCandidateWindowProperty(); | 420 engine->GetCandidateWindowProperty(); |
415 bool modified = false; | 421 bool modified = false; |
416 | 422 |
417 if (properties.cursor_visible) { | 423 if (properties.cursor_visible) { |
418 properties_out.is_cursor_visible = *properties.cursor_visible; | 424 properties_out.is_cursor_visible = *properties.cursor_visible; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 if (candidate_in.label) | 483 if (candidate_in.label) |
478 candidates_out.back().label = *candidate_in.label; | 484 candidates_out.back().label = *candidate_in.label; |
479 if (candidate_in.annotation) | 485 if (candidate_in.annotation) |
480 candidates_out.back().annotation = *candidate_in.annotation; | 486 candidates_out.back().annotation = *candidate_in.annotation; |
481 if (candidate_in.usage) { | 487 if (candidate_in.usage) { |
482 candidates_out.back().usage.title = candidate_in.usage->title; | 488 candidates_out.back().usage.title = candidate_in.usage->title; |
483 candidates_out.back().usage.body = candidate_in.usage->body; | 489 candidates_out.back().usage.body = candidate_in.usage->body; |
484 } | 490 } |
485 } | 491 } |
486 | 492 |
487 return RespondNow(OneArgument(base::MakeUnique<base::FundamentalValue>( | 493 std::string error; |
488 engine->SetCandidates(params.context_id, candidates_out, &error_)))); | 494 bool success = |
| 495 engine->SetCandidates(params.context_id, candidates_out, &error); |
| 496 if (!success) |
| 497 SetError(error); |
| 498 return RespondNow( |
| 499 OneArgument(base::MakeUnique<base::FundamentalValue>(success))); |
489 } | 500 } |
490 | 501 |
491 ExtensionFunction::ResponseAction InputImeSetCursorPositionFunction::Run() { | 502 ExtensionFunction::ResponseAction InputImeSetCursorPositionFunction::Run() { |
492 InputMethodEngine* engine = GetActiveEngine( | 503 InputMethodEngine* engine = GetActiveEngine( |
493 Profile::FromBrowserContext(browser_context()), extension_id()); | 504 Profile::FromBrowserContext(browser_context()), extension_id()); |
494 if (!engine) { | 505 if (!engine) { |
495 return RespondNow( | 506 return RespondNow( |
496 OneArgument(base::MakeUnique<base::FundamentalValue>(false))); | 507 OneArgument(base::MakeUnique<base::FundamentalValue>(false))); |
497 } | 508 } |
498 | 509 |
499 std::unique_ptr<SetCursorPosition::Params> parent_params( | 510 std::unique_ptr<SetCursorPosition::Params> parent_params( |
500 SetCursorPosition::Params::Create(*args_)); | 511 SetCursorPosition::Params::Create(*args_)); |
501 const SetCursorPosition::Params::Parameters& params = | 512 const SetCursorPosition::Params::Parameters& params = |
502 parent_params->parameters; | 513 parent_params->parameters; |
503 | 514 |
504 return RespondNow(OneArgument( | 515 std::string error; |
505 base::MakeUnique<base::FundamentalValue>(engine->SetCursorPosition( | 516 bool success = |
506 params.context_id, params.candidate_id, &error_)))); | 517 engine->SetCursorPosition(params.context_id, params.candidate_id, &error); |
| 518 if (!success) |
| 519 SetError(error); |
| 520 return RespondNow( |
| 521 OneArgument(base::MakeUnique<base::FundamentalValue>(success))); |
507 } | 522 } |
508 | 523 |
509 ExtensionFunction::ResponseAction InputImeSetMenuItemsFunction::Run() { | 524 ExtensionFunction::ResponseAction InputImeSetMenuItemsFunction::Run() { |
510 std::unique_ptr<SetMenuItems::Params> parent_params( | 525 std::unique_ptr<SetMenuItems::Params> parent_params( |
511 SetMenuItems::Params::Create(*args_)); | 526 SetMenuItems::Params::Create(*args_)); |
512 const SetMenuItems::Params::Parameters& params = | 527 const SetMenuItems::Params::Parameters& params = |
513 parent_params->parameters; | 528 parent_params->parameters; |
514 | 529 |
515 InputImeEventRouter* event_router = | 530 InputImeEventRouter* event_router = |
516 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())); | 531 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 parent_params->parameters; | 578 parent_params->parameters; |
564 | 579 |
565 InputImeEventRouter* event_router = | 580 InputImeEventRouter* event_router = |
566 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())); | 581 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())); |
567 InputMethodEngine* engine = | 582 InputMethodEngine* engine = |
568 event_router ? event_router->GetEngine(extension_id(), params.engine_id) | 583 event_router ? event_router->GetEngine(extension_id(), params.engine_id) |
569 : nullptr; | 584 : nullptr; |
570 if (!engine) | 585 if (!engine) |
571 return RespondNow(Error(kErrorEngineNotAvailable)); | 586 return RespondNow(Error(kErrorEngineNotAvailable)); |
572 | 587 |
| 588 std::string error; |
573 engine->DeleteSurroundingText(params.context_id, params.offset, params.length, | 589 engine->DeleteSurroundingText(params.context_id, params.offset, params.length, |
574 &error_); | 590 &error); |
| 591 SetError(error); |
575 return RespondNow(NoArguments()); | 592 return RespondNow(NoArguments()); |
576 } | 593 } |
577 | 594 |
578 ExtensionFunction::ResponseAction | 595 ExtensionFunction::ResponseAction |
579 InputMethodPrivateNotifyImeMenuItemActivatedFunction::Run() { | 596 InputMethodPrivateNotifyImeMenuItemActivatedFunction::Run() { |
580 chromeos::input_method::InputMethodDescriptor current_input_method = | 597 chromeos::input_method::InputMethodDescriptor current_input_method = |
581 chromeos::input_method::InputMethodManager::Get() | 598 chromeos::input_method::InputMethodManager::Get() |
582 ->GetActiveIMEState() | 599 ->GetActiveIMEState() |
583 ->GetCurrentInputMethod(); | 600 ->GetCurrentInputMethod(); |
584 std::string active_extension_id = | 601 std::string active_extension_id = |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 return; | 644 return; |
628 InputMethodEngine* engine = | 645 InputMethodEngine* engine = |
629 GetActiveEngine(Profile::FromBrowserContext(details.browser_context), | 646 GetActiveEngine(Profile::FromBrowserContext(details.browser_context), |
630 details.extension_id); | 647 details.extension_id); |
631 // Notifies the IME extension for IME ready with onActivate/onFocus events. | 648 // Notifies the IME extension for IME ready with onActivate/onFocus events. |
632 if (engine) | 649 if (engine) |
633 engine->Enable(engine->GetActiveComponentId()); | 650 engine->Enable(engine->GetActiveComponentId()); |
634 } | 651 } |
635 | 652 |
636 } // namespace extensions | 653 } // namespace extensions |
OLD | NEW |