nsCOMPtr<nsIAppShellService> appShell(do_GetService("@mozilla.org/appshell/appShellService;1")); nsCOMPtr <nsICmdLineService> cmdLine(do_GetService("@mozilla.org/appshell/commandLineService;1")); if (appShell && cmdLine) { nsCOMPtr<nsINativeAppSupport> nativeApp; if (NS_SUCCEEDED(appShell->GetNativeAppSupport(getter_AddRefs(nativeApp)))) {     if (NS_FAILED(nativeApp->EnsureProfile(cmdLine))) return NS_ERROR_NOT_INITIALIZED; } }
static nsresult OpenWindow(const nsAFlatCString& aChromeURL,                           const nsAFlatString& aAppArgs,                           PRInt32 aWidth, PRInt32 aHeight){#ifdef DEBUG_CMD_LINE  printf("OpenWindow(%s, %s, %d, %d)\n", aChromeURL.get(),                                         NS_ConvertUCS2toUTF8(aAppArgs).get(),                                         aWidth, aHeight);#endif /* DEBUG_CMD_LINE */  nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));  nsCOMPtr<nsISupportsWString> sarg(do_CreateInstance(NS_SUPPORTS_WSTRING_CONTRACTID));  if (!wwatch || !sarg)    return NS_ERROR_FAILURE;  sarg->SetData(aAppArgs.get());  nsCAutoString features("chrome,dialog=no,all");  if (aHeight != nsIAppShellService::SIZE_TO_CONTENT) {    features.Append(",height=");    features.AppendInt(aHeight);  }  if (aWidth != nsIAppShellService::SIZE_TO_CONTENT) {    features.Append(",width=");    features.AppendInt(aWidth);  }#ifdef DEBUG_CMD_LINE  printf("features: %s...\n", features.get());#endif /* DEBUG_CMD_LINE */  nsCOMPtr<nsIDOMWindow> newWindow;  return wwatch->OpenWindow(0, aChromeURL.get(), "_blank",                            features.get(), sarg,                            getter_AddRefs(newWindow));}