App quit sequence

From MozillaWiki
Revision as of 21:25, 19 June 2007 by Mwu (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Current quit sequence

Right now, there are a few steps required for quitting a toolkit app:

  1. Notify observers of quit-application-requested. Observers can abort the quit by setting the nsISupportsPRBool passed in the subject to true.
  2. If the quit isn't aborted at this point, observers of quit-application-granted are notified.
  3. 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.
  4. quit in the app startup service is called, which then..
    1. 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.
    2. Observers of quit-application are notified.
    3. Dispatch exit event.
  5. The app can quit some time after the function returns.

This sequence is wrapped up in a few places, such as toolkit/content/globalOverlay.js (implements all of this sequence), toolkit/components/startup/src/nsCloseAllWindows.js (implements just the tryToClose part).

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.
  • Put the quit-application-granted notification into the quit call in app startup.
  • Wrap the quit-application-requested into a function that just returns true/false.