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 3 // found in the LICENSE file. 4 5 #include "ui/base/ime/input_method_initializer.h" 6 7 #if defined(TOOLKIT_VIEWS) || defined(USE_AURA) 8 #include "ui/base/ime/input_method_factory.h" 9 #endif 10 11 #if defined(OS_CHROMEOS) 12 #include "base/logging.h" 13 #include "chromeos/dbus/dbus_thread_manager.h" 14 #include "ui/base/ime/chromeos/ibus_bridge.h" 15 #elif defined(USE_AURA) && defined(USE_X11) 16 #include "ui/base/ime/input_method_auralinux.h" 17 #include "ui/base/ime/linux/fake_input_method_context_factory.h" 18 #elif defined(OS_WIN) 19 #include "base/win/metro.h" 20 #include "ui/base/ime/win/tsf_bridge.h" 21 #endif 22 23 namespace { 24 25 #if defined(OS_CHROMEOS) 26 bool dbus_thread_manager_was_initialized = false; 27 #elif defined(USE_AURA) && defined(USE_X11) 28 const ui::LinuxInputMethodContextFactory* g_linux_input_method_context_factory; 29 #endif 30 31 } // namespace 32 33 namespace ui { 34 InitializeInputMethod()35void InitializeInputMethod() { 36 #if defined(OS_CHROMEOS) 37 chromeos::IBusBridge::Initialize(); 38 #elif defined(USE_AURA) && defined(USE_X11) 39 InputMethodAuraLinux::Initialize(); 40 #elif defined(OS_WIN) 41 if (base::win::IsTSFAwareRequired()) 42 TSFBridge::Initialize(); 43 #endif 44 } 45 ShutdownInputMethod()46void ShutdownInputMethod() { 47 #if defined(TOOLKIT_VIEWS) || defined(USE_AURA) 48 InputMethodFactory::ClearInstance(); 49 #endif 50 #if defined(OS_CHROMEOS) 51 chromeos::IBusBridge::Shutdown(); 52 #elif defined(OS_WIN) 53 internal::DestroySharedInputMethod(); 54 if (base::win::IsTSFAwareRequired()) 55 TSFBridge::Shutdown(); 56 #endif 57 } 58 InitializeInputMethodForTesting()59void InitializeInputMethodForTesting() { 60 #if defined(OS_CHROMEOS) 61 chromeos::IBusBridge::Initialize(); 62 // TODO(nona): Remove DBusThreadManager initialize. 63 if (!chromeos::DBusThreadManager::IsInitialized()) { 64 chromeos::DBusThreadManager::InitializeWithStub(); 65 dbus_thread_manager_was_initialized = true; 66 } 67 #elif defined(USE_AURA) && defined(USE_X11) 68 if (!g_linux_input_method_context_factory) 69 g_linux_input_method_context_factory = new FakeInputMethodContextFactory(); 70 const LinuxInputMethodContextFactory* factory = 71 LinuxInputMethodContextFactory::instance(); 72 CHECK(!factory || factory == g_linux_input_method_context_factory) 73 << "LinuxInputMethodContextFactory was already initialized somewhere " 74 << "else."; 75 LinuxInputMethodContextFactory::SetInstance( 76 g_linux_input_method_context_factory); 77 #elif defined(OS_WIN) 78 if (base::win::IsTSFAwareRequired()) { 79 // Make sure COM is initialized because TSF depends on COM. 80 CoInitialize(NULL); 81 TSFBridge::Initialize(); 82 } 83 #endif 84 } 85 ShutdownInputMethodForTesting()86void ShutdownInputMethodForTesting() { 87 #if defined(TOOLKIT_VIEWS) || defined(USE_AURA) 88 InputMethodFactory::ClearInstance(); 89 #endif 90 #if defined(OS_CHROMEOS) 91 chromeos::IBusBridge::Shutdown(); 92 // TODO(nona): Remove DBusThreadManager finalize. 93 if (dbus_thread_manager_was_initialized) { 94 chromeos::DBusThreadManager::Shutdown(); 95 dbus_thread_manager_was_initialized = false; 96 } 97 #elif defined(USE_AURA) && defined(USE_X11) 98 const LinuxInputMethodContextFactory* factory = 99 LinuxInputMethodContextFactory::instance(); 100 CHECK(!factory || factory == g_linux_input_method_context_factory) 101 << "An unknown LinuxInputMethodContextFactory was set."; 102 LinuxInputMethodContextFactory::SetInstance(NULL); 103 delete g_linux_input_method_context_factory; 104 g_linux_input_method_context_factory = NULL; 105 #elif defined(OS_WIN) 106 internal::DestroySharedInputMethod(); 107 if (base::win::IsTSFAwareRequired()) { 108 TSFBridge::Shutdown(); 109 CoUninitialize(); 110 } 111 #endif 112 } 113 114 } // namespace ui 115