Backing out bug 58523 because it didn't handle bare URLs on the command line

This commit is contained in:
neil%parkwaycc.co.uk 2005-03-02 12:44:53 +00:00
Родитель 12d7b90a92
Коммит 0d2af9150a
3 изменённых файлов: 89 добавлений и 43 удалений

Просмотреть файл

@ -728,51 +728,56 @@ 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);
//first apply command line options
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;
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])) {
// skip over the - (or / on windows)
char *command = argv[i] + 1;
if (IsStartupCommand(argv[i])) {
// 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] == '-')) {
// 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
@ -781,19 +786,9 @@ nsresult DoCommandLines(nsICmdLineService* cmdLineArgs, PRBool *windowOpened)
height, width, windowOpened);
if (rv == NS_ERROR_NOT_AVAILABLE || rv == NS_ERROR_ABORT)
return rv;
}
}
}
}
// second if no window 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;
}
@ -1245,8 +1240,36 @@ static nsresult main1(int argc, char* argv[], nsISupports *nativeApp )
appStartup->CreateHiddenWindow();
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");

Просмотреть файл

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

Просмотреть файл

@ -1835,9 +1835,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 "mozilla -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.