Bug 1518639: Add boilerplate support for a windows remote client and server. r=jimm,froydnj
☠☠ backed out by 3d8dd3615c45 ☠ ☠
authorDave Townsend <dtownsend@oxymoronical.com>
Wed, 06 Feb 2019 11:09:06 -0800
changeset 462608 276ca640adc8ff16ff3ff7252e8aa5016205b1e0
parent 462607 73ca9a68d7714e9bfc4d4ed59c8dda5ffdc3cd86
child 462609 4ef3cc37f719d02443a2058192fdb4c61d3e3dca
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, froydnj
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: Add boilerplate support for a windows remote client and server. r=jimm,froydnj Adds build config and stubs for a windows implementation of the remote client and server. Differential Revision: https://phabricator.services.mozilla.com/D19074
toolkit/components/moz.build
toolkit/components/remote/moz.build
toolkit/components/remote/nsRemoteService.cpp
toolkit/components/remote/nsWinRemoteClient.cpp
toolkit/components/remote/nsWinRemoteClient.h
toolkit/components/remote/nsWinRemoteServer.cpp
toolkit/components/remote/nsWinRemoteServer.h
toolkit/moz.configure
toolkit/xre/moz.build
toolkit/xre/nsAppRunner.cpp
--- a/toolkit/components/moz.build
+++ b/toolkit/components/moz.build
@@ -3,17 +3,17 @@
 # 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', 'General')
 
 # These component dirs are built for all apps (including suite)
