App quit sequence

From MozillaWiki
Jump to: navigation, 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. (Gecko 1.8.1 and older)
  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. (Removed in Gecko 1.9 by bug 386002)
  4. quit in the app startup service is called, which then..
    1. Notifies observers of quit-application-granted. (Gecko 1.9+)
    2. 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.
    3. Observers of quit-application are notified.
    4. Dispatch exit event.
  5. 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.