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.
5 #include "ui/base/ime/input_method_initializer.h"
7 #include "ui/base/ime/input_method_factory.h"
9 #if defined(OS_CHROMEOS)
10 #include "base/logging.h"
11 #include "chromeos/dbus/dbus_thread_manager.h"
12 #include "ui/base/ime/chromeos/ibus_bridge.h"
13 #elif defined(USE_AURA) && defined(USE_X11)
14 #include "base/memory/scoped_ptr.h"
15 #include "ui/base/ime/input_method_auralinux.h"
16 #include "ui/base/ime/linux/fake_input_method_context_factory.h"
18 #include "base/win/metro.h"
19 #include "ui/base/ime/win/tsf_bridge.h"
24 #if defined(OS_CHROMEOS)
25 bool dbus_thread_manager_was_initialized
= false;
26 #elif defined(USE_AURA) && defined(USE_X11)
27 const ui::LinuxInputMethodContextFactory
* g_linux_input_method_context_factory
;
34 void InitializeInputMethod() {
35 #if defined(OS_CHROMEOS)
36 chromeos::IBusBridge::Initialize();
37 #elif defined(USE_AURA) && defined(USE_X11)
38 InputMethodAuraLinux::Initialize();
40 if (base::win::IsTSFAwareRequired())
41 TSFBridge::Initialize();
45 void ShutdownInputMethod() {
46 #if defined(OS_CHROMEOS)
47 chromeos::IBusBridge::Shutdown();
49 internal::DestroySharedInputMethod();
50 if (base::win::IsTSFAwareRequired())
51 TSFBridge::Shutdown();
55 void InitializeInputMethodForTesting() {
56 #if defined(OS_CHROMEOS)
57 chromeos::IBusBridge::Initialize();
58 // TODO(nona): Remove DBusThreadManager initialize.
59 if (!chromeos::DBusThreadManager::IsInitialized()) {
60 chromeos::DBusThreadManager::InitializeWithStub();
61 dbus_thread_manager_was_initialized
= true;
63 #elif defined(USE_AURA) && defined(USE_X11)
64 if (!g_linux_input_method_context_factory
)
65 g_linux_input_method_context_factory
= new FakeInputMethodContextFactory();
66 const LinuxInputMethodContextFactory
* factory
=
67 LinuxInputMethodContextFactory::instance();
68 CHECK(!factory
|| factory
== g_linux_input_method_context_factory
)
69 << "LinuxInputMethodContextFactory was already initialized somewhere "
71 LinuxInputMethodContextFactory::SetInstance(
72 g_linux_input_method_context_factory
);
74 if (base::win::IsTSFAwareRequired()) {
75 // Make sure COM is initialized because TSF depends on COM.
77 TSFBridge::Initialize();
82 void ShutdownInputMethodForTesting() {
83 #if defined(OS_CHROMEOS)
84 chromeos::IBusBridge::Shutdown();
85 // TODO(nona): Remove DBusThreadManager finalize.
86 if (dbus_thread_manager_was_initialized
) {
87 chromeos::DBusThreadManager::Shutdown();
88 dbus_thread_manager_was_initialized
= false;
90 ui::InputMethodFactory::SetInstance(NULL
);
91 #elif defined(USE_AURA) && defined(USE_X11)
92 const LinuxInputMethodContextFactory
* factory
=
93 LinuxInputMethodContextFactory::instance();
94 CHECK(!factory
|| factory
== g_linux_input_method_context_factory
)
95 << "An unknown LinuxInputMethodContextFactory was set.";
96 LinuxInputMethodContextFactory::SetInstance(NULL
);
97 delete g_linux_input_method_context_factory
;
98 g_linux_input_method_context_factory
= NULL
;
100 internal::DestroySharedInputMethod();
101 if (base::win::IsTSFAwareRequired()) {
102 TSFBridge::Shutdown();