OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/input_method/input_method_engine.h" | 5 #include "chrome/browser/chromeos/input_method/input_method_engine.h" |
6 | 6 |
7 #undef FocusIn | 7 #undef FocusIn |
8 #undef FocusOut | 8 #undef FocusOut |
9 #undef RootWindow | 9 #undef RootWindow |
10 #include <map> | 10 #include <map> |
11 | 11 |
12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "chrome/browser/profiles/profile_manager.h" | |
20 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
21 #include "ui/aura/window_tree_host.h" | 22 #include "ui/aura/window_tree_host.h" |
22 #include "ui/base/ime/candidate_window.h" | 23 #include "ui/base/ime/candidate_window.h" |
23 #include "ui/base/ime/chromeos/component_extension_ime_manager.h" | 24 #include "ui/base/ime/chromeos/component_extension_ime_manager.h" |
24 #include "ui/base/ime/chromeos/composition_text.h" | 25 #include "ui/base/ime/chromeos/composition_text.h" |
25 #include "ui/base/ime/chromeos/extension_ime_util.h" | 26 #include "ui/base/ime/chromeos/extension_ime_util.h" |
26 #include "ui/base/ime/chromeos/ime_keymap.h" | 27 #include "ui/base/ime/chromeos/ime_keymap.h" |
27 #include "ui/base/ime/chromeos/input_method_manager.h" | 28 #include "ui/base/ime/chromeos/input_method_manager.h" |
28 #include "ui/base/ime/text_input_flags.h" | 29 #include "ui/base/ime/text_input_flags.h" |
29 #include "ui/chromeos/ime/input_method_menu_item.h" | 30 #include "ui/chromeos/ime/input_method_menu_item.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 } // namespace | 156 } // namespace |
156 | 157 |
157 InputMethodEngine::InputMethodEngine() | 158 InputMethodEngine::InputMethodEngine() |
158 : current_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 159 : current_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
159 context_id_(0), | 160 context_id_(0), |
160 next_context_id_(1), | 161 next_context_id_(1), |
161 composition_text_(new CompositionText()), | 162 composition_text_(new CompositionText()), |
162 composition_cursor_(0), | 163 composition_cursor_(0), |
163 candidate_window_(new ui::CandidateWindow()), | 164 candidate_window_(new ui::CandidateWindow()), |
164 window_visible_(false), | 165 window_visible_(false), |
165 sent_key_event_(NULL) { | 166 sent_key_event_(NULL), |
167 profile_(NULL) { | |
166 } | 168 } |
167 | 169 |
168 InputMethodEngine::~InputMethodEngine() { | 170 InputMethodEngine::~InputMethodEngine() { |
169 } | 171 } |
170 | 172 |
171 void InputMethodEngine::Initialize( | 173 void InputMethodEngine::Initialize( |
172 scoped_ptr<InputMethodEngineInterface::Observer> observer, | 174 scoped_ptr<InputMethodEngineInterface::Observer> observer, |
173 const char* extension_id) { | 175 const char* extension_id, |
176 Profile* profile) { | |
174 DCHECK(observer) << "Observer must not be null."; | 177 DCHECK(observer) << "Observer must not be null."; |
175 | 178 |
176 // TODO(komatsu): It is probably better to set observer out of Initialize. | 179 // TODO(komatsu): It is probably better to set observer out of Initialize. |
177 observer_ = observer.Pass(); | 180 observer_ = observer.Pass(); |
178 extension_id_ = extension_id; | 181 extension_id_ = extension_id; |
182 profile_ = profile; | |
179 } | 183 } |
180 | 184 |
181 const std::string& InputMethodEngine::GetActiveComponentId() const { | 185 const std::string& InputMethodEngine::GetActiveComponentId() const { |
182 return active_component_id_; | 186 return active_component_id_; |
183 } | 187 } |
184 | 188 |
185 bool InputMethodEngine::SetComposition( | 189 bool InputMethodEngine::SetComposition( |
186 int context_id, | 190 int context_id, |
187 const char* text, | 191 const char* text, |
188 int selection_start, | 192 int selection_start, |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
494 keyboard::KeyboardController* keyboard_controller = | 498 keyboard::KeyboardController* keyboard_controller = |
495 keyboard::KeyboardController::GetInstance(); | 499 keyboard::KeyboardController::GetInstance(); |
496 if (keyboard_controller) { | 500 if (keyboard_controller) { |
497 keyboard_controller->HideKeyboard( | 501 keyboard_controller->HideKeyboard( |
498 keyboard::KeyboardController::HIDE_REASON_MANUAL); | 502 keyboard::KeyboardController::HIDE_REASON_MANUAL); |
499 } | 503 } |
500 } | 504 } |
501 | 505 |
502 void InputMethodEngine::SetCompositionBounds( | 506 void InputMethodEngine::SetCompositionBounds( |
503 const std::vector<gfx::Rect>& bounds) { | 507 const std::vector<gfx::Rect>& bounds) { |
508 if (!CheckProfile()) | |
Alexander Alekseev
2015/05/13 17:50:38
This might be tricky, as we've seen delayed events
Shu Chen
2015/05/14 04:53:05
Theoretically CheckProfile() here should always re
| |
509 return; | |
504 observer_->OnCompositionBoundsChanged(bounds); | 510 observer_->OnCompositionBoundsChanged(bounds); |
505 } | 511 } |
506 | 512 |
507 void InputMethodEngine::EnableInputView() { | 513 void InputMethodEngine::EnableInputView() { |
508 keyboard::SetOverrideContentUrl(input_method::InputMethodManager::Get() | 514 keyboard::SetOverrideContentUrl(input_method::InputMethodManager::Get() |
509 ->GetActiveIMEState() | 515 ->GetActiveIMEState() |
510 ->GetCurrentInputMethod() | 516 ->GetCurrentInputMethod() |
511 .input_view_url()); | 517 .input_view_url()); |
512 keyboard::KeyboardController* keyboard_controller = | 518 keyboard::KeyboardController* keyboard_controller = |
513 keyboard::KeyboardController::GetInstance(); | 519 keyboard::KeyboardController::GetInstance(); |
514 if (keyboard_controller) | 520 if (keyboard_controller) |
515 keyboard_controller->Reload(); | 521 keyboard_controller->Reload(); |
516 } | 522 } |
517 | 523 |
518 void InputMethodEngine::FocusIn( | 524 void InputMethodEngine::FocusIn( |
519 const IMEEngineHandlerInterface::InputContext& input_context) { | 525 const IMEEngineHandlerInterface::InputContext& input_context) { |
526 if (!CheckProfile()) | |
527 return; | |
520 current_input_type_ = input_context.type; | 528 current_input_type_ = input_context.type; |
521 | 529 |
522 if (!IsActive() || current_input_type_ == ui::TEXT_INPUT_TYPE_NONE) | 530 if (!IsActive() || current_input_type_ == ui::TEXT_INPUT_TYPE_NONE) |
523 return; | 531 return; |
524 | 532 |
525 context_id_ = next_context_id_; | 533 context_id_ = next_context_id_; |
526 ++next_context_id_; | 534 ++next_context_id_; |
527 | 535 |
528 InputMethodEngineInterface::InputContext context; | 536 InputMethodEngineInterface::InputContext context; |
529 context.id = context_id_; | 537 context.id = context_id_; |
(...skipping 25 matching lines...) Expand all Loading... | |
555 !(input_context.flags & ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF); | 563 !(input_context.flags & ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF); |
556 context.auto_complete = | 564 context.auto_complete = |
557 !(input_context.flags & ui::TEXT_INPUT_FLAG_AUTOCOMPLETE_OFF); | 565 !(input_context.flags & ui::TEXT_INPUT_FLAG_AUTOCOMPLETE_OFF); |
558 context.spell_check = | 566 context.spell_check = |
559 !(input_context.flags & ui::TEXT_INPUT_FLAG_SPELLCHECK_OFF); | 567 !(input_context.flags & ui::TEXT_INPUT_FLAG_SPELLCHECK_OFF); |
560 | 568 |
561 observer_->OnFocus(context); | 569 observer_->OnFocus(context); |
562 } | 570 } |
563 | 571 |
564 void InputMethodEngine::FocusOut() { | 572 void InputMethodEngine::FocusOut() { |
573 if (!CheckProfile()) | |
574 return; | |
565 if (!IsActive() || current_input_type_ == ui::TEXT_INPUT_TYPE_NONE) | 575 if (!IsActive() || current_input_type_ == ui::TEXT_INPUT_TYPE_NONE) |
566 return; | 576 return; |
567 | 577 |
568 current_input_type_ = ui::TEXT_INPUT_TYPE_NONE; | 578 current_input_type_ = ui::TEXT_INPUT_TYPE_NONE; |
569 | 579 |
570 int context_id = context_id_; | 580 int context_id = context_id_; |
571 context_id_ = -1; | 581 context_id_ = -1; |
572 observer_->OnBlur(context_id); | 582 observer_->OnBlur(context_id); |
573 } | 583 } |
574 | 584 |
575 void InputMethodEngine::Enable(const std::string& component_id) { | 585 void InputMethodEngine::Enable(const std::string& component_id) { |
586 if (!CheckProfile()) | |
587 return; | |
576 DCHECK(!component_id.empty()); | 588 DCHECK(!component_id.empty()); |
577 active_component_id_ = component_id; | 589 active_component_id_ = component_id; |
578 observer_->OnActivate(component_id); | 590 observer_->OnActivate(component_id); |
579 const IMEEngineHandlerInterface::InputContext& input_context = | 591 const IMEEngineHandlerInterface::InputContext& input_context = |
580 IMEBridge::Get()->GetCurrentInputContext(); | 592 IMEBridge::Get()->GetCurrentInputContext(); |
581 current_input_type_ = input_context.type; | 593 current_input_type_ = input_context.type; |
582 FocusIn(input_context); | 594 FocusIn(input_context); |
583 EnableInputView(); | 595 EnableInputView(); |
584 } | 596 } |
585 | 597 |
586 void InputMethodEngine::Disable() { | 598 void InputMethodEngine::Disable() { |
599 if (!CheckProfile()) | |
600 return; | |
587 active_component_id_.clear(); | 601 active_component_id_.clear(); |
588 observer_->OnDeactivated(active_component_id_); | 602 observer_->OnDeactivated(active_component_id_); |
589 } | 603 } |
590 | 604 |
591 void InputMethodEngine::PropertyActivate(const std::string& property_name) { | 605 void InputMethodEngine::PropertyActivate(const std::string& property_name) { |
606 if (!CheckProfile()) | |
607 return; | |
592 observer_->OnMenuItemActivated(active_component_id_, property_name); | 608 observer_->OnMenuItemActivated(active_component_id_, property_name); |
593 } | 609 } |
594 | 610 |
595 void InputMethodEngine::Reset() { | 611 void InputMethodEngine::Reset() { |
612 if (!CheckProfile()) | |
613 return; | |
596 observer_->OnReset(active_component_id_); | 614 observer_->OnReset(active_component_id_); |
597 } | 615 } |
598 | 616 |
599 bool InputMethodEngine::IsInterestedInKeyEvent() const { | 617 bool InputMethodEngine::IsInterestedInKeyEvent() const { |
600 return observer_->IsInterestedInKeyEvent(); | 618 return observer_->IsInterestedInKeyEvent(); |
601 } | 619 } |
602 | 620 |
603 void InputMethodEngine::ProcessKeyEvent( | 621 void InputMethodEngine::ProcessKeyEvent( |
604 const ui::KeyEvent& key_event, | 622 const ui::KeyEvent& key_event, |
605 const KeyEventDoneCallback& callback) { | 623 const KeyEventDoneCallback& callback) { |
624 if (!CheckProfile()) | |
625 return; | |
606 | 626 |
607 KeyEventDoneCallback* handler = new KeyEventDoneCallback(); | 627 KeyEventDoneCallback* handler = new KeyEventDoneCallback(); |
608 *handler = callback; | 628 *handler = callback; |
609 | 629 |
610 KeyboardEvent ext_event; | 630 KeyboardEvent ext_event; |
611 GetExtensionKeyboardEventFromKeyEvent(key_event, &ext_event); | 631 GetExtensionKeyboardEventFromKeyEvent(key_event, &ext_event); |
612 | 632 |
613 // If the given key event is equal to the key event sent by | 633 // If the given key event is equal to the key event sent by |
614 // SendKeyEvents, this engine ID is propagated to the extension IME. | 634 // SendKeyEvents, this engine ID is propagated to the extension IME. |
615 // Note, this check relies on that ui::KeyEvent is propagated as | 635 // Note, this check relies on that ui::KeyEvent is propagated as |
616 // reference without copying. | 636 // reference without copying. |
617 if (&key_event == sent_key_event_) | 637 if (&key_event == sent_key_event_) |
618 ext_event.extension_id = extension_id_; | 638 ext_event.extension_id = extension_id_; |
619 | 639 |
620 observer_->OnKeyEvent( | 640 observer_->OnKeyEvent( |
621 active_component_id_, | 641 active_component_id_, |
622 ext_event, | 642 ext_event, |
623 reinterpret_cast<input_method::KeyEventHandle*>(handler)); | 643 reinterpret_cast<input_method::KeyEventHandle*>(handler)); |
624 } | 644 } |
625 | 645 |
626 void InputMethodEngine::CandidateClicked(uint32 index) { | 646 void InputMethodEngine::CandidateClicked(uint32 index) { |
647 if (!CheckProfile()) | |
648 return; | |
627 if (index > candidate_ids_.size()) { | 649 if (index > candidate_ids_.size()) { |
628 return; | 650 return; |
629 } | 651 } |
630 | 652 |
631 // Only left button click is supported at this moment. | 653 // Only left button click is supported at this moment. |
632 observer_->OnCandidateClicked( | 654 observer_->OnCandidateClicked( |
633 active_component_id_, candidate_ids_.at(index), MOUSE_BUTTON_LEFT); | 655 active_component_id_, candidate_ids_.at(index), MOUSE_BUTTON_LEFT); |
634 } | 656 } |
635 | 657 |
636 void InputMethodEngine::SetSurroundingText(const std::string& text, | 658 void InputMethodEngine::SetSurroundingText(const std::string& text, |
637 uint32 cursor_pos, | 659 uint32 cursor_pos, |
638 uint32 anchor_pos) { | 660 uint32 anchor_pos) { |
661 if (!CheckProfile()) | |
662 return; | |
639 observer_->OnSurroundingTextChanged(active_component_id_, | 663 observer_->OnSurroundingTextChanged(active_component_id_, |
640 text, | 664 text, |
641 static_cast<int>(cursor_pos), | 665 static_cast<int>(cursor_pos), |
642 static_cast<int>(anchor_pos)); | 666 static_cast<int>(anchor_pos)); |
643 } | 667 } |
644 | 668 |
669 bool InputMethodEngine::CheckProfile() const { | |
670 Profile* active_profile = ProfileManager::GetActiveUserProfile(); | |
671 return active_profile == profile_ || profile_->IsSameProfile(active_profile); | |
672 } | |
673 | |
645 // TODO(uekawa): rename this method to a more reasonable name. | 674 // TODO(uekawa): rename this method to a more reasonable name. |
646 void InputMethodEngine::MenuItemToProperty( | 675 void InputMethodEngine::MenuItemToProperty( |
647 const MenuItem& item, | 676 const MenuItem& item, |
648 ui::ime::InputMethodMenuItem* property) { | 677 ui::ime::InputMethodMenuItem* property) { |
649 property->key = item.id; | 678 property->key = item.id; |
650 | 679 |
651 if (item.modified & MENU_ITEM_MODIFIED_LABEL) { | 680 if (item.modified & MENU_ITEM_MODIFIED_LABEL) { |
652 property->label = item.label; | 681 property->label = item.label; |
653 } | 682 } |
654 if (item.modified & MENU_ITEM_MODIFIED_VISIBLE) { | 683 if (item.modified & MENU_ITEM_MODIFIED_VISIBLE) { |
(...skipping 23 matching lines...) Expand all Loading... | |
678 // TODO(nona): Implement it. | 707 // TODO(nona): Implement it. |
679 break; | 708 break; |
680 } | 709 } |
681 } | 710 } |
682 } | 711 } |
683 | 712 |
684 // TODO(nona): Support item.children. | 713 // TODO(nona): Support item.children. |
685 } | 714 } |
686 | 715 |
687 } // namespace chromeos | 716 } // namespace chromeos |
OLD | NEW |