-if 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT']:
+if CONFIG['MOZ_HAS_REMOTE']:
     DIRS += ['remote']
 
 DIRS += [
     'aboutcache',
     'aboutcheckerboard',
     'aboutmemory',
     'aboutperformance',
     'alerts',
--- a/toolkit/components/remote/moz.build
+++ b/toolkit/components/remote/moz.build
@@ -22,12 +22,18 @@ if 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT']
     if CONFIG['MOZ_ENABLE_DBUS']:
         SOURCES += [
             'nsDBusRemoteClient.cpp',
             'nsDBusRemoteServer.cpp',
         ]
         CXXFLAGS += CONFIG['MOZ_DBUS_GLIB_CFLAGS']
     CXXFLAGS += CONFIG['TK_CFLAGS']
 
+if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
+    SOURCES += [
+        'nsWinRemoteClient.cpp',
+        'nsWinRemoteServer.cpp',
+    ]
+
 LOCAL_INCLUDES += [
     '../../profile',
 ]
 FINAL_LIBRARY = 'xul'
--- a/toolkit/components/remote/nsRemoteService.cpp
+++ b/toolkit/components/remote/nsRemoteService.cpp
@@ -12,16 +12,19 @@
 
 #ifdef MOZ_WIDGET_GTK
 #  include "nsGTKRemoteServer.h"
 #  include "nsXRemoteClient.h"
 #  ifdef MOZ_ENABLE_DBUS
 #    include "nsDBusRemoteServer.h"
 #    include "nsDBusRemoteClient.h"
 #  endif
+#elif defined(XP_WIN)
+#  include "nsWinRemoteServer.h"
+#  include "nsWinRemoteClient.h"
 #endif
 #include "nsRemoteService.h"
 
 #include "nsString.h"
 #include "nsServiceManagerUtils.h"
 #include "mozilla/ModuleUtils.h"
 #include "SpecialSystemDirectory.h"
 #include "mozilla/CmdLineAndEnvUtils.h"
@@ -97,16 +100,21 @@ RemoteResult nsRemoteService::StartClien
 #  if defined(MOZ_ENABLE_DBUS)
   if (!useX11Remote) {
     client = new nsDBusRemoteClient();
   }
 #  endif
   if (useX11Remote) {
     client = new nsXRemoteClient();
   }
+#elif defined(XP_WIN)
+  client = new nsWinRemoteClient();
+#else
+  return REMOTE_NOT_FOUND;
+#endif
 
   nsresult rv = client ? client->Init() : NS_ERROR_FAILURE;
   if (NS_FAILED(rv)) return REMOTE_NOT_FOUND;
 
   nsCString response;
   bool success = false;
   rv = client->SendCommandLine(mProgram.get(), mProfile.get(), gArgc, gArgv,
                                aDesktopStartupID, getter_Copies(response),
@@ -117,19 +125,16 @@ RemoteResult nsRemoteService::StartClien
   // 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;
 
   if (NS_FAILED(rv)) return REMOTE_NOT_FOUND;
 
   return REMOTE_FOUND;
-#else
-  return REMOTE_NOT_FOUND;
-#endif
 }
 
 void nsRemoteService::StartupServer() {
   if (mRemoteServer) {
     return;
   }
 
   if (mProfile.IsEmpty()) {
@@ -142,16 +147,20 @@ void nsRemoteService::StartupServer() {
 #  if defined(MOZ_ENABLE_DBUS)
   if (!useX11Remote) {
     mRemoteServer = MakeUnique<nsDBusRemoteServer>();
   }
 #  endif
   if (useX11Remote) {
     mRemoteServer = MakeUnique<nsGTKRemoteServer>();
   }
+#elif defined(XP_WIN)
+  mRemoteServer = MakeUnique<nsWinRemoteServer>();
+#else
+  return;
 #endif
 
   nsresult rv = mRemoteServer->Startup(mProgram.get(), mProfile.get());
 
   if (NS_FAILED(rv)) {
     mRemoteServer = nullptr;
     return;
   }
new file mode 100644
--- /dev/null
+++ b/toolkit/components/remote/nsWinRemoteClient.cpp
@@ -0,0 +1,20 @@
+/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:expandtab:shiftwidth=4:tabstop=4:
+ */
+/* 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 "nsWinRemoteClient.h"
+
+nsresult nsWinRemoteClient::Init() {
+  return NS_OK;
+}
+
+nsresult nsWinRemoteClient::SendCommandLine(const char *aProgram, const char *aProfile,
+                                            int32_t argc, char **argv,
+                                            const char *aDesktopStartupID,
+                                            char **aResponse, bool *aSucceeded) {
+  *aSucceeded = false;
+  return NS_OK;
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/components/remote/nsWinRemoteClient.h
@@ -0,0 +1,30 @@
+/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:expandtab:shiftwidth=4:tabstop=4:
+ */
+/* 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 nsWinRemoteClient_h__
+#define nsWinRemoteClient_h__
+
+#include "nscore.h"
+#include "nsRemoteClient.h"
+
+/**
+ * Pure-virtual common base class for remoting implementations.
+ */
+
+class nsWinRemoteClient : public nsRemoteClient {
+ public:
+  virtual ~nsWinRemoteClient() = default;
+
+  nsresult Init() override;
+
+  nsresult SendCommandLine(const char *aProgram, const char *aProfile,
+                           int32_t argc, char **argv,
+                           const char *aDesktopStartupID,
+                           char **aResponse, bool *aSucceeded) override;
+};
+
+#endif  // nsWinRemoteClient_h__
new file mode 100644
--- /dev/null
+++ b/toolkit/components/remote/nsWinRemoteServer.cpp
@@ -0,0 +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 "nsWinRemoteServer.h"
+
+nsresult nsWinRemoteServer::Startup(const char* aAppName,
+    const char* aProfileName) {
+  return NS_OK;
+}
+
+void nsWinRemoteServer::Shutdown() {
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/components/remote/nsWinRemoteServer.h
@@ -0,0 +1,22 @@
+/* -*- 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 __nsWinRemoteServer_h__
+#define __nsWinRemoteServer_h__
+
+#include "nsRemoteServer.h"
+
+class nsWinRemoteServer final : public nsRemoteServer {
+ public:
+  nsWinRemoteServer() = default;
+  ~nsWinRemoteServer() override = default;
+
+  nsresult Startup(const char* aAppName, const char* aProfileName) override;
+  void Shutdown() override;
+};
+
+#endif  // __nsWinRemoteService_h__
--- a/toolkit/moz.configure
+++ b/toolkit/moz.configure
@@ -1647,8 +1647,19 @@ with only_when(compile_environment & tar
             return namespace(name=name, path=path)
         die('Could not find {} {}'.format(name, error_extra))
 
 
     set_config('MOZ_ANGLE_RENDERER', True)
     set_config('MOZ_D3DCOMPILER_VISTA_DLL', d3d_compiler_dll.name,
                when=d3d_compiler_dll.path)
     set_config('MOZ_D3DCOMPILER_VISTA_DLL_PATH', d3d_compiler_dll.path)
+
+# Remoting protocol support
+# ==============================================================
+
+@depends(toolkit)
+def has_remote(toolkit):
+    if 'gtk' in toolkit or toolkit == 'windows':
+        return True
+
+set_config('MOZ_HAS_REMOTE', has_remote)
+set_define('MOZ_HAS_REMOTE', has_remote)
--- a/toolkit/xre/moz.build
+++ b/toolkit/xre/moz.build
@@ -86,25 +86,26 @@ 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_HAS_REMOTE']:
+    LOCAL_INCLUDES += [
+        '../components/remote',
+    ]
+
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gtk3':
     UNIFIED_SOURCES += [
         'nsGDKErrorHandler.cpp',
     ]
 
 if CONFIG['MOZ_X11']:
     EXPORTS += ['nsX11ErrorHandler.h']
     UNIFIED_SOURCES += [
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -182,25 +182,18 @@
 #endif
 
 #ifdef XP_MACOSX
 #  include "nsILocalFileMac.h"
 #  include "nsCommandLineServiceMac.h"
 #endif
 
 // for X remote support
-#if defined(MOZ_WIDGET_GTK)
-#  include "nsXRemoteClient.h"
+#if defined(MOZ_HAS_REMOTE)
 #  include "nsRemoteService.h"
-#  include "nsProfileLock.h"
-#  include "SpecialSystemDirectory.h"
-#  include <sched.h>
-#  ifdef MOZ_ENABLE_DBUS
-#    include "nsDBusRemoteClient.h"
-#  endif
 #endif
 
 #if defined(DEBUG) && defined(XP_WIN32)
 #  include <malloc.h>
 #endif
 
 #if defined(XP_MACOSX)
 #  include <Carbon/Carbon.h>
@@ -305,16 +298,19 @@ FuzzerRunner* fuzzerRunner = 0;
 
 #  ifdef LIBFUZZER
 void XRE_LibFuzzerSetDriver(LibFuzzerDriver aDriver) {
   mozilla::fuzzerRunner->setParams(aDriver);
 }
 #  endif
 #endif  // FUZZING
 
+// Undo X11/X.h's definition of None
+#undef None
+
 namespace mozilla {
 int (*RunGTest)(int*, char**) = 0;
 }  // namespace mozilla
 
 using namespace mozilla;
 using namespace mozilla::startup;
 using mozilla::Unused;
 using mozilla::dom::ContentChild;
@@ -2849,19 +2845,22 @@ bool fire_glxtest_process();
 #include "GeckoProfiler.h"
 
 // Encapsulates startup and shutdown state for XRE_main
 class XREMain {
  public:
   XREMain()
       : mStartOffline(false),
         mShuttingDown(false)
+#ifdef MOZ_HAS_REMOTE
+        ,
+        mDisableRemote(false)
+#endif
 #if defined(MOZ_WIDGET_GTK)
         ,
-        mDisableRemote(false),
         mGdkDisplay(nullptr)
 #endif
             {};
 
   ~XREMain() {
     mScopedXPCOM = nullptr;
     mAppData = nullptr;
   }
@@ -2873,29 +2872,29 @@ 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)
+#if defined(MOZ_HAS_REMOTE)
   RefPtr<nsRemoteService> mRemoteService;
 #endif
 
   UniquePtr<ScopedXPCOMStartup> mScopedXPCOM;
   UniquePtr<XREAppData> mAppData;
 
   nsXREDirProvider mDirProvider;
   nsAutoCString mDesktopStartupID;
 
   bool mStartOffline;
   bool mShuttingDown;
-#if defined(MOZ_WIDGET_GTK)
+#if defined(MOZ_HAS_REMOTE)
   bool mDisableRemote;
 #endif
 
 #if defined(MOZ_WIDGET_GTK)
   GdkDisplay* mGdkDisplay;
 #endif
 };
 
@@ -3401,24 +3400,24 @@ int XREMain::XRE_mainInit(bool* aExitFla
   if (ar == ARG_BAD) {
     PR_fprintf(PR_STDERR,
                "Error: argument --no-remote is invalid when argument --osint "
                "is specified\n");
     return 1;
   }
   if (ar == ARG_FOUND) {
     SaveToEnv("MOZ_NO_REMOTE=1");
-#ifdef MOZ_WIDGET_GTK
+#if defined(MOZ_HAS_REMOTE)
     mDisableRemote = true;
   } else if (EnvHasValue("MOZ_NO_REMOTE")) {
     mDisableRemote = true;
 #endif
   }
 
-#ifdef MOZ_WIDGET_GTK
+#if defined(MOZ_HAS_REMOTE)
   ar = CheckArg("new-instance", nullptr,
                 CheckArgFlag::CheckOSInt | CheckArgFlag::RemoveArg);
   if (ar == ARG_BAD) {
     PR_fprintf(PR_STDERR,
                "Error: argument --new-instance is invalid when argument "
                "--osint is specified\n");
     return 1;
   }
@@ -3817,16 +3816,22 @@ int XREMain::XRE_mainStartup(bool* aExit
     } else {
       result = 1;
       printf("TEST-UNEXPECTED-FAIL | gtest | Not compiled with enable-tests\n");
     }
     *aExitFlag = true;
     return result;
   }
 
+#ifdef MOZ_HAS_REMOTE
+  if (gfxPlatform::IsHeadless()) {
+    mDisableRemote = true;
+  }
+#endif
+
 #ifdef MOZ_X11
   // Init X11 in thread-safe mode. Must be called prior to the first call to
   // XOpenDisplay (called inside gdk_display_open). This is a requirement for
   // off main tread compositing.
   if (!gfxPlatform::IsHeadless()) {
     XInitThreads();
   }
 #endif
@@ -3887,21 +3892,19 @@ int XREMain::XRE_mainStartup(bool* aExit
       }
     }
 #  ifdef MOZ_WIDGET_GTK
     else {
       mGdkDisplay =
           gdk_display_manager_open_display(gdk_display_manager_get(), nullptr);
     }
 #  endif
-  } else {
-    mDisableRemote = true;
   }
 #endif
-#if defined(MOZ_WIDGET_GTK)
+#if defined(MOZ_HAS_REMOTE)
   // handle --remote now that xpcom is fired up
   if (!mDisableRemote) {
     mRemoteService = new nsRemoteService(gAppData->remotingName);
     if (mRemoteService) {
       mRemoteService->LockStartup();
     }
   }
 #endif
@@ -4020,17 +4023,17 @@ int XREMain::XRE_mainStartup(bool* aExit
   }
 
   if (NS_FAILED(rv)) {
     // We failed to choose or create profile - notify user and quit
     ProfileMissingDialog(mNativeApp);
     return 1;
   }
 
-#if defined(MOZ_WIDGET_GTK)
+#if defined(MOZ_HAS_REMOTE)
   if (mRemoteService) {
     // We want a unique profile name to identify the remote instance.
     nsCString profileName;
     if (profile) {
       rv = profile->GetName(profileName);
     }
     if (!profile || NS_FAILED(rv) || profileName.IsEmpty()) {
       // Couldn't get a name from the profile. Use the directory name?
@@ -4548,17 +4551,17 @@ nsresult XREMain::XRE_mainRun() {
   if (!mShuttingDown) {
     rv = cmdLine->Run();
     NS_ENSURE_SUCCESS_LOG(rv, NS_ERROR_FAILURE);
 
     appStartup->GetShuttingDown(&mShuttingDown);
   }
 
   if (!mShuttingDown) {
-#if defined(MOZ_WIDGET_GTK)
+#if defined(MOZ_HAS_REMOTE)
     // if we have X remote support, start listening for requests on the
     // proxy window.
     if (mRemoteService) {
       mRemoteService->StartupServer();
       mRemoteService->UnlockStartup();
     }
 #endif /* MOZ_WIDGET_GTK */
 
@@ -4756,17 +4759,17 @@ int XREMain::XRE_main(int argc, char* ar
     appInitiatedRestart = true;
 
     // We have an application restart don't do any shutdown checks here
     // In particular we don't want to poison IO for checking late-writes.
     gShutdownChecks = SCM_NOTHING;
   }
 
   if (!mShuttingDown) {
-#if defined(MOZ_WIDGET_GTK)
+#if defined(MOZ_HAS_REMOTE)
     // shut down the x remote proxy window
     if (mRemoteService) {
       mRemoteService->ShutdownServer();
     }
 #endif /* MOZ_WIDGET_GTK */
   }
 
   mScopedXPCOM = nullptr;