if (NS_SUCCEEDED(rv) && !arg.IsEmpty() ) {
if (NS_FAILED(rv)) return;  if (!arg.IsEmpty() ) {
nsNativeAppSupportWin::HandleRequest( LPBYTE request, PRBool newWindow, nsIDOMWindow **aResult ) {    // 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 NS_ERROR_FAILURE;    }    // Parse command line.    nsCOMPtr<nsICmdLineService> args;    nsresult rv;    rv = GetCmdLineArgs( request, getter_AddRefs( args ) );    if (NS_FAILED(rv)) return rv;    nsCOMPtr<nsIAppStartup> appStartup (do_GetService(NS_APPSTARTUP_CONTRACTID, &rv));    if (NS_FAILED(rv)) return rv;    nsCOMPtr<nsINativeAppSupport> nativeApp;    rv = appStartup->GetNativeAppSupport(getter_AddRefs( nativeApp ));    if (NS_FAILED(rv)) return rv;    // first see if there is a url    nsXPIDLCString arg;    rv = args->GetURLToLoad(getter_Copies(arg));    if (NS_SUCCEEDED(rv) && !arg.IsEmpty() ) {      // Launch browser.#if MOZ_DEBUG_DDE      printf( "Launching browser on url [%s]...\n", arg.get() );#endif      rv = nativeApp->EnsureProfile(args);      if (NS_SUCCEEDED(rv))        rv = OpenBrowserWindow( arg.get(), newWindow, aResult );      return rv;    }    // ok, let's try the -chrome argument    rv = args->GetCmdLineValue("-chrome", getter_Copies(arg));    if (NS_SUCCEEDED(rv) && !arg.IsEmpty() ) {      // Launch chrome.#if MOZ_DEBUG_DDE      printf( "Launching chrome url [%s]...\n", arg.get() );#endif      rv = nativeApp->EnsureProfile(args);      if (NS_SUCCEEDED(rv))        rv = OpenWindow( arg.get(), "", aResult );      return rv;    }    // 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) && !arg.IsEmpty() ) { // -profilemanager on command line      nsCOMPtr<nsIDOMWindowInternal> window;      GetMostRecentWindow(0, getter_AddRefs(window));      if (!window) { // there are no open windows        mForceProfileStartup = PR_TRUE;      }    }    // try for the "-kill" argument, to shut down the server    rv = args->GetCmdLineValue( "-kill", getter_Copies(arg));    if ( NS_SUCCEEDED(rv) && !arg.IsEmpty() ) {      // Turn off server mode.      nsCOMPtr<nsIAppStartup> appStartup        (do_GetService(NS_APPSTARTUP_CONTRACTID, &rv));      if (NS_FAILED(rv)) return rv;      nsCOMPtr<nsINativeAppSupport> native;      rv = appStartup->GetNativeAppSupport( getter_AddRefs( native ));      if (NS_SUCCEEDED(rv)) {        native->SetIsServerMode( PR_FALSE );        // close app if there are no more top-level windows.        rv = appStartup->Quit(nsIAppStartup::eConsiderQuit);      }      return rv;    }    // 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) && !arg.IsEmpty()) {      return nativeApp->EnsureProfile(args);    }    // 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 rv;    // This will tell us whether the command line processing opened a window.    PRBool windowOpened = PR_FALSE;    // Process command line options.    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.    if (rv == NS_ERROR_NOT_AVAILABLE || rv == NS_ERROR_ABORT || windowOpened) {      return NS_OK;    }    // 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 rv;    nsXPIDLString defaultArgs;    rv = handler->GetDefaultArgs(getter_Copies(defaultArgs));    if (NS_FAILED(rv) || defaultArgs.IsEmpty()) return rv;    NS_ConvertUTF16toUTF8 url( defaultArgs );    return OpenBrowserWindow(url.get(), newWindow, aResult);}