nsCOMPtr<nsICmdLineHandler> handler(do_GetService("@mozilla.org/commandlinehandler/general-startup;1?type=browser", &rv)); if (NS_FAILED(rv)) return rv;
nsNativeAppSupportOS2::OpenBrowserWindow( const char *args, PRBool newWindow ) {    nsresult rv = NS_OK;    // Open the argument URL in the most recently used Navigator window.    // If there is no Nav window, open a new one.    // Get most recently used Nav window.    nsCOMPtr<nsIDOMWindowInternal> navWin;    GetMostRecentWindow( NS_LITERAL_STRING( "navigator:browser" ).get(), getter_AddRefs( navWin ) );    // This isn't really a loop.  We just use "break" statements to fall    // out to the OpenWindow call when things go awry.    do {        // If caller requires a new window, then don't use an existing one.        if ( newWindow ) {            break;        }        if ( !navWin ) {            // Have to open a new one.            break;        }        // Get content window.        nsCOMPtr<nsIDOMWindow> content;        navWin->GetContent( getter_AddRefs( content ) );        if ( !content ) {            break;        }        // Convert that to internal interface.        nsCOMPtr<nsIDOMWindowInternal> internalContent( do_QueryInterface( content ) );        if ( !internalContent ) {            break;        }        // Get location.        nsCOMPtr<nsIDOMLocation> location;        internalContent->GetLocation( getter_AddRefs( location ) );        if ( !location ) {            break;        }        // Set up environment.        SafeJSContext context;        if ( NS_FAILED( context.Push() ) ) {            break;        }        // Set href.        nsAutoString url; url.AssignWithConversion( args );        if ( NS_FAILED( location->SetHref( url ) ) ) {            break;        }        // Finally, if we get here, we're done.        return NS_OK;    } while ( PR_FALSE );    nsCOMPtr<nsICmdLineHandler> handler(do_GetService("@mozilla.org/commandlinehandler/general-startup;1?type=browser", &rv));    if (NS_FAILED(rv)) return rv;    nsXPIDLCString chromeUrlForTask;    rv = handler->GetChromeUrlForTask(getter_Copies(chromeUrlForTask));    if (NS_FAILED(rv)) return rv;    // Last resort is to open a brand new window.    return OpenWindow( chromeUrlForTask, args );}