nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
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<nsISupportsString> sarg(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID));  if (!wwatch || !sarg)    return NS_ERROR_FAILURE;  // Make sure a profile is selected.  // We need the native app support object, which we get from  // the app shell service.  If this fails, we still proceed.  // That's because some platforms don't have a native app  // support implementation.  On those platforms, "ensuring a  // profile" is moot (because they don't support "-turbo",  // basically).  Specifically, because they don't do turbo, they will  // *always* have a profile selected.  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))))    {      // Make sure profile has been selected.      // At this point, we have to look for failure.  That      // handles the case where the user chooses "Exit" on      // the profile manager window.      if (NS_FAILED(nativeApp->EnsureProfile(cmdLine)))        return NS_ERROR_NOT_INITIALIZED;    }  }  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));}