Skip to content

Commit

Permalink
[ozone/x11/headless] Use FakeInputMethodContextFactory to avoid crash…
Browse files Browse the repository at this point in the history
…ing.

That is, after we've added ime imeplementation for Wayland, other
ozone platforms started to crash. To avoid this, use fake factory.

fixup! [ozone/x11/headless] Use FakeInputMethodContextFactory to avoid crashing.

Added condition before setting LinuxInputMethodContextFactory.

fixup! [ozone/x11/headless] Use FakeInputMethodContextFactory to avoid crashing.

It needs to skip DCHEK at InitializeInputMethodForTesting() as
LinuxInputMethodContextFactory's already set at
OzonePlatform::InitializeUI().
  • Loading branch information
msisov committed Feb 25, 2019
1 parent e025836 commit a45ea77
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ui/base/ime/input_method_initializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ void InitializeInputMethodForTesting() {
if (!g_linux_input_method_context_factory_for_testing)
g_linux_input_method_context_factory_for_testing =
new FakeInputMethodContextFactory();
#if !defined(USE_OZONE)
const LinuxInputMethodContextFactory* factory =
LinuxInputMethodContextFactory::instance();
CHECK(!factory || factory == g_linux_input_method_context_factory_for_testing)
<< "LinuxInputMethodContextFactory was already initialized somewhere "
<< "else.";
#endif
LinuxInputMethodContextFactory::SetInstance(
g_linux_input_method_context_factory_for_testing);
#elif defined(OS_WIN)
Expand Down
1 change: 1 addition & 0 deletions ui/ozone/platform/headless/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ source_set("headless") {
"//base",
"//skia",
"//ui/base",
"//ui/base/ime",
"//ui/display/manager",
"//ui/events",
"//ui/events/ozone:events_ozone_layout",
Expand Down
9 changes: 9 additions & 0 deletions ui/ozone/platform/headless/ozone_platform_headless.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "base/files/file_path.h"
#include "base/macros.h"
#include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h"
#include "ui/base/ime/linux/fake_input_method_context_factory.h"
#include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
#include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h"
#include "ui/events/platform/platform_event_source.h"
Expand Down Expand Up @@ -90,6 +91,13 @@ class OzonePlatformHeadless : public OzonePlatform {
input_controller_ = CreateStubInputController();
cursor_factory_ozone_ = std::make_unique<BitmapCursorFactoryOzone>();
gpu_platform_support_host_.reset(CreateStubGpuPlatformSupportHost());

if (LinuxInputMethodContextFactory::instance())
return;
fake_input_method_factory_ =
std::make_unique<FakeInputMethodContextFactory>();
LinuxInputMethodContextFactory::SetInstance(
fake_input_method_factory_.get());
}

void InitializeGPU(const InitParams& params) override {
Expand All @@ -105,6 +113,7 @@ class OzonePlatformHeadless : public OzonePlatform {
std::unique_ptr<InputController> input_controller_;
std::unique_ptr<GpuPlatformSupportHost> gpu_platform_support_host_;
std::unique_ptr<OverlayManagerOzone> overlay_manager_;
std::unique_ptr<FakeInputMethodContextFactory> fake_input_method_factory_;
base::FilePath file_path_;

DISALLOW_COPY_AND_ASSIGN(OzonePlatformHeadless);
Expand Down
1 change: 1 addition & 0 deletions ui/ozone/platform/x11/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ source_set("x11") {
"//gpu/vulkan:buildflags",
"//skia",
"//ui/base",
"//ui/base/ime",
"//ui/base/x",
"//ui/display/manager",
"//ui/events",
Expand Down
1 change: 1 addition & 0 deletions ui/ozone/platform/x11/DEPS
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include_rules = [
"+ui/base/x",
"+ui/base/ime",
]
9 changes: 8 additions & 1 deletion ui/ozone/platform/x11/ozone_platform_x11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "base/message_loop/message_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/base/ime/linux/fake_input_method_context_factory.h"
#include "ui/base/x/x11_util.h"
#include "ui/display/manager/fake_display_delegate.h"
#include "ui/events/devices/x11/touch_factory_x11.h"
Expand Down Expand Up @@ -89,8 +90,13 @@ class OzonePlatformX11 : public OzonePlatform {
input_controller_ = CreateStubInputController();
cursor_factory_ozone_ = std::make_unique<X11CursorFactoryOzone>();
gpu_platform_support_host_.reset(CreateStubGpuPlatformSupportHost());

TouchFactory::SetTouchDeviceListFromCommandLine();

if (LinuxInputMethodContextFactory::instance())
return;
fake_input_method_factory_ =
std::make_unique<FakeInputMethodContextFactory>();
LinuxInputMethodContextFactory::SetInstance(fake_input_method_factory_.get());
}

void InitializeGPU(const InitParams& params) override {
Expand Down Expand Up @@ -147,6 +153,7 @@ class OzonePlatformX11 : public OzonePlatform {
std::unique_ptr<InputController> input_controller_;
std::unique_ptr<X11CursorFactoryOzone> cursor_factory_ozone_;
std::unique_ptr<GpuPlatformSupportHost> gpu_platform_support_host_;
std::unique_ptr<FakeInputMethodContextFactory> fake_input_method_factory_;

// Objects in the GPU process.
std::unique_ptr<X11SurfaceFactory> surface_factory_ozone_;
Expand Down

0 comments on commit a45ea77

Please sign in to comment.