Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: chrome/browser/extensions/api/input_ime/input_ime_api_chromeos.cc

Issue 2285573002: [Extensions] Convert some SyncExtensionFunctions (Closed)
Patch Set: fix Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 } 350 }
351 351
352 InputMethodEngineBase* InputImeEventRouter::GetActiveEngine( 352 InputMethodEngineBase* InputImeEventRouter::GetActiveEngine(
353 const std::string& extension_id) { 353 const std::string& extension_id) {
354 std::map<std::string, InputMethodEngine*>::iterator it = 354 std::map<std::string, InputMethodEngine*>::iterator it =
355 engine_map_.find(extension_id); 355 engine_map_.find(extension_id);
356 return (it != engine_map_.end() && it->second->IsActive()) ? it->second 356 return (it != engine_map_.end() && it->second->IsActive()) ? it->second
357 : nullptr; 357 : nullptr;
358 } 358 }
359 359
360 bool InputImeClearCompositionFunction::RunSync() { 360 ExtensionFunction::ResponseAction InputImeClearCompositionFunction::Run() {
361 InputMethodEngine* engine = GetActiveEngine( 361 InputMethodEngine* engine = GetActiveEngine(
362 Profile::FromBrowserContext(browser_context()), extension_id()); 362 Profile::FromBrowserContext(browser_context()), extension_id());
363 if (!engine) { 363 if (!engine) {
364 SetResult(base::MakeUnique<base::FundamentalValue>(false)); 364 return RespondNow(
365 return true; 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 SetResult(base::MakeUnique<base::FundamentalValue>( 373 return RespondNow(OneArgument(base::MakeUnique<base::FundamentalValue>(
374 engine->ClearComposition(params.context_id, &error_))); 374 engine->ClearComposition(params.context_id, &error_))));
375 return true;
376 } 375 }
377 376
378 bool InputImeHideInputViewFunction::RunAsync() { 377 bool InputImeHideInputViewFunction::RunAsync() {
379 InputMethodEngine* engine = GetActiveEngine( 378 InputMethodEngine* engine = GetActiveEngine(
380 Profile::FromBrowserContext(browser_context()), extension_id()); 379 Profile::FromBrowserContext(browser_context()), extension_id());
381 if (!engine) { 380 if (!engine) {
382 return true; 381 return true;
383 } 382 }
384 engine->HideInputView(); 383 engine->HideInputView();
385 return true; 384 return true;
386 } 385 }
387 386
388 bool InputImeSetCandidateWindowPropertiesFunction::RunSync() { 387 ExtensionFunction::ResponseAction
388 InputImeSetCandidateWindowPropertiesFunction::Run() {
389 std::unique_ptr<SetCandidateWindowProperties::Params> parent_params( 389 std::unique_ptr<SetCandidateWindowProperties::Params> parent_params(
390 SetCandidateWindowProperties::Params::Create(*args_)); 390 SetCandidateWindowProperties::Params::Create(*args_));
391 const SetCandidateWindowProperties::Params::Parameters& 391 const SetCandidateWindowProperties::Params::Parameters&
392 params = parent_params->parameters; 392 params = parent_params->parameters;
393 393
394 InputImeEventRouter* event_router = 394 InputImeEventRouter* event_router =
395 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())); 395 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context()));
396 InputMethodEngine* engine = 396 InputMethodEngine* engine =
397 event_router ? event_router->GetEngine(extension_id(), params.engine_id) 397 event_router ? event_router->GetEngine(extension_id(), params.engine_id)
398 : nullptr; 398 : nullptr;
399 if (!engine) { 399 if (!engine) {
400 SetResult(base::MakeUnique<base::FundamentalValue>(false)); 400 return RespondNow(
401 return true; 401 OneArgument(base::MakeUnique<base::FundamentalValue>(false)));
402 } 402 }
403 403
404 const SetCandidateWindowProperties::Params::Parameters::Properties& 404 const SetCandidateWindowProperties::Params::Parameters::Properties&
405 properties = params.properties; 405 properties = params.properties;
406 406
407 if (properties.visible && 407 if (properties.visible &&
408 !engine->SetCandidateWindowVisible(*properties.visible, &error_)) { 408 !engine->SetCandidateWindowVisible(*properties.visible, &error_)) {
409 SetResult(base::MakeUnique<base::FundamentalValue>(false)); 409 return RespondNow(
410 return true; 410 OneArgument(base::MakeUnique<base::FundamentalValue>(false)));
411 } 411 }
412 412
413 InputMethodEngine::CandidateWindowProperty properties_out = 413 InputMethodEngine::CandidateWindowProperty properties_out =
414 engine->GetCandidateWindowProperty(); 414 engine->GetCandidateWindowProperty();
415 bool modified = false; 415 bool modified = false;
416 416
417 if (properties.cursor_visible) { 417 if (properties.cursor_visible) {
418 properties_out.is_cursor_visible = *properties.cursor_visible; 418 properties_out.is_cursor_visible = *properties.cursor_visible;
419 modified = true; 419 modified = true;
420 } 420 }
(...skipping 24 matching lines...) Expand all
445 if (properties.auxiliary_text_visible) { 445 if (properties.auxiliary_text_visible) {
446 properties_out.is_auxiliary_text_visible = 446 properties_out.is_auxiliary_text_visible =
447 *properties.auxiliary_text_visible; 447 *properties.auxiliary_text_visible;
448 modified = true; 448 modified = true;
449 } 449 }
450 450
451 if (modified) { 451 if (modified) {
452 engine->SetCandidateWindowProperty(properties_out); 452 engine->SetCandidateWindowProperty(properties_out);
453 } 453 }
454 454
455 SetResult(base::MakeUnique<base::FundamentalValue>(true)); 455 return RespondNow(
456 456 OneArgument(base::MakeUnique<base::FundamentalValue>(true)));
457 return true;
458 } 457 }
459 458
460 bool InputImeSetCandidatesFunction::RunSync() { 459 ExtensionFunction::ResponseAction InputImeSetCandidatesFunction::Run() {
461 InputMethodEngine* engine = GetActiveEngine( 460 InputMethodEngine* engine = GetActiveEngine(
462 Profile::FromBrowserContext(browser_context()), extension_id()); 461 Profile::FromBrowserContext(browser_context()), extension_id());
463 if (!engine) { 462 if (!engine) {
464 SetResult(base::MakeUnique<base::FundamentalValue>(true)); 463 return RespondNow(
465 return true; 464 OneArgument(base::MakeUnique<base::FundamentalValue>(true)));
466 } 465 }
467 466
468 std::unique_ptr<SetCandidates::Params> parent_params( 467 std::unique_ptr<SetCandidates::Params> parent_params(
469 SetCandidates::Params::Create(*args_)); 468 SetCandidates::Params::Create(*args_));
470 const SetCandidates::Params::Parameters& params = 469 const SetCandidates::Params::Parameters& params =
471 parent_params->parameters; 470 parent_params->parameters;
472 471
473 std::vector<InputMethodEngine::Candidate> candidates_out; 472 std::vector<InputMethodEngine::Candidate> candidates_out;
474 for (const auto& candidate_in : params.candidates) { 473 for (const auto& candidate_in : params.candidates) {
475 candidates_out.push_back(InputMethodEngine::Candidate()); 474 candidates_out.push_back(InputMethodEngine::Candidate());
476 candidates_out.back().value = candidate_in.candidate; 475 candidates_out.back().value = candidate_in.candidate;
477 candidates_out.back().id = candidate_in.id; 476 candidates_out.back().id = candidate_in.id;
478 if (candidate_in.label) 477 if (candidate_in.label)
479 candidates_out.back().label = *candidate_in.label; 478 candidates_out.back().label = *candidate_in.label;
480 if (candidate_in.annotation) 479 if (candidate_in.annotation)
481 candidates_out.back().annotation = *candidate_in.annotation; 480 candidates_out.back().annotation = *candidate_in.annotation;
482 if (candidate_in.usage) { 481 if (candidate_in.usage) {
483 candidates_out.back().usage.title = candidate_in.usage->title; 482 candidates_out.back().usage.title = candidate_in.usage->title;
484 candidates_out.back().usage.body = candidate_in.usage->body; 483 candidates_out.back().usage.body = candidate_in.usage->body;
485 } 484 }
486 } 485 }
487 486
488 SetResult(base::MakeUnique<base::FundamentalValue>( 487 return RespondNow(OneArgument(base::MakeUnique<base::FundamentalValue>(
489 engine->SetCandidates(params.context_id, candidates_out, &error_))); 488 engine->SetCandidates(params.context_id, candidates_out, &error_))));
490 return true;
491 } 489 }
492 490
493 bool InputImeSetCursorPositionFunction::RunSync() { 491 ExtensionFunction::ResponseAction InputImeSetCursorPositionFunction::Run() {
494 InputMethodEngine* engine = GetActiveEngine( 492 InputMethodEngine* engine = GetActiveEngine(
495 Profile::FromBrowserContext(browser_context()), extension_id()); 493 Profile::FromBrowserContext(browser_context()), extension_id());
496 if (!engine) { 494 if (!engine) {
497 SetResult(base::MakeUnique<base::FundamentalValue>(false)); 495 return RespondNow(
498 return true; 496 OneArgument(base::MakeUnique<base::FundamentalValue>(false)));
499 } 497 }
500 498
501 std::unique_ptr<SetCursorPosition::Params> parent_params( 499 std::unique_ptr<SetCursorPosition::Params> parent_params(
502 SetCursorPosition::Params::Create(*args_)); 500 SetCursorPosition::Params::Create(*args_));
503 const SetCursorPosition::Params::Parameters& params = 501 const SetCursorPosition::Params::Parameters& params =
504 parent_params->parameters; 502 parent_params->parameters;
505 503
506 SetResult(base::MakeUnique<base::FundamentalValue>(engine->SetCursorPosition( 504 return RespondNow(OneArgument(
507 params.context_id, params.candidate_id, &error_))); 505 base::MakeUnique<base::FundamentalValue>(engine->SetCursorPosition(
508 return true; 506 params.context_id, params.candidate_id, &error_))));
509 } 507 }
510 508
511 bool InputImeSetMenuItemsFunction::RunSync() { 509 ExtensionFunction::ResponseAction InputImeSetMenuItemsFunction::Run() {
512 std::unique_ptr<SetMenuItems::Params> parent_params( 510 std::unique_ptr<SetMenuItems::Params> parent_params(
513 SetMenuItems::Params::Create(*args_)); 511 SetMenuItems::Params::Create(*args_));
514 const SetMenuItems::Params::Parameters& params = 512 const SetMenuItems::Params::Parameters& params =
515 parent_params->parameters; 513 parent_params->parameters;
516 514
517 InputImeEventRouter* event_router = 515 InputImeEventRouter* event_router =
518 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())); 516 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context()));
519 InputMethodEngine* engine = 517 InputMethodEngine* engine =
520 event_router ? event_router->GetEngine(extension_id(), params.engine_id) 518 event_router ? event_router->GetEngine(extension_id(), params.engine_id)
521 : nullptr; 519 : nullptr;
522 if (!engine) { 520 if (!engine)
523 error_ = kErrorEngineNotAvailable; 521 return RespondNow(Error(kErrorEngineNotAvailable));
524 return false;
525 }
526 522
527 std::vector<chromeos::input_method::InputMethodManager::MenuItem> items_out; 523 std::vector<chromeos::input_method::InputMethodManager::MenuItem> items_out;
528 for (const input_ime::MenuItem& item_in : params.items) { 524 for (const input_ime::MenuItem& item_in : params.items) {
529 items_out.push_back(chromeos::input_method::InputMethodManager::MenuItem()); 525 items_out.push_back(chromeos::input_method::InputMethodManager::MenuItem());
530 SetMenuItemToMenu(item_in, &items_out.back()); 526 SetMenuItemToMenu(item_in, &items_out.back());
531 } 527 }
532 528
533 if (!engine->SetMenuItems(items_out)) 529 if (!engine->SetMenuItems(items_out))
534 error_ = kErrorSetMenuItemsFail; 530 return RespondNow(Error(kErrorSetMenuItemsFail));
535 return true; 531 return RespondNow(NoArguments());
536 } 532 }
537 533
538 bool InputImeUpdateMenuItemsFunction::RunSync() { 534 ExtensionFunction::ResponseAction InputImeUpdateMenuItemsFunction::Run() {
539 std::unique_ptr<UpdateMenuItems::Params> parent_params( 535 std::unique_ptr<UpdateMenuItems::Params> parent_params(
540 UpdateMenuItems::Params::Create(*args_)); 536 UpdateMenuItems::Params::Create(*args_));
541 const UpdateMenuItems::Params::Parameters& params = 537 const UpdateMenuItems::Params::Parameters& params =
542 parent_params->parameters; 538 parent_params->parameters;
543 539
544 InputImeEventRouter* event_router = 540 InputImeEventRouter* event_router =
545 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())); 541 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context()));
546 InputMethodEngine* engine = 542 InputMethodEngine* engine =
547 event_router ? event_router->GetEngine(extension_id(), params.engine_id) 543 event_router ? event_router->GetEngine(extension_id(), params.engine_id)
548 : nullptr; 544 : nullptr;
549 if (!engine) { 545 if (!engine)
550 error_ = kErrorEngineNotAvailable; 546 return RespondNow(Error(kErrorEngineNotAvailable));
551 return false;
552 }
553 547
554 std::vector<chromeos::input_method::InputMethodManager::MenuItem> items_out; 548 std::vector<chromeos::input_method::InputMethodManager::MenuItem> items_out;
555 for (const input_ime::MenuItem& item_in : params.items) { 549 for (const input_ime::MenuItem& item_in : params.items) {
556 items_out.push_back(chromeos::input_method::InputMethodManager::MenuItem()); 550 items_out.push_back(chromeos::input_method::InputMethodManager::MenuItem());
557 SetMenuItemToMenu(item_in, &items_out.back()); 551 SetMenuItemToMenu(item_in, &items_out.back());
558 } 552 }
559 553
560 if (!engine->UpdateMenuItems(items_out)) 554 if (!engine->UpdateMenuItems(items_out))
561 error_ = kErrorUpdateMenuItemsFail; 555 return RespondNow(Error(kErrorUpdateMenuItemsFail));
562 return true; 556 return RespondNow(NoArguments());
563 } 557 }
564 558
565 bool InputImeDeleteSurroundingTextFunction::RunSync() { 559 ExtensionFunction::ResponseAction InputImeDeleteSurroundingTextFunction::Run() {
566 std::unique_ptr<DeleteSurroundingText::Params> parent_params( 560 std::unique_ptr<DeleteSurroundingText::Params> parent_params(
567 DeleteSurroundingText::Params::Create(*args_)); 561 DeleteSurroundingText::Params::Create(*args_));
568 const DeleteSurroundingText::Params::Parameters& params = 562 const DeleteSurroundingText::Params::Parameters& params =
569 parent_params->parameters; 563 parent_params->parameters;
570 564
571 InputImeEventRouter* event_router = 565 InputImeEventRouter* event_router =
572 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())); 566 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context()));
573 InputMethodEngine* engine = 567 InputMethodEngine* engine =
574 event_router ? event_router->GetEngine(extension_id(), params.engine_id) 568 event_router ? event_router->GetEngine(extension_id(), params.engine_id)
575 : nullptr; 569 : nullptr;
576 if (!engine) { 570 if (!engine)
577 error_ = kErrorEngineNotAvailable; 571 return RespondNow(Error(kErrorEngineNotAvailable));
578 return false;
579 }
580 572
581 engine->DeleteSurroundingText(params.context_id, params.offset, params.length, 573 engine->DeleteSurroundingText(params.context_id, params.offset, params.length,
582 &error_); 574 &error_);
583 return true; 575 return RespondNow(NoArguments());
584 } 576 }
585 577
586 ExtensionFunction::ResponseAction 578 ExtensionFunction::ResponseAction
587 InputMethodPrivateNotifyImeMenuItemActivatedFunction::Run() { 579 InputMethodPrivateNotifyImeMenuItemActivatedFunction::Run() {
588 chromeos::input_method::InputMethodDescriptor current_input_method = 580 chromeos::input_method::InputMethodDescriptor current_input_method =
589 chromeos::input_method::InputMethodManager::Get() 581 chromeos::input_method::InputMethodManager::Get()
590 ->GetActiveIMEState() 582 ->GetActiveIMEState()
591 ->GetCurrentInputMethod(); 583 ->GetCurrentInputMethod();
592 std::string active_extension_id = 584 std::string active_extension_id =
593 chromeos::extension_ime_util::GetExtensionIDFromInputMethodID( 585 chromeos::extension_ime_util::GetExtensionIDFromInputMethodID(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 return; 627 return;
636 InputMethodEngine* engine = 628 InputMethodEngine* engine =
637 GetActiveEngine(Profile::FromBrowserContext(details.browser_context), 629 GetActiveEngine(Profile::FromBrowserContext(details.browser_context),
638 details.extension_id); 630 details.extension_id);
639 // Notifies the IME extension for IME ready with onActivate/onFocus events. 631 // Notifies the IME extension for IME ready with onActivate/onFocus events.
640 if (engine) 632 if (engine)
641 engine->Enable(engine->GetActiveComponentId()); 633 engine->Enable(engine->GetActiveComponentId());
642 } 634 }
643 635
644 } // namespace extensions 636 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698