Bug 1417890 - Install nsClipboard hook at nsWindow init, r?jhorak
MozReview-Commit-ID: GA3USkXtEhe
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -123,16 +123,19 @@ using namespace mozilla::widget;
#ifdef MOZ_X11
#include "X11CompositorWidget.h"
#include "gfxXlibSurface.h"
#include "WindowSurfaceX11Image.h"
#include "WindowSurfaceX11SHM.h"
#include "WindowSurfaceXRender.h"
#endif // MOZ_X11
+#ifdef MOZ_WAYLAND
+#include "nsIClipboard.h"
+#endif
#include "nsShmImage.h"
#include "nsIDOMWheelEvent.h"
#include "NativeKeyBindings.h"
#include <dlfcn.h>
@@ -452,21 +455,33 @@ nsWindow::nsWindow()
#ifdef MOZ_X11
mOldFocusWindow = 0;
mXDisplay = nullptr;
mXWindow = X11None;
mXVisual = nullptr;
mXDepth = 0;
#endif /* MOZ_X11 */
+
if (!gGlobalsInitialized) {
gGlobalsInitialized = true;
// It's OK if either of these fail, but it may not be one day.
initialize_prefs();
+
+#ifdef MOZ_WAYLAND
+ // Wayland provides clipboard data to application on focus-in event
+ // so we need to init our clipboard hooks before we create window
+ // and get focus.
+ if (!mIsX11Display) {
+ nsCOMPtr<nsIClipboard> clipboard =
+ do_GetService("@mozilla.org/widget/clipboard;1");
+ NS_ASSERTION(clipboard, "Failed to init clipboard!");
+ }
+#endif
}
mLastMotionPressure = 0;
#ifdef ACCESSIBILITY
mRootAccessible = nullptr;
#endif