Attachment #275672: Move quit-application-granted notifications for bug #386810

View | Details | Raw Unified | Return to bug 386810
Collapse All | Expand All

(-)a/layout/tools/pageloader/quit.js (-19 lines)
Line     Link Here 
 Lines 59-75   function canQuitApplication() Link Here 
59
    if (cancelQuit.data)
59
    if (cancelQuit.data)
60
    {
60
    {
61
      return false;
61
      return false;
62
    }
62
    }
63
  }
63
  }
64
  catch (ex) 
64
  catch (ex) 
65
  {
65
  {
66
  }
66
  }
67
  os.notifyObservers(null, "quit-application-granted", null);
68
  return true;
67
  return true;
69
}
68
}
70
69
71
function goQuitApplication()
70
function goQuitApplication()
72
{
71
{
73
  if (!canQuitApplication())
72
  if (!canQuitApplication())
74
  {
73
  {
75
    return false;
74
    return false;
 Lines 92-125   function goQuitApplication() Link Here 
92
      getService(Components.interfaces.nsIAppShellService);
91
      getService(Components.interfaces.nsIAppShellService);
93
    forceQuit = Components.interfaces.nsIAppShellService.eForceQuit;
92
    forceQuit = Components.interfaces.nsIAppShellService.eForceQuit;
94
  }
93
  }
95
  else
94
  else
96
  {
95
  {
97
    throw 'goQuitApplication: no AppStartup/appShell';
96
    throw 'goQuitApplication: no AppStartup/appShell';
98
  }
97
  }
99
98
100
  var windowManager = Components.
101
    classes['@mozilla.org/appshell/window-mediator;1'].getService();
102
103
  var windowManagerInterface = windowManager.
104
    QueryInterface(Components.interfaces.nsIWindowMediator);
105
106
  var enumerator = windowManagerInterface.getEnumerator(null);
107
108
  while (enumerator.hasMoreElements())
109
  {
110
    var domWindow = enumerator.getNext();
111
    if (("tryToClose" in domWindow) && !domWindow.tryToClose())
112
    {
113
      return false;
114
    }
115
    domWindow.close();
116
  }
117
118
  try
99
  try
119
  {
100
  {
120
    appService.quit(forceQuit);
101
    appService.quit(forceQuit);
121
  }
102
  }
122
  catch(ex)
103
  catch(ex)
123
  {
104
  {
124
    throw('goQuitApplication: ' + ex);
105
    throw('goQuitApplication: ' + ex);
125
  }
106
  }
(-)a/layout/tools/reftest/quit.js (-1 lines)
Line     Link Here 
 Lines 59-75   function canQuitApplication() Link Here 
59
    if (cancelQuit.data)
59
    if (cancelQuit.data)
60
    {
60
    {
61
      return false;
61
      return false;
62
    }
62
    }
63
  }
63
  }
64
  catch (ex) 
64
  catch (ex) 
65
  {
65
  {
66
  }
66
  }
67
  os.notifyObservers(null, "quit-application-granted", null);
68
  return true;
67
  return true;
