Bug 386810, Move quit-application-granted notification to nsAppStartup::Quit, r=benjamin
authorflamingice@sourmilk.net
Thu, 09 Aug 2007 20:05:53 -0700
changeset 4442 49f9ac08a39340043e2c010ff6a924b5629ca908
parent 4441 87589320dd4bb4f2ef2e8abd45f04e95bcd4d125
child 4443 c2cbfe888301063343ddb8e6c3a1b2fc14edf289
push idunknown
push userunknown
push dateunknown
reviewersbenjamin
bugs386810
milestone1.9a8pre
Bug 386810, Move quit-application-granted notification to nsAppStartup::Quit, r=benjamin
layout/tools/pageloader/quit.js
layout/tools/reftest/quit.js
testing/mochitest/tests/SimpleTest/quit.js
toolkit/components/startup/src/nsAppStartup.cpp
toolkit/content/globalOverlay.js
toolkit/mozapps/extensions/content/extensions.js
toolkit/mozapps/extensions/content/list.js
toolkit/mozapps/update/content/updates.js
toolkit/xre/MacApplicationDelegate.mm
toolkit/xre/nsCommandLineServiceMac.cpp
toolkit/xre/nsNativeAppSupportUnix.cpp
toolkit/xre/nsNativeAppSupportWin.cpp
--- a/layout/tools/pageloader/quit.js
+++ b/layout/tools/pageloader/quit.js
@@ -59,17 +59,16 @@ function canQuitApplication()
     if (cancelQuit.data)
     {
       return false;
     }
   }
   catch (ex) 
   {
   }
-  os.notifyObservers(null, "quit-application-granted", null);
   return true;
 }
 
 function goQuitApplication()
 {
   if (!canQuitApplication())
   {
     return false;
@@ -92,34 +91,16 @@ function goQuitApplication()
       getService(Components.interfaces.nsIAppShellService);
     forceQuit = Components.interfaces.nsIAppShellService.eForceQuit;
   }
   else
   {
     throw 'goQuitApplication: no AppStartup/appShell';
   }
 
-  var windowManager = Components.
-    classes['@mozilla.org/appshell/window-mediator;1'].getService();
-
-  var windowManagerInterface = windowManager.
-    QueryInterface(Components.interfaces.nsIWindowMediator);
-
-  var enumerator = windowManagerInterface.getEnumerator(null);
-
-  while (enumerator.hasMoreElements())
-  {
-    var domWindow = enumerator.getNext();
-    if (("tryToClose" in domWindow) && !domWindow.tryToClose())
-    {
-      return false;
-    }
-    domWindow.close();
-  }
-
   try
   {
     appService.quit(forceQuit);
   }
   catch(ex)
   {
     throw('goQuitApplication: ' + ex);
   }
--- a/layout/tools/reftest/quit.js
+++ b/layout/tools/reftest/quit.js
@@ -59,17 +59,16 @@ function canQuitApplication()
     if (cancelQuit.data)
     {
       return false;
     }
   }
   catch (ex) 
   {
   }
