Bug 1518639: Break out the remote server pieces from nsRemoteService and deCOMtaminate. r=jimm
☠☠ backed out by 3d8dd3615c45 ☠ ☠
authorDave Townsend <dtownsend@oxymoronical.com>
Wed, 27 Feb 2019 15:45:51 -0800
changeset 462601 28c7186745e3d5de5f44a72a81e0068cb23ce547
parent 462600 35287afd3acea1602bed159dc879aa666e64b9c8
child 462602 a7490cdfb635f95c1eb8c33283064842bc490cbd
push id112316
push userdtownsend@mozilla.com
push dateWed, 06 Mar 2019 17:25:08 +0000
treeherdermozilla-inbound@84e8066625fd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs1518639
milestone67.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 1518639: Break out the remote server pieces from nsRemoteService and deCOMtaminate. r=jimm This code is only ever used from c++ so does not need to be an XPCOM component. Broken out a single nsRemoteService that is responsible for choosing the server implementation to use. Differential Revision: https://phabricator.services.mozilla.com/D19067
toolkit/components/remote/components.conf
toolkit/components/remote/moz.build
toolkit/components/remote/nsDBusRemoteServer.cpp
toolkit/components/remote/nsDBusRemoteServer.h
toolkit/components/remote/nsDBusRemoteService.cpp
toolkit/components/remote/nsDBusRemoteService.h
toolkit/components/remote/nsGTKRemoteServer.cpp
toolkit/components/remote/nsGTKRemoteServer.h
toolkit/components/remote/nsGTKRemoteService.cpp
toolkit/components/remote/nsGTKRemoteService.h
toolkit/components/remote/nsIRemoteService.idl
toolkit/components/remote/nsRemoteServer.h
toolkit/components/remote/nsRemoteService.cpp
toolkit/components/remote/nsRemoteService.h
toolkit/components/remote/nsUnixRemoteServer.cpp
toolkit/components/remote/nsUnixRemoteServer.h
toolkit/components/remote/nsXRemoteServer.cpp
toolkit/components/remote/nsXRemoteServer.h
toolkit/components/remote/nsXRemoteService.cpp
toolkit/components/remote/nsXRemoteService.h
toolkit/xre/moz.build
toolkit/xre/nsAppRunner.cpp
uriloader/exthandler/DBusHelpers.h
deleted file mode 100644
--- a/toolkit/components/remote/components.conf
+++ /dev/null
@@ -1,14 +0,0 @@
-# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
-# vim: set filetype=python:
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-Classes = [
-    {
-        'cid': '{c0773e90-5799-4eff-ad03-3ebcd85624ac}',
-        'contract_ids': ['@mozilla.org/toolkit/remote-service;1'],
-        'type': 'nsRemoteService',
-        'headers': ['/toolkit/components/remote/nsRemoteService.h'],
-    },
-]
--- a/toolkit/components/remote/moz.build
+++ b/toolkit/components/remote/moz.build
@@ -2,36 +2,26 @@
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 with Files('**'):
     BUG_COMPONENT = ('Toolkit', 'Startup and Profile System')
 
-XPIDL_SOURCES += [
-    'nsIRemoteService.idl',
-]
-
-XPIDL_MODULE = 'toolkitremote'
-
 SOURCES += [
-    'nsXRemoteService.cpp',
+    'nsRemoteService.cpp',
 ]
 
 if 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT']:
     SOURCES += [
-        'nsGTKRemoteService.cpp',
-        'nsRemoteService.cpp',
+        'nsGTKRemoteServer.cpp',
+        'nsUnixRemoteServer.cpp',
+        'nsXRemoteServer.cpp',
     ]
     if CONFIG['MOZ_ENABLE_DBUS']:
         SOURCES += [
-            'nsDBusRemoteService.cpp',
+            'nsDBusRemoteServer.cpp',
         ]
         CXXFLAGS += CONFIG['MOZ_DBUS_GLIB_CFLAGS']
-
-    XPCOM_MANIFESTS += [
-        'components.conf',
-    ]
+    CXXFLAGS += CONFIG['TK_CFLAGS']
 
 FINAL_LIBRARY = 'xul'
-
-CXXFLAGS += CONFIG['TK_CFLAGS']
rename from toolkit/components/remote/nsDBusRemoteService.cpp
rename to toolkit/components/remote/nsDBusRemoteServer.cpp
--- a/toolkit/components/remote/nsDBusRemoteService.cpp
+++ b/toolkit/components/remote/nsDBusRemoteServer.cpp
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:expandtab:shiftwidth=2:tabstop=2:
  */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "nsDBusRemoteService.h"
-#include "nsRemoteService.h"
+#include "nsDBusRemoteServer.h"
 
 #include "nsIBaseWindow.h"
 #include "nsIDocShell.h"
 #include "nsPIDOMWindow.h"
 #include "mozilla/ModuleUtils.h"
 #include "mozilla/Base64.h"
 #include "nsIServiceManager.h"
 #include "nsIWidget.h"
@@ -23,18 +22,16 @@
 
 #include "nsGTKToolkit.h"
 
 #include <dbus/dbus.h>
 #include <dbus/dbus-glib-lowlevel.h>
 
 #include <dlfcn.h>
 
-NS_IMPL_ISUPPORTS(nsDBusRemoteService, nsIRemoteService)
-
 const char *introspect_template =
     "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection "
     "1.0//EN\"\n"
     "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\";>\n"
     "<node>\n"
     " <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
     "   <method name=\"Introspect\">\n"
     "     <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
@@ -42,17 +39,17 @@ const char *introspect_template =
     " </interface>\n"
     " <interface name=\"org.mozilla.%s\">\n"
     "   <method name=\"OpenURL\">\n"
     "     <arg name=\"url\" direction=\"in\" type=\"s\"/>\n"
     "   </method>\n"
     " </interface>\n"
     "</node>\n";
 