69
}
68
}
70
69
71
function goQuitApplication()
70
function goQuitApplication()
72
{
71
{
73
  if (!canQuitApplication())
72
  if (!canQuitApplication())
74
  {
73
  {
75
    return false;
74
    return false;
(-)a/testing/mochitest/tests/SimpleTest/quit.js (-1 lines)
Line     Link Here 
 Lines 73-89   function canQuitApplication() Link Here 
73
    if (cancelQuit.data)
73
    if (cancelQuit.data)
74
    {
74
    {
75
      return false;
75
      return false;
76
    }
76
    }
77
  }
77
  }
78
  catch (ex) 
78
  catch (ex) 
79
  {
79
  {
80
  }
80
  }
81
  os.notifyObservers(null, "quit-application-granted", null);
82
  return true;
81
  return true;
83
}
82
}
84
83
85
function goQuitApplication()
84
function goQuitApplication()
86
{
85
{
87
  const privs = 'UniversalXPConnect';
86
  const privs = 'UniversalXPConnect';
88
87
89
  try
88
  try
(-)a/toolkit/components/startup/src/nsAppStartup.cpp (-2 / +5 lines)
Line     Link Here 
 Lines 185-200   nsAppStartup::Quit(PRUint32 aMode) Link Here 
185
  // Exit() method via nsAppExitEvent to allow one last pass
185
  // Exit() method via nsAppExitEvent to allow one last pass
186
  // through any events in the queue. This guarantees a tidy cleanup.
186
  // through any events in the queue. This guarantees a tidy cleanup.
187
  nsresult rv = NS_OK;
187
  nsresult rv = NS_OK;
188
  PRBool postedExitEvent = PR_FALSE;
188
  PRBool postedExitEvent = PR_FALSE;
189
189
190
  if (mShuttingDown)
190
  if (mShuttingDown)
191
    return NS_OK;
191
    return NS_OK;
192
192
193
  nsCOMPtr<nsIObserverService> obsService
194
    (do_GetService("@mozilla.org/observer-service;1"));
195
  if (obsService)
196
    obsService->NotifyObservers(nsnull, "quit-application-granted", nsnull);
197
193
  /* eForceQuit doesn't actually work; it can cause a subtle crash if
198
  /* eForceQuit doesn't actually work; it can cause a subtle crash if
194
     there are windows open which have unload handlers which open
199
     there are windows open which have unload handlers which open
195
     new windows. Use eAttemptQuit for now. */
200
     new windows. Use eAttemptQuit for now. */
196
  if (ferocity == eForceQuit) {
201
  if (ferocity == eForceQuit) {
197
    NS_WARNING("attempted to force quit");
202
    NS_WARNING("attempted to force quit");
198
    // it will be treated the same as eAttemptQuit, below
203
    // it will be treated the same as eAttemptQuit, below
199
  }
204
  }
200
205
 Lines 259-276   nsAppStartup::Quit(PRUint32 aMode) Link Here 
259
    }
264
    }
260
  }
265
  }
261
266
262
  if (ferocity == eForceQuit) {
267
  if (ferocity == eForceQuit) {
263
    // do it!
268
    // do it!
264
269
265
    // No chance of the shutdown being cancelled from here on; tell people
270
    // No chance of the shutdown being cancelled from here on; tell people
266
    // we're shutting down for sure while all services are still available.
271
    // we're shutting down for sure while all services are still available.
267
    nsCOMPtr<nsIObserverService> obsService
268
      (do_GetService("@mozilla.org/observer-service;1"));
269
    if (obsService) {
272
    if (obsService) {
270
      NS_NAMED_LITERAL_STRING(shutdownStr, "shutdown");
273
      NS_NAMED_LITERAL_STRING(shutdownStr, "shutdown");
271
      NS_NAMED_LITERAL_STRING(restartStr, "restart");
274
      NS_NAMED_LITERAL_STRING(restartStr, "restart");
272
      obsService->NotifyObservers(nsnull, "quit-application",
275
      obsService->NotifyObservers(nsnull, "quit-application",
273
        mRestart ? restartStr.get() : shutdownStr.get());
276
        mRestart ? restartStr.get() : shutdownStr.get());
274
    }
277
    }
275
278
276
    nsCOMPtr<nsIAppShellService> appShellService
279
    nsCOMPtr<nsIAppShellService> appShellService
(-)a/toolkit/content/globalOverlay.js (-1 lines)
Line     Link Here 
 Lines 38-54   function canQuitApplication() Link Here 
38
                              .createInstance(Components.interfaces.nsISupportsPRBool);
38
                              .createInstance(Components.interfaces.nsISupportsPRBool);
39
    os.notifyObservers(cancelQuit, "quit-application-requested", null);
39
    os.notifyObservers(cancelQuit, "quit-application-requested", null);
40
    
40
    
41
    // Something aborted the quit process. 
41
    // Something aborted the quit process. 
42
    if (cancelQuit.data)
42
    if (cancelQuit.data)
43
      return false;
43
      return false;
44
  }
44
  }
