Bug 1355147 - Change Firefox to a background application when headless. r=mstange
authorBrendan Dahl <brendan.dahl@gmail.com>
Thu, 06 Jul 2017 13:46:33 -0700
changeset 422845 a9e070c60d4b27ec494cf9d4955ec0a444803c1c
parent 422844 19854c39011d6650b0e70f6ff8e8f27999c18c02
child 422846 c18686139dbd358532c4e8becb1f56bb272052ac
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1355147
milestone56.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 1355147 - Change Firefox to a background application when headless. r=mstange To avoid headless Firefox creating an icon in the dock and taking focus away from the terminal, it is now changed to a background app on startup. MozReview-Commit-ID: DyKk0Zxq0Uq
toolkit/xre/nsAppRunner.cpp
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -3173,16 +3173,28 @@ XREMain::XRE_mainInit(bool* aExitFlag)
 
   if (gfxPlatform::IsHeadless()) {
 #if defined(XP_WIN) || defined(MOZ_WIDGET_GTK) || defined(XP_MACOSX)
     printf_stderr("*** You are running in headless mode.\n");
 #else
     Output(true, "Error: headless mode is not currently supported on this platform.\n");
     return 1;
 #endif
+
+#ifdef XP_MACOSX
+    // To avoid taking focus when running in headless mode immediately
+    // transition Firefox to a background application.
+    ProcessSerialNumber psn = { 0, kCurrentProcess };
+    OSStatus transformStatus = TransformProcessType(&psn, kProcessTransformToBackgroundApplication);
+    if (transformStatus != noErr) {
+      NS_ERROR("Failed to make process a background application.");
+      return 1;
+    }
+#endif
+
   }
 
   nsresult rv;
   ArgResult ar;
 
 #ifdef DEBUG
   if (PR_GetEnv("XRE_MAIN_BREAK"))
     NS_BREAK();