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