back out bug 58523 as it breaks windows seamonkey builds and has no approval.
git-svn-id: svn://10.0.0.236/trunk@172913 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
baf6570080
commit
95b4ed25bd
@ -558,8 +558,12 @@ LaunchApplicationWithArgs(const char *commandLineArg,
|
||||
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsICmdLineService> cmdLine =
|
||||
do_GetService(NS_COMMANDLINESERVICE_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr <nsICmdLineHandler> handler;
|
||||
rv = cmdLineArgs->GetHandlerForParam(aParam, getter_AddRefs(handler));
|
||||
rv = cmdLine->GetHandlerForParam(aParam, getter_AddRefs(handler));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (!handler) return NS_ERROR_FAILURE;
|
||||
@ -659,96 +663,67 @@ static PRBool IsStartupCommand(const char *arg)
|
||||
|
||||
|
||||
// This should be done by app shell enumeration someday
|
||||
nsresult DoCommandLines(nsICmdLineService* cmdLineArgs, PRBool *windowOpened)
|
||||
nsresult DoCommandLines(nsICmdLineService* cmdLineArgs, PRBool heedGeneralStartupPrefs, PRBool *windowOpened)
|
||||
{
|
||||
NS_ENSURE_ARG(windowOpened);
|
||||
*windowOpened = PR_FALSE;
|
||||
|
||||
nsresult rv;
|
||||
|
||||
PRInt32 height = nsIAppShellService::SIZE_TO_CONTENT;
|
||||
PRInt32 width = nsIAppShellService::SIZE_TO_CONTENT;
|
||||
nsXPIDLCString tempString;
|
||||
PRInt32 height = nsIAppShellService::SIZE_TO_CONTENT;
|
||||
PRInt32 width = nsIAppShellService::SIZE_TO_CONTENT;
|
||||
nsXPIDLCString tempString;
|
||||
|
||||
// Get the value of -width option
|
||||
rv = cmdLineArgs->GetCmdLineValue("-width", getter_Copies(tempString));
|
||||
if (NS_SUCCEEDED(rv) && !tempString.IsEmpty())
|
||||
// Get the value of -width option
|
||||
rv = cmdLineArgs->GetCmdLineValue("-width", getter_Copies(tempString));
|
||||
if (NS_SUCCEEDED(rv) && !tempString.IsEmpty())
|
||||
PR_sscanf(tempString.get(), "%d", &width);
|
||||
|
||||
// Get the value of -height option
|
||||
rv = cmdLineArgs->GetCmdLineValue("-height", getter_Copies(tempString));
|
||||
if (NS_SUCCEEDED(rv) && !tempString.IsEmpty())
|
||||
// Get the value of -height option
|
||||
rv = cmdLineArgs->GetCmdLineValue("-height", getter_Copies(tempString));
|
||||
if (NS_SUCCEEDED(rv) && !tempString.IsEmpty())
|
||||
PR_sscanf(tempString.get(), "%d", &height);
|
||||
|
||||
PRInt32 argc = 0;
|
||||
rv = cmdLineArgs->GetArgc(&argc);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
if (heedGeneralStartupPrefs) {
|
||||
nsCOMPtr<nsIAppStartup> 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;
|
||||
|
||||
char **argv = nsnull;
|
||||
rv = cmdLineArgs->GetArgv(&argv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
char **argv = nsnull;
|
||||
rv = cmdLineArgs->GetArgv(&argv);
|
||||
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;i<argc;i++) {
|
||||
PRInt32 i = 0;
|
||||
for (i=1;i<argc;i++) {
|
||||
#ifdef DEBUG_CMD_LINE
|
||||
printf("XXX argv[%d] = %s\n",i,argv[i]);
|
||||
printf("XXX argv[%d] = %s\n",i,argv[i]);
|
||||
#endif /* DEBUG_CMD_LINE */
|
||||
if (IsStartupCommand(argv[i])) {
|
||||
if (IsStartupCommand(argv[i])) {
|
||||
|
||||
// skip over the - (or / on windows)
|
||||
char *command = argv[i] + 1;
|
||||
// skip over the - (or / on windows)
|
||||
char *command = argv[i] + 1;
|
||||
#ifdef XP_UNIX
|
||||
// unix allows -mail and --mail
|
||||
if ((argv[i][0] == '-') && (argv[i][1] == '-')) {
|
||||
command = argv[i] + 2;
|
||||
}
|
||||
// unix allows -mail and --mail
|
||||
if ((argv[i][0] == '-') && (argv[i][1] == '-')) {
|
||||
command = argv[i] + 2;
|
||||
}
|
||||
#endif /* XP_UNIX */
|
||||
|
||||
// this can fail, as someone could do -foo, where -foo is not handled
|
||||
rv = LaunchApplicationWithArgs((const char *)(argv[i]),
|
||||
// this can fail, as someone could do -foo, where -foo is not handled
|
||||
rv = LaunchApplicationWithArgs((const char *)(argv[i]),
|
||||
cmdLineArgs, command,
|
||||
height, width, windowOpened);
|
||||
if (rv == NS_ERROR_NOT_AVAILABLE || rv == NS_ERROR_ABORT)
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
// second if an URL is given in the command line
|
||||
// then open a browser window with the URL
|
||||
nsXPIDLCString urlToLoad;
|
||||
rv = cmdLineArgs->GetURLToLoad(getter_Copies(urlToLoad));
|
||||
if (NS_SUCCEEDED(rv) && !urlToLoad.IsEmpty()) {
|
||||
nsAutoString url;
|
||||
nsXPIDLCString chromeUrlForTask;
|
||||
nsCOMPtr<nsICmdLineHandler> handler(
|
||||
do_GetService("@mozilla.org/commandlinehandler/general-startup;1?type=browser", &rv));
|
||||
|
||||
// convert the cmdLine URL to Unicode
|
||||
rv = NS_CopyNativeToUnicode(nsDependentCString(urlToLoad), url);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = handler->GetChromeUrlForTask(getter_Copies(chromeUrlForTask));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = OpenWindow(chromeUrlForTask, url, width, height);
|
||||
}
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
*windowOpened = PR_TRUE;
|
||||
if (rv == NS_ERROR_NOT_AVAILABLE || rv == NS_ERROR_ABORT)
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// third if no window is opened then apply the startup preferences
|
||||
if (!*windowOpened) {
|
||||
nsCOMPtr<nsIAppStartup> 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;
|
||||
}
|
||||
|
||||
@ -1201,15 +1176,42 @@ 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;
|
||||
rv = DoCommandLines(cmdLineArgs, &windowOpened);
|
||||
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);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
NS_WARNING("failed to process command line");
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (obsService)
|
||||
if (obsService)
|
||||
{
|
||||
NS_NAMED_LITERAL_STRING(userMessage, "Creating first window...");
|
||||
obsService->NotifyObservers(nsnull, "startup_user_notifcations", userMessage.get());
|
||||
|
||||
@ -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 *windowOpened);
|
||||
nsresult DoCommandLines(nsICmdLineService* cmdLine, PRBool heedGeneralStartupPrefs, PRBool *windowOpened);
|
||||
|
||||
|
||||
@ -1838,8 +1838,32 @@ nsNativeAppSupportWin::HandleRequest( LPBYTE request, PRBool newWindow ) {
|
||||
// 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<nsIDOMWindowInternal> win;
|
||||
GetMostRecentWindow( 0, getter_AddRefs( win ) );
|
||||
if ( !win ) {
|
||||
heedStartupPrefs = PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
// Process command line options.
|
||||
rv = DoCommandLines( args, &windowOpened );
|
||||
rv = DoCommandLines( args, heedStartupPrefs, &windowOpened );
|
||||
|
||||
// If a window was opened, then we're done.
|
||||
// Note that we keep on trying in the unlikely event of an error.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user