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
--- 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();