-  os.notifyObservers(null, "quit-application-granted", null);
   return true;
 }
 
 function goQuitApplication()
 {
   if (!canQuitApplication())
   {
     return false;
--- a/testing/mochitest/tests/SimpleTest/quit.js
+++ b/testing/mochitest/tests/SimpleTest/quit.js
@@ -73,17 +73,16 @@ function canQuitApplication()
     if (cancelQuit.data)
     {
       return false;
     }
   }
   catch (ex) 
   {
   }
-  os.notifyObservers(null, "quit-application-granted", null);
   return true;
 }
 
 function goQuitApplication()
 {
   const privs = 'UniversalXPConnect';
 
   try
--- a/toolkit/components/startup/src/nsAppStartup.cpp
+++ b/toolkit/components/startup/src/nsAppStartup.cpp
@@ -185,16 +185,21 @@ nsAppStartup::Quit(PRUint32 aMode)
   // Exit() method via nsAppExitEvent to allow one last pass
   // through any events in the queue. This guarantees a tidy cleanup.
   nsresult rv = NS_OK;
   PRBool postedExitEvent = PR_FALSE;
 
   if (mShuttingDown)
     return NS_OK;
 
+  nsCOMPtr<nsIObserverService> obsService
+    (do_GetService("@mozilla.org/observer-service;1"));
+  if (obsService)
+    obsService->NotifyObservers(nsnull, "quit-application-granted", nsnull);
+
   /* eForceQuit doesn't actually work; it can cause a subtle crash if
      there are windows open which have unload handlers which open
      new windows. Use eAttemptQuit for now. */
   if (ferocity == eForceQuit) {
     NS_WARNING("attempted to force quit");
     // it will be treated the same as eAttemptQuit, below
   }
 
@@ -259,18 +264,16 @@ nsAppStartup::Quit(PRUint32 aMode)
     }
   }
 
   if (ferocity == eForceQuit) {
     // do it!
 
     // No chance of the shutdown being cancelled from here on; tell people
     // we're shutting down for sure while all services are still available.
-    nsCOMPtr<nsIObserverService> obsService
-      (do_GetService("@mozilla.org/observer-service;1"));
     if (obsService) {
       NS_NAMED_LITERAL_STRING(shutdownStr, "shutdown");
       NS_NAMED_LITERAL_STRING(restartStr, "restart");
       obsService->NotifyObservers(nsnull, "quit-application",
         mRestart ? restartStr.get() : shutdownStr.get());
     }
 
     nsCOMPtr<nsIAppShellService> appShellService
--- a/toolkit/content/globalOverlay.js
+++ b/toolkit/content/globalOverlay.js
@@ -38,17 +38,16 @@ function canQuitApplication()
                               .createInstance(Components.interfaces.nsISupportsPRBool);
     os.notifyObservers(cancelQuit, "quit-application-requested", null);
     
     // Something aborted the quit process. 
     if (cancelQuit.data)
       return false;
   }
   catch (ex) { }
