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

Side by Side Diff: chrome/browser/chromeos/input_method/input_method_manager_impl.cc

Issue 389913002: Moving IME manifests to chrome resources. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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 (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/chromeos/input_method/input_method_manager_impl.h" 5 #include "chrome/browser/chromeos/input_method/input_method_manager_impl.h"
6 6
7 #include <algorithm> // std::find 7 #include <algorithm> // std::find
8 8
9 #include "ash/ime/input_method_menu_item.h" 9 #include "ash/ime/input_method_menu_item.h"
10 #include "ash/ime/input_method_menu_manager.h" 10 #include "ash/ime/input_method_menu_manager.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 bool InputMethodManagerImpl::MigrateInputMethods( 54 bool InputMethodManagerImpl::MigrateInputMethods(
55 std::vector<std::string>* input_method_ids) { 55 std::vector<std::string>* input_method_ids) {
56 return util_.MigrateInputMethods(input_method_ids); 56 return util_.MigrateInputMethods(input_method_ids);
57 } 57 }
58 58
59 InputMethodManagerImpl::InputMethodManagerImpl( 59 InputMethodManagerImpl::InputMethodManagerImpl(
60 scoped_ptr<InputMethodDelegate> delegate) 60 scoped_ptr<InputMethodDelegate> delegate)
61 : delegate_(delegate.Pass()), 61 : delegate_(delegate.Pass()),
62 state_(STATE_LOGIN_SCREEN), 62 state_(STATE_LOGIN_SCREEN),
63 util_(delegate_.get(), whitelist_.GetSupportedInputMethods()), 63 util_(delegate_.get()),
64 component_extension_ime_manager_(new ComponentExtensionIMEManager()), 64 component_extension_ime_manager_(new ComponentExtensionIMEManager()),
65 weak_ptr_factory_(this) { 65 weak_ptr_factory_(this) {
66 if (base::SysInfo::IsRunningOnChromeOS())
67 keyboard_.reset(ImeKeyboard::Create());
68 else
69 keyboard_.reset(new FakeImeKeyboard());
66 } 70 }
67 71
68 InputMethodManagerImpl::~InputMethodManagerImpl() { 72 InputMethodManagerImpl::~InputMethodManagerImpl() {
69 if (candidate_window_controller_.get()) 73 if (candidate_window_controller_.get())
70 candidate_window_controller_->RemoveObserver(this); 74 candidate_window_controller_->RemoveObserver(this);
71 } 75 }
72 76
73 void InputMethodManagerImpl::AddObserver( 77 void InputMethodManagerImpl::AddObserver(
74 InputMethodManager::Observer* observer) { 78 InputMethodManager::Observer* observer) {
75 observers_.AddObserver(observer); 79 observers_.AddObserver(observer);
(...skipping 30 matching lines...) Expand all
106 case STATE_TERMINATING: { 110 case STATE_TERMINATING: {
107 if (candidate_window_controller_.get()) 111 if (candidate_window_controller_.get())
108 candidate_window_controller_.reset(); 112 candidate_window_controller_.reset();
109 break; 113 break;
110 } 114 }
111 } 115 }
112 } 116 }
113 117
114 scoped_ptr<InputMethodDescriptors> 118 scoped_ptr<InputMethodDescriptors>
115 InputMethodManagerImpl::GetSupportedInputMethods() const { 119 InputMethodManagerImpl::GetSupportedInputMethods() const {
116 if (!IsXkbComponentExtensionAvailable())
117 return whitelist_.GetSupportedInputMethods().Pass();
118 return scoped_ptr<InputMethodDescriptors>(new InputMethodDescriptors).Pass(); 120 return scoped_ptr<InputMethodDescriptors>(new InputMethodDescriptors).Pass();
119 } 121 }
120 122
121 scoped_ptr<InputMethodDescriptors> 123 scoped_ptr<InputMethodDescriptors>
122 InputMethodManagerImpl::GetActiveInputMethods() const { 124 InputMethodManagerImpl::GetActiveInputMethods() const {
123 scoped_ptr<InputMethodDescriptors> result(new InputMethodDescriptors); 125 scoped_ptr<InputMethodDescriptors> result(new InputMethodDescriptors);
124 // Build the active input method descriptors from the active input 126 // Build the active input method descriptors from the active input
125 // methods cache |active_input_method_ids_|. 127 // methods cache |active_input_method_ids_|.
126 for (size_t i = 0; i < active_input_method_ids_.size(); ++i) { 128 for (size_t i = 0; i < active_input_method_ids_.size(); ++i) {
127 const std::string& input_method_id = active_input_method_ids_[i]; 129 const std::string& input_method_id = active_input_method_ids_[i];
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 scoped_ptr<InputMethodDescriptors> input_methods(GetActiveInputMethods()); 320 scoped_ptr<InputMethodDescriptors> input_methods(GetActiveInputMethods());
319 DCHECK(!input_methods->empty()); 321 DCHECK(!input_methods->empty());
320 input_method_id_to_switch = input_methods->at(0).id(); 322 input_method_id_to_switch = input_methods->at(0).id();
321 if (!input_method_id.empty()) { 323 if (!input_method_id.empty()) {
322 DVLOG(1) << "Can't change the current input method to " 324 DVLOG(1) << "Can't change the current input method to "
323 << input_method_id << " since the engine is not enabled. " 325 << input_method_id << " since the engine is not enabled. "
324 << "Switch to " << input_method_id_to_switch << " instead."; 326 << "Switch to " << input_method_id_to_switch << " instead.";
325 } 327 }
326 } 328 }
327 329
328 if (!component_extension_ime_manager_->IsInitialized() &&
329 !InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch)) {
330 // We can't change input method before the initialization of
331 // component extension ime manager. ChangeInputMethod will be
332 // called with |pending_input_method_| when the initialization is
333 // done.
334 pending_input_method_ = input_method_id_to_switch;
335 return false;
336 }
337 pending_input_method_.clear();
338
339 // Hide candidate window and info list. 330 // Hide candidate window and info list.
340 if (candidate_window_controller_.get()) 331 if (candidate_window_controller_.get())
341 candidate_window_controller_->Hide(); 332 candidate_window_controller_->Hide();
342 333
343 // Disable the current engine handler. 334 // Disable the current engine handler.
344 IMEEngineHandlerInterface* engine = 335 IMEEngineHandlerInterface* engine =
345 IMEBridge::Get()->GetCurrentEngineHandler(); 336 IMEBridge::Get()->GetCurrentEngineHandler();
346 if (engine) 337 if (engine)
347 engine->Disable(); 338 engine->Disable();
348 339
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 << current_input_method_.GetPreferredKeyboardLayout(); 388 << current_input_method_.GetPreferredKeyboardLayout();
398 } 389 }
399 390
400 // Update input method indicators (e.g. "US", "DV") in Chrome windows. 391 // Update input method indicators (e.g. "US", "DV") in Chrome windows.
401 FOR_EACH_OBSERVER(InputMethodManager::Observer, 392 FOR_EACH_OBSERVER(InputMethodManager::Observer,
402 observers_, 393 observers_,
403 InputMethodChanged(this, show_message)); 394 InputMethodChanged(this, show_message));
404 return true; 395 return true;
405 } 396 }
406 397
407 bool InputMethodManagerImpl::IsXkbComponentExtensionAvailable() const {
408 if (!component_extension_ime_manager_->IsInitialized())
409 return false;
410 InputMethodDescriptors imes =
411 component_extension_ime_manager_->GetAllIMEAsInputMethodDescriptor();
412 for (size_t i = 0; i < imes.size(); ++i) {
413 if (StartsWithASCII(extension_ime_util::MaybeGetLegacyXkbId(
414 imes[i].id()), "xkb:", true))
415 return true;
416 }
417 return false;
418 }
419
420 void InputMethodManagerImpl::OnComponentExtensionInitialized( 398 void InputMethodManagerImpl::OnComponentExtensionInitialized(
421 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate) { 399 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate) {
422 DCHECK(thread_checker_.CalledOnValidThread()); 400 DCHECK(thread_checker_.CalledOnValidThread());
423 component_extension_ime_manager_->Initialize(delegate.Pass()); 401 component_extension_ime_manager_->Initialize(delegate.Pass());
424 InputMethodDescriptors imes = 402
425 component_extension_ime_manager_->GetAllIMEAsInputMethodDescriptor(); 403 util_.ResetInputMethods(
426 // In case of XKB extension is not available (e.g. linux_chromeos), don't 404 component_extension_ime_manager_->GetAllIMEAsInputMethodDescriptor());
427 // reset the input methods in InputMethodUtil, Instead append input methods.
428 if (IsXkbComponentExtensionAvailable())
429 util_.ResetInputMethods(imes);
430 else
431 util_.AppendInputMethods(imes);
432 405
433 LoadNecessaryComponentExtensions(); 406 LoadNecessaryComponentExtensions();
434
435 if (!pending_input_method_.empty())
436 ChangeInputMethodInternal(pending_input_method_, false);
437 } 407 }
438 408
439 void InputMethodManagerImpl::LoadNecessaryComponentExtensions() { 409 void InputMethodManagerImpl::LoadNecessaryComponentExtensions() {
440 if (!component_extension_ime_manager_->IsInitialized())
441 return;
442 // Load component extensions but also update |active_input_method_ids_| as 410 // Load component extensions but also update |active_input_method_ids_| as
443 // some component extension IMEs may have been removed from the Chrome OS 411 // some component extension IMEs may have been removed from the Chrome OS
444 // image. If specified component extension IME no longer exists, falling back 412 // image. If specified component extension IME no longer exists, falling back
445 // to an existing IME. 413 // to an existing IME.
446 std::vector<std::string> unfiltered_input_method_ids; 414 std::vector<std::string> unfiltered_input_method_ids;
447 unfiltered_input_method_ids.swap(active_input_method_ids_); 415 unfiltered_input_method_ids.swap(active_input_method_ids_);
448 for (size_t i = 0; i < unfiltered_input_method_ids.size(); ++i) { 416 for (size_t i = 0; i < unfiltered_input_method_ids.size(); ++i) {
449 if (!extension_ime_util::IsComponentExtensionIME( 417 if (!extension_ime_util::IsComponentExtensionIME(
450 unfiltered_input_method_ids[i])) { 418 unfiltered_input_method_ids[i])) {
451 // Legacy IMEs or xkb layouts are alwayes active. 419 // Legacy IMEs or xkb layouts are alwayes active.
452 active_input_method_ids_.push_back(unfiltered_input_method_ids[i]); 420 active_input_method_ids_.push_back(unfiltered_input_method_ids[i]);
453 } else if (component_extension_ime_manager_->IsWhitelisted( 421 } else if (component_extension_ime_manager_->IsWhitelisted(
454 unfiltered_input_method_ids[i])) { 422 unfiltered_input_method_ids[i])) {
455 component_extension_ime_manager_->LoadComponentExtensionIME( 423 component_extension_ime_manager_->LoadComponentExtensionIME(
456 unfiltered_input_method_ids[i]); 424 unfiltered_input_method_ids[i]);
457 active_input_method_ids_.push_back(unfiltered_input_method_ids[i]); 425 active_input_method_ids_.push_back(unfiltered_input_method_ids[i]);
458 } 426 }
459 } 427 }
460 // TODO(shuchen): move this call in ComponentExtensionIMEManager.
461 component_extension_ime_manager_->NotifyInitialized();
462 } 428 }
463 429
464 void InputMethodManagerImpl::ActivateInputMethodMenuItem( 430 void InputMethodManagerImpl::ActivateInputMethodMenuItem(
465 const std::string& key) { 431 const std::string& key) {
466 DCHECK(!key.empty()); 432 DCHECK(!key.empty());
467 433
468 if (ash::ime::InputMethodMenuManager::GetInstance()-> 434 if (ash::ime::InputMethodMenuManager::GetInstance()->
469 HasInputMethodMenuItemForKey(key)) { 435 HasInputMethodMenuItemForKey(key)) {
470 IMEEngineHandlerInterface* engine = 436 IMEEngineHandlerInterface* engine =
471 IMEBridge::Get()->GetCurrentEngineHandler(); 437 IMEBridge::Get()->GetCurrentEngineHandler();
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 return &util_; 766 return &util_;
801 } 767 }
802 768
803 ComponentExtensionIMEManager* 769 ComponentExtensionIMEManager*
804 InputMethodManagerImpl::GetComponentExtensionIMEManager() { 770 InputMethodManagerImpl::GetComponentExtensionIMEManager() {
805 DCHECK(thread_checker_.CalledOnValidThread()); 771 DCHECK(thread_checker_.CalledOnValidThread());
806 return component_extension_ime_manager_.get(); 772 return component_extension_ime_manager_.get();
807 } 773 }
808 774
809 void InputMethodManagerImpl::InitializeComponentExtension() { 775 void InputMethodManagerImpl::InitializeComponentExtension() {
810 ComponentExtensionIMEManagerImpl* impl = 776 active_input_method_ids_.push_back(
811 new ComponentExtensionIMEManagerImpl(); 777 InputMethodUtil::GetFallbackInputMethodDescriptor().id());
812 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate(impl); 778 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate(
813 impl->InitializeAsync(base::Bind( 779 new ComponentExtensionIMEManagerImpl());
814 &InputMethodManagerImpl::OnComponentExtensionInitialized, 780 OnComponentExtensionInitialized(delegate.Pass());
815 weak_ptr_factory_.GetWeakPtr(),
816 base::Passed(&delegate)));
817 }
818
819 void InputMethodManagerImpl::Init(base::SequencedTaskRunner* ui_task_runner) {
820 DCHECK(thread_checker_.CalledOnValidThread());
821
822 if (base::SysInfo::IsRunningOnChromeOS())
823 keyboard_.reset(ImeKeyboard::Create());
824 else
825 keyboard_.reset(new FakeImeKeyboard());
826
827 // We can't call impl->Initialize here, because file thread is not available
828 // at this moment.
829 ui_task_runner->PostTask(
830 FROM_HERE,
831 base::Bind(&InputMethodManagerImpl::InitializeComponentExtension,
832 weak_ptr_factory_.GetWeakPtr()));
833 } 781 }
834 782
835 void InputMethodManagerImpl::SetCandidateWindowControllerForTesting( 783 void InputMethodManagerImpl::SetCandidateWindowControllerForTesting(
836 CandidateWindowController* candidate_window_controller) { 784 CandidateWindowController* candidate_window_controller) {
837 candidate_window_controller_.reset(candidate_window_controller); 785 candidate_window_controller_.reset(candidate_window_controller);
838 candidate_window_controller_->AddObserver(this); 786 candidate_window_controller_->AddObserver(this);
839 } 787 }
840 788
841 void InputMethodManagerImpl::SetImeKeyboardForTesting(ImeKeyboard* keyboard) { 789 void InputMethodManagerImpl::SetImeKeyboardForTesting(ImeKeyboard* keyboard) {
842 keyboard_.reset(keyboard); 790 keyboard_.reset(keyboard);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 CandidateWindowController::CreateCandidateWindowController()); 870 CandidateWindowController::CreateCandidateWindowController());
923 candidate_window_controller_->AddObserver(this); 871 candidate_window_controller_->AddObserver(this);
924 } 872 }
925 873
926 Profile* InputMethodManagerImpl::GetProfile() const { 874 Profile* InputMethodManagerImpl::GetProfile() const {
927 return ProfileManager::GetActiveUserProfile(); 875 return ProfileManager::GetActiveUserProfile();
928 } 876 }
929 877
930 } // namespace input_method 878 } // namespace input_method
931 } // namespace chromeos 879 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698