Bug 1511080: Add launcher process pref and enable reflection to/from the registry; r=mhowell
authorAaron Klotz <aklotz@mozilla.com>
Tue, 15 Jan 2019 23:14:49 +0000
changeset 513987 d1dbe1bc3e9498f841231601e1b4433a23ee4dab
parent 513986 73e3a031b232f16866c02598fb72c951d998a211
child 513988 b46d5d689c8dcf861537da5f9d6bec81e073c910
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmhowell
bugs1511080
milestone66.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 1511080: Add launcher process pref and enable reflection to/from the registry; r=mhowell Differential Revision: https://phabricator.services.mozilla.com/D15757
browser/app/profile/firefox.js
toolkit/xre/nsAppRunner.cpp
toolkit/xre/nsAppRunner.h
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1789,8 +1789,13 @@ pref("browser.discovery.containers.enabl
 pref("browser.discovery.sites", "addons.mozilla.org");
 
 pref("browser.engagement.recent_visited_origins.expiry", 86400); // 24 * 60 * 60 (24 hours in seconds)
 
 // Show the warning page for the new about config. Will replace general.warnOnAboutConfig.
 #ifdef NIGHTLY_BUILD
 pref("browser.aboutConfig.showWarning", true);
 #endif
+
+#if defined(XP_WIN) && defined(MOZ_LAUNCHER_PROCESS)
+// Launcher process is disabled by default, will be selectively enabled via SHIELD
+pref("browser.launcherProcess.enabled", false);
+#endif // defined(XP_WIN) && defined(MOZ_LAUNCHER_PROCESS)
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -105,16 +105,20 @@
 #include <intrin.h>
 #include <math.h>
 #include "cairo/cairo-features.h"
 #include "mozilla/WindowsDllBlocklist.h"
 #include "mozilla/WinHeaderOnlyUtils.h"
 #include "mozilla/mscom/MainThreadRuntime.h"
 #include "mozilla/widget/AudioSession.h"
 
+#if defined(MOZ_LAUNCHER_PROCESS)
+#include "mozilla/LauncherRegistryInfo.h"
+#endif
+
 #ifndef PROCESS_DEP_ENABLE
 #define PROCESS_DEP_ENABLE 0x1
 #endif
 #endif
 
 #if defined(MOZ_CONTENT_SANDBOX)
 #include "mozilla/SandboxSettings.h"
 #if (defined(XP_WIN) || defined(XP_MACOSX))
@@ -1623,16 +1627,47 @@ static void RegisterApplicationRestartCh
       // should be restarted if terminated by an update or restart.
       ::RegisterApplicationRestart(restartCommandLine.get(),
                                    RESTART_NO_CRASH | RESTART_NO_HANG);
     }
   } else if (wasRegistered) {
     ::UnregisterApplicationRestart();
   }
 }
+
+#if defined(MOZ_LAUNCHER_PROCESS)
+
+static void OnLauncherPrefChanged(const char* aPref, void* aData) {
+  bool prefVal = Preferences::GetBool(PREF_WIN_LAUNCHER_PROCESS_ENABLED, false);
+
+  mozilla::LauncherRegistryInfo launcherRegInfo;
+  mozilla::LauncherVoidResult reflectResult =
+      launcherRegInfo.ReflectPrefToRegistry(prefVal);
+  MOZ_ASSERT(reflectResult.isOk());
+}
+
+static void SetupLauncherProcessPref() {
+  mozilla::LauncherRegistryInfo launcherRegInfo;
+
+  mozilla::LauncherResult<mozilla::LauncherRegistryInfo::EnabledState>
+      enabledState = launcherRegInfo.IsEnabled();
+
+  if (enabledState.isOk()) {
+    Preferences::SetBool(
+        PREF_WIN_LAUNCHER_PROCESS_ENABLED,
+        enabledState.unwrap() !=
+            mozilla::LauncherRegistryInfo::EnabledState::ForceDisabled);
+  }
+
+  Preferences::RegisterCallback(&OnLauncherPrefChanged,
+                                PREF_WIN_LAUNCHER_PROCESS_ENABLED);
+}
+
+#endif  // defined(MOZ_LAUNCHER_PROCESS)
+
 #endif  // XP_WIN
 
 // If aBlankCommandLine is true, then the application will be launched with a
 // blank command line instead of being launched with the same command line that
 // it was initially started with.
 static nsresult LaunchChild(nsINativeAppSupport* aNative,
                             bool aBlankCommandLine = false) {
   aNative->Quit();  // release DDE mutex, if we're holding it
@@ -4225,16 +4260,19 @@ nsresult XREMain::XRE_mainRun() {
 
   if (!mShuttingDown) {
     rv = appStartup->CreateHiddenWindow();
     NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
 
 #ifdef XP_WIN
     Preferences::RegisterCallbackAndCall(RegisterApplicationRestartChanged,
                                          PREF_WIN_REGISTER_APPLICATION_RESTART);
+#if defined(MOZ_LAUNCHER_PROCESS)
+    SetupLauncherProcessPref();
+#endif  // defined(MOZ_LAUNCHER_PROCESS)
 #endif
 
 #if defined(HAVE_DESKTOP_STARTUP_ID) && defined(MOZ_WIDGET_GTK)
     nsGTKToolkit* toolkit = nsGTKToolkit::GetToolkit();
     if (toolkit && !mDesktopStartupID.IsEmpty()) {
       toolkit->SetDesktopStartupID(mDesktopStartupID);
     }
     // Clear the environment variable so it won't be inherited by
--- a/toolkit/xre/nsAppRunner.h
+++ b/toolkit/xre/nsAppRunner.h
@@ -97,16 +97,20 @@ void MozExpectedExit();
 #ifdef XP_WIN
 void UseParentConsole();
 
 BOOL WinLaunchChild(const wchar_t* exePath, int argc, char** argv,
                     HANDLE userToken = nullptr, HANDLE* hProcess = nullptr);
 
 #define PREF_WIN_REGISTER_APPLICATION_RESTART \
   "toolkit.winRegisterApplicationRestart"
+
+#if defined(MOZ_LAUNCHER_PROCESS)
+#define PREF_WIN_LAUNCHER_PROCESS_ENABLED "browser.launcherProcess.enabled"
+#endif  // defined(MOZ_LAUNCHER_PROCESS)
 #endif
 
 namespace mozilla {
 namespace startup {
 Result<nsCOMPtr<nsIFile>, nsresult> GetIncompleteStartupFile(nsIFile* aProfLD);
 
 extern GeckoProcessType sChildProcessType;
 }  // namespace startup