NS_ENSURE_ARG_POINTER(aWindow);   if (mWindowMediator) mWindowMediator->UnregisterWindow(aWindow);   if (mWindowWatcher) { nsCOMPtr<nsIDocShell> docShell; aWindow->GetDocShell(getter_AddRefs(docShell)); if (docShell) { nsCOMPtr<nsIDOMWindow> domWindow(do_GetInterface(docShell)); if (domWindow) mWindowWatcher->RemoveWindow(domWindow); } }  return NS_OK;
PRUint32 cnt; rv = mWindowList->Count(&cnt); if (NS_FAILED(rv)) return rv; if (0 == cnt) mAppShell->Exit(); return rv;
nsAppShellService::UnregisterTopLevelWindow(nsIXULWindow* aWindow){  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)    mWindowMediator->UnregisterWindow(aWindow);	  // 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);    }  }  return NS_OK;}