if (mWindowWatcher) { nsCOMPtr<nsIDocShell> docShell; aWindow->GetDocShell(getter_AddRefs(docShell)); if (docShell) { nsCOMPtr<nsIDOMWindow> domWindow(do_GetInterface(docShell)); if (domWindow) mWindowWatcher->AddWindow(domWindow, 0); }
nsIWebShellContainer* wsc; rv = aWindow->QueryInterface(kIWebShellContainerIID, (void **) &wsc); if (NS_SUCCEEDED(rv)) { mWindowList->AppendElement(wsc); NS_RELEASE(wsc);  nsIWindowMediator* service; if (NS_SUCCEEDED(nsServiceManager::GetService(kWindowMediatorCID, kIWindowMediatorIID, (nsISupports**) &service ) ) ) { service->RegisterWindow( aWindow); nsServiceManager::ReleaseService(kWindowMediatorCID, service); }
nsAppShellService::RegisterTopLevelWindow(nsIXULWindow* aWindow){  // tell the window mediator about the new window  if (mWindowMediator)    mWindowMediator->RegisterWindow(aWindow);  // tell the window watcher about the new window  if (mWindowWatcher) {    nsCOMPtr<nsIDocShell> docShell;    aWindow->GetDocShell(getter_AddRefs(docShell));    if (docShell) {      nsCOMPtr<nsIDOMWindow> domWindow(do_GetInterface(docShell));      if (domWindow)        mWindowWatcher->AddWindow(domWindow, 0);    }  }  // an ongoing attempt to quit is stopped by a newly opened window  AttemptingQuit(PR_FALSE);  return NS_OK;}