Bug 1431049 - don't crash when keyboard is not present, based on patch by Takuro Ashie. r?jhorak draft
authorMartin Stransky <stransky@redhat.com>
Fri, 19 Jan 2018 10:08:48 +0100
changeset 737893 1509e4886e095e9ed64e5159c4ad0e32e8be225f
parent 722069 abbe0ca5d9693e06484fcb52bbcac189c3461f50
push id96798
push userstransky@redhat.com
push dateThu, 25 Jan 2018 11:23:48 +0000
reviewersjhorak
bugs1431049
milestone59.0a1
Bug 1431049 - don't crash when keyboard is not present, based on patch by Takuro Ashie. r?jhorak MozReview-Commit-ID: 4o7P8Dzui22
widget/gtk/nsClipboardWayland.cpp
--- a/widget/gtk/nsClipboardWayland.cpp
+++ b/widget/gtk/nsClipboardWayland.cpp
@@ -204,17 +204,17 @@ void
 nsRetrievalContextWayland::ConfigureKeyboard(wl_seat_capability caps)
 {
   // ConfigureKeyboard() is called when wl_seat configuration is changed.
   // We look for the keyboard only, get it when is't available and release it
   // when it's lost (we don't have focus for instance).
   if (caps & WL_SEAT_CAPABILITY_KEYBOARD) {
       mKeyboard = wl_seat_get_keyboard(mSeat);
       wl_keyboard_add_listener(mKeyboard, &keyboard_listener, this);
-  } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD)) {
+  } else if (mKeyboard && !(caps & WL_SEAT_CAPABILITY_KEYBOARD)) {
       wl_keyboard_destroy(mKeyboard);
       mKeyboard = nullptr;
   }
 }
 
 static void
 seat_handle_capabilities(void *data, struct wl_seat *seat,
                          unsigned int caps)
@@ -271,36 +271,42 @@ gdk_registry_handle_global_remove(void  
 }
 
 static const struct wl_registry_listener clipboard_registry_listener = {
     gdk_registry_handle_global,
     gdk_registry_handle_global_remove
 };
 
 nsRetrievalContextWayland::nsRetrievalContextWayland(void)
-  : mInitialized(false),
-    mDataDeviceManager(nullptr),
-    mDataOffer(nullptr)
+  : mInitialized(false)
+  , mSeat(nullptr)
+  , mDataDeviceManager(nullptr)
+  , mDataOffer(nullptr)
+  , mKeyboard(nullptr)
 {
     const gchar* charset;
     g_get_charset(&charset);
     mTextPlainLocale = g_strdup_printf("text/plain;charset=%s", charset);
 
     // Available as of GTK 3.8+
     static auto sGdkWaylandDisplayGetWlDisplay =
         (wl_display *(*)(GdkDisplay *))
         dlsym(RTLD_DEFAULT, "gdk_wayland_display_get_wl_display");
 
     mDisplay = sGdkWaylandDisplayGetWlDisplay(gdk_display_get_default());
     wl_registry_add_listener(wl_display_get_registry(mDisplay),
                              &clipboard_registry_listener, this);
+    // Call wl_display_roundtrip() twice to make sure all
+    // callbacks are processed.
     wl_display_roundtrip(mDisplay);
     wl_display_roundtrip(mDisplay);
 
-    // We don't have Wayland support here so just give up
+    // mSeat/mDataDeviceManager should be set now by
+    // gdk_registry_handle_global() as a response to
+    // wl_registry_add_listener() call.
     if (!mDataDeviceManager || !mSeat)
         return;
 
     wl_data_device *dataDevice =
         wl_data_device_manager_get_data_device(mDataDeviceManager, mSeat);
     wl_data_device_add_listener(dataDevice, &data_device_listener, this);
     // We have to call wl_display_roundtrip() twice otherwise data_offer_listener
     // may not be processed because it's called from data_device_data_offer