45
  catch (ex) { }
45
  catch (ex) { }
46
  os.notifyObservers(null, "quit-application-granted", null);
47
  return true;
46
  return true;
48
}
47
}
49
48
50
function goQuitApplication()
49
function goQuitApplication()
51
{
50
{
52
  if (!canQuitApplication())
51
  if (!canQuitApplication())
53
    return false;
52
    return false;
54
53
(-)a/toolkit/mozapps/extensions/content/extensions.js (-3 lines)
Line     Link Here 
 Lines 1584-1602   function restartApp() { Link Here 
1584
  var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
1584
  var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
1585
                             .createInstance(Components.interfaces.nsISupportsPRBool);
1585
                             .createInstance(Components.interfaces.nsISupportsPRBool);
1586
  os.notifyObservers(cancelQuit, "quit-application-requested", "restart");
1586
  os.notifyObservers(cancelQuit, "quit-application-requested", "restart");
1587
1587
1588
  // Something aborted the quit process. 
1588
  // Something aborted the quit process. 
1589
  if (cancelQuit.data)
1589
  if (cancelQuit.data)
1590
    return;
1590
    return;
1591
1591
1592
  // Notify all windows that an application quit has been granted.
1593
  os.notifyObservers(null, "quit-application-granted", null);
1594
1595
  Components.classes["@mozilla.org/toolkit/app-startup;1"].getService(nsIAppStartup)
1592
  Components.classes["@mozilla.org/toolkit/app-startup;1"].getService(nsIAppStartup)
1596
            .quit(nsIAppStartup.eRestart | nsIAppStartup.eAttemptQuit);
1593
            .quit(nsIAppStartup.eRestart | nsIAppStartup.eAttemptQuit);
1597
}
1594
}
1598
1595
1599
function installWithFilePicker() {
1596
function installWithFilePicker() {
1600
  if (!isXPInstallEnabled())
1597
  if (!isXPInstallEnabled())
1601
    return;
1598
    return;
1602
1599
(-)a/toolkit/mozapps/extensions/content/list.js (-3 lines)
Line     Link Here 
 Lines 207-225   function restartApp() { Link Here 
207
  var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
207
  var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
208
                             .createInstance(Components.interfaces.nsISupportsPRBool);
208
                             .createInstance(Components.interfaces.nsISupportsPRBool);
209
  os.notifyObservers(cancelQuit, "quit-application-requested", null);
209
  os.notifyObservers(cancelQuit, "quit-application-requested", null);
210
210
211
  // Something aborted the quit process. 
211
  // Something aborted the quit process. 
212
  if (cancelQuit.data)
212
  if (cancelQuit.data)
213
    return;
213
    return;
214
214
215
  // Notify all windows that an application quit has been granted.
216
  os.notifyObservers(null, "quit-application-granted", null);
217
218
  Components.classes["@mozilla.org/toolkit/app-startup;1"].getService(nsIAppStartup)
215
  Components.classes["@mozilla.org/toolkit/app-startup;1"].getService(nsIAppStartup)
219
            .quit(nsIAppStartup.eRestart | nsIAppStartup.eAttemptQuit);
216
            .quit(nsIAppStartup.eRestart | nsIAppStartup.eAttemptQuit);
220
}
217
}
221
218
222
/**
219
/**
223
 * Watch for the user hitting one of the buttons to dismiss the dialog
220
 * Watch for the user hitting one of the buttons to dismiss the dialog
224
 * and report the result back to the caller through the |result| property on
221
 * and report the result back to the caller through the |result| property on
225
 * the arguments object.
222
 * the arguments object.
(-)a/toolkit/mozapps/update/content/updates.js (-3 lines)
Line     Link Here 
 Lines 1650-1668   var gFinishedPage = { Link Here 
1650
        Components.classes["@mozilla.org/supports-PRBool;1"].
1650
        Components.classes["@mozilla.org/supports-PRBool;1"].
1651
        createInstance(Components.interfaces.nsISupportsPRBool);
1651
        createInstance(Components.interfaces.nsISupportsPRBool);
1652
    os.notifyObservers(cancelQuit, "quit-application-requested", "restart");
1652
    os.notifyObservers(cancelQuit, "quit-application-requested", "restart");
1653
1653
1654
    // Something aborted the quit process. 
1654
    // Something aborted the quit process. 
1655
    if (cancelQuit.data)
1655
    if (cancelQuit.data)
1656
      return;
1656
      return;
1657
    
1657
    
1658
    // Notify all windows that an application quit has been granted.
1659
    os.notifyObservers(null, "quit-application-granted", null);
1660
1661
    var appStartup = 
1658
    var appStartup = 
1662
        Components.classes["@mozilla.org/toolkit/app-startup;1"].
1659
        Components.classes["@mozilla.org/toolkit/app-startup;1"].
1663
        getService(Components.interfaces.nsIAppStartup);
1660
        getService(Components.interfaces.nsIAppStartup);
1664
    appStartup.quit(appStartup.eAttemptQuit | appStartup.eRestart);
1661
    appStartup.quit(appStartup.eAttemptQuit | appStartup.eRestart);
1665
  },
1662
  },
1666
  
1663
  
1667
  /**
1664
  /**
1668
   * Called when the wizard is canceled, i.e. when the "Later" button is
1665
   * Called when the wizard is canceled, i.e. when the "Later" button is
(-)a/toolkit/xre/MacApplicationDelegate.mm (-2 lines)
Line     Link Here 
 Lines 268-285   static NSWindow* GetCocoaWindowForXULWin Link Here 
268
  cancelQuit->SetData(PR_FALSE);
268
  cancelQuit->SetData(PR_FALSE);
269
  obsServ->NotifyObservers(cancelQuit, "quit-application-requested", nsnull);
269
  obsServ->NotifyObservers(cancelQuit, "quit-application-requested", nsnull);
270
270
271
  PRBool abortQuit;
271
  PRBool abortQuit;
272
  cancelQuit->GetData(&abortQuit);
272
  cancelQuit->GetData(&abortQuit);
273
  if (abortQuit)
273
  if (abortQuit)
274
    return NSTerminateCancel;
274
    return NSTerminateCancel;
275
275
276
  obsServ->NotifyObservers(nsnull, "quit-application-granted", nsnull);
277
278
  nsCOMPtr<nsIAppStartup> appService =
276
  nsCOMPtr<nsIAppStartup> appService =
279
           do_GetService("@mozilla.org/toolkit/app-startup;1");
277
           do_GetService("@mozilla.org/toolkit/app-startup;1");
280
  if (appService)
278
  if (appService)
281
    appService->Quit(nsIAppStartup::eForceQuit);
279
    appService->Quit(nsIAppStartup::eForceQuit);
282
280
283
  return NSTerminateNow;
281
  return NSTerminateNow;
284
}
282
}
285
283
(-)a/toolkit/xre/nsCommandLineServiceMac.cpp (-1 lines)
Line     Link Here 
 Lines 475-491   OSErr nsMacCommandLine::Quit(TAskSave as Link Here 
475
  if (abortQuit)
475
  if (abortQuit)
476
    return userCanceledErr;
476
    return userCanceledErr;
477
477
478
  nsCOMPtr<nsIAppStartup> appStartup =
478
  nsCOMPtr<nsIAppStartup> appStartup =
479
           do_GetService(NS_APPSTARTUP_CONTRACTID, &rv);
479
           do_GetService(NS_APPSTARTUP_CONTRACTID, &rv);
480
  if (NS_FAILED(rv))
480
  if (NS_FAILED(rv))
481
    return errAEEventNotHandled;
481
    return errAEEventNotHandled;
482
482
483
  obsServ->NotifyObservers(nsnull, "quit-application-granted", nsnull);
484
  appStartup->Quit(nsIAppStartup::eAttemptQuit);
483
  appStartup->Quit(nsIAppStartup::eAttemptQuit);
485
  return noErr;
484
  return noErr;
486
}
485
}
487
486
488
#pragma mark -
487
#pragma mark -
489
488
490
//----------------------------------------------------------------------------------------
489
//----------------------------------------------------------------------------------------
491
void SetupMacCommandLine(int& argc, char**& argv)
490
void SetupMacCommandLine(int& argc, char**& argv)
(-)a/toolkit/xre/nsNativeAppSupportUnix.cpp (-5 lines)
Line     Link Here 
 Lines 112-135   gboolean save_yourself_cb(GnomeClient *c Link Here 
112
  if (interact == GNOME_INTERACT_ANY)
112
  if (interact == GNOME_INTERACT_ANY)
113
    gnome_client_request_interaction(client, GNOME_DIALOG_NORMAL,
113
    gnome_client_request_interaction(client, GNOME_DIALOG_NORMAL,
114
                                     interact_cb, nsnull);
114
                                     interact_cb, nsnull);
115
  return TRUE;
115
  return TRUE;
116
}
116
}
117
117
118
void die_cb(GnomeClient *client, gpointer user_data)
118
void die_cb(GnomeClient *client, gpointer user_data)
119
{
119
{
120
  nsCOMPtr<nsIObserverService> obsServ =
121
    do_GetService("@mozilla.org/observer-service;1");
122
  nsCOMPtr<nsIAppStartup> appService =
120
  nsCOMPtr<nsIAppStartup> appService =
123
    do_GetService("@mozilla.org/toolkit/app-startup;1");
121
    do_GetService("@mozilla.org/toolkit/app-startup;1");
124
122
125
  if (obsServ)
126
    obsServ->NotifyObservers(nsnull, "quit-application-granted", nsnull);
127
128
  if (appService)
123
  if (appService)
129
    appService->Quit(nsIAppStartup::eForceQuit);
124
    appService->Quit(nsIAppStartup::eForceQuit);
130
}
125
}
131
126
132
class nsNativeAppSupportUnix : public nsNativeAppSupportBase
127
class nsNativeAppSupportUnix : public nsNativeAppSupportBase
133
{
128
{
134
public:
129
public:
135
  NS_IMETHOD Start(PRBool* aRetVal);
130
  NS_IMETHOD Start(PRBool* aRetVal);
(-)a/toolkit/xre/nsNativeAppSupportWin.cpp (-5 lines)
Line     Link Here 
 Lines 641-664   #endif Link Here 
641
            return !abortQuit;
641
            return !abortQuit;
642
        } else if ( msg == WM_ENDSESSION ) {
642
        } else if ( msg == WM_ENDSESSION ) {
643
            if (!nsNativeAppSupportWin::mCanHandleRequests)
643
            if (!nsNativeAppSupportWin::mCanHandleRequests)
644
                return FALSE;
644
                return FALSE;
645
645
646
            if (wp == FALSE)
646
            if (wp == FALSE)
647
                return TRUE;
647
                return TRUE;
648
648
649
            nsCOMPtr<nsIObserverService> obsServ =
650
                do_GetService("@mozilla.org/observer-service;1");
651
            nsCOMPtr<nsIAppStartup> appService =
649
            nsCOMPtr<nsIAppStartup> appService =
652
                do_GetService("@mozilla.org/toolkit/app-startup;1");
650
                do_GetService("@mozilla.org/toolkit/app-startup;1");
653
651
654
            if (obsServ)
655
                obsServ->NotifyObservers(nsnull, "quit-application-granted", nsnull);
656
657
            if (appService)
652
            if (appService)
658
                appService->Quit(nsIAppStartup::eForceQuit);
653
                appService->Quit(nsIAppStartup::eForceQuit);
659
654
660
            return TRUE;
655
            return TRUE;
661
        }
656
        }
662
        return DefWindowProc( msgWindow, msg, wp, lp );
657
        return DefWindowProc( msgWindow, msg, wp, lp );
663
    }
658
    }
664
659

Return to bug 386810