rv = nativeApp->EnsureProfile(args); if (NS_FAILED(rv)) return;
nsNativeAppSupportWin::HandleRequest( LPBYTE request, PRBool newWindow ) {    // if initial hidden window is still being displayed, we need to ignore requests    // because such requests might not function properly.  See bug 147223 for details    if (mInitialWindowActive) {      return;    }    // Parse command line.    nsCOMPtr<nsICmdLineService> args;    nsresult rv;    rv = GetCmdLineArgs( request, getter_AddRefs( args ) );    if (NS_FAILED(rv)) return;    nsCOMPtr<nsIAppShellService> appShell(do_GetService("@mozilla.org/appshell/appShellService;1", &rv));    if (NS_FAILED(rv)) return;    nsCOMPtr<nsINativeAppSupport> nativeApp;    rv = appShell->GetNativeAppSupport(getter_AddRefs( nativeApp ));    if (NS_FAILED(rv)) return;    // first see if there is a url    nsXPIDLCString arg;    rv = args->GetURLToLoad(getter_Copies(arg));    if (NS_SUCCEEDED(rv) && (const char*)arg ) {      // Launch browser.#if MOZ_DEBUG_DDE      printf( "Launching browser on url [%s]...\n", (const char*)arg );#endif      if (NS_SUCCEEDED(nativeApp->EnsureProfile(args)))        (void)OpenBrowserWindow( arg, newWindow );      return;    }    // ok, let's try the -chrome argument    rv = args->GetCmdLineValue("-chrome", getter_Copies(arg));    if (NS_SUCCEEDED(rv) && (const char*)arg ) {      // Launch chrome.#if MOZ_DEBUG_DDE      printf( "Launching chrome url [%s]...\n", (const char*)arg );#endif      if (NS_SUCCEEDED(nativeApp->EnsureProfile(args)))        (void)OpenWindow( arg, "" );      return;    }    // try for the "-profilemanager" argument, in which case we want the    // profile manager to appear, but only if there are no windows open    rv = args->GetCmdLineValue( "-profilemanager", getter_Copies(arg));    if ( NS_SUCCEEDED(rv) && (const char*)arg ) { // -profilemanager on command line      nsCOMPtr<nsIDOMWindowInternal> window;      GetMostRecentWindow(0, getter_AddRefs(window));      if (!window) { // there are no open windows        mForceProfileStartup = PR_TRUE;      }    }#ifdef MOZ_THUNDERBIRD    // check wheather it is a MAPI request.  If yes, don't open any new    // windows and just return.    rv = args->GetCmdLineValue(MAPI_STARTUP_ARG, getter_Copies(arg));    if (NS_SUCCEEDED(rv) && (const char*)arg) {      nativeApp->EnsureProfile(args);      return;    }#endif    // Try standard startup's command-line handling logic from nsAppRunner.cpp...    // Need profile before opening windows.    rv = nativeApp->EnsureProfile(args);    if (NS_FAILED(rv)) return;    // 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, heedStartupPrefs, &windowOpened );    // If a window was opened, then we're done.    // Note that we keep on trying in the unlikely event of an error.    if (rv == NS_ERROR_NOT_AVAILABLE || rv == NS_ERROR_ABORT || windowOpened) {      return;    }    // ok, no idea what the param is.#if MOZ_DEBUG_DDE    printf( "Unknown request [%s]\n", (char*) request );#endif    // if all else fails, open a browser window    const char * const contractID =      "@mozilla.org/commandlinehandler/general-startup;1?type=browser";    nsCOMPtr<nsICmdLineHandler> handler = do_GetService(contractID, &rv);    if (NS_FAILED(rv)) return;    nsXPIDLString defaultArgs;    rv = handler->GetDefaultArgs(getter_Copies(defaultArgs));    if (NS_FAILED(rv) || !defaultArgs) return;    if (defaultArgs) {      nsCAutoString url;      url.AssignWithConversion( defaultArgs );      OpenBrowserWindow(url.get());    } else {      OpenBrowserWindow("about:blank");    }}