-DBusHandlerResult nsDBusRemoteService::Introspect(DBusMessage *msg) {
+DBusHandlerResult nsDBusRemoteServer::Introspect(DBusMessage *msg) {
   DBusMessage *reply;
 
   reply = dbus_message_new_method_return(msg);
   if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY;
 
   nsAutoCString introspect_xml;
   introspect_xml = nsPrintfCString(introspect_template, mAppName.get());
 
@@ -61,43 +58,43 @@ DBusHandlerResult nsDBusRemoteService::I
                            DBUS_TYPE_INVALID);
 
   dbus_connection_send(mConnection, reply, nullptr);
   dbus_message_unref(reply);
 
   return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-DBusHandlerResult nsDBusRemoteService::OpenURL(DBusMessage *msg) {
+DBusHandlerResult nsDBusRemoteServer::OpenURL(DBusMessage *msg) {
   DBusMessage *reply = nullptr;
   const char *commandLine;
   int length;
 
   if (!dbus_message_get_args(msg, nullptr, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
                              &commandLine, &length, DBUS_TYPE_INVALID) ||
       length == 0) {
     nsAutoCString errorMsg;
     errorMsg = nsPrintfCString("org.mozilla.%s.Error", mAppName.get());
     reply = dbus_message_new_error(msg, errorMsg.get(), "Wrong argument");
   } else {
     guint32 timestamp = gtk_get_current_event_time();
     if (timestamp == GDK_CURRENT_TIME) {
       timestamp = guint32(g_get_monotonic_time() / 1000);
     }
-    nsRemoteService::HandleCommandLine(commandLine, timestamp);
+    HandleCommandLine(commandLine, timestamp);
     reply = dbus_message_new_method_return(msg);
   }
 
   dbus_connection_send(mConnection, reply, nullptr);
   dbus_message_unref(reply);
 
   return DBUS_HANDLER_RESULT_HANDLED;
 }
 
-DBusHandlerResult nsDBusRemoteService::HandleDBusMessage(
+DBusHandlerResult nsDBusRemoteServer::HandleDBusMessage(
     DBusConnection *aConnection, DBusMessage *msg) {
   NS_ASSERTION(mConnection == aConnection, "Wrong D-Bus connection.");
 
   const char *method = dbus_message_get_member(msg);
   const char *iface = dbus_message_get_interface(msg);
 
   if ((strcmp("Introspect", method) == 0) &&
       (strcmp("org.freedesktop.DBus.Introspectable", iface) == 0)) {
@@ -110,39 +107,39 @@ DBusHandlerResult nsDBusRemoteService::H
   if ((strcmp("OpenURL", method) == 0) &&
       (strcmp(ourInterfaceName.get(), iface) == 0)) {
     return OpenURL(msg);
   }
 
   return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
 
-void nsDBusRemoteService::UnregisterDBusInterface(DBusConnection *aConnection) {
+void nsDBusRemoteServer::UnregisterDBusInterface(DBusConnection *aConnection) {
   NS_ASSERTION(mConnection == aConnection, "Wrong D-Bus connection.");
   // Not implemented
 }
 
 static DBusHandlerResult message_handler(DBusConnection *conn, DBusMessage *msg,
                                          void *user_data) {
-  auto interface = static_cast<nsDBusRemoteService *>(user_data);
+  auto interface = static_cast<nsDBusRemoteServer *>(user_data);
   return interface->HandleDBusMessage(conn, msg);
 }
 
 static void unregister(DBusConnection *conn, void *user_data) {
-  auto interface = static_cast<nsDBusRemoteService *>(user_data);
+  auto interface = static_cast<nsDBusRemoteServer *>(user_data);
   interface->UnregisterDBusInterface(conn);
 }
 
 static DBusObjectPathVTable remoteHandlersTable = {
     .unregister_function = unregister,
     .message_function = message_handler,
 };
 
-NS_IMETHODIMP
-nsDBusRemoteService::Startup(const char *aAppName, const char *aProfileName) {
+nsresult nsDBusRemoteServer::Startup(const char *aAppName,
+                                     const char *aProfileName) {
   if (mConnection && dbus_connection_get_is_connected(mConnection)) {
     // We're already connected so we don't need to reconnect
     return NS_ERROR_ALREADY_INITIALIZED;
   }
 
   // Don't even try to start without any application/profile name
   if (!aAppName || aAppName[0] == '\0' || !aProfileName ||
       aProfileName[0] == '\0')
@@ -205,16 +202,18 @@ nsDBusRemoteService::Startup(const char 
                                             &remoteHandlersTable, this)) {
     mConnection = nullptr;
     return NS_ERROR_FAILURE;
   }
 
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsDBusRemoteService::Shutdown() {
+void nsDBusRemoteServer::Shutdown() {
+  if (!mConnection) {
+    return;
+  }
+
   dbus_connection_unregister_object_path(mConnection, mPathName.get());
 
   // dbus_connection_unref() will be called by RefPtr here.
   mConnection = nullptr;
-  return NS_OK;
 }
rename from toolkit/components/remote/nsDBusRemoteService.h
rename to toolkit/components/remote/nsDBusRemoteServer.h
--- a/toolkit/components/remote/nsDBusRemoteService.h
+++ b/toolkit/components/remote/nsDBusRemoteServer.h
@@ -1,39 +1,38 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:expandtab:shiftwidth=2:tabstop=2:
  */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#ifndef __nsDBusRemoteService_h__
-#define __nsDBusRemoteService_h__
+#ifndef __nsDBusRemoteServer_h__
+#define __nsDBusRemoteServer_h__
 
-#include "nsIRemoteService.h"
+#include "nsRemoteServer.h"
+#include "nsUnixRemoteServer.h"
 #include "mozilla/DBusHelpers.h"
-#include "nsString.h"
 
-class nsDBusRemoteService final : public nsIRemoteService {
+class nsDBusRemoteServer final : public nsRemoteServer,
+                                 public nsUnixRemoteServer {
  public:
-  // We will be a static singleton, so don't use the ordinary methods.
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIREMOTESERVICE
+  nsDBusRemoteServer() : mConnection(nullptr), mAppName(nullptr) {}
+  ~nsDBusRemoteServer() override { Shutdown(); }
 
-  nsDBusRemoteService() : mConnection(nullptr), mAppName(nullptr) {}
+  nsresult Startup(const char *aAppName, const char *aProfileName) override;
+  void Shutdown() override;
 
   DBusHandlerResult HandleDBusMessage(DBusConnection *aConnection,
                                       DBusMessage *msg);
   void UnregisterDBusInterface(DBusConnection *aConnection);
 
  private:
-  ~nsDBusRemoteService() {}
-
   DBusHandlerResult OpenURL(DBusMessage *msg);
   DBusHandlerResult Introspect(DBusMessage *msg);
 
   // The connection is owned by DBus library
   RefPtr<DBusConnection> mConnection;
   nsCString mAppName;
   nsCString mPathName;
 };
 
-#endif  // __nsDBusRemoteService_h__
+#endif  // __nsDBusRemoteServer_h__
rename from toolkit/components/remote/nsGTKRemoteService.cpp
rename to toolkit/components/remote/nsGTKRemoteServer.cpp
--- a/toolkit/components/remote/nsGTKRemoteService.cpp
+++ b/toolkit/components/remote/nsGTKRemoteServer.cpp
@@ -1,16 +1,16 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:expandtab:shiftwidth=2:tabstop=8:
  */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "nsGTKRemoteService.h"
+#include "nsGTKRemoteServer.h"
 
 #include <gtk/gtk.h>
 #include <gdk/gdk.h>
 #include <gdk/gdkx.h>
 
 #include "nsIBaseWindow.h"
 #include "nsIDocShell.h"
 #include "nsPIDOMWindow.h"
@@ -18,58 +18,57 @@
 #include "nsIServiceManager.h"
 #include "nsIAppShellService.h"
 #include "nsAppShellCID.h"
 
 #include "nsCOMPtr.h"
 
 #include "nsGTKToolkit.h"
 
-NS_IMPL_ISUPPORTS(nsGTKRemoteService, nsIRemoteService)
-
-NS_IMETHODIMP
-nsGTKRemoteService::Startup(const char* aAppName, const char* aProfileName) {
+nsresult nsGTKRemoteServer::Startup(const char* aAppName,
+                                    const char* aProfileName) {
   NS_ASSERTION(aAppName, "Don't pass a null appname!");
 
-  if (mServerWindow) return NS_ERROR_ALREADY_INITIALIZED;
+  if (mServerWindow) {
+    return NS_ERROR_ALREADY_INITIALIZED;
+  }
 
   XRemoteBaseStartup(aAppName, aProfileName);
 
   mServerWindow = gtk_invisible_new();
   gtk_widget_realize(mServerWindow);
   HandleCommandsFor(mServerWindow);
 
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsGTKRemoteService::Shutdown() {
-  if (!mServerWindow) return NS_ERROR_NOT_INITIALIZED;
+void nsGTKRemoteServer::Shutdown() {
+  if (!mServerWindow) {
+    return;
+  }
 
   gtk_widget_destroy(mServerWindow);
   mServerWindow = nullptr;
-
-  return NS_OK;
 }
 
-void nsGTKRemoteService::HandleCommandsFor(GtkWidget* widget) {
+void nsGTKRemoteServer::HandleCommandsFor(GtkWidget* widget) {
   g_signal_connect(G_OBJECT(widget), "property_notify_event",
-                   G_CALLBACK(HandlePropertyChange), nullptr);
+                   G_CALLBACK(HandlePropertyChange), this);
 
   gtk_widget_add_events(widget, GDK_PROPERTY_CHANGE_MASK);
 
   Window window = gdk_x11_window_get_xid(gtk_widget_get_window(widget));
-  nsXRemoteService::HandleCommandsFor(window);
+  nsXRemoteServer::HandleCommandsFor(window);
 }
 
-gboolean nsGTKRemoteService::HandlePropertyChange(GtkWidget* aWidget,
-                                                  GdkEventProperty* pevent,
-                                                  void* aData) {
+gboolean nsGTKRemoteServer::HandlePropertyChange(GtkWidget* aWidget,
+                                                 GdkEventProperty* pevent,
+                                                 nsGTKRemoteServer* aThis) {
   if (pevent->state == GDK_PROPERTY_NEW_VALUE) {
     Atom changedAtom = gdk_x11_atom_to_xatom(pevent->atom);
 
     XID window = gdk_x11_window_get_xid(gtk_widget_get_window(aWidget));
-    return HandleNewProperty(window,
-                             GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
-                             pevent->time, changedAtom);
+    return aThis->HandleNewProperty(
+        window, GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), pevent->time,
+        changedAtom);
   }
   return FALSE;
 }
rename from toolkit/components/remote/nsGTKRemoteService.h
rename to toolkit/components/remote/nsGTKRemoteServer.h
--- a/toolkit/components/remote/nsGTKRemoteService.h
+++ b/toolkit/components/remote/nsGTKRemoteServer.h
@@ -1,38 +1,37 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:expandtab:shiftwidth=2:tabstop=2:
  */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#ifndef __nsGTKRemoteService_h__
-#define __nsGTKRemoteService_h__
+#ifndef __nsGTKRemoteServer_h__
+#define __nsGTKRemoteServer_h__
 
 #include <gdk/gdk.h>
 #include <gdk/gdkx.h>
 #include <gtk/gtk.h>
 
-#include "nsIRemoteService.h"
-#include "nsXRemoteService.h"
+#include "nsRemoteServer.h"
+#include "nsXRemoteServer.h"
 #include "mozilla/Attributes.h"
 
-class nsGTKRemoteService final : public nsIRemoteService,
-                                 public nsXRemoteService {
+class nsGTKRemoteServer final : public nsXRemoteServer {
  public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIREMOTESERVICE
+  nsGTKRemoteServer() : mServerWindow(nullptr) {}
+  ~nsGTKRemoteServer() override { Shutdown(); }
 
-  nsGTKRemoteService() : mServerWindow(nullptr) {}
+  nsresult Startup(const char* aAppName, const char* aProfileName) override;
+  void Shutdown() override;
 
   static gboolean HandlePropertyChange(GtkWidget* widget,
-                                       GdkEventProperty* event, void* aData);
+                                       GdkEventProperty* event,
+                                       nsGTKRemoteServer* aData);
 
  private:
-  ~nsGTKRemoteService() {}
-
   void HandleCommandsFor(GtkWidget* aWidget);
 
   GtkWidget* mServerWindow;
 };
 
 #endif  // __nsGTKRemoteService_h__
deleted file mode 100644
--- a/toolkit/components/remote/nsIRemoteService.idl
+++ /dev/null
@@ -1,38 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsISupports.idl"
-
-interface mozIDOMWindow;
-
-/**
- * Start and stop the remote service (xremote/phremote), and register
- * windows with the service for backwards compatibility with old xremote
- * clients.
- *
- * @status FLUID This interface is not frozen and is not intended for embedders
- *               who want a frozen API. If you are an embedder and need this
- *               functionality, contact Benjamin Smedberg about the possibility
- *               of freezing the functionality you need.
- */
-
-[scriptable, uuid(bf23f1c3-7012-42dd-b0bb-a84060ccc52e)]
-interface nsIRemoteService : nsISupports
-{
-  /**
-   * Start the remote service. This should not be done until app startup
-   * appears to have been successful.
-   *
-   * @param appName     (Required) Sets a window property identifying the
-   *                    application.
-   * @param profileName (May be null) Sets a window property identifying the
-   *                    profile name.
-   */
-  void startup(in string appName, in string profileName);
-
-  /**
-   * Stop the remote service from accepting additional requests.
-   */
-  void shutdown();
-};
new file mode 100644
--- /dev/null
+++ b/toolkit/components/remote/nsRemoteServer.h
@@ -0,0 +1,21 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:expandtab:shiftwidth=2:tabstop=2:
+ */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef __nsRemoteServer_h__
+#define __nsRemoteServer_h__
+
+#include "nsString.h"
+
+class nsRemoteServer {
+ public:
+  virtual ~nsRemoteServer() = default;
+
+  virtual nsresult Startup(const char* aAppName, const char* aProfileName) = 0;
+  virtual void Shutdown() = 0;
+};
+
+#endif  // __nsRemoteServer_h__
--- a/toolkit/components/remote/nsRemoteService.cpp
+++ b/toolkit/components/remote/nsRemoteService.cpp
@@ -1,183 +1,68 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:expandtab:shiftwidth=2:tabstop=8:
  */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include "nsGTKRemoteService.h"
-#ifdef MOZ_ENABLE_DBUS
-#  include "nsDBusRemoteService.h"
+#ifdef MOZ_WIDGET_GTK
+#  include "nsGTKRemoteServer.h"
+#  ifdef MOZ_ENABLE_DBUS
+#    include "nsDBusRemoteServer.h"
+#  endif
 #endif
 #include "nsRemoteService.h"
 
-#include <gtk/gtk.h>
-#include <gdk/gdk.h>
-#include <gdk/gdkx.h>
+#include "nsString.h"
+#include "nsServiceManagerUtils.h"
+#include "mozilla/ModuleUtils.h"
+
+using namespace mozilla;
 
-#include "nsIServiceManager.h"
-#include "nsIAppShellService.h"
-#include "nsAppShellCID.h"
-#include "nsInterfaceHashtable.h"
-#include "nsGTKToolkit.h"
-#include "nsICommandLineRunner.h"
-#include "nsCommandLine.h"
-#include "nsString.h"
-#include "nsIFile.h"
+NS_IMPL_ISUPPORTS(nsRemoteService, nsIObserver)
 
-NS_IMPL_ISUPPORTS(nsRemoteService, nsIRemoteService, nsIObserver)
+void nsRemoteService::Startup(const char* aAppName, const char* aProfileName) {
+  if (mRemoteServer) {
+    return;
+  }
 
-NS_IMETHODIMP
-nsRemoteService::Startup(const char* aAppName, const char* aProfileName) {
+#ifdef MOZ_WIDGET_GTK
   bool useX11Remote = GDK_IS_X11_DISPLAY(gdk_display_get_default());
 
-#if defined(MOZ_ENABLE_DBUS)
+#  if defined(MOZ_ENABLE_DBUS)
   if (!useX11Remote) {
-    nsresult rv;
-    mDBusRemoteService = new nsDBusRemoteService();
-    rv = mDBusRemoteService->Startup(aAppName, aProfileName);
-    if (NS_FAILED(rv)) {
-      mDBusRemoteService = nullptr;
-    }
+    mRemoteServer = MakeUnique<nsDBusRemoteServer>();
+  }
+#  endif
+  if (useX11Remote) {
+    mRemoteServer = MakeUnique<nsGTKRemoteServer>();
   }
 #endif
-  if (useX11Remote) {
-    mGtkRemoteService = new nsGTKRemoteService();
-    mGtkRemoteService->Startup(aAppName, aProfileName);
+
+  nsresult rv = mRemoteServer->Startup(aAppName, aProfileName);
+
+  if (NS_FAILED(rv)) {
+    mRemoteServer = nullptr;
+    return;
   }
 
-  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);
   }
-
-  return NS_OK;
 }
 
-NS_IMETHODIMP
-nsRemoteService::Shutdown() {
-#if defined(MOZ_ENABLE_DBUS)
-  if (mDBusRemoteService) {
-    mDBusRemoteService->Shutdown();
-    mDBusRemoteService = nullptr;
-  }
-#endif
-  if (mGtkRemoteService) {
-    mGtkRemoteService->Shutdown();
-    mGtkRemoteService = nullptr;
-  }
-  return NS_OK;
-}
+void nsRemoteService::Shutdown() { mRemoteServer = nullptr; }
 
 nsRemoteService::~nsRemoteService() { Shutdown(); }
 
 NS_IMETHODIMP
 nsRemoteService::Observe(nsISupports* aSubject, const char* aTopic,
                          const char16_t* aData) {
   // This can be xpcom-shutdown or quit-application, but it's the same either
   // way.
   Shutdown();
   return NS_OK;
 }
-
-// Set desktop startup ID to the passed ID, if there is one, so that any created
-// windows get created with the right window manager metadata, and any windows
-// that get new tabs and are activated also get the right WM metadata.
-// The timestamp will be used if there is no desktop startup ID, or if we're
-// raising an existing window rather than showing a new window for the first
-// time.
-void nsRemoteService::SetDesktopStartupIDOrTimestamp(
-    const nsACString& aDesktopStartupID, uint32_t aTimestamp) {
-  nsGTKToolkit* toolkit = nsGTKToolkit::GetToolkit();
-  if (!toolkit) return;
-
-  if (!aDesktopStartupID.IsEmpty()) {
-    toolkit->SetDesktopStartupID(aDesktopStartupID);
-  }
-
-  toolkit->SetFocusTimestamp(aTimestamp);
-}
-
-static bool FindExtensionParameterInCommand(const char* aParameterName,
-                                            const nsACString& aCommand,
-                                            char aSeparator,
-                                            nsACString* aValue) {
-  nsAutoCString searchFor;
-  searchFor.Append(aSeparator);
-  searchFor.Append(aParameterName);
-  searchFor.Append('=');
-
-  nsACString::const_iterator start, end;
-  aCommand.BeginReading(start);
-  aCommand.EndReading(end);
-  if (!FindInReadable(searchFor, start, end)) return false;
-
-  nsACString::const_iterator charStart, charEnd;
-  charStart = end;
-  aCommand.EndReading(charEnd);
-  nsACString::const_iterator idStart = charStart, idEnd;
-  if (FindCharInReadable(aSeparator, charStart, charEnd)) {
-    idEnd = charStart;
-  } else {
-    idEnd = charEnd;
-  }
-  *aValue = nsDependentCSubstring(idStart, idEnd);
-  return true;
-}
-
-const char* nsRemoteService::HandleCommandLine(const char* aBuffer,
-                                               uint32_t aTimestamp) {
-  nsCOMPtr<nsICommandLineRunner> cmdline(new nsCommandLine());
-
-  // the commandline property is constructed as an array of int32_t
-  // followed by a series of null-terminated strings:
-  //
-  // [argc][offsetargv0][offsetargv1...]<workingdir>\0<argv[0]>\0argv[1]...\0
-  // (offset is from the beginning of the buffer)
-
-  int32_t argc = TO_LITTLE_ENDIAN32(*reinterpret_cast<const int32_t*>(aBuffer));
-  const char* wd = aBuffer + ((argc + 1) * sizeof(int32_t));
-
-  nsCOMPtr<nsIFile> lf;
-  nsresult rv =
-      NS_NewNativeLocalFile(nsDependentCString(wd), true, getter_AddRefs(lf));
-  if (NS_FAILED(rv)) return "509 internal error";
-
-  nsAutoCString desktopStartupID;
-
-  const char** argv = (const char**)malloc(sizeof(char*) * argc);
-  if (!argv) return "509 internal error";
-
-  const int32_t* offset = reinterpret_cast<const int32_t*>(aBuffer) + 1;
-
-  for (int i = 0; i < argc; ++i) {
-    argv[i] = aBuffer + TO_LITTLE_ENDIAN32(offset[i]);
-
-    if (i == 0) {
-      nsDependentCString cmd(argv[0]);
-      FindExtensionParameterInCommand("DESKTOP_STARTUP_ID", cmd, ' ',
-                                      &desktopStartupID);
-    }
-  }
-
-  rv = cmdline->Init(argc, argv, lf, nsICommandLine::STATE_REMOTE_AUTO);
-
-  free(argv);
-  if (NS_FAILED(rv)) {
-    return "509 internal error";
-  }
-
-  SetDesktopStartupIDOrTimestamp(desktopStartupID, aTimestamp);
-
-  rv = cmdline->Run();
-
-  if (NS_ERROR_ABORT == rv) return "500 command not parseable";
-
-  if (NS_FAILED(rv)) return "509 internal error";
-
-  return "200 executed command";
-}
--- a/toolkit/components/remote/nsRemoteService.h
+++ b/toolkit/components/remote/nsRemoteService.h
@@ -3,36 +3,32 @@
  */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef __nsRemoteService_h__
 #define __nsRemoteService_h__
 
-#include "nsIRemoteService.h"
+#include "nsRemoteServer.h"
 #include "nsIObserverService.h"
 #include "nsIObserver.h"
 #include "nsPIDOMWindow.h"
+#include "mozilla/UniquePtr.h"
 
-class nsRemoteService final : public nsIRemoteService, public nsIObserver {
+class nsRemoteService final : public nsIObserver {
  public:
   // We will be a static singleton, so don't use the ordinary methods.
   NS_DECL_ISUPPORTS
-  NS_DECL_NSIREMOTESERVICE
   NS_DECL_NSIOBSERVER
 
-  static const char* HandleCommandLine(const char* aBuffer,
-                                       uint32_t aTimestamp);
+  nsRemoteService() = default;
 
-  nsCOMPtr<nsIRemoteService> mDBusRemoteService;
-  nsCOMPtr<nsIRemoteService> mGtkRemoteService;
-
-  nsRemoteService() {}
+  void Startup(const char* aAppName, const char* aProfileName);
+  void Shutdown();
 
  private:
   ~nsRemoteService();
 
-  static void SetDesktopStartupIDOrTimestamp(
-      const nsACString& aDesktopStartupID, uint32_t aTimestamp);
+  mozilla::UniquePtr<nsRemoteServer> mRemoteServer;
 };
 
 #endif  // __nsRemoteService_h__
new file mode 100644
--- /dev/null
+++ b/toolkit/components/remote/nsUnixRemoteServer.cpp
@@ -0,0 +1,111 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:expandtab:shiftwidth=2:tabstop=2:
+ */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "nsUnixRemoteServer.h"
+#include "nsGTKToolkit.h"
+#include "nsCOMPtr.h"
+#include "nsICommandLineRunner.h"
+#include "nsCommandLine.h"
+#include "nsIFile.h"
+
+// Set desktop startup ID to the passed ID, if there is one, so that any created
+// windows get created with the right window manager metadata, and any windows
+// that get new tabs and are activated also get the right WM metadata.
+// The timestamp will be used if there is no desktop startup ID, or if we're
+// raising an existing window rather than showing a new window for the first
+// time.
+void nsUnixRemoteServer::SetDesktopStartupIDOrTimestamp(
+    const nsACString& aDesktopStartupID, uint32_t aTimestamp) {
+  nsGTKToolkit* toolkit = nsGTKToolkit::GetToolkit();
+  if (!toolkit) return;
+
+  if (!aDesktopStartupID.IsEmpty()) {
+    toolkit->SetDesktopStartupID(aDesktopStartupID);
+  }
+
+  toolkit->SetFocusTimestamp(aTimestamp);
+}
+
+static bool FindExtensionParameterInCommand(const char* aParameterName,
+                                            const nsACString& aCommand,
+                                            char aSeparator,
+                                            nsACString* aValue) {
+  nsAutoCString searchFor;
+  searchFor.Append(aSeparator);
+  searchFor.Append(aParameterName);
+  searchFor.Append('=');
+
+  nsACString::const_iterator start, end;
+  aCommand.BeginReading(start);
+  aCommand.EndReading(end);
+  if (!FindInReadable(searchFor, start, end)) return false;
+
+  nsACString::const_iterator charStart, charEnd;
+  charStart = end;
+  aCommand.EndReading(charEnd);
+  nsACString::const_iterator idStart = charStart, idEnd;
+  if (FindCharInReadable(aSeparator, charStart, charEnd)) {
+    idEnd = charStart;
+  } else {
+    idEnd = charEnd;
+  }
+  *aValue = nsDependentCSubstring(idStart, idEnd);
+  return true;
+}
+
+const char* nsUnixRemoteServer::HandleCommandLine(const char* aBuffer,
+                                                  uint32_t aTimestamp) {
+  nsCOMPtr<nsICommandLineRunner> cmdline(new nsCommandLine());
+
+  // the commandline property is constructed as an array of int32_t
+  // followed by a series of null-terminated strings:
+  //
+  // [argc][offsetargv0][offsetargv1...]<workingdir>\0<argv[0]>\0argv[1]...\0
+  // (offset is from the beginning of the buffer)
+
+  int32_t argc = TO_LITTLE_ENDIAN32(*reinterpret_cast<const int32_t*>(aBuffer));
+  const char* wd = aBuffer + ((argc + 1) * sizeof(int32_t));
+
+  nsCOMPtr<nsIFile> lf;
+  nsresult rv =
+      NS_NewNativeLocalFile(nsDependentCString(wd), true, getter_AddRefs(lf));
+  if (NS_FAILED(rv)) return "509 internal error";
+
+  nsAutoCString desktopStartupID;
+
+  const char** argv = (const char**)malloc(sizeof(char*) * argc);
+  if (!argv) return "509 internal error";
+
+  const int32_t* offset = reinterpret_cast<const int32_t*>(aBuffer) + 1;
+
+  for (int i = 0; i < argc; ++i) {
+    argv[i] = aBuffer + TO_LITTLE_ENDIAN32(offset[i]);
+
+    if (i == 0) {
+      nsDependentCString cmd(argv[0]);
+      FindExtensionParameterInCommand("DESKTOP_STARTUP_ID", cmd, ' ',
+                                      &desktopStartupID);
+    }
+  }
+
+  rv = cmdline->Init(argc, argv, lf, nsICommandLine::STATE_REMOTE_AUTO);
+
+  free(argv);
+  if (NS_FAILED(rv)) {
+    return "509 internal error";
+  }
+
+  SetDesktopStartupIDOrTimestamp(desktopStartupID, aTimestamp);
+
+  rv = cmdline->Run();
+
+  if (NS_ERROR_ABORT == rv) return "500 command not parseable";
+
+  if (NS_FAILED(rv)) return "509 internal error";
+
+  return "200 executed command";
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/components/remote/nsUnixRemoteServer.h
@@ -0,0 +1,28 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:expandtab:shiftwidth=2:tabstop=2:
+ */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef __nsUnixRemoteServer_h__
+#define __nsUnixRemoteServer_h__
+
+#include "nsString.h"
+
+#ifdef IS_BIG_ENDIAN
+#  define TO_LITTLE_ENDIAN32(x)                           \
+    ((((x)&0xff000000) >> 24) | (((x)&0x00ff0000) >> 8) | \
+     (((x)&0x0000ff00) << 8) | (((x)&0x000000ff) << 24))
+#else
+#  define TO_LITTLE_ENDIAN32(x) (x)
+#endif
+
+class nsUnixRemoteServer {
+ protected:
+  void SetDesktopStartupIDOrTimestamp(const nsACString& aDesktopStartupID,
+                                      uint32_t aTimestamp);
+  const char* HandleCommandLine(const char* aBuffer, uint32_t aTimestamp);
+};
+
+#endif  // __nsGTKRemoteService_h__
rename from toolkit/components/remote/nsXRemoteService.cpp
rename to toolkit/components/remote/nsXRemoteServer.cpp
--- a/toolkit/components/remote/nsXRemoteService.cpp
+++ b/toolkit/components/remote/nsXRemoteServer.cpp
@@ -2,18 +2,17 @@
 /* vim:expandtab:shiftwidth=2:tabstop=8:
  */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/ArrayUtils.h"
 
-#include "nsXRemoteService.h"
-#include "nsRemoteService.h"
+#include "nsXRemoteServer.h"
 #include "nsIObserverService.h"
 #include "nsCOMPtr.h"
 #include "nsIServiceManager.h"
 #include "nsICommandLineRunner.h"
 #include "nsICommandLine.h"
 
 #include "nsIBaseWindow.h"
 #include "nsIDocShell.h"
@@ -49,37 +48,37 @@ const unsigned char kRemoteVersion[] = "
 
 // Minimize the roundtrips to the X server by getting all the atoms at once
 static const char *XAtomNames[] = {
     MOZILLA_VERSION_PROP,    MOZILLA_LOCK_PROP,    MOZILLA_RESPONSE_PROP,
     MOZILLA_USER_PROP,       MOZILLA_PROFILE_PROP, MOZILLA_PROGRAM_PROP,
     MOZILLA_COMMANDLINE_PROP};
 static Atom XAtoms[MOZ_ARRAY_LENGTH(XAtomNames)];
 
-Atom nsXRemoteService::sMozVersionAtom;
-Atom nsXRemoteService::sMozLockAtom;
-Atom nsXRemoteService::sMozResponseAtom;
-Atom nsXRemoteService::sMozUserAtom;
-Atom nsXRemoteService::sMozProfileAtom;
-Atom nsXRemoteService::sMozProgramAtom;
-Atom nsXRemoteService::sMozCommandLineAtom;
+Atom nsXRemoteServer::sMozVersionAtom;
+Atom nsXRemoteServer::sMozLockAtom;
+Atom nsXRemoteServer::sMozResponseAtom;
+Atom nsXRemoteServer::sMozUserAtom;
+Atom nsXRemoteServer::sMozProfileAtom;
+Atom nsXRemoteServer::sMozProgramAtom;
+Atom nsXRemoteServer::sMozCommandLineAtom;
 
-nsXRemoteService::nsXRemoteService() = default;
+nsXRemoteServer::nsXRemoteServer() = default;
 
-void nsXRemoteService::XRemoteBaseStartup(const char *aAppName,
-                                          const char *aProfileName) {
+void nsXRemoteServer::XRemoteBaseStartup(const char *aAppName,
+                                         const char *aProfileName) {
   EnsureAtoms();
 
   mAppName = aAppName;
   ToLowerCase(mAppName);
 
   mProfileName = aProfileName;
 }
 
-void nsXRemoteService::HandleCommandsFor(Window aWindowId) {
+void nsXRemoteServer::HandleCommandsFor(Window aWindowId) {
   // set our version
   XChangeProperty(mozilla::DefaultXDisplay(), aWindowId, sMozVersionAtom,
                   XA_STRING, 8, PropModeReplace, kRemoteVersion,
                   sizeof(kRemoteVersion) - 1);
 
   // get our username
   unsigned char *logname;
   logname = (unsigned char *)PR_GetEnv("LOGNAME");
@@ -96,18 +95,18 @@ void nsXRemoteService::HandleCommandsFor
 
   if (!mProfileName.IsEmpty()) {
     XChangeProperty(mozilla::DefaultXDisplay(), aWindowId, sMozProfileAtom,
                     XA_STRING, 8, PropModeReplace,
                     (unsigned char *)mProfileName.get(), mProfileName.Length());
   }
 }
 
-bool nsXRemoteService::HandleNewProperty(XID aWindowId, Display *aDisplay,
-                                         Time aEventTime, Atom aChangedAtom) {
+bool nsXRemoteServer::HandleNewProperty(XID aWindowId, Display *aDisplay,
+                                        Time aEventTime, Atom aChangedAtom) {
   if (aChangedAtom == sMozCommandLineAtom) {
     // We got a new command atom.
     int result;
     Atom actual_type;
     int actual_format;
     unsigned long nitems, bytes_after;
     char *data = 0;
 
@@ -127,17 +126,17 @@ bool nsXRemoteService::HandleNewProperty
     // Failed to get property off the window?
     if (result != Success) return false;
 
     // Failed to get the data off the window or it was the wrong type?
     if (!data || !TO_LITTLE_ENDIAN32(*reinterpret_cast<int32_t *>(data)))
       return false;
 
     // cool, we got the property data.
-    const char *response = nsRemoteService::HandleCommandLine(data, aEventTime);
+    const char *response = HandleCommandLine(data, aEventTime);
 
     // put the property onto the window as the response
     XChangeProperty(aDisplay, aWindowId, sMozResponseAtom, XA_STRING, 8,
                     PropModeReplace, (const unsigned char *)response,
                     strlen(response));
     XFree(data);
     return true;
   }
@@ -150,17 +149,17 @@ bool nsXRemoteService::HandleNewProperty
   else if (aChangedAtom == sMozLockAtom) {
     // someone locked the window
     return true;
   }
 
   return false;
 }
 
-void nsXRemoteService::EnsureAtoms(void) {
+void nsXRemoteServer::EnsureAtoms(void) {
   if (sMozVersionAtom) return;
 
   XInternAtoms(mozilla::DefaultXDisplay(), const_cast<char **>(XAtomNames),
                ArrayLength(XAtomNames), False, XAtoms);
 
   int i = 0;
   sMozVersionAtom = XAtoms[i++];
   sMozLockAtom = XAtoms[i++];
rename from toolkit/components/remote/nsXRemoteService.h
rename to toolkit/components/remote/nsXRemoteServer.h
--- a/toolkit/components/remote/nsXRemoteService.h
+++ b/toolkit/components/remote/nsXRemoteServer.h
@@ -1,41 +1,33 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:expandtab:shiftwidth=2:tabstop=8:
  */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#ifndef NSXREMOTESERVICE_H
-#define NSXREMOTESERVICE_H
+#ifndef NSXREMOTESERVER_H
+#define NSXREMOTESERVER_H
 
 #include "nsString.h"
+#include "nsRemoteServer.h"
+#include "nsUnixRemoteServer.h"
 
 #include <X11/Xlib.h>
 #include <X11/X.h>
 
-class nsIDOMWindow;
-
-#ifdef IS_BIG_ENDIAN
-#  define TO_LITTLE_ENDIAN32(x)                           \
-    ((((x)&0xff000000) >> 24) | (((x)&0x00ff0000) >> 8) | \
-     (((x)&0x0000ff00) << 8) | (((x)&0x000000ff) << 24))
-#else
-#  define TO_LITTLE_ENDIAN32(x) (x)
-#endif
-
 /**
   Base class for GTK/Qt remote service
 */
-class nsXRemoteService {
+class nsXRemoteServer : public nsRemoteServer, public nsUnixRemoteServer {
  protected:
-  nsXRemoteService();
-  static bool HandleNewProperty(Window aWindowId, Display* aDisplay,
-                                Time aEventTime, Atom aChangedAtom);
+  nsXRemoteServer();
+  bool HandleNewProperty(Window aWindowId, Display* aDisplay, Time aEventTime,
+                         Atom aChangedAtom);
   void XRemoteBaseStartup(const char* aAppName, const char* aProfileName);
   void HandleCommandsFor(Window aWindowId);
 
  private:
   void EnsureAtoms();
 
   nsCString mAppName;
   nsCString mProfileName;
@@ -44,9 +36,9 @@ class nsXRemoteService {
   static Atom sMozLockAtom;
   static Atom sMozResponseAtom;
   static Atom sMozUserAtom;
   static Atom sMozProfileAtom;
   static Atom sMozProgramAtom;
   static Atom sMozCommandLineAtom;
 };
 
-#endif  // NSXREMOTESERVICE_H
+#endif  // NSXREMOTESERVER_H
--- a/toolkit/xre/moz.build
+++ b/toolkit/xre/moz.build
@@ -86,16 +86,20 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'ui
     UNIFIED_SOURCES += [
         'nsNativeAppSupportDefault.cpp',
         'UIKitDirProvider.mm',
     ]
 elif 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT']:
     UNIFIED_SOURCES += [
         'nsNativeAppSupportUnix.cpp',
     ]
+
+    LOCAL_INCLUDES += [
+        '../components/remote',
+    ]
 else:
     UNIFIED_SOURCES += [
         'nsNativeAppSupportDefault.cpp',
     ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk3':
     UNIFIED_SOURCES += [
         'nsGDKErrorHandler.cpp',
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -184,17 +184,17 @@
 #ifdef XP_MACOSX
 #  include "nsILocalFileMac.h"
 #  include "nsCommandLineServiceMac.h"
 #endif
 
 // for X remote support
 #if defined(MOZ_WIDGET_GTK)
 #  include "XRemoteClient.h"
-#  include "nsIRemoteService.h"
+#  include "nsRemoteService.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
@@ -2920,17 +2920,17 @@ class XREMain {
   Result<bool, nsresult> CheckLastStartupWasCrash();
 
   nsCOMPtr<nsINativeAppSupport> mNativeApp;
   RefPtr<nsToolkitProfileService> mProfileSvc;
   nsCOMPtr<nsIFile> mProfD;
   nsCOMPtr<nsIFile> mProfLD;
   nsCOMPtr<nsIProfileLock> mProfileLock;
 #if defined(MOZ_WIDGET_GTK)
-  nsCOMPtr<nsIRemoteService> mRemoteService;
+  RefPtr<nsRemoteService> mRemoteService;
   nsProfileLock mRemoteLock;
   nsCOMPtr<nsIFile> mRemoteLockDir;
 #endif
 
   UniquePtr<ScopedXPCOMStartup> mScopedXPCOM;
   UniquePtr<XREAppData> mAppData;
 
   nsXREDirProvider mDirProvider;
@@ -4623,20 +4623,22 @@ nsresult XREMain::XRE_mainRun() {
 
     appStartup->GetShuttingDown(&mShuttingDown);
   }
 
   if (!mShuttingDown) {
 #if defined(MOZ_WIDGET_GTK)
     // if we have X remote support, start listening for requests on the
     // proxy window.
-    if (!mDisableRemote)
-      mRemoteService = do_GetService("@mozilla.org/toolkit/remote-service;1");
-    if (mRemoteService)
+    if (!mDisableRemote) {
+      mRemoteService = new nsRemoteService();
+    }
+    if (mRemoteService) {
       mRemoteService->Startup(mAppData->remotingName, mProfileName.get());
+    }
     if (mRemoteLockDir) {
       mRemoteLock.Unlock();
       mRemoteLock.Cleanup();
       mRemoteLockDir->Remove(false);
     }
 #endif /* MOZ_WIDGET_GTK */
 
     mNativeApp->Enable();
--- a/uriloader/exthandler/DBusHelpers.h
+++ b/uriloader/exthandler/DBusHelpers.h
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_DBusHelpers_h
 #define mozilla_DBusHelpers_h
 
 #include <dbus/dbus.h>
 #include "mozilla/UniquePtr.h"
+#include "mozilla/RefPtr.h"
 
 namespace mozilla {
 
 template <>
 struct RefPtrTraits<DBusMessage> {
   static void AddRef(DBusMessage* aMessage) {
     MOZ_ASSERT(aMessage);
     dbus_message_ref(aMessage);