bug 369147, "Warning: unrecognized command line flag -foreground" on launch

r=josh
Don't add the '-foreground' flag to the list of command line arguments if we're not restarting,
since no-one outside of XRE_main knows how to handle it.
This commit is contained in:
Nickolay Ponomarev 2010-04-17 13:50:17 +04:00
parent a6560e18bb
commit db0525f091
4 changed files with 25 additions and 24 deletions

View File

@ -1714,7 +1714,7 @@ static nsresult LaunchChild(nsINativeAppSupport* aNative,
PR_SetEnv("MOZ_LAUNCHED_CHILD=1"); PR_SetEnv("MOZ_LAUNCHED_CHILD=1");
#if defined(XP_MACOSX) #if defined(XP_MACOSX)
SetupMacCommandLine(gRestartArgc, gRestartArgv); SetupMacCommandLine(gRestartArgc, gRestartArgv, PR_TRUE);
LaunchChildMac(gRestartArgc, gRestartArgv); LaunchChildMac(gRestartArgc, gRestartArgv);
#else #else
nsCOMPtr<nsILocalFile> lf; nsCOMPtr<nsILocalFile> lf;
@ -1919,7 +1919,7 @@ ShowProfileManager(nsIToolkitProfileService* aProfileSvc,
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
#ifdef XP_MACOSX #ifdef XP_MACOSX
SetupMacCommandLine(gRestartArgc, gRestartArgv); SetupMacCommandLine(gRestartArgc, gRestartArgv, PR_TRUE);
#endif #endif
#ifdef XP_WIN #ifdef XP_WIN
@ -2009,7 +2009,7 @@ ImportProfiles(nsIToolkitProfileService* aPService,
xpcom.RegisterProfileService(); xpcom.RegisterProfileService();
#ifdef XP_MACOSX #ifdef XP_MACOSX
SetupMacCommandLine(gRestartArgc, gRestartArgv); SetupMacCommandLine(gRestartArgc, gRestartArgv, PR_TRUE);
#endif #endif
nsCOMPtr<nsIProfileMigrator> migrator nsCOMPtr<nsIProfileMigrator> migrator
@ -3468,7 +3468,7 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
cmdLine = do_CreateInstance("@mozilla.org/toolkit/command-line;1"); cmdLine = do_CreateInstance("@mozilla.org/toolkit/command-line;1");
NS_ENSURE_TRUE(cmdLine, 1); NS_ENSURE_TRUE(cmdLine, 1);
SetupMacCommandLine(gArgc, gArgv); SetupMacCommandLine(gArgc, gArgv, PR_FALSE);
rv = cmdLine->Init(gArgc, gArgv, rv = cmdLine->Init(gArgc, gArgv,
workingDir, nsICommandLine::STATE_INITIAL_LAUNCH); workingDir, nsICommandLine::STATE_INITIAL_LAUNCH);
@ -3557,7 +3557,7 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
#endif #endif
#ifdef XP_MACOSX #ifdef XP_MACOSX
SetupMacCommandLine(gRestartArgc, gRestartArgv); SetupMacCommandLine(gRestartArgc, gRestartArgv, PR_TRUE);
#endif #endif
} }
} }

View File

@ -143,7 +143,7 @@ nsresult nsMacCommandLine::Initialize(int& argc, char**& argv)
return NS_OK; return NS_OK;
} }
void nsMacCommandLine::SetupCommandLine(int& argc, char**& argv) void nsMacCommandLine::SetupCommandLine(int& argc, char**& argv, PRBool forRestart)
{ {
// Initializes the command line from Apple Events and other sources, // Initializes the command line from Apple Events and other sources,
// as appropriate for OS X. // as appropriate for OS X.
@ -157,20 +157,21 @@ void nsMacCommandLine::SetupCommandLine(int& argc, char**& argv)
// Process Apple Events and put them into the arguments. // Process Apple Events and put them into the arguments.
Initialize(argc, argv); Initialize(argc, argv);
Boolean isForeground = PR_FALSE; if (forRestart) {
ProcessSerialNumber psnSelf, psnFront; Boolean isForeground = PR_FALSE;
ProcessSerialNumber psnSelf, psnFront;
// If the process will be relaunched, the child should be in the foreground // If the process will be relaunched, the child should be in the foreground
// if the parent is in the foreground. This will be communicated in a // if the parent is in the foreground. This will be communicated in a
// command-line argument to the child. Adding this argument is harmless // command-line argument to the child.
// if not relaunching. if (::GetCurrentProcess(&psnSelf) == noErr &&
if (::GetCurrentProcess(&psnSelf) == noErr && ::GetFrontProcess(&psnFront) == noErr &&
::GetFrontProcess(&psnFront) == noErr && ::SameProcess(&psnSelf, &psnFront, &isForeground) == noErr &&
::SameProcess(&psnSelf, &psnFront, &isForeground) == noErr && isForeground) {
isForeground) { // The process is currently in the foreground. The relaunched
// The process is currently in the foreground. The relaunched // process should come to the front, too.
// process should come to the front, too. AddToCommandLine("-foreground");
AddToCommandLine("-foreground"); }
} }
argc = mArgsUsed; argc = mArgsUsed;
@ -322,8 +323,8 @@ nsresult nsMacCommandLine::DispatchURLToNewBrowser(const char* url)
#pragma mark - #pragma mark -
void SetupMacCommandLine(int& argc, char**& argv) void SetupMacCommandLine(int& argc, char**& argv, PRBool forRestart)
{ {
nsMacCommandLine& cmdLine = nsMacCommandLine::GetMacCommandLine(); nsMacCommandLine& cmdLine = nsMacCommandLine::GetMacCommandLine();
return cmdLine.SetupCommandLine(argc, argv); return cmdLine.SetupCommandLine(argc, argv, forRestart);
} }

View File

@ -59,7 +59,7 @@ public:
~nsMacCommandLine(); ~nsMacCommandLine();
nsresult Initialize(int& argc, char**& argv); nsresult Initialize(int& argc, char**& argv);
void SetupCommandLine(int& argc, char**& argv); void SetupCommandLine(int& argc, char**& argv, PRBool forRestart);
nsresult AddToCommandLine(const char* inArgText); nsresult AddToCommandLine(const char* inArgText);
nsresult AddToCommandLine(const char* inOptionString, const CFURLRef file); nsresult AddToCommandLine(const char* inOptionString, const CFURLRef file);
@ -92,6 +92,6 @@ private:
}; };
void SetupMacCommandLine(int& argc, char**& argv); void SetupMacCommandLine(int& argc, char**& argv, PRBool forRestart);
#endif // nsCommandLineServiceMac_h_ #endif // nsCommandLineServiceMac_h_

View File

@ -542,7 +542,7 @@ ApplyUpdate(nsIFile *greDir, nsIFile *updateDir, nsILocalFile *statusFile,
goto end; goto end;
#ifdef XP_MACOSX #ifdef XP_MACOSX
SetupMacCommandLine(argc, argv); SetupMacCommandLine(argc, argv, PR_TRUE);
#endif #endif
PR_CreateProcessDetached(updaterPath.get(), argv, nsnull, attr); PR_CreateProcessDetached(updaterPath.get(), argv, nsnull, attr);