From f6dc803f75ab587b9a9b494563d7a73e0efac4d4 Mon Sep 17 00:00:00 2001 From: "ginn.chen%sun.com" Date: Wed, 28 Sep 2005 06:52:32 +0000 Subject: [PATCH] Bug 58523 -P, -nosplash, -splash, -console, -ProfileManager, -installer switches (arguments) unable to launch anything other than the browser (mail does not open on startup) patch maker=brian.lu@sun.com r=neil sr=bryner git-svn-id: svn://10.0.0.236/trunk@181115 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpfe/bootstrap/nsAppRunner.cpp | 81 +++++++++---------- mozilla/xpfe/bootstrap/nsNativeAppSupport.h | 2 +- .../xpfe/bootstrap/nsNativeAppSupportOS2.cpp | 26 +----- .../xpfe/bootstrap/nsNativeAppSupportWin.cpp | 26 +----- 4 files changed, 42 insertions(+), 93 deletions(-) diff --git a/mozilla/xpfe/bootstrap/nsAppRunner.cpp b/mozilla/xpfe/bootstrap/nsAppRunner.cpp index 689867ef2b8..a0cbe721a1d 100644 --- a/mozilla/xpfe/bootstrap/nsAppRunner.cpp +++ b/mozilla/xpfe/bootstrap/nsAppRunner.cpp @@ -535,12 +535,8 @@ LaunchApplicationWithArgs(const char *commandLineArg, nsresult rv; - nsCOMPtr cmdLine = - do_GetService(NS_COMMANDLINESERVICE_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; - nsCOMPtr handler; - rv = cmdLine->GetHandlerForParam(aParam, getter_AddRefs(handler)); + rv = cmdLineArgs->GetHandlerForParam(aParam, getter_AddRefs(handler)); if (NS_FAILED(rv)) return rv; if (!handler) return NS_ERROR_FAILURE; @@ -640,7 +636,7 @@ static PRBool IsStartupCommand(const char *arg) // This should be done by app shell enumeration someday -nsresult DoCommandLines(nsICmdLineService* cmdLineArgs, PRBool heedGeneralStartupPrefs, PRBool *windowOpened) +nsresult DoCommandLines(nsICmdLineService* cmdLineArgs, PRBool *windowOpened) { NS_ENSURE_ARG(windowOpened); *windowOpened = PR_FALSE; @@ -661,21 +657,18 @@ nsresult DoCommandLines(nsICmdLineService* cmdLineArgs, PRBool heedGeneralStartu if (NS_SUCCEEDED(rv) && !tempString.IsEmpty()) PR_sscanf(tempString.get(), "%d", &height); - if (heedGeneralStartupPrefs) { - nsCOMPtr appStartup(do_GetService(NS_APPSTARTUP_CONTRACTID, &rv)); - if (NS_FAILED(rv)) return rv; - rv = appStartup->CreateStartupState(width, height, windowOpened); - if (NS_FAILED(rv)) return rv; - } - else { PRInt32 argc = 0; rv = cmdLineArgs->GetArgc(&argc); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; char **argv = nsnull; rv = cmdLineArgs->GetArgv(&argv); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; + // first apply command line args + // if there is any window opened, startup preferences are ignored PRInt32 i = 0; for (i=1;iGetURLToLoad(getter_Copies(urlToLoad)); + if (NS_SUCCEEDED(rv) && !urlToLoad.IsEmpty()) { + nsCOMPtr handler( + do_GetService("@mozilla.org/commandlinehandler/general-startup;1?type=browser")); + + nsXPIDLCString chromeUrlForTask; + rv = handler->GetChromeUrlForTask(getter_Copies(chromeUrlForTask)); + + if (NS_SUCCEEDED(rv)) { + // convert the cmdLine URL to Unicode + NS_ConvertUTF8toUTF16 url(urlToLoad); + rv = OpenWindow(chromeUrlForTask, url, width, height); + } + + if (NS_SUCCEEDED(rv)) { + *windowOpened = PR_TRUE; + } + } + + // third if no window is opened then apply the startup preferences + if (!*windowOpened) { + nsCOMPtr appStartup(do_GetService(NS_APPSTARTUP_CONTRACTID, &rv)); + if (NS_FAILED(rv)) + return rv; + rv = appStartup->CreateStartupState(width, height, windowOpened); + if (NS_FAILED(rv)) + return rv; } return NS_OK; } @@ -1153,35 +1176,9 @@ static nsresult main1(int argc, char* argv[], nsISupports *nativeApp ) NS_TIMELINE_LEAVE("appStartup->CreateHiddenWindow"); // This will go away once Components are handling there own commandlines - // if we have no command line arguments, we need to heed the - // "general.startup.*" prefs - // if we had no command line arguments, argc == 1. PRBool windowOpened = PR_FALSE; - PRBool defaultStartup; -#if defined(XP_MAC) || defined(XP_MACOSX) - // On Mac, nsCommandLineServiceMac may have added synthetic - // args. Check this adjusted value instead of the raw value. - PRInt32 processedArgc; - cmdLineArgs->GetArgc(&processedArgc); - defaultStartup = (processedArgc == 1); -#if defined(XP_MACOSX) - // On OSX, we get passed two args if double-clicked from the Finder. - // The second is our PSN. Check for this and consider it to be default. - if (argc == 2 && processedArgc == 2) { - ProcessSerialNumber ourPSN; - if (::MacGetCurrentProcess(&ourPSN) == noErr) { - char argBuf[64]; - sprintf(argBuf, "-psn_%ld_%ld", ourPSN.highLongOfPSN, ourPSN.lowLongOfPSN); - if (!strcmp(argBuf, argv[1])) - defaultStartup = PR_TRUE; - } - } -#endif /* XP_MACOSX */ -#else - defaultStartup = (argc == 1); -#endif - rv = DoCommandLines(cmdLineArgs, defaultStartup, &windowOpened); + rv = DoCommandLines(cmdLineArgs, &windowOpened); if (NS_FAILED(rv)) { NS_WARNING("failed to process command line"); diff --git a/mozilla/xpfe/bootstrap/nsNativeAppSupport.h b/mozilla/xpfe/bootstrap/nsNativeAppSupport.h index 3715d3a7afb..e7a2803625b 100644 --- a/mozilla/xpfe/bootstrap/nsNativeAppSupport.h +++ b/mozilla/xpfe/bootstrap/nsNativeAppSupport.h @@ -46,5 +46,5 @@ nsresult NS_CreateNativeAppSupport( nsINativeAppSupport **aResult ); // This function is implemented in nsAppRunner.cpp and called from there and // from nsNativeAppSupportWin.cpp. -nsresult DoCommandLines(nsICmdLineService* cmdLine, PRBool heedGeneralStartupPrefs, PRBool *windowOpened); +nsresult DoCommandLines(nsICmdLineService* cmdLine, PRBool *windowOpened); diff --git a/mozilla/xpfe/bootstrap/nsNativeAppSupportOS2.cpp b/mozilla/xpfe/bootstrap/nsNativeAppSupportOS2.cpp index 6c6e43deea0..5dfe697a4d8 100644 --- a/mozilla/xpfe/bootstrap/nsNativeAppSupportOS2.cpp +++ b/mozilla/xpfe/bootstrap/nsNativeAppSupportOS2.cpp @@ -1948,32 +1948,8 @@ nsNativeAppSupportOS2::HandleRequest( LPBYTE request, PRBool newWindow, nsIDOMWi // This will tell us whether the command line processing opened a window. PRBool windowOpened = PR_FALSE; - // If there are no command line arguments, then we want to open windows - // based on startup prefs (which say to open navigator and/or mailnews - // and/or composer), or, open just a Navigator window. We do the former - // if there are no open windows (i.e., we're in turbo mode), the latter - // if there are open windows. Note that we call DoCommandLines in the - // case where there are no command line args but there are windows open - // (i.e., with heedStartupPrefs==PR_FALSE) despite the fact that it may - // not actually do anything in that case. That way we're covered if the - // logic in DoCommandLines changes. Note that we cover this case below - // by opening a navigator window if DoCommandLines doesn't open one. We - // have to cover that case anyway, because DoCommandLines won't open a - // window when given "seamonkey -foobar" or the like. - PRBool heedStartupPrefs = PR_FALSE; - PRInt32 argc = 0; - args->GetArgc( &argc ); - if ( argc <= 1 ) { - // Use startup prefs iff there are no windows currently open. - nsCOMPtr win; - GetMostRecentWindow( 0, getter_AddRefs( win ) ); - if ( !win ) { - heedStartupPrefs = PR_TRUE; - } - } - // Process command line options. - rv = DoCommandLines( args, heedStartupPrefs, &windowOpened ); + rv = DoCommandLines( args, &windowOpened ); // If a window was opened, then we're done. // Note that we keep on trying in the unlikely event of an error. diff --git a/mozilla/xpfe/bootstrap/nsNativeAppSupportWin.cpp b/mozilla/xpfe/bootstrap/nsNativeAppSupportWin.cpp index 03664b2fd0e..9cb05f750b5 100644 --- a/mozilla/xpfe/bootstrap/nsNativeAppSupportWin.cpp +++ b/mozilla/xpfe/bootstrap/nsNativeAppSupportWin.cpp @@ -1887,32 +1887,8 @@ nsNativeAppSupportWin::HandleRequest( LPBYTE request, PRBool newWindow, nsIDOMWi // This will tell us whether the command line processing opened a window. PRBool windowOpened = PR_FALSE; - // If there are no command line arguments, then we want to open windows - // based on startup prefs (which say to open navigator and/or mailnews - // and/or composer), or, open just a Navigator window. We do the former - // if there are no open windows (i.e., we're in turbo mode), the latter - // if there are open windows. Note that we call DoCommandLines in the - // case where there are no command line args but there are windows open - // (i.e., with heedStartupPrefs==PR_FALSE) despite the fact that it may - // not actually do anything in that case. That way we're covered if the - // logic in DoCommandLines changes. Note that we cover this case below - // by opening a navigator window if DoCommandLines doesn't open one. We - // have to cover that case anyway, because DoCommandLines won't open a - // window when given "seamonkey -foobar" or the like. - PRBool heedStartupPrefs = PR_FALSE; - PRInt32 argc = 0; - args->GetArgc( &argc ); - if ( argc <= 1 ) { - // Use startup prefs iff there are no windows currently open. - nsCOMPtr win; - GetMostRecentWindow( 0, getter_AddRefs( win ) ); - if ( !win ) { - heedStartupPrefs = PR_TRUE; - } - } - // Process command line options. - rv = DoCommandLines( args, heedStartupPrefs, &windowOpened ); + rv = DoCommandLines( args, &windowOpened ); // If a window was opened, then we're done. // Note that we keep on trying in the unlikely event of an error.