Bug 1504937 - Use DBus remote only when running on Wayland display, r=jhorak
authorMartin Stransky <stransky@redhat.com>
Tue, 06 Nov 2018 14:59:58 +0000
changeset 444744 2c5ec5ff0ec3
parent 444743 36bd1b75c561
child 444745 04a5b29e9c89
push id35001
push userncsoregi@mozilla.com
push dateWed, 07 Nov 2018 09:52:11 +0000
treeherdermozilla-central@bc83ec5a338d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjhorak
bugs1504937
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1504937 - Use DBus remote only when running on Wayland display, r=jhorak Differential Revision: https://phabricator.services.mozilla.com/D11004
toolkit/components/remote/nsRemoteService.cpp
toolkit/xre/nsAppRunner.cpp
widget/xremoteclient/DBusRemoteClient.cpp
widget/xremoteclient/moz.build
--- a/toolkit/components/remote/nsRemoteService.cpp
+++ b/toolkit/components/remote/nsRemoteService.cpp
@@ -28,27 +28,32 @@
 
 NS_IMPL_ISUPPORTS(nsRemoteService,
                   nsIRemoteService,
                   nsIObserver)
 
 NS_IMETHODIMP
 nsRemoteService::Startup(const char* aAppName, const char* aProfileName)
 {
-#if defined(MOZ_ENABLE_DBUS) && defined(MOZ_WAYLAND)
-    nsresult rv;
-    mDBusRemoteService = new nsDBusRemoteService();
-    rv = mDBusRemoteService->Startup(aAppName, aProfileName);
-    if (NS_FAILED(rv)) {
-        mDBusRemoteService = nullptr;
+    bool useX11Remote = GDK_IS_X11_DISPLAY(gdk_display_get_default());
+
+#if defined(MOZ_ENABLE_DBUS)
+    if (!useX11Remote) {
+        nsresult rv;
+        mDBusRemoteService = new nsDBusRemoteService();
+        rv = mDBusRemoteService->Startup(aAppName, aProfileName);
+        if (NS_FAILED(rv)) {
+            mDBusRemoteService = nullptr;
+        }
     }
-#elif !defined(MOZ_WAYLAND)
-    mGtkRemoteService = new nsGTKRemoteService();
-    mGtkRemoteService->Startup(aAppName, aProfileName);
 #endif
+    if (useX11Remote) {
+        mGtkRemoteService = new nsGTKRemoteService();
+        mGtkRemoteService->Startup(aAppName, aProfileName);
+    }
 
     if (!mDBusRemoteService && !mGtkRemoteService)
         return NS_ERROR_FAILURE;
 
     nsCOMPtr<nsIObserverService> obs(do_GetService("@mozilla.org/observer-service;1"));
     if (obs) {
         obs->AddObserver(this, "xpcom-shutdown", false);
         obs->AddObserver(this, "quit-application", false);
@@ -65,17 +70,17 @@ nsRemoteService::RegisterWindow(mozIDOMW
         mGtkRemoteService->RegisterWindow(aWindow);
     }
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsRemoteService::Shutdown()
 {
-#if defined(MOZ_ENABLE_DBUS) && defined(MOZ_WAYLAND)
+#if defined(MOZ_ENABLE_DBUS)
     if (mDBusRemoteService) {
         mDBusRemoteService->Shutdown();
         mDBusRemoteService = nullptr;
     }
 #endif
     if (mGtkRemoteService) {
         mGtkRemoteService->Shutdown();
         mGtkRemoteService = nullptr;
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -1695,21 +1695,26 @@ ParseRemoteCommandLine(nsCString& progra
 static RemoteResult
 StartRemoteClient(const char* aDesktopStartupID,
                   nsCString& program,
                   const char* profile,
                   const char* username)
 {
   nsAutoPtr<nsRemoteClient> client;
 
-#if defined(MOZ_ENABLE_DBUS) && defined(MOZ_WAYLAND)
-  client = new DBusRemoteClient();
-#else
-  client = new XRemoteClient();
+  bool useX11Remote = GDK_IS_X11_DISPLAY(gdk_display_get_default());
+
+#if defined(MOZ_ENABLE_DBUS)
+  if (!useX11Remote) {
+    client = new DBusRemoteClient();
+  } else
 #endif
+  {
+    client = new XRemoteClient();
+  }
 
   nsresult rv = client->Init();
   if (NS_FAILED(rv))
     return REMOTE_NOT_FOUND;
 
   nsCString response;
   bool success = false;
   rv = client->SendCommandLine(program.get(), username, profile,
--- a/widget/xremoteclient/DBusRemoteClient.cpp
+++ b/widget/xremoteclient/DBusRemoteClient.cpp
@@ -187,20 +187,13 @@ DBusRemoteClient::DoSendDBusCommandLine(
 
   // append arguments
   if (!dbus_message_append_args(msg, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
                                 &aBuffer, aLength, DBUS_TYPE_INVALID)) {
     return NS_ERROR_FAILURE;
   }
 
   // send message and get a handle for a reply
-  DBusError err;
-  dbus_error_init(&err);
   RefPtr<DBusMessage> reply = already_AddRefed<DBusMessage>(
-      dbus_connection_send_with_reply_and_block(mConnection, msg, -1, &err));
+      dbus_connection_send_with_reply_and_block(mConnection, msg, -1, nullptr));
 
-  if (dbus_error_is_set(&err)) {
-      dbus_error_free(&err);
-      return NS_ERROR_FAILURE;
-  }
-
-  return NS_OK;
+  return reply ? NS_OK : NS_ERROR_FAILURE;
 }
--- a/widget/xremoteclient/moz.build
+++ b/widget/xremoteclient/moz.build
@@ -6,20 +6,17 @@
 
 with Files("**"):
     BUG_COMPONENT = ("Core", "Widget")
 
 FINAL_LIBRARY = 'xul'
 
 SOURCES += [
     'RemoteUtils.cpp',
+    'XRemoteClient.cpp',
 ]
 
-if CONFIG['MOZ_ENABLE_DBUS'] and CONFIG['MOZ_WAYLAND']:
+if CONFIG['MOZ_ENABLE_DBUS']:
     SOURCES += [
         'DBusRemoteClient.cpp',
     ]
     CXXFLAGS += CONFIG['TK_CFLAGS']
     CXXFLAGS += CONFIG['MOZ_DBUS_GLIB_CFLAGS']
-else:
-    SOURCES += [
-        'XRemoteClient.cpp',
-    ]