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" |
| 11 #include "base/memory/ptr_util.h" |
11 #include "chrome/browser/chromeos/input_method/input_method_engine.h" | 12 #include "chrome/browser/chromeos/input_method/input_method_engine.h" |
12 #include "chrome/browser/chromeos/login/lock/screen_locker.h" | 13 #include "chrome/browser/chromeos/login/lock/screen_locker.h" |
13 #include "chrome/browser/chromeos/login/session/user_session_manager.h" | 14 #include "chrome/browser/chromeos/login/session/user_session_manager.h" |
14 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 15 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
15 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
16 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
17 #include "chrome/common/extensions/api/input_ime.h" | 18 #include "chrome/common/extensions/api/input_ime.h" |
18 #include "chrome/common/extensions/api/input_method_private.h" | 19 #include "chrome/common/extensions/api/input_method_private.h" |
19 #include "extensions/browser/extension_system.h" | 20 #include "extensions/browser/extension_system.h" |
20 #include "extensions/common/manifest_handlers/background_info.h" | 21 #include "extensions/common/manifest_handlers/background_info.h" |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 std::map<std::string, InputMethodEngine*>::iterator it = | 354 std::map<std::string, InputMethodEngine*>::iterator it = |
354 engine_map_.find(extension_id); | 355 engine_map_.find(extension_id); |
355 return (it != engine_map_.end() && it->second->IsActive()) ? it->second | 356 return (it != engine_map_.end() && it->second->IsActive()) ? it->second |
356 : nullptr; | 357 : nullptr; |
357 } | 358 } |
358 | 359 |
359 bool InputImeClearCompositionFunction::RunSync() { | 360 bool InputImeClearCompositionFunction::RunSync() { |
360 InputMethodEngine* engine = GetActiveEngine( | 361 InputMethodEngine* engine = GetActiveEngine( |
361 Profile::FromBrowserContext(browser_context()), extension_id()); | 362 Profile::FromBrowserContext(browser_context()), extension_id()); |
362 if (!engine) { | 363 if (!engine) { |
363 SetResult(new base::FundamentalValue(false)); | 364 SetResult(base::MakeUnique<base::FundamentalValue>(false)); |
364 return true; | 365 return true; |
365 } | 366 } |
366 | 367 |
367 std::unique_ptr<ClearComposition::Params> parent_params( | 368 std::unique_ptr<ClearComposition::Params> parent_params( |
368 ClearComposition::Params::Create(*args_)); | 369 ClearComposition::Params::Create(*args_)); |
369 const ClearComposition::Params::Parameters& params = | 370 const ClearComposition::Params::Parameters& params = |
370 parent_params->parameters; | 371 parent_params->parameters; |
371 | 372 |
372 SetResult(new base::FundamentalValue( | 373 SetResult(base::MakeUnique<base::FundamentalValue>( |
373 engine->ClearComposition(params.context_id, &error_))); | 374 engine->ClearComposition(params.context_id, &error_))); |
374 return true; | 375 return true; |
375 } | 376 } |
376 | 377 |
377 bool InputImeHideInputViewFunction::RunAsync() { | 378 bool InputImeHideInputViewFunction::RunAsync() { |
378 InputMethodEngine* engine = GetActiveEngine( | 379 InputMethodEngine* engine = GetActiveEngine( |
379 Profile::FromBrowserContext(browser_context()), extension_id()); | 380 Profile::FromBrowserContext(browser_context()), extension_id()); |
380 if (!engine) { | 381 if (!engine) { |
381 return true; | 382 return true; |
382 } | 383 } |
383 engine->HideInputView(); | 384 engine->HideInputView(); |
384 return true; | 385 return true; |
385 } | 386 } |
386 | 387 |
387 bool InputImeSetCandidateWindowPropertiesFunction::RunSync() { | 388 bool InputImeSetCandidateWindowPropertiesFunction::RunSync() { |
388 std::unique_ptr<SetCandidateWindowProperties::Params> parent_params( | 389 std::unique_ptr<SetCandidateWindowProperties::Params> parent_params( |
389 SetCandidateWindowProperties::Params::Create(*args_)); | 390 SetCandidateWindowProperties::Params::Create(*args_)); |
390 const SetCandidateWindowProperties::Params::Parameters& | 391 const SetCandidateWindowProperties::Params::Parameters& |
391 params = parent_params->parameters; | 392 params = parent_params->parameters; |
392 | 393 |
393 InputImeEventRouter* event_router = | 394 InputImeEventRouter* event_router = |
394 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())); | 395 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())); |
395 InputMethodEngine* engine = | 396 InputMethodEngine* engine = |
396 event_router ? event_router->GetEngine(extension_id(), params.engine_id) | 397 event_router ? event_router->GetEngine(extension_id(), params.engine_id) |
397 : nullptr; | 398 : nullptr; |
398 if (!engine) { | 399 if (!engine) { |
399 SetResult(new base::FundamentalValue(false)); | 400 SetResult(base::MakeUnique<base::FundamentalValue>(false)); |
400 return true; | 401 return true; |
401 } | 402 } |
402 | 403 |
403 const SetCandidateWindowProperties::Params::Parameters::Properties& | 404 const SetCandidateWindowProperties::Params::Parameters::Properties& |
404 properties = params.properties; | 405 properties = params.properties; |
405 | 406 |
406 if (properties.visible && | 407 if (properties.visible && |
407 !engine->SetCandidateWindowVisible(*properties.visible, &error_)) { | 408 !engine->SetCandidateWindowVisible(*properties.visible, &error_)) { |
408 SetResult(new base::FundamentalValue(false)); | 409 SetResult(base::MakeUnique<base::FundamentalValue>(false)); |
409 return true; | 410 return true; |
410 } | 411 } |
411 | 412 |
412 InputMethodEngine::CandidateWindowProperty properties_out = | 413 InputMethodEngine::CandidateWindowProperty properties_out = |
413 engine->GetCandidateWindowProperty(); | 414 engine->GetCandidateWindowProperty(); |
414 bool modified = false; | 415 bool modified = false; |
415 | 416 |
416 if (properties.cursor_visible) { | 417 if (properties.cursor_visible) { |
417 properties_out.is_cursor_visible = *properties.cursor_visible; | 418 properties_out.is_cursor_visible = *properties.cursor_visible; |
418 modified = true; | 419 modified = true; |
(...skipping 25 matching lines...) Expand all Loading... |
444 if (properties.auxiliary_text_visible) { | 445 if (properties.auxiliary_text_visible) { |
445 properties_out.is_auxiliary_text_visible = | 446 properties_out.is_auxiliary_text_visible = |
446 *properties.auxiliary_text_visible; | 447 *properties.auxiliary_text_visible; |
447 modified = true; | 448 modified = true; |
448 } | 449 } |
449 | 450 |
450 if (modified) { | 451 if (modified) { |
451 engine->SetCandidateWindowProperty(properties_out); | 452 engine->SetCandidateWindowProperty(properties_out); |
452 } | 453 } |
453 | 454 |
454 SetResult(new base::FundamentalValue(true)); | 455 SetResult(base::MakeUnique<base::FundamentalValue>(true)); |
455 | 456 |
456 return true; | 457 return true; |
457 } | 458 } |
458 | 459 |
459 bool InputImeSetCandidatesFunction::RunSync() { | 460 bool InputImeSetCandidatesFunction::RunSync() { |
460 InputMethodEngine* engine = GetActiveEngine( | 461 InputMethodEngine* engine = GetActiveEngine( |
461 Profile::FromBrowserContext(browser_context()), extension_id()); | 462 Profile::FromBrowserContext(browser_context()), extension_id()); |
462 if (!engine) { | 463 if (!engine) { |
463 SetResult(new base::FundamentalValue(false)); | 464 SetResult(base::MakeUnique<base::FundamentalValue>(true)); |
464 return true; | 465 return true; |
465 } | 466 } |
466 | 467 |
467 std::unique_ptr<SetCandidates::Params> parent_params( | 468 std::unique_ptr<SetCandidates::Params> parent_params( |
468 SetCandidates::Params::Create(*args_)); | 469 SetCandidates::Params::Create(*args_)); |
469 const SetCandidates::Params::Parameters& params = | 470 const SetCandidates::Params::Parameters& params = |
470 parent_params->parameters; | 471 parent_params->parameters; |
471 | 472 |
472 std::vector<InputMethodEngine::Candidate> candidates_out; | 473 std::vector<InputMethodEngine::Candidate> candidates_out; |
473 for (const auto& candidate_in : params.candidates) { | 474 for (const auto& candidate_in : params.candidates) { |
474 candidates_out.push_back(InputMethodEngine::Candidate()); | 475 candidates_out.push_back(InputMethodEngine::Candidate()); |
475 candidates_out.back().value = candidate_in.candidate; | 476 candidates_out.back().value = candidate_in.candidate; |
476 candidates_out.back().id = candidate_in.id; | 477 candidates_out.back().id = candidate_in.id; |
477 if (candidate_in.label) | 478 if (candidate_in.label) |
478 candidates_out.back().label = *candidate_in.label; | 479 candidates_out.back().label = *candidate_in.label; |
479 if (candidate_in.annotation) | 480 if (candidate_in.annotation) |
480 candidates_out.back().annotation = *candidate_in.annotation; | 481 candidates_out.back().annotation = *candidate_in.annotation; |
481 if (candidate_in.usage) { | 482 if (candidate_in.usage) { |
482 candidates_out.back().usage.title = candidate_in.usage->title; | 483 candidates_out.back().usage.title = candidate_in.usage->title; |
483 candidates_out.back().usage.body = candidate_in.usage->body; | 484 candidates_out.back().usage.body = candidate_in.usage->body; |
484 } | 485 } |
485 } | 486 } |
486 | 487 |
487 SetResult(new base::FundamentalValue( | 488 SetResult(base::MakeUnique<base::FundamentalValue>( |
488 engine->SetCandidates(params.context_id, candidates_out, &error_))); | 489 engine->SetCandidates(params.context_id, candidates_out, &error_))); |
489 return true; | 490 return true; |
490 } | 491 } |
491 | 492 |
492 bool InputImeSetCursorPositionFunction::RunSync() { | 493 bool InputImeSetCursorPositionFunction::RunSync() { |
493 InputMethodEngine* engine = GetActiveEngine( | 494 InputMethodEngine* engine = GetActiveEngine( |
494 Profile::FromBrowserContext(browser_context()), extension_id()); | 495 Profile::FromBrowserContext(browser_context()), extension_id()); |
495 if (!engine) { | 496 if (!engine) { |
496 SetResult(new base::FundamentalValue(false)); | 497 SetResult(base::MakeUnique<base::FundamentalValue>(false)); |
497 return true; | 498 return true; |
498 } | 499 } |
499 | 500 |
500 std::unique_ptr<SetCursorPosition::Params> parent_params( | 501 std::unique_ptr<SetCursorPosition::Params> parent_params( |
501 SetCursorPosition::Params::Create(*args_)); | 502 SetCursorPosition::Params::Create(*args_)); |
502 const SetCursorPosition::Params::Parameters& params = | 503 const SetCursorPosition::Params::Parameters& params = |
503 parent_params->parameters; | 504 parent_params->parameters; |
504 | 505 |
505 SetResult(new base::FundamentalValue( | 506 SetResult(base::MakeUnique<base::FundamentalValue>(engine->SetCursorPosition( |
506 engine->SetCursorPosition(params.context_id, params.candidate_id, | 507 params.context_id, params.candidate_id, &error_))); |
507 &error_))); | |
508 return true; | 508 return true; |
509 } | 509 } |
510 | 510 |
511 bool InputImeSetMenuItemsFunction::RunSync() { | 511 bool InputImeSetMenuItemsFunction::RunSync() { |
512 std::unique_ptr<SetMenuItems::Params> parent_params( | 512 std::unique_ptr<SetMenuItems::Params> parent_params( |
513 SetMenuItems::Params::Create(*args_)); | 513 SetMenuItems::Params::Create(*args_)); |
514 const SetMenuItems::Params::Parameters& params = | 514 const SetMenuItems::Params::Parameters& params = |
515 parent_params->parameters; | 515 parent_params->parameters; |
516 | 516 |
517 InputImeEventRouter* event_router = | 517 InputImeEventRouter* event_router = |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 return; | 635 return; |
636 InputMethodEngine* engine = | 636 InputMethodEngine* engine = |
637 GetActiveEngine(Profile::FromBrowserContext(details.browser_context), | 637 GetActiveEngine(Profile::FromBrowserContext(details.browser_context), |
638 details.extension_id); | 638 details.extension_id); |
639 // Notifies the IME extension for IME ready with onActivate/onFocus events. | 639 // Notifies the IME extension for IME ready with onActivate/onFocus events. |
640 if (engine) | 640 if (engine) |
641 engine->Enable(engine->GetActiveComponentId()); | 641 engine->Enable(engine->GetActiveComponentId()); |
642 } | 642 } |
643 | 643 |
644 } // namespace extensions | 644 } // namespace extensions |
OLD | NEW |