nsAppShellService::JustCreateTopWindow(nsIXULWindow *aParent,
nsAppShellService::JustCreateTopWindow(nsIWebShellWindow *aParent,
nsAppShellService::JustCreateTopWindow(nsIXULWindow *aParent,                                 nsIURI *aUrl,                                  PRBool aShowWindow, PRBool aLoadDefaultPage,                                 PRUint32 aChromeMask,                                 PRInt32 aInitialWidth, PRInt32 aInitialHeight,                                 PRBool aIsHiddenWindow, nsIXULWindow **aResult){  nsresult rv;  nsWebShellWindow* window;  PRBool intrinsicallySized;  PRUint32 zlevel;  *aResult = nsnull;  intrinsicallySized = PR_FALSE;  window = new nsWebShellWindow();  // Bump count to one so it doesn't die on us while doing init.  nsCOMPtr<nsIXULWindow> tempRef(window);   if (!window)    rv = NS_ERROR_OUT_OF_MEMORY;  else {    nsWidgetInitData widgetInitData;#if TARGET_CARBON    if (aIsHiddenWindow)      widgetInitData.mWindowType = eWindowType_invisible;    else#endif      widgetInitData.mWindowType = aChromeMask & nsIWebBrowserChrome::CHROME_OPENAS_DIALOG ?                                    eWindowType_dialog : eWindowType_toplevel;    // note default chrome overrides other OS chrome settings, but    // not internal chrome    if (aChromeMask & nsIWebBrowserChrome::CHROME_DEFAULT)      widgetInitData.mBorderStyle = eBorderStyle_default;    else if ((aChromeMask & nsIWebBrowserChrome::CHROME_ALL) == nsIWebBrowserChrome::CHROME_ALL)      widgetInitData.mBorderStyle = eBorderStyle_all;    else {      widgetInitData.mBorderStyle = eBorderStyle_none; // assumes none == 0x00      if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_BORDERS)        widgetInitData.mBorderStyle = NS_STATIC_CAST(enum nsBorderStyle, widgetInitData.mBorderStyle | eBorderStyle_border);      if (aChromeMask & nsIWebBrowserChrome::CHROME_TITLEBAR)        widgetInitData.mBorderStyle = NS_STATIC_CAST(enum nsBorderStyle, widgetInitData.mBorderStyle | eBorderStyle_title);      if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_CLOSE)        widgetInitData.mBorderStyle = NS_STATIC_CAST(enum nsBorderStyle, widgetInitData.mBorderStyle | eBorderStyle_close);      if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_RESIZE) {        widgetInitData.mBorderStyle = NS_STATIC_CAST(enum nsBorderStyle, widgetInitData.mBorderStyle | eBorderStyle_resizeh);        /* Associate the resize flag with min/max buttons and system menu.           but not for dialogs. This is logic better associated with the           platform implementation, and partially covered by the           eBorderStyle_default style. But since I know of no platform           that wants min/max buttons on dialogs, it works here, too.           If you have such a platform, this is where the fun starts: */        if (!(aChromeMask & nsIWebBrowserChrome::CHROME_OPENAS_DIALOG))          widgetInitData.mBorderStyle = NS_STATIC_CAST(enum nsBorderStyle, widgetInitData.mBorderStyle | eBorderStyle_minimize | eBorderStyle_maximize | eBorderStyle_menu);      }      // Min button only?      if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_MIN) {        widgetInitData.mBorderStyle = NS_STATIC_CAST(enum nsBorderStyle, widgetInitData.mBorderStyle | eBorderStyle_minimize );      }      }    zlevel = nsIXULWindow::normalZ;    if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_RAISED)      zlevel = nsIXULWindow::raisedZ;    else if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_LOWERED)      zlevel = nsIXULWindow::loweredZ;#ifdef XP_MAC    /* Platforms on which modal windows are always application-modal, not       window-modal (that's just the Mac, right) want modal windows to       be stacked on top of everyone else. */    zlevel = nsIXULWindow::highestZ;#else    /* Platforms with native support for dependent windows (that's everyone       but the Mac, right?) know how to stack dependent windows. On these       platforms, give the dependent window the same level as its parent,       so we won't try to override the normal platform behaviour. */    if ((aChromeMask & nsIWebBrowserChrome::CHROME_DEPENDENT) && aParent)      aParent->GetZlevel(&zlevel);#endif    if (aInitialWidth == NS_SIZETOCONTENT ||        aInitialHeight == NS_SIZETOCONTENT) {      aInitialWidth = 1;      aInitialHeight = 1;      intrinsicallySized = PR_TRUE;      window->SetIntrinsicallySized(PR_TRUE);    }    rv = window->Initialize(aParent, mAppShell, aUrl,                            aShowWindow, aLoadDefaultPage, zlevel,                            aInitialWidth, aInitialHeight, aIsHiddenWindow, widgetInitData);          if (NS_SUCCEEDED(rv)) {      // this does the AddRef of the return value      rv = CallQueryInterface(NS_STATIC_CAST(nsIWebShellWindow*, window), aResult);      if (aParent)        aParent->AddChildWindow(*aResult);    }    if (aChromeMask & nsIWebBrowserChrome::CHROME_CENTER_SCREEN)      window->Center(nsnull, PR_TRUE, PR_FALSE);  }  return rv;}