| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extension_input_ime_api.h" | 5 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/chromeos/input_method/input_method_engine.h" | 11 #include "chrome/browser/chromeos/input_method/input_method_engine.h" |
| 12 #include "chrome/browser/extensions/event_router.h" | 12 #include "chrome/browser/extensions/event_router.h" |
| 13 #include "chrome/browser/extensions/extension_input_module_constants.h" | 13 #include "chrome/browser/extensions/extension_input_module_constants.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 | 15 |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 GURL()); | 226 GURL()); |
| 227 } | 227 } |
| 228 | 228 |
| 229 virtual void OnKeyEvent(const std::string& engine_id, | 229 virtual void OnKeyEvent(const std::string& engine_id, |
| 230 const InputMethodEngine::KeyboardEvent& event, | 230 const InputMethodEngine::KeyboardEvent& event, |
| 231 chromeos::input_method::KeyEventHandle* key_data) { | 231 chromeos::input_method::KeyEventHandle* key_data) { |
| 232 if (profile_ == NULL || extension_id_.empty()) | 232 if (profile_ == NULL || extension_id_.empty()) |
| 233 return; | 233 return; |
| 234 | 234 |
| 235 std::string request_id = | 235 std::string request_id = |
| 236 ExtensionInputImeEventRouter::GetInstance()->AddRequest(engine_id, | 236 extensions::InputImeEventRouter::GetInstance()->AddRequest(engine_id, |
| 237 key_data); | 237 key_data); |
| 238 | 238 |
| 239 DictionaryValue* dict = new DictionaryValue(); | 239 DictionaryValue* dict = new DictionaryValue(); |
| 240 dict->SetString("type", event.type); | 240 dict->SetString("type", event.type); |
| 241 dict->SetString("requestId", request_id); | 241 dict->SetString("requestId", request_id); |
| 242 dict->SetString("key", event.key); | 242 dict->SetString("key", event.key); |
| 243 dict->SetBoolean("altKey", event.alt_key); | 243 dict->SetBoolean("altKey", event.alt_key); |
| 244 dict->SetBoolean("ctrlKey", event.ctrl_key); | 244 dict->SetBoolean("ctrlKey", event.ctrl_key); |
| 245 dict->SetBoolean("shiftKey", event.shift_key); | 245 dict->SetBoolean("shiftKey", event.shift_key); |
| 246 | 246 |
| 247 ListValue args; | 247 ListValue args; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 private: | 306 private: |
| 307 Profile* profile_; | 307 Profile* profile_; |
| 308 std::string extension_id_; | 308 std::string extension_id_; |
| 309 std::string engine_id_; | 309 std::string engine_id_; |
| 310 | 310 |
| 311 DISALLOW_COPY_AND_ASSIGN(ImeObserver); | 311 DISALLOW_COPY_AND_ASSIGN(ImeObserver); |
| 312 }; | 312 }; |
| 313 | 313 |
| 314 } // namespace chromeos | 314 } // namespace chromeos |
| 315 | 315 |
| 316 ExtensionInputImeEventRouter* | 316 namespace extensions { |
| 317 ExtensionInputImeEventRouter::GetInstance() { | 317 |
| 318 return Singleton<ExtensionInputImeEventRouter>::get(); | 318 InputImeEventRouter* |
| 319 InputImeEventRouter::GetInstance() { |
| 320 return Singleton<InputImeEventRouter>::get(); |
| 319 } | 321 } |
| 320 | 322 |
| 321 void ExtensionInputImeEventRouter::Init() {} | 323 void InputImeEventRouter::Init() {} |
| 322 | 324 |
| 323 #if defined(OS_CHROMEOS) | 325 #if defined(OS_CHROMEOS) |
| 324 bool ExtensionInputImeEventRouter::RegisterIme( | 326 bool InputImeEventRouter::RegisterIme( |
| 325 Profile* profile, | 327 Profile* profile, |
| 326 const std::string& extension_id, | 328 const std::string& extension_id, |
| 327 const extensions::Extension::InputComponentInfo& component) { | 329 const extensions::Extension::InputComponentInfo& component) { |
| 328 VLOG(1) << "RegisterIme: " << extension_id << " id: " << component.id; | 330 VLOG(1) << "RegisterIme: " << extension_id << " id: " << component.id; |
| 329 | 331 |
| 330 std::map<std::string, chromeos::InputMethodEngine*>& engine_map = | 332 std::map<std::string, chromeos::InputMethodEngine*>& engine_map = |
| 331 engines_[extension_id]; | 333 engines_[extension_id]; |
| 332 | 334 |
| 333 std::map<std::string, chromeos::InputMethodEngine*>::iterator engine_ix = | 335 std::map<std::string, chromeos::InputMethodEngine*>::iterator engine_ix = |
| 334 engine_map.find(component.id); | 336 engine_map.find(component.id); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 357 engine_map[component.id] = engine; | 359 engine_map[component.id] = engine; |
| 358 | 360 |
| 359 std::map<std::string, chromeos::ImeObserver*>& observer_list = | 361 std::map<std::string, chromeos::ImeObserver*>& observer_list = |
| 360 observers_[extension_id]; | 362 observers_[extension_id]; |
| 361 | 363 |
| 362 observer_list[component.id] = observer; | 364 observer_list[component.id] = observer; |
| 363 | 365 |
| 364 return true; | 366 return true; |
| 365 } | 367 } |
| 366 | 368 |
| 367 void ExtensionInputImeEventRouter::UnregisterAllImes( | 369 void InputImeEventRouter::UnregisterAllImes( |
| 368 Profile* profile, const std::string& extension_id) { | 370 Profile* profile, const std::string& extension_id) { |
| 369 std::map<std::string, | 371 std::map<std::string, |
| 370 std::map<std::string, | 372 std::map<std::string, |
| 371 chromeos::InputMethodEngine*> >::iterator engine_map = | 373 chromeos::InputMethodEngine*> >::iterator engine_map = |
| 372 engines_.find(extension_id); | 374 engines_.find(extension_id); |
| 373 if (engine_map != engines_.end()) { | 375 if (engine_map != engines_.end()) { |
| 374 STLDeleteContainerPairSecondPointers(engine_map->second.begin(), | 376 STLDeleteContainerPairSecondPointers(engine_map->second.begin(), |
| 375 engine_map->second.end()); | 377 engine_map->second.end()); |
| 376 engines_.erase(engine_map); | 378 engines_.erase(engine_map); |
| 377 } | 379 } |
| 378 | 380 |
| 379 std::map<std::string, | 381 std::map<std::string, |
| 380 std::map<std::string, | 382 std::map<std::string, |
| 381 chromeos::ImeObserver*> >::iterator observer_list = | 383 chromeos::ImeObserver*> >::iterator observer_list = |
| 382 observers_.find(extension_id); | 384 observers_.find(extension_id); |
| 383 if (observer_list != observers_.end()) { | 385 if (observer_list != observers_.end()) { |
| 384 STLDeleteContainerPairSecondPointers(observer_list->second.begin(), | 386 STLDeleteContainerPairSecondPointers(observer_list->second.begin(), |
| 385 observer_list->second.end()); | 387 observer_list->second.end()); |
| 386 observers_.erase(observer_list); | 388 observers_.erase(observer_list); |
| 387 } | 389 } |
| 388 } | 390 } |
| 389 #endif | 391 #endif |
| 390 | 392 |
| 391 chromeos::InputMethodEngine* ExtensionInputImeEventRouter::GetEngine( | 393 chromeos::InputMethodEngine* InputImeEventRouter::GetEngine( |
| 392 const std::string& extension_id, const std::string& engine_id) { | 394 const std::string& extension_id, const std::string& engine_id) { |
| 393 std::map<std::string, | 395 std::map<std::string, |
| 394 std::map<std::string, chromeos::InputMethodEngine*> >::const_iterator | 396 std::map<std::string, chromeos::InputMethodEngine*> >::const_iterator |
| 395 engine_list = engines_.find(extension_id); | 397 engine_list = engines_.find(extension_id); |
| 396 if (engine_list != engines_.end()) { | 398 if (engine_list != engines_.end()) { |
| 397 std::map<std::string, chromeos::InputMethodEngine*>::const_iterator | 399 std::map<std::string, chromeos::InputMethodEngine*>::const_iterator |
| 398 engine_ix = engine_list->second.find(engine_id); | 400 engine_ix = engine_list->second.find(engine_id); |
| 399 if (engine_ix != engine_list->second.end()) { | 401 if (engine_ix != engine_list->second.end()) { |
| 400 return engine_ix->second; | 402 return engine_ix->second; |
| 401 } | 403 } |
| 402 } | 404 } |
| 403 return NULL; | 405 return NULL; |
| 404 } | 406 } |
| 405 | 407 |
| 406 chromeos::InputMethodEngine* ExtensionInputImeEventRouter::GetActiveEngine( | 408 chromeos::InputMethodEngine* InputImeEventRouter::GetActiveEngine( |
| 407 const std::string& extension_id) { | 409 const std::string& extension_id) { |
| 408 std::map<std::string, | 410 std::map<std::string, |
| 409 std::map<std::string, chromeos::InputMethodEngine*> >::const_iterator | 411 std::map<std::string, chromeos::InputMethodEngine*> >::const_iterator |
| 410 engine_list = engines_.find(extension_id); | 412 engine_list = engines_.find(extension_id); |
| 411 if (engine_list != engines_.end()) { | 413 if (engine_list != engines_.end()) { |
| 412 std::map<std::string, chromeos::InputMethodEngine*>::const_iterator | 414 std::map<std::string, chromeos::InputMethodEngine*>::const_iterator |
| 413 engine_ix; | 415 engine_ix; |
| 414 for (engine_ix = engine_list->second.begin(); | 416 for (engine_ix = engine_list->second.begin(); |
| 415 engine_ix != engine_list->second.end(); | 417 engine_ix != engine_list->second.end(); |
| 416 ++engine_ix) { | 418 ++engine_ix) { |
| 417 if (engine_ix->second->IsActive()) { | 419 if (engine_ix->second->IsActive()) { |
| 418 return engine_ix->second; | 420 return engine_ix->second; |
| 419 } | 421 } |
| 420 } | 422 } |
| 421 } | 423 } |
| 422 return NULL; | 424 return NULL; |
| 423 } | 425 } |
| 424 | 426 |
| 425 void ExtensionInputImeEventRouter::OnEventHandled( | 427 void InputImeEventRouter::OnEventHandled( |
| 426 const std::string& extension_id, | 428 const std::string& extension_id, |
| 427 const std::string& request_id, | 429 const std::string& request_id, |
| 428 bool handled) { | 430 bool handled) { |
| 429 RequestMap::iterator request = request_map_.find(request_id); | 431 RequestMap::iterator request = request_map_.find(request_id); |
| 430 if (request == request_map_.end()) { | 432 if (request == request_map_.end()) { |
| 431 LOG(ERROR) << "Request ID not found: " << request_id; | 433 LOG(ERROR) << "Request ID not found: " << request_id; |
| 432 return; | 434 return; |
| 433 } | 435 } |
| 434 | 436 |
| 435 std::string engine_id = request->second.first; | 437 std::string engine_id = request->second.first; |
| 436 chromeos::input_method::KeyEventHandle* key_data = request->second.second; | 438 chromeos::input_method::KeyEventHandle* key_data = request->second.second; |
| 437 request_map_.erase(request); | 439 request_map_.erase(request); |
| 438 | 440 |
| 439 chromeos::InputMethodEngine* engine = GetEngine(extension_id, engine_id); | 441 chromeos::InputMethodEngine* engine = GetEngine(extension_id, engine_id); |
| 440 if (!engine) { | 442 if (!engine) { |
| 441 LOG(ERROR) << "Engine does not exist: " << engine_id; | 443 LOG(ERROR) << "Engine does not exist: " << engine_id; |
| 442 return; | 444 return; |
| 443 } | 445 } |
| 444 | 446 |
| 445 engine->KeyEventDone(key_data, handled); | 447 engine->KeyEventDone(key_data, handled); |
| 446 } | 448 } |
| 447 | 449 |
| 448 std::string ExtensionInputImeEventRouter::AddRequest( | 450 std::string InputImeEventRouter::AddRequest( |
| 449 const std::string& engine_id, | 451 const std::string& engine_id, |
| 450 chromeos::input_method::KeyEventHandle* key_data) { | 452 chromeos::input_method::KeyEventHandle* key_data) { |
| 451 std::string request_id = base::IntToString(next_request_id_); | 453 std::string request_id = base::IntToString(next_request_id_); |
| 452 ++next_request_id_; | 454 ++next_request_id_; |
| 453 | 455 |
| 454 request_map_[request_id] = std::make_pair(engine_id, key_data); | 456 request_map_[request_id] = std::make_pair(engine_id, key_data); |
| 455 | 457 |
| 456 return request_id; | 458 return request_id; |
| 457 } | 459 } |
| 458 | 460 |
| 459 ExtensionInputImeEventRouter::ExtensionInputImeEventRouter() | 461 InputImeEventRouter::InputImeEventRouter() |
| 460 : next_request_id_(1) { | 462 : next_request_id_(1) { |
| 461 } | 463 } |
| 462 | 464 |
| 463 ExtensionInputImeEventRouter::~ExtensionInputImeEventRouter() {} | 465 InputImeEventRouter::~InputImeEventRouter() {} |
| 464 | 466 |
| 465 bool SetCompositionFunction::RunImpl() { | 467 bool SetCompositionFunction::RunImpl() { |
| 466 chromeos::InputMethodEngine* engine = | 468 chromeos::InputMethodEngine* engine = |
| 467 ExtensionInputImeEventRouter::GetInstance()-> | 469 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); |
| 468 GetActiveEngine(extension_id()); | |
| 469 if (!engine) { | 470 if (!engine) { |
| 470 SetResult(Value::CreateBooleanValue(false)); | 471 SetResult(Value::CreateBooleanValue(false)); |
| 471 return true; | 472 return true; |
| 472 } | 473 } |
| 473 | 474 |
| 474 DictionaryValue* args; | 475 DictionaryValue* args; |
| 475 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 476 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
| 476 int context_id; | 477 int context_id; |
| 477 std::string text; | 478 std::string text; |
| 478 int selection_start; | 479 int selection_start; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 selection_end, cursor, segments, &error_)) { | 534 selection_end, cursor, segments, &error_)) { |
| 534 SetResult(Value::CreateBooleanValue(true)); | 535 SetResult(Value::CreateBooleanValue(true)); |
| 535 } else { | 536 } else { |
| 536 SetResult(Value::CreateBooleanValue(false)); | 537 SetResult(Value::CreateBooleanValue(false)); |
| 537 } | 538 } |
| 538 return true; | 539 return true; |
| 539 } | 540 } |
| 540 | 541 |
| 541 bool ClearCompositionFunction::RunImpl() { | 542 bool ClearCompositionFunction::RunImpl() { |
| 542 chromeos::InputMethodEngine* engine = | 543 chromeos::InputMethodEngine* engine = |
| 543 ExtensionInputImeEventRouter::GetInstance()-> | 544 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); |
| 544 GetActiveEngine(extension_id()); | |
| 545 if (!engine) { | 545 if (!engine) { |
| 546 SetResult(Value::CreateBooleanValue(false)); | 546 SetResult(Value::CreateBooleanValue(false)); |
| 547 return true; | 547 return true; |
| 548 } | 548 } |
| 549 | 549 |
| 550 DictionaryValue* args; | 550 DictionaryValue* args; |
| 551 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 551 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
| 552 int context_id; | 552 int context_id; |
| 553 | 553 |
| 554 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, | 554 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, |
| 555 &context_id)); | 555 &context_id)); |
| 556 | 556 |
| 557 if (engine->ClearComposition(context_id, &error_)) { | 557 if (engine->ClearComposition(context_id, &error_)) { |
| 558 SetResult(Value::CreateBooleanValue(true)); | 558 SetResult(Value::CreateBooleanValue(true)); |
| 559 } else { | 559 } else { |
| 560 SetResult(Value::CreateBooleanValue(false)); | 560 SetResult(Value::CreateBooleanValue(false)); |
| 561 } | 561 } |
| 562 return true; | 562 return true; |
| 563 } | 563 } |
| 564 | 564 |
| 565 bool CommitTextFunction::RunImpl() { | 565 bool CommitTextFunction::RunImpl() { |
| 566 // TODO(zork): Support committing when not active. | 566 // TODO(zork): Support committing when not active. |
| 567 chromeos::InputMethodEngine* engine = | 567 chromeos::InputMethodEngine* engine = |
| 568 ExtensionInputImeEventRouter::GetInstance()-> | 568 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); |
| 569 GetActiveEngine(extension_id()); | |
| 570 if (!engine) { | 569 if (!engine) { |
| 571 SetResult(Value::CreateBooleanValue(false)); | 570 SetResult(Value::CreateBooleanValue(false)); |
| 572 return true; | 571 return true; |
| 573 } | 572 } |
| 574 | 573 |
| 575 DictionaryValue* args; | 574 DictionaryValue* args; |
| 576 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 575 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
| 577 int context_id; | 576 int context_id; |
| 578 std::string text; | 577 std::string text; |
| 579 | 578 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 590 } | 589 } |
| 591 | 590 |
| 592 bool SetCandidateWindowPropertiesFunction::RunImpl() { | 591 bool SetCandidateWindowPropertiesFunction::RunImpl() { |
| 593 DictionaryValue* args; | 592 DictionaryValue* args; |
| 594 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 593 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
| 595 | 594 |
| 596 std::string engine_id; | 595 std::string engine_id; |
| 597 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); | 596 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); |
| 598 | 597 |
| 599 chromeos::InputMethodEngine* engine = | 598 chromeos::InputMethodEngine* engine = |
| 600 ExtensionInputImeEventRouter::GetInstance()->GetEngine(extension_id(), | 599 InputImeEventRouter::GetInstance()->GetEngine(extension_id(), engine_id); |
| 601 engine_id); | |
| 602 if (!engine) { | 600 if (!engine) { |
| 603 SetResult(Value::CreateBooleanValue(false)); | 601 SetResult(Value::CreateBooleanValue(false)); |
| 604 return true; | 602 return true; |
| 605 } | 603 } |
| 606 | 604 |
| 607 DictionaryValue* properties; | 605 DictionaryValue* properties; |
| 608 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(keys::kPropertiesKey, | 606 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(keys::kPropertiesKey, |
| 609 &properties)); | 607 &properties)); |
| 610 | 608 |
| 611 if (properties->HasKey(keys::kVisibleKey)) { | 609 if (properties->HasKey(keys::kVisibleKey)) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 return false; | 699 return false; |
| 702 } | 700 } |
| 703 } | 701 } |
| 704 } | 702 } |
| 705 | 703 |
| 706 return true; | 704 return true; |
| 707 } | 705 } |
| 708 | 706 |
| 709 bool SetCandidatesFunction::RunImpl() { | 707 bool SetCandidatesFunction::RunImpl() { |
| 710 chromeos::InputMethodEngine* engine = | 708 chromeos::InputMethodEngine* engine = |
| 711 ExtensionInputImeEventRouter::GetInstance()-> | 709 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); |
| 712 GetActiveEngine(extension_id()); | |
| 713 if (!engine) { | 710 if (!engine) { |
| 714 SetResult(Value::CreateBooleanValue(false)); | 711 SetResult(Value::CreateBooleanValue(false)); |
| 715 return true; | 712 return true; |
| 716 } | 713 } |
| 717 | 714 |
| 718 DictionaryValue* args; | 715 DictionaryValue* args; |
| 719 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 716 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
| 720 | 717 |
| 721 int context_id; | 718 int context_id; |
| 722 std::vector<chromeos::InputMethodEngine::Candidate> candidates; | 719 std::vector<chromeos::InputMethodEngine::Candidate> candidates; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 736 if (engine->SetCandidates(context_id, candidates, &error_)) { | 733 if (engine->SetCandidates(context_id, candidates, &error_)) { |
| 737 SetResult(Value::CreateBooleanValue(true)); | 734 SetResult(Value::CreateBooleanValue(true)); |
| 738 } else { | 735 } else { |
| 739 SetResult(Value::CreateBooleanValue(false)); | 736 SetResult(Value::CreateBooleanValue(false)); |
| 740 } | 737 } |
| 741 return true; | 738 return true; |
| 742 } | 739 } |
| 743 | 740 |
| 744 bool SetCursorPositionFunction::RunImpl() { | 741 bool SetCursorPositionFunction::RunImpl() { |
| 745 chromeos::InputMethodEngine* engine = | 742 chromeos::InputMethodEngine* engine = |
| 746 ExtensionInputImeEventRouter::GetInstance()-> | 743 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); |
| 747 GetActiveEngine(extension_id()); | |
| 748 if (!engine) { | 744 if (!engine) { |
| 749 SetResult(Value::CreateBooleanValue(false)); | 745 SetResult(Value::CreateBooleanValue(false)); |
| 750 return true; | 746 return true; |
| 751 } | 747 } |
| 752 | 748 |
| 753 DictionaryValue* args; | 749 DictionaryValue* args; |
| 754 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 750 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
| 755 int context_id; | 751 int context_id; |
| 756 int candidate_id; | 752 int candidate_id; |
| 757 | 753 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 769 } | 765 } |
| 770 | 766 |
| 771 bool SetMenuItemsFunction::RunImpl() { | 767 bool SetMenuItemsFunction::RunImpl() { |
| 772 DictionaryValue* args; | 768 DictionaryValue* args; |
| 773 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 769 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
| 774 | 770 |
| 775 std::string engine_id; | 771 std::string engine_id; |
| 776 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); | 772 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); |
| 777 | 773 |
| 778 chromeos::InputMethodEngine* engine = | 774 chromeos::InputMethodEngine* engine = |
| 779 ExtensionInputImeEventRouter::GetInstance()->GetEngine(extension_id(), | 775 InputImeEventRouter::GetInstance()->GetEngine(extension_id(), engine_id); |
| 780 engine_id); | |
| 781 if (!engine) { | 776 if (!engine) { |
| 782 error_ = kErrorEngineNotAvailable; | 777 error_ = kErrorEngineNotAvailable; |
| 783 return false; | 778 return false; |
| 784 } | 779 } |
| 785 | 780 |
| 786 ListValue* items; | 781 ListValue* items; |
| 787 EXTENSION_FUNCTION_VALIDATE(args->GetList(keys::kItemsKey, &items)); | 782 EXTENSION_FUNCTION_VALIDATE(args->GetList(keys::kItemsKey, &items)); |
| 788 | 783 |
| 789 std::vector<chromeos::InputMethodEngine::MenuItem> menu_items; | 784 std::vector<chromeos::InputMethodEngine::MenuItem> menu_items; |
| 790 EXTENSION_FUNCTION_VALIDATE(ReadMenuItems(items, &menu_items)); | 785 EXTENSION_FUNCTION_VALIDATE(ReadMenuItems(items, &menu_items)); |
| 791 | 786 |
| 792 if (!engine->SetMenuItems(menu_items)) { | 787 if (!engine->SetMenuItems(menu_items)) { |
| 793 error_ = kErrorSetMenuItemsFail; | 788 error_ = kErrorSetMenuItemsFail; |
| 794 } | 789 } |
| 795 return true; | 790 return true; |
| 796 } | 791 } |
| 797 | 792 |
| 798 bool UpdateMenuItemsFunction::RunImpl() { | 793 bool UpdateMenuItemsFunction::RunImpl() { |
| 799 DictionaryValue* args; | 794 DictionaryValue* args; |
| 800 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); | 795 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); |
| 801 | 796 |
| 802 std::string engine_id; | 797 std::string engine_id; |
| 803 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); | 798 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); |
| 804 | 799 |
| 805 chromeos::InputMethodEngine* engine = | 800 chromeos::InputMethodEngine* engine = |
| 806 ExtensionInputImeEventRouter::GetInstance()->GetEngine(extension_id(), | 801 InputImeEventRouter::GetInstance()->GetEngine(extension_id(), engine_id); |
| 807 engine_id); | |
| 808 if (!engine) { | 802 if (!engine) { |
| 809 error_ = kErrorEngineNotAvailable; | 803 error_ = kErrorEngineNotAvailable; |
| 810 return false; | 804 return false; |
| 811 } | 805 } |
| 812 | 806 |
| 813 ListValue* items; | 807 ListValue* items; |
| 814 EXTENSION_FUNCTION_VALIDATE(args->GetList(keys::kItemsKey, &items)); | 808 EXTENSION_FUNCTION_VALIDATE(args->GetList(keys::kItemsKey, &items)); |
| 815 | 809 |
| 816 std::vector<chromeos::InputMethodEngine::MenuItem> menu_items; | 810 std::vector<chromeos::InputMethodEngine::MenuItem> menu_items; |
| 817 EXTENSION_FUNCTION_VALIDATE(ReadMenuItems(items, &menu_items)); | 811 EXTENSION_FUNCTION_VALIDATE(ReadMenuItems(items, &menu_items)); |
| 818 | 812 |
| 819 if (!engine->UpdateMenuItems(menu_items)) { | 813 if (!engine->UpdateMenuItems(menu_items)) { |
| 820 error_ = kErrorUpdateMenuItemsFail; | 814 error_ = kErrorUpdateMenuItemsFail; |
| 821 } | 815 } |
| 822 return true; | 816 return true; |
| 823 } | 817 } |
| 824 | 818 |
| 825 bool InputEventHandled::RunImpl() { | 819 bool InputEventHandled::RunImpl() { |
| 826 std::string request_id_str; | 820 std::string request_id_str; |
| 827 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &request_id_str)); | 821 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &request_id_str)); |
| 828 | 822 |
| 829 bool handled = false; | 823 bool handled = false; |
| 830 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &handled)); | 824 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &handled)); |
| 831 | 825 |
| 832 ExtensionInputImeEventRouter::GetInstance()->OnEventHandled( | 826 InputImeEventRouter::GetInstance()->OnEventHandled( |
| 833 extension_id(), request_id_str, handled); | 827 extension_id(), request_id_str, handled); |
| 834 | 828 |
| 835 return true; | 829 return true; |
| 836 } | 830 } |
| 837 #endif | 831 #endif |
| 832 |
| 833 } // namespace extensions |
| OLD | NEW |