| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/chromeos/extensions/input_ime_extension_api.h" | 5 #include "chrome/browser/extensions/extension_input_ime_api.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/chromeos/input_method/input_method_engine.h" | 10 #include "chrome/browser/chromeos/input_method/input_method_engine.h" |
| 11 #include "chrome/browser/extensions/extension_event_router.h" | 11 #include "chrome/browser/extensions/extension_event_router.h" |
| 12 #include "chrome/browser/extensions/extension_input_module_constants.h" | 12 #include "chrome/browser/extensions/extension_input_module_constants.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 | 14 |
| 15 namespace keys = extension_input_module_constants; | 15 namespace keys = extension_input_module_constants; |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 GURL()); | 269 GURL()); |
| 270 } | 270 } |
| 271 | 271 |
| 272 virtual void OnKeyEvent(const std::string& engine_id, | 272 virtual void OnKeyEvent(const std::string& engine_id, |
| 273 const InputMethodEngine::KeyboardEvent& event, | 273 const InputMethodEngine::KeyboardEvent& event, |
| 274 chromeos::input_method::KeyEventHandle* key_data) { | 274 chromeos::input_method::KeyEventHandle* key_data) { |
| 275 if (profile_ == NULL || extension_id_.empty()) | 275 if (profile_ == NULL || extension_id_.empty()) |
| 276 return; | 276 return; |
| 277 | 277 |
| 278 std::string request_id = | 278 std::string request_id = |
| 279 InputImeExtensionEventRouter::GetInstance()->AddRequest(engine_id, | 279 ExtensionInputImeEventRouter::GetInstance()->AddRequest(engine_id, |
| 280 key_data); | 280 key_data); |
| 281 | 281 |
| 282 DictionaryValue* dict = new DictionaryValue(); | 282 DictionaryValue* dict = new DictionaryValue(); |
| 283 dict->SetString("type", event.type); | 283 dict->SetString("type", event.type); |
| 284 dict->SetString("requestId", request_id); | 284 dict->SetString("requestId", request_id); |
| 285 dict->SetString("key", event.key); | 285 dict->SetString("key", event.key); |
| 286 dict->SetString("keyCode", event.key_code); | 286 dict->SetString("keyCode", event.key_code); |
| 287 dict->SetBoolean("altKey", event.alt_key); | 287 dict->SetBoolean("altKey", event.alt_key); |
| 288 dict->SetBoolean("ctrlKey", event.ctrl_key); | 288 dict->SetBoolean("ctrlKey", event.ctrl_key); |
| 289 dict->SetBoolean("shiftKey", event.shift_key); | 289 dict->SetBoolean("shiftKey", event.shift_key); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 private: | 350 private: |
| 351 Profile* profile_; | 351 Profile* profile_; |
| 352 std::string extension_id_; | 352 std::string extension_id_; |
| 353 std::string engine_id_; | 353 std::string engine_id_; |
| 354 | 354 |
| 355 DISALLOW_COPY_AND_ASSIGN(ImeObserver); | 355 DISALLOW_COPY_AND_ASSIGN(ImeObserver); |
| 356 }; | 356 }; |
| 357 } // namespace chromeos | 357 } // namespace chromeos |
| 358 | 358 |
| 359 | 359 |
| 360 InputImeExtensionEventRouter* | 360 ExtensionInputImeEventRouter* |
| 361 InputImeExtensionEventRouter::GetInstance() { | 361 ExtensionInputImeEventRouter::GetInstance() { |
| 362 return Singleton<InputImeExtensionEventRouter>::get(); | 362 return Singleton<ExtensionInputImeEventRouter>::get(); |
| 363 } | 363 } |
| 364 | 364 |
| 365 InputImeExtensionEventRouter::InputImeExtensionEventRouter() | 365 ExtensionInputImeEventRouter::ExtensionInputImeEventRouter() |
| 366 : next_request_id_(1) { | 366 : next_request_id_(1) { |
| 367 } | 367 } |
| 368 | 368 |
| 369 InputImeExtensionEventRouter::~InputImeExtensionEventRouter() { | 369 ExtensionInputImeEventRouter::~ExtensionInputImeEventRouter() { |
| 370 } | 370 } |
| 371 | 371 |
| 372 void InputImeExtensionEventRouter::Init() { | 372 void ExtensionInputImeEventRouter::Init() { |
| 373 } | 373 } |
| 374 | 374 |
| 375 #if defined(OS_CHROMEOS) | 375 #if defined(OS_CHROMEOS) |
| 376 bool InputImeExtensionEventRouter::RegisterIme( | 376 bool ExtensionInputImeEventRouter::RegisterIme( |
| 377 Profile* profile, | 377 Profile* profile, |
| 378 const std::string& extension_id, | 378 const std::string& extension_id, |
| 379 const Extension::InputComponentInfo& component) { | 379 const Extension::InputComponentInfo& component) { |
| 380 VLOG(1) << "RegisterIme: " << extension_id << " id: " << component.id; | 380 VLOG(1) << "RegisterIme: " << extension_id << " id: " << component.id; |
| 381 | 381 |
| 382 std::map<std::string, chromeos::InputMethodEngine*>& engine_map = | 382 std::map<std::string, chromeos::InputMethodEngine*>& engine_map = |
| 383 engines_[extension_id]; | 383 engines_[extension_id]; |
| 384 | 384 |
| 385 std::map<std::string, chromeos::InputMethodEngine*>::iterator engine_ix = | 385 std::map<std::string, chromeos::InputMethodEngine*>::iterator engine_ix = |
| 386 engine_map.find(component.id); | 386 engine_map.find(component.id); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 | 418 |
| 419 std::map<std::string, chromeos::ImeObserver*>& observer_list = | 419 std::map<std::string, chromeos::ImeObserver*>& observer_list = |
| 420 observers_[extension_id]; | 420 observers_[extension_id]; |
| 421 | 421 |
| 422 observer_list[component.id] = observer; | 422 observer_list[component.id] = observer; |
| 423 | 423 |
| 424 return true; | 424 return true; |
| 425 } | 425 } |
| 426 #endif | 426 #endif |
| 427 | 427 |
| 428 chromeos::InputMethodEngine* InputImeExtensionEventRouter::GetEngine( | 428 chromeos::InputMethodEngine* ExtensionInputImeEventRouter::GetEngine( |
| 429 const std::string& extension_id, const std::string& engine_id) { | 429 const std::string& extension_id, const std::string& engine_id) { |
| 430 std::map<std::string, | 430 std::map<std::string, |
| 431 std::map<std::string, chromeos::InputMethodEngine*> >::const_iterator | 431 std::map<std::string, chromeos::InputMethodEngine*> >::const_iterator |
| 432 engine_list = engines_.find(extension_id); | 432 engine_list = engines_.find(extension_id); |
| 433 if (engine_list != engines_.end()) { | 433 if (engine_list != engines_.end()) { |
| 434 std::map<std::string, chromeos::InputMethodEngine*>::const_iterator | 434 std::map<std::string, chromeos::InputMethodEngine*>::const_iterator |
| 435 engine_ix = engine_list->second.find(engine_id); | 435 engine_ix = engine_list->second.find(engine_id); |
| 436 if (engine_ix != engine_list->second.end()) { | 436 if (engine_ix != engine_list->second.end()) { |
| 437 return engine_ix->second; | 437 return engine_ix->second; |
| 438 } | 438 } |
| 439 } | 439 } |
| 440 return NULL; | 440 return NULL; |
| 441 } | 441 } |
| 442 | 442 |
| 443 chromeos::InputMethodEngine* InputImeExtensionEventRouter::GetActiveEngine( | 443 chromeos::InputMethodEngine* ExtensionInputImeEventRouter::GetActiveEngine( |
| 444 const std::string& extension_id) { | 444 const std::string& extension_id) { |
| 445 std::map<std::string, | 445 std::map<std::string, |
| 446 std::map<std::string, chromeos::InputMethodEngine*> >::const_iterator | 446 std::map<std::string, chromeos::InputMethodEngine*> >::const_iterator |
| 447 engine_list = engines_.find(extension_id); | 447 engine_list = engines_.find(extension_id); |
| 448 if (engine_list != engines_.end()) { | 448 if (engine_list != engines_.end()) { |
| 449 std::map<std::string, chromeos::InputMethodEngine*>::const_iterator | 449 std::map<std::string, chromeos::InputMethodEngine*>::const_iterator |
| 450 engine_ix; | 450 engine_ix; |
| 451 for (engine_ix = engine_list->second.begin(); | 451 for (engine_ix = engine_list->second.begin(); |
| 452 engine_ix != engine_list->second.end(); | 452 engine_ix != engine_list->second.end(); |
| 453 ++engine_ix) { | 453 ++engine_ix) { |
| 454 if (engine_ix->second->IsActive()) { | 454 if (engine_ix->second->IsActive()) { |
| 455 return engine_ix->second; | 455 return engine_ix->second; |
| 456 } | 456 } |
| 457 } | 457 } |
| 458 } | 458 } |
| 459 return NULL; | 459 return NULL; |
| 460 } | 460 } |
| 461 | 461 |
| 462 void InputImeExtensionEventRouter::OnEventHandled( | 462 void ExtensionInputImeEventRouter::OnEventHandled( |
| 463 const std::string& extension_id, | 463 const std::string& extension_id, |
| 464 const std::string& request_id, | 464 const std::string& request_id, |
| 465 bool handled) { | 465 bool handled) { |
| 466 RequestMap::iterator request = request_map_.find(request_id); | 466 RequestMap::iterator request = request_map_.find(request_id); |
| 467 if (request == request_map_.end()) { | 467 if (request == request_map_.end()) { |
| 468 LOG(ERROR) << "Request ID not found: " << request_id; | 468 LOG(ERROR) << "Request ID not found: " << request_id; |
| 469 return; | 469 return; |
| 470 } | 470 } |
| 471 | 471 |
| 472 std::string engine_id = request->second.first; | 472 std::string engine_id = request->second.first; |
| 473 chromeos::input_method::KeyEventHandle* key_data = request->second.second; | 473 chromeos::input_method::KeyEventHandle* key_data = request->second.second; |
| 474 request_map_.erase(request); | 474 request_map_.erase(request); |
| 475 | 475 |
| 476 chromeos::InputMethodEngine* engine = GetEngine(extension_id, engine_id); | 476 chromeos::InputMethodEngine* engine = GetEngine(extension_id, engine_id); |
| 477 if (!engine) { | 477 if (!engine) { |
| 478 LOG(ERROR) << "Engine does not exist: " << engine_id; | 478 LOG(ERROR) << "Engine does not exist: " << engine_id; |
| 479 return; | 479 return; |
| 480 } | 480 } |
| 481 | 481 |
| 482 engine->KeyEventDone(key_data, handled); | 482 engine->KeyEventDone(key_data, handled); |
| 483 } | 483 } |
| 484 | 484 |
| 485 std::string InputImeExtensionEventRouter::AddRequest( | 485 std::string ExtensionInputImeEventRouter::AddRequest( |
| 486 const std::string& engine_id, | 486 const std::string& engine_id, |
| 487 chromeos::input_method::KeyEventHandle* key_data) { | 487 chromeos::input_method::KeyEventHandle* key_data) { |
| 488 std::string request_id = base::IntToString(next_request_id_); | 488 std::string request_id = base::IntToString(next_request_id_); |
| 489 ++next_request_id_; | 489 ++next_request_id_; |
| 490 | 490 |
| 491 request_map_[request_id] = std::make_pair(engine_id, key_data); | 491 request_map_[request_id] = std::make_pair(engine_id, key_data); |
| 492 | 492 |
| 493 return request_id; | 493 return request_id; |
| 494 } | 494 } |
| 495 | 495 |
| 496 bool SetCompositionFunction::RunImpl() { | 496 bool SetCompositionFunction::RunImpl() { |
| 497 chromeos::InputMethodEngine* engine = | 497 chromeos::InputMethodEngine* engine = |
| 498 InputImeExtensionEventRouter::GetInstance()-> | 498 ExtensionInputImeEventRouter::GetInstance()-> |
| 499 GetActiveEngine(extension_id()); | 499 GetActiveEngine(extension_id()); |
| 500 if (!engine) { | 500 if (!engine) { |
| 501 result_.reset(Value::CreateBooleanValue(false)); | 501 result_.reset(Value::CreateBooleanValue(false)); |
| 502 return true; | 502 return true; |
| 503 } | 503 } |
| 504 | 504 |
| 505 DictionaryValue* args; | 505 DictionaryValue* args; |
| 506 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 506 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
| 507 int context_id; | 507 int context_id; |
| 508 std::string text; | 508 std::string text; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 selection_end, segments, &error_)) { | 556 selection_end, segments, &error_)) { |
| 557 result_.reset(Value::CreateBooleanValue(true)); | 557 result_.reset(Value::CreateBooleanValue(true)); |
| 558 } else { | 558 } else { |
| 559 result_.reset(Value::CreateBooleanValue(false)); | 559 result_.reset(Value::CreateBooleanValue(false)); |
| 560 } | 560 } |
| 561 return true; | 561 return true; |
| 562 } | 562 } |
| 563 | 563 |
| 564 bool ClearCompositionFunction::RunImpl() { | 564 bool ClearCompositionFunction::RunImpl() { |
| 565 chromeos::InputMethodEngine* engine = | 565 chromeos::InputMethodEngine* engine = |
| 566 InputImeExtensionEventRouter::GetInstance()-> | 566 ExtensionInputImeEventRouter::GetInstance()-> |
| 567 GetActiveEngine(extension_id()); | 567 GetActiveEngine(extension_id()); |
| 568 if (!engine) { | 568 if (!engine) { |
| 569 result_.reset(Value::CreateBooleanValue(false)); | 569 result_.reset(Value::CreateBooleanValue(false)); |
| 570 return true; | 570 return true; |
| 571 } | 571 } |
| 572 | 572 |
| 573 DictionaryValue* args; | 573 DictionaryValue* args; |
| 574 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 574 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
| 575 int context_id; | 575 int context_id; |
| 576 | 576 |
| 577 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, | 577 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, |
| 578 &context_id)); | 578 &context_id)); |
| 579 | 579 |
| 580 if (engine->ClearComposition(context_id, &error_)) { | 580 if (engine->ClearComposition(context_id, &error_)) { |
| 581 result_.reset(Value::CreateBooleanValue(true)); | 581 result_.reset(Value::CreateBooleanValue(true)); |
| 582 } else { | 582 } else { |
| 583 result_.reset(Value::CreateBooleanValue(false)); | 583 result_.reset(Value::CreateBooleanValue(false)); |
| 584 } | 584 } |
| 585 return true; | 585 return true; |
| 586 } | 586 } |
| 587 | 587 |
| 588 bool CommitTextFunction::RunImpl() { | 588 bool CommitTextFunction::RunImpl() { |
| 589 // TODO(zork): Support committing when not active. | 589 // TODO(zork): Support committing when not active. |
| 590 chromeos::InputMethodEngine* engine = | 590 chromeos::InputMethodEngine* engine = |
| 591 InputImeExtensionEventRouter::GetInstance()-> | 591 ExtensionInputImeEventRouter::GetInstance()-> |
| 592 GetActiveEngine(extension_id()); | 592 GetActiveEngine(extension_id()); |
| 593 if (!engine) { | 593 if (!engine) { |
| 594 result_.reset(Value::CreateBooleanValue(false)); | 594 result_.reset(Value::CreateBooleanValue(false)); |
| 595 return true; | 595 return true; |
| 596 } | 596 } |
| 597 | 597 |
| 598 DictionaryValue* args; | 598 DictionaryValue* args; |
| 599 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 599 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
| 600 int context_id; | 600 int context_id; |
| 601 std::string text; | 601 std::string text; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 613 } | 613 } |
| 614 | 614 |
| 615 bool SetCandidateWindowPropertiesFunction::RunImpl() { | 615 bool SetCandidateWindowPropertiesFunction::RunImpl() { |
| 616 DictionaryValue* args; | 616 DictionaryValue* args; |
| 617 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 617 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
| 618 | 618 |
| 619 std::string engine_id; | 619 std::string engine_id; |
| 620 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); | 620 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); |
| 621 | 621 |
| 622 chromeos::InputMethodEngine* engine = | 622 chromeos::InputMethodEngine* engine = |
| 623 InputImeExtensionEventRouter::GetInstance()->GetEngine(extension_id(), | 623 ExtensionInputImeEventRouter::GetInstance()->GetEngine(extension_id(), |
| 624 engine_id); | 624 engine_id); |
| 625 if (!engine) { | 625 if (!engine) { |
| 626 result_.reset(Value::CreateBooleanValue(false)); | 626 result_.reset(Value::CreateBooleanValue(false)); |
| 627 return true; | 627 return true; |
| 628 } | 628 } |
| 629 | 629 |
| 630 DictionaryValue* properties; | 630 DictionaryValue* properties; |
| 631 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(keys::kPropertiesKey, | 631 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(keys::kPropertiesKey, |
| 632 &properties)); | 632 &properties)); |
| 633 | 633 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 return false; | 724 return false; |
| 725 } | 725 } |
| 726 } | 726 } |
| 727 } | 727 } |
| 728 | 728 |
| 729 return true; | 729 return true; |
| 730 } | 730 } |
| 731 | 731 |
| 732 bool SetCandidatesFunction::RunImpl() { | 732 bool SetCandidatesFunction::RunImpl() { |
| 733 chromeos::InputMethodEngine* engine = | 733 chromeos::InputMethodEngine* engine = |
| 734 InputImeExtensionEventRouter::GetInstance()-> | 734 ExtensionInputImeEventRouter::GetInstance()-> |
| 735 GetActiveEngine(extension_id()); | 735 GetActiveEngine(extension_id()); |
| 736 if (!engine) { | 736 if (!engine) { |
| 737 result_.reset(Value::CreateBooleanValue(false)); | 737 result_.reset(Value::CreateBooleanValue(false)); |
| 738 return true; | 738 return true; |
| 739 } | 739 } |
| 740 | 740 |
| 741 DictionaryValue* args; | 741 DictionaryValue* args; |
| 742 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 742 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
| 743 | 743 |
| 744 int context_id; | 744 int context_id; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 759 if (engine->SetCandidates(context_id, candidates, &error_)) { | 759 if (engine->SetCandidates(context_id, candidates, &error_)) { |
| 760 result_.reset(Value::CreateBooleanValue(true)); | 760 result_.reset(Value::CreateBooleanValue(true)); |
| 761 } else { | 761 } else { |
| 762 result_.reset(Value::CreateBooleanValue(false)); | 762 result_.reset(Value::CreateBooleanValue(false)); |
| 763 } | 763 } |
| 764 return true; | 764 return true; |
| 765 } | 765 } |
| 766 | 766 |
| 767 bool SetCursorPositionFunction::RunImpl() { | 767 bool SetCursorPositionFunction::RunImpl() { |
| 768 chromeos::InputMethodEngine* engine = | 768 chromeos::InputMethodEngine* engine = |
| 769 InputImeExtensionEventRouter::GetInstance()-> | 769 ExtensionInputImeEventRouter::GetInstance()-> |
| 770 GetActiveEngine(extension_id()); | 770 GetActiveEngine(extension_id()); |
| 771 if (!engine) { | 771 if (!engine) { |
| 772 result_.reset(Value::CreateBooleanValue(false)); | 772 result_.reset(Value::CreateBooleanValue(false)); |
| 773 return true; | 773 return true; |
| 774 } | 774 } |
| 775 | 775 |
| 776 DictionaryValue* args; | 776 DictionaryValue* args; |
| 777 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 777 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
| 778 int context_id; | 778 int context_id; |
| 779 int candidate_id; | 779 int candidate_id; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 792 } | 792 } |
| 793 | 793 |
| 794 bool SetMenuItemsFunction::RunImpl() { | 794 bool SetMenuItemsFunction::RunImpl() { |
| 795 DictionaryValue* args; | 795 DictionaryValue* args; |
| 796 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 796 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
| 797 | 797 |
| 798 std::string engine_id; | 798 std::string engine_id; |
| 799 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); | 799 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); |
| 800 | 800 |
| 801 chromeos::InputMethodEngine* engine = | 801 chromeos::InputMethodEngine* engine = |
| 802 InputImeExtensionEventRouter::GetInstance()->GetEngine(extension_id(), | 802 ExtensionInputImeEventRouter::GetInstance()->GetEngine(extension_id(), |
| 803 engine_id); | 803 engine_id); |
| 804 if (!engine) { | 804 if (!engine) { |
| 805 error_ = kErrorEngineNotAvailable; | 805 error_ = kErrorEngineNotAvailable; |
| 806 return false; | 806 return false; |
| 807 } | 807 } |
| 808 | 808 |
| 809 ListValue* items; | 809 ListValue* items; |
| 810 EXTENSION_FUNCTION_VALIDATE(args->GetList(keys::kItemsKey, &items)); | 810 EXTENSION_FUNCTION_VALIDATE(args->GetList(keys::kItemsKey, &items)); |
| 811 | 811 |
| 812 std::vector<chromeos::InputMethodEngine::MenuItem> menu_items; | 812 std::vector<chromeos::InputMethodEngine::MenuItem> menu_items; |
| 813 EXTENSION_FUNCTION_VALIDATE(ReadMenuItems(items, &menu_items)); | 813 EXTENSION_FUNCTION_VALIDATE(ReadMenuItems(items, &menu_items)); |
| 814 | 814 |
| 815 if (!engine->SetMenuItems(menu_items)) { | 815 if (!engine->SetMenuItems(menu_items)) { |
| 816 error_ = kErrorSetMenuItemsFail; | 816 error_ = kErrorSetMenuItemsFail; |
| 817 } | 817 } |
| 818 return true; | 818 return true; |
| 819 } | 819 } |
| 820 | 820 |
| 821 bool UpdateMenuItemsFunction::RunImpl() { | 821 bool UpdateMenuItemsFunction::RunImpl() { |
| 822 DictionaryValue* args; | 822 DictionaryValue* args; |
| 823 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 823 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
| 824 | 824 |
| 825 std::string engine_id; | 825 std::string engine_id; |
| 826 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); | 826 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); |
| 827 | 827 |
| 828 chromeos::InputMethodEngine* engine = | 828 chromeos::InputMethodEngine* engine = |
| 829 InputImeExtensionEventRouter::GetInstance()->GetEngine(extension_id(), | 829 ExtensionInputImeEventRouter::GetInstance()->GetEngine(extension_id(), |
| 830 engine_id); | 830 engine_id); |
| 831 if (!engine) { | 831 if (!engine) { |
| 832 error_ = kErrorEngineNotAvailable; | 832 error_ = kErrorEngineNotAvailable; |
| 833 return false; | 833 return false; |
| 834 } | 834 } |
| 835 | 835 |
| 836 ListValue* items; | 836 ListValue* items; |
| 837 EXTENSION_FUNCTION_VALIDATE(args->GetList(keys::kItemsKey, &items)); | 837 EXTENSION_FUNCTION_VALIDATE(args->GetList(keys::kItemsKey, &items)); |
| 838 | 838 |
| 839 std::vector<chromeos::InputMethodEngine::MenuItem> menu_items; | 839 std::vector<chromeos::InputMethodEngine::MenuItem> menu_items; |
| 840 EXTENSION_FUNCTION_VALIDATE(ReadMenuItems(items, &menu_items)); | 840 EXTENSION_FUNCTION_VALIDATE(ReadMenuItems(items, &menu_items)); |
| 841 | 841 |
| 842 if (!engine->UpdateMenuItems(menu_items)) { | 842 if (!engine->UpdateMenuItems(menu_items)) { |
| 843 error_ = kErrorUpdateMenuItemsFail; | 843 error_ = kErrorUpdateMenuItemsFail; |
| 844 } | 844 } |
| 845 return true; | 845 return true; |
| 846 } | 846 } |
| 847 | 847 |
| 848 bool InputEventHandled::RunImpl() { | 848 bool InputEventHandled::RunImpl() { |
| 849 std::string request_id_str; | 849 std::string request_id_str; |
| 850 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &request_id_str)); | 850 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &request_id_str)); |
| 851 | 851 |
| 852 bool handled = false; | 852 bool handled = false; |
| 853 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &handled)); | 853 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &handled)); |
| 854 | 854 |
| 855 InputImeExtensionEventRouter::GetInstance()->OnEventHandled( | 855 ExtensionInputImeEventRouter::GetInstance()->OnEventHandled( |
| 856 extension_id(), request_id_str, handled); | 856 extension_id(), request_id_str, handled); |
| 857 | 857 |
| 858 return true; | 858 return true; |
| 859 } | 859 } |
| 860 #endif | 860 #endif |
| OLD | NEW |