nsAppShellService::UnregisterTopLevelWindow(nsIXULWindow* aWindow)
nsAppShellService::UnregisterTopLevelWindow(nsIWebShellWindow* aWindow)
nsAppShellService::UnregisterTopLevelWindow(nsIXULWindow* aWindow){  PRBool windowsRemain = PR_TRUE;  if (mDeleteCalled) {    /* return an error code in order to:       - avoid doing anything with other member variables while we are in         the destructor       - notify the caller not to release the AppShellService after         unregistering the window         (we don't want to be deleted twice consecutively to         mHiddenWindow->Close() in our destructor)    */    return NS_ERROR_FAILURE;  }    NS_ENSURE_ARG_POINTER(aWindow);  // tell the window mediator  if (mWindowMediator) {    nsCOMPtr<nsISimpleEnumerator> windowEnumerator;    mWindowMediator->UnregisterWindow(aWindow);    mWindowMediator->GetEnumerator(nsnull, getter_AddRefs(windowEnumerator));    if (windowEnumerator)      windowEnumerator->HasMoreElements(&windowsRemain);  }	  // tell the window watcher  if (mWindowWatcher) {    nsCOMPtr<nsIDocShell> docShell;    aWindow->GetDocShell(getter_AddRefs(docShell));    if (docShell) {      nsCOMPtr<nsIDOMWindow> domWindow(do_GetInterface(docShell));      if (domWindow)        mWindowWatcher->RemoveWindow(domWindow);    }  }  // now quit if the last window has been unregistered (unless we shouldn't)  if (!mQuitOnLastWindowClosing)    return NS_OK;  if (!windowsRemain) {      #if XP_MAC    // if no hidden window is available (perhaps due to initial    // Profile Manager window being cancelled), then just quit. We don't have    // to worry about focussing the hidden window, because it will get activated    // by the OS since it is visible (but waaaay offscreen).    nsCOMPtr<nsIBaseWindow> hiddenWin(do_QueryInterface(mHiddenWindow));    if (!hiddenWin)      Quit();#else    // Check to see if we should quit in this case.    if (mNativeAppSupport) {      PRBool serverMode = PR_FALSE;      mNativeAppSupport->GetIsServerMode(&serverMode);      if (serverMode) {        mNativeAppSupport->OnLastWindowClosing(aWindow);        return NS_OK;      }    }    Quit();#endif   }  return NS_OK;}