App quit sequence
From MozillaWiki
Current quit sequence
Right now, there are a few steps required for quitting a toolkit app:
- Notify observers of quit-application-requested. Observers can abort the quit by setting the nsISupportsPRBool passed in the subject to true.
- If the quit isn't aborted at this point, observers of quit-application-granted are notified. (Gecko 1.8.1 and older)
- The window mediator service is then used to enumerate through all windows. If the window has a function named tryToClose defined, it is called. If tryToClose returns false, the shutdown is aborted at this point. If not, the window is closed and the next window is checked for tryToClose and so on. (Removed in Gecko 1.9 by bug 386002)
- quit in the app startup service is called, which then..
- Notifies observers of quit-application-granted. (Gecko 1.9+)
- Try to close every window. If this doesn't work out, the quit is aborted in the hopes that the last window will close soon.
- Observers of quit-application are notified.
- Dispatch exit event.
- The app can quit some time after the function returns.
This sequence is wrapped up in toolkit/content/globalOverlay.js.
Things to do to improve this
- Eliminate tryToClose. tryToClose has problems:
- It's arbitrary and not defined in an interface anywhere.
- It's called after quit-application-granted.
- It always closes the window after tryToClose returns true, which is not always desirable.
- Applications can implement this properly just by registering an observer for quit-application-requested and enumerating through windows, if needed. Firefox doesn't need this anymore. Fixed in bug 386002 for Gecko 1.9
- Put the quit-application-granted notification into the quit call in app startup. Fixed in bug 386810 for Gecko 1.9
- Wrap the quit-application-requested into a function that just returns true/false.