Bug 1360560 - Use DBusRemoteService when running on Wayland and DBus is available, r?glandium draft
authorMartin Stransky <stransky@redhat.com>
Thu, 02 Nov 2017 16:24:44 +0100
changeset 695547 41f4d3e7997484ee6db32b735ebfc8a8e71cc37a
parent 695546 74f218980e48de6832a70563dcc33d85f0e33bb0
child 739636 ae12e05778ba79bdde0f80c26e17e42cbf5fae3c
push id88463
push userstransky@redhat.com
push dateThu, 09 Nov 2017 12:17:48 +0000
reviewersglandium
bugs1360560
milestone58.0a1
Bug 1360560 - Use DBusRemoteService when running on Wayland and DBus is available, r?glandium MozReview-Commit-ID: EeDDNmEfL4L
toolkit/xre/nsAppRunner.cpp
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -172,16 +172,19 @@
 
 // for X remote support
 #ifdef MOZ_ENABLE_XREMOTE
 #include "XRemoteClient.h"
 #include "nsIRemoteService.h"
 #include "nsProfileLock.h"
 #include "SpecialSystemDirectory.h"
 #include <sched.h>
+#ifdef MOZ_ENABLE_DBUS
+#include "DBusRemoteClient.h"
+#endif
 // Time to wait for the remoting service to start
 #define MOZ_XREMOTE_START_TIMEOUT_SEC 5
 #endif
 
 #if defined(DEBUG) && defined(XP_WIN32)
 #include <malloc.h>
 #endif
 
@@ -1824,28 +1827,41 @@ ParseRemoteCommandLine(nsCString& progra
 
   return REMOTE_FOUND;
 }
 
 static RemoteResult
 StartRemoteClient(const char* aDesktopStartupID,
                   nsCString& program,
                   const char* profile,
-                  const char* username)
+                  const char* username,
+                  bool aIsX11Display)
 {
-  XRemoteClient client;
-  nsresult rv = client.Init();
+  nsAutoPtr<nsRemoteClient> client;
+
+  if (aIsX11Display) {
+    client = new XRemoteClient();
+  } else {
+#if defined(MOZ_ENABLE_DBUS) && defined(MOZ_WAYLAND)
+    client = new DBusRemoteClient();
+#else
+    MOZ_ASSERT(false, "Missing remote implementation!");
+    return REMOTE_NOT_FOUND;
+#endif
+  }
+
+  nsresult rv = client->Init();
   if (NS_FAILED(rv))
     return REMOTE_NOT_FOUND;
 
   nsCString response;
   bool success = false;
-  rv = client.SendCommandLine(program.get(), username, profile,
-                              gArgc, gArgv, aDesktopStartupID,
-                              getter_Copies(response), &success);
+  rv = client->SendCommandLine(program.get(), username, profile,
+                               gArgc, gArgv, aDesktopStartupID,
+                               getter_Copies(response), &success);
   // did the command fail?
   if (!success)
     return REMOTE_NOT_FOUND;
 
   // The "command not parseable" error is returned when the
   // nsICommandLineHandler throws a NS_ERROR_ABORT.
   if (response.EqualsLiteral("500 command not parseable"))
     return REMOTE_ARG_BAD;
@@ -4021,17 +4037,18 @@ XREMain::XRE_mainStartup(bool* aExitFlag
         NS_WARNING("Cannot lock XRemote start mutex");
       }
     }
 
     // Try to remote the entire command line. If this fails, start up normally.
     const char* desktopStartupIDPtr =
       mDesktopStartupID.IsEmpty() ? nullptr : mDesktopStartupID.get();
 
-    rr = StartRemoteClient(desktopStartupIDPtr, program, profile, username);
+    rr = StartRemoteClient(desktopStartupIDPtr, program, profile, username,
+                           GDK_IS_X11_DISPLAY(mGdkDisplay));
     if (rr == REMOTE_FOUND) {
       *aExitFlag = true;
       return 0;
     }
     if (rr == REMOTE_ARG_BAD) {
       return 1;
     }
   }