| 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 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 engine_map_.find(extension_id); | 357 engine_map_.find(extension_id); |
| 358 return (it != engine_map_.end() && it->second->IsActive()) ? it->second | 358 return (it != engine_map_.end() && it->second->IsActive()) ? it->second |
| 359 : nullptr; | 359 : nullptr; |
| 360 } | 360 } |
| 361 | 361 |
| 362 ExtensionFunction::ResponseAction InputImeClearCompositionFunction::Run() { | 362 ExtensionFunction::ResponseAction InputImeClearCompositionFunction::Run() { |
| 363 InputMethodEngine* engine = GetActiveEngine( | 363 InputMethodEngine* engine = GetActiveEngine( |
| 364 Profile::FromBrowserContext(browser_context()), extension_id()); | 364 Profile::FromBrowserContext(browser_context()), extension_id()); |
| 365 if (!engine) { | 365 if (!engine) { |
| 366 return RespondNow( | 366 return RespondNow( |
| 367 OneArgument(base::MakeUnique<base::FundamentalValue>(false))); | 367 OneArgument(base::MakeUnique<base::Value>(false))); |
| 368 } | 368 } |
| 369 | 369 |
| 370 std::unique_ptr<ClearComposition::Params> parent_params( | 370 std::unique_ptr<ClearComposition::Params> parent_params( |
| 371 ClearComposition::Params::Create(*args_)); | 371 ClearComposition::Params::Create(*args_)); |
| 372 const ClearComposition::Params::Parameters& params = | 372 const ClearComposition::Params::Parameters& params = |
| 373 parent_params->parameters; | 373 parent_params->parameters; |
| 374 | 374 |
| 375 std::string error; | 375 std::string error; |
| 376 bool success = engine->ClearComposition(params.context_id, &error); | 376 bool success = engine->ClearComposition(params.context_id, &error); |
| 377 std::unique_ptr<base::ListValue> results = | 377 std::unique_ptr<base::ListValue> results = |
| 378 base::MakeUnique<base::ListValue>(); | 378 base::MakeUnique<base::ListValue>(); |
| 379 results->Append(base::MakeUnique<base::FundamentalValue>(success)); | 379 results->Append(base::MakeUnique<base::Value>(success)); |
| 380 return RespondNow(success ? ArgumentList(std::move(results)) | 380 return RespondNow(success ? ArgumentList(std::move(results)) |
| 381 : ErrorWithArguments(std::move(results), error)); | 381 : ErrorWithArguments(std::move(results), error)); |
| 382 } | 382 } |
| 383 | 383 |
| 384 bool InputImeHideInputViewFunction::RunAsync() { | 384 bool InputImeHideInputViewFunction::RunAsync() { |
| 385 InputMethodEngine* engine = GetActiveEngine( | 385 InputMethodEngine* engine = GetActiveEngine( |
| 386 Profile::FromBrowserContext(browser_context()), extension_id()); | 386 Profile::FromBrowserContext(browser_context()), extension_id()); |
| 387 if (!engine) { | 387 if (!engine) { |
| 388 return true; | 388 return true; |
| 389 } | 389 } |
| 390 engine->HideInputView(); | 390 engine->HideInputView(); |
| 391 return true; | 391 return true; |
| 392 } | 392 } |
| 393 | 393 |
| 394 ExtensionFunction::ResponseAction | 394 ExtensionFunction::ResponseAction |
| 395 InputImeSetCandidateWindowPropertiesFunction::Run() { | 395 InputImeSetCandidateWindowPropertiesFunction::Run() { |
| 396 std::unique_ptr<SetCandidateWindowProperties::Params> parent_params( | 396 std::unique_ptr<SetCandidateWindowProperties::Params> parent_params( |
| 397 SetCandidateWindowProperties::Params::Create(*args_)); | 397 SetCandidateWindowProperties::Params::Create(*args_)); |
| 398 const SetCandidateWindowProperties::Params::Parameters& | 398 const SetCandidateWindowProperties::Params::Parameters& |
| 399 params = parent_params->parameters; | 399 params = parent_params->parameters; |
| 400 | 400 |
| 401 InputImeEventRouter* event_router = | 401 InputImeEventRouter* event_router = |
| 402 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())); | 402 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())); |
| 403 InputMethodEngine* engine = | 403 InputMethodEngine* engine = |
| 404 event_router ? event_router->GetEngine(extension_id(), params.engine_id) | 404 event_router ? event_router->GetEngine(extension_id(), params.engine_id) |
| 405 : nullptr; | 405 : nullptr; |
| 406 if (!engine) { | 406 if (!engine) { |
| 407 return RespondNow( | 407 return RespondNow( |
| 408 OneArgument(base::MakeUnique<base::FundamentalValue>(false))); | 408 OneArgument(base::MakeUnique<base::Value>(false))); |
| 409 } | 409 } |
| 410 | 410 |
| 411 const SetCandidateWindowProperties::Params::Parameters::Properties& | 411 const SetCandidateWindowProperties::Params::Parameters::Properties& |
| 412 properties = params.properties; | 412 properties = params.properties; |
| 413 | 413 |
| 414 std::string error; | 414 std::string error; |
| 415 if (properties.visible && | 415 if (properties.visible && |
| 416 !engine->SetCandidateWindowVisible(*properties.visible, &error)) { | 416 !engine->SetCandidateWindowVisible(*properties.visible, &error)) { |
| 417 std::unique_ptr<base::ListValue> results = | 417 std::unique_ptr<base::ListValue> results = |
| 418 base::MakeUnique<base::ListValue>(); | 418 base::MakeUnique<base::ListValue>(); |
| 419 results->Append(base::MakeUnique<base::FundamentalValue>(false)); | 419 results->Append(base::MakeUnique<base::Value>(false)); |
| 420 return RespondNow(ErrorWithArguments(std::move(results), error)); | 420 return RespondNow(ErrorWithArguments(std::move(results), error)); |
| 421 } | 421 } |
| 422 | 422 |
| 423 InputMethodEngine::CandidateWindowProperty properties_out = | 423 InputMethodEngine::CandidateWindowProperty properties_out = |
| 424 engine->GetCandidateWindowProperty(); | 424 engine->GetCandidateWindowProperty(); |
| 425 bool modified = false; | 425 bool modified = false; |
| 426 | 426 |
| 427 if (properties.cursor_visible) { | 427 if (properties.cursor_visible) { |
| 428 properties_out.is_cursor_visible = *properties.cursor_visible; | 428 properties_out.is_cursor_visible = *properties.cursor_visible; |
| 429 modified = true; | 429 modified = true; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 456 properties_out.is_auxiliary_text_visible = | 456 properties_out.is_auxiliary_text_visible = |
| 457 *properties.auxiliary_text_visible; | 457 *properties.auxiliary_text_visible; |
| 458 modified = true; | 458 modified = true; |
| 459 } | 459 } |
| 460 | 460 |
| 461 if (modified) { | 461 if (modified) { |
| 462 engine->SetCandidateWindowProperty(properties_out); | 462 engine->SetCandidateWindowProperty(properties_out); |
| 463 } | 463 } |
| 464 | 464 |
| 465 return RespondNow( | 465 return RespondNow( |
| 466 OneArgument(base::MakeUnique<base::FundamentalValue>(true))); | 466 OneArgument(base::MakeUnique<base::Value>(true))); |
| 467 } | 467 } |
| 468 | 468 |
| 469 ExtensionFunction::ResponseAction InputImeSetCandidatesFunction::Run() { | 469 ExtensionFunction::ResponseAction InputImeSetCandidatesFunction::Run() { |
| 470 InputMethodEngine* engine = GetActiveEngine( | 470 InputMethodEngine* engine = GetActiveEngine( |
| 471 Profile::FromBrowserContext(browser_context()), extension_id()); | 471 Profile::FromBrowserContext(browser_context()), extension_id()); |
| 472 if (!engine) { | 472 if (!engine) { |
| 473 return RespondNow( | 473 return RespondNow( |
| 474 OneArgument(base::MakeUnique<base::FundamentalValue>(true))); | 474 OneArgument(base::MakeUnique<base::Value>(true))); |
| 475 } | 475 } |
| 476 | 476 |
| 477 std::unique_ptr<SetCandidates::Params> parent_params( | 477 std::unique_ptr<SetCandidates::Params> parent_params( |
| 478 SetCandidates::Params::Create(*args_)); | 478 SetCandidates::Params::Create(*args_)); |
| 479 const SetCandidates::Params::Parameters& params = | 479 const SetCandidates::Params::Parameters& params = |
| 480 parent_params->parameters; | 480 parent_params->parameters; |
| 481 | 481 |
| 482 std::vector<InputMethodEngine::Candidate> candidates_out; | 482 std::vector<InputMethodEngine::Candidate> candidates_out; |
| 483 for (const auto& candidate_in : params.candidates) { | 483 for (const auto& candidate_in : params.candidates) { |
| 484 candidates_out.push_back(InputMethodEngine::Candidate()); | 484 candidates_out.push_back(InputMethodEngine::Candidate()); |
| 485 candidates_out.back().value = candidate_in.candidate; | 485 candidates_out.back().value = candidate_in.candidate; |
| 486 candidates_out.back().id = candidate_in.id; | 486 candidates_out.back().id = candidate_in.id; |
| 487 if (candidate_in.label) | 487 if (candidate_in.label) |
| 488 candidates_out.back().label = *candidate_in.label; | 488 candidates_out.back().label = *candidate_in.label; |
| 489 if (candidate_in.annotation) | 489 if (candidate_in.annotation) |
| 490 candidates_out.back().annotation = *candidate_in.annotation; | 490 candidates_out.back().annotation = *candidate_in.annotation; |
| 491 if (candidate_in.usage) { | 491 if (candidate_in.usage) { |
| 492 candidates_out.back().usage.title = candidate_in.usage->title; | 492 candidates_out.back().usage.title = candidate_in.usage->title; |
| 493 candidates_out.back().usage.body = candidate_in.usage->body; | 493 candidates_out.back().usage.body = candidate_in.usage->body; |
| 494 } | 494 } |
| 495 } | 495 } |
| 496 | 496 |
| 497 std::string error; | 497 std::string error; |
| 498 bool success = | 498 bool success = |
| 499 engine->SetCandidates(params.context_id, candidates_out, &error); | 499 engine->SetCandidates(params.context_id, candidates_out, &error); |
| 500 std::unique_ptr<base::ListValue> results = | 500 std::unique_ptr<base::ListValue> results = |
| 501 base::MakeUnique<base::ListValue>(); | 501 base::MakeUnique<base::ListValue>(); |
| 502 results->Append(base::MakeUnique<base::FundamentalValue>(success)); | 502 results->Append(base::MakeUnique<base::Value>(success)); |
| 503 return RespondNow(success ? ArgumentList(std::move(results)) | 503 return RespondNow(success ? ArgumentList(std::move(results)) |
| 504 : ErrorWithArguments(std::move(results), error)); | 504 : ErrorWithArguments(std::move(results), error)); |
| 505 } | 505 } |
| 506 | 506 |
| 507 ExtensionFunction::ResponseAction InputImeSetCursorPositionFunction::Run() { | 507 ExtensionFunction::ResponseAction InputImeSetCursorPositionFunction::Run() { |
| 508 InputMethodEngine* engine = GetActiveEngine( | 508 InputMethodEngine* engine = GetActiveEngine( |
| 509 Profile::FromBrowserContext(browser_context()), extension_id()); | 509 Profile::FromBrowserContext(browser_context()), extension_id()); |
| 510 if (!engine) { | 510 if (!engine) { |
| 511 return RespondNow( | 511 return RespondNow( |
| 512 OneArgument(base::MakeUnique<base::FundamentalValue>(false))); | 512 OneArgument(base::MakeUnique<base::Value>(false))); |
| 513 } | 513 } |
| 514 | 514 |
| 515 std::unique_ptr<SetCursorPosition::Params> parent_params( | 515 std::unique_ptr<SetCursorPosition::Params> parent_params( |
| 516 SetCursorPosition::Params::Create(*args_)); | 516 SetCursorPosition::Params::Create(*args_)); |
| 517 const SetCursorPosition::Params::Parameters& params = | 517 const SetCursorPosition::Params::Parameters& params = |
| 518 parent_params->parameters; | 518 parent_params->parameters; |
| 519 | 519 |
| 520 std::string error; | 520 std::string error; |
| 521 bool success = | 521 bool success = |
| 522 engine->SetCursorPosition(params.context_id, params.candidate_id, &error); | 522 engine->SetCursorPosition(params.context_id, params.candidate_id, &error); |
| 523 std::unique_ptr<base::ListValue> results = | 523 std::unique_ptr<base::ListValue> results = |
| 524 base::MakeUnique<base::ListValue>(); | 524 base::MakeUnique<base::ListValue>(); |
| 525 results->Append(base::MakeUnique<base::FundamentalValue>(success)); | 525 results->Append(base::MakeUnique<base::Value>(success)); |
| 526 return RespondNow(success ? ArgumentList(std::move(results)) | 526 return RespondNow(success ? ArgumentList(std::move(results)) |
| 527 : ErrorWithArguments(std::move(results), error)); | 527 : ErrorWithArguments(std::move(results), error)); |
| 528 } | 528 } |
| 529 | 529 |
| 530 ExtensionFunction::ResponseAction InputImeSetMenuItemsFunction::Run() { | 530 ExtensionFunction::ResponseAction InputImeSetMenuItemsFunction::Run() { |
| 531 std::unique_ptr<SetMenuItems::Params> parent_params( | 531 std::unique_ptr<SetMenuItems::Params> parent_params( |
| 532 SetMenuItems::Params::Create(*args_)); | 532 SetMenuItems::Params::Create(*args_)); |
| 533 const SetMenuItems::Params::Parameters& params = | 533 const SetMenuItems::Params::Parameters& params = |
| 534 parent_params->parameters; | 534 parent_params->parameters; |
| 535 | 535 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 return; | 649 return; |
| 650 InputMethodEngine* engine = | 650 InputMethodEngine* engine = |
| 651 GetActiveEngine(Profile::FromBrowserContext(details.browser_context), | 651 GetActiveEngine(Profile::FromBrowserContext(details.browser_context), |
| 652 details.extension_id); | 652 details.extension_id); |
| 653 // Notifies the IME extension for IME ready with onActivate/onFocus events. | 653 // Notifies the IME extension for IME ready with onActivate/onFocus events. |
| 654 if (engine) | 654 if (engine) |
| 655 engine->Enable(engine->GetActiveComponentId()); | 655 engine->Enable(engine->GetActiveComponentId()); |
| 656 } | 656 } |
| 657 | 657 |
| 658 } // namespace extensions | 658 } // namespace extensions |
| OLD | NEW |