-  os.notifyObservers(null, "quit-application-granted", null);
   return true;
 }
 
 function goQuitApplication()
 {
   if (!canQuitApplication())
     return false;
 
--- a/toolkit/mozapps/extensions/content/extensions.js
+++ b/toolkit/mozapps/extensions/content/extensions.js
@@ -1538,19 +1538,16 @@ function restartApp() {
   var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
                              .createInstance(Components.interfaces.nsISupportsPRBool);
   os.notifyObservers(cancelQuit, "quit-application-requested", "restart");
 
   // Something aborted the quit process. 
   if (cancelQuit.data)
     return;
 
-  // Notify all windows that an application quit has been granted.
-  os.notifyObservers(null, "quit-application-granted", null);
-
   Components.classes["@mozilla.org/toolkit/app-startup;1"].getService(nsIAppStartup)
             .quit(nsIAppStartup.eRestart | nsIAppStartup.eAttemptQuit);
 }
 
 function installWithFilePicker() {
   if (!isXPInstallEnabled())
     return;
 
--- a/toolkit/mozapps/extensions/content/list.js
+++ b/toolkit/mozapps/extensions/content/list.js
@@ -207,19 +207,16 @@ function restartApp() {
   var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
                              .createInstance(Components.interfaces.nsISupportsPRBool);
   os.notifyObservers(cancelQuit, "quit-application-requested", null);
 
   // Something aborted the quit process. 
   if (cancelQuit.data)
     return;
 
-  // Notify all windows that an application quit has been granted.
-  os.notifyObservers(null, "quit-application-granted", null);
-
   Components.classes["@mozilla.org/toolkit/app-startup;1"].getService(nsIAppStartup)
             .quit(nsIAppStartup.eRestart | nsIAppStartup.eAttemptQuit);
 }
 
 /**
  * Watch for the user hitting one of the buttons to dismiss the dialog
  * and report the result back to the caller through the |result| property on
  * the arguments object.
--- a/toolkit/mozapps/update/content/updates.js
+++ b/toolkit/mozapps/update/content/updates.js
@@ -1650,19 +1650,16 @@ var gFinishedPage = {
         Components.classes["@mozilla.org/supports-PRBool;1"].
         createInstance(Components.interfaces.nsISupportsPRBool);
     os.notifyObservers(cancelQuit, "quit-application-requested", "restart");
 
     // Something aborted the quit process. 
     if (cancelQuit.data)
       return;
     
-    // Notify all windows that an application quit has been granted.
-    os.notifyObservers(null, "quit-application-granted", null);
-
     var appStartup = 
         Components.classes["@mozilla.org/toolkit/app-startup;1"].
         getService(Components.interfaces.nsIAppStartup);
     appStartup.quit(appStartup.eAttemptQuit | appStartup.eRestart);
   },
   
   /**
    * Called when the wizard is canceled, i.e. when the "Later" button is
--- a/toolkit/xre/MacApplicationDelegate.mm
+++ b/toolkit/xre/MacApplicationDelegate.mm
@@ -268,18 +268,16 @@ static NSWindow* GetCocoaWindowForXULWin
   cancelQuit->SetData(PR_FALSE);
   obsServ->NotifyObservers(cancelQuit, "quit-application-requested", nsnull);
 
   PRBool abortQuit;
   cancelQuit->GetData(&abortQuit);
   if (abortQuit)
     return NSTerminateCancel;
 
-  obsServ->NotifyObservers(nsnull, "quit-application-granted", nsnull);
-
   nsCOMPtr<nsIAppStartup> appService =
            do_GetService("@mozilla.org/toolkit/app-startup;1");
   if (appService)
     appService->Quit(nsIAppStartup::eForceQuit);
 
   return NSTerminateNow;
 }
 
--- a/toolkit/xre/nsCommandLineServiceMac.cpp
+++ b/toolkit/xre/nsCommandLineServiceMac.cpp
@@ -475,17 +475,16 @@ OSErr nsMacCommandLine::Quit(TAskSave as
   if (abortQuit)
     return userCanceledErr;
 
   nsCOMPtr<nsIAppStartup> appStartup =
            do_GetService(NS_APPSTARTUP_CONTRACTID, &rv);
   if (NS_FAILED(rv))
     return errAEEventNotHandled;
 
-  obsServ->NotifyObservers(nsnull, "quit-application-granted", nsnull);
   appStartup->Quit(nsIAppStartup::eAttemptQuit);
   return noErr;
 }
 
 #pragma mark -
 
 //----------------------------------------------------------------------------------------
 void SetupMacCommandLine(int& argc, char**& argv)
--- a/toolkit/xre/nsNativeAppSupportUnix.cpp
+++ b/toolkit/xre/nsNativeAppSupportUnix.cpp
@@ -112,24 +112,19 @@ gboolean save_yourself_cb(GnomeClient *c
   if (interact == GNOME_INTERACT_ANY)
     gnome_client_request_interaction(client, GNOME_DIALOG_NORMAL,
                                      interact_cb, nsnull);
   return TRUE;
 }
 
 void die_cb(GnomeClient *client, gpointer user_data)
 {
-  nsCOMPtr<nsIObserverService> obsServ =
-    do_GetService("@mozilla.org/observer-service;1");
   nsCOMPtr<nsIAppStartup> appService =
     do_GetService("@mozilla.org/toolkit/app-startup;1");
 
-  if (obsServ)
-    obsServ->NotifyObservers(nsnull, "quit-application-granted", nsnull);
-
   if (appService)
     appService->Quit(nsIAppStartup::eForceQuit);
 }
 
 class nsNativeAppSupportUnix : public nsNativeAppSupportBase
 {
 public:
   NS_IMETHOD Start(PRBool* aRetVal);
--- a/toolkit/xre/nsNativeAppSupportWin.cpp
+++ b/toolkit/xre/nsNativeAppSupportWin.cpp
@@ -641,24 +641,19 @@ struct MessageWindow {
             return !abortQuit;
         } else if ( msg == WM_ENDSESSION ) {
             if (!nsNativeAppSupportWin::mCanHandleRequests)
                 return FALSE;
 
             if (wp == FALSE)
                 return TRUE;
 
-            nsCOMPtr<nsIObserverService> obsServ =
-                do_GetService("@mozilla.org/observer-service;1");
             nsCOMPtr<nsIAppStartup> appService =
                 do_GetService("@mozilla.org/toolkit/app-startup;1");
 
-            if (obsServ)
-                obsServ->NotifyObservers(nsnull, "quit-application-granted", nsnull);
-
             if (appService)
                 appService->Quit(nsIAppStartup::eForceQuit);
 
             return TRUE;
         }
         return DefWindowProc( msgWindow, msg, wp, lp );
     }