1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 function closeWindow(aClose, aPromptFunction) {
6 let { AppConstants } = ChromeUtils.import(
7 "resource://gre/modules/AppConstants.jsm"
10 // Closing the last window doesn't quit the application on OS X.
11 if (AppConstants.platform != "macosx") {
13 for (let w of Services.wm.getEnumerator(null)) {
17 if (++windowCount == 2) {
22 // If we're down to the last window and someone tries to shut down, check to make sure we can!
23 if (windowCount == 1 && !canQuitApplication("lastwindow")) {
28 typeof aPromptFunction == "function" &&
33 } else if (typeof aPromptFunction == "function" && !aPromptFunction()) {
45 function canQuitApplication(aData) {
47 var cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(
50 Services.obs.notifyObservers(
52 "quit-application-requested",
56 // Something aborted the quit process.
57 if (cancelQuit.data) {
64 function goQuitApplication() {
65 if (!canQuitApplication()) {
69 Services.startup.quit(Ci.nsIAppStartup.eAttemptQuit);
74 // Command Updater functions
76 function goUpdateCommand(aCommand) {
78 var controller = top.document.commandDispatcher.getControllerForCommand(
84 enabled = controller.isCommandEnabled(aCommand);
87 goSetCommandEnabled(aCommand, enabled);
90 "An error occurred updating the " + aCommand + " command: " + e
95 function goDoCommand(aCommand) {
97 var controller = top.document.commandDispatcher.getControllerForCommand(
100 if (controller && controller.isCommandEnabled(aCommand)) {
101 controller.doCommand(aCommand);
105 "An error occurred executing the " + aCommand + " command: " + e
110 function goSetCommandEnabled(aID, aEnabled) {
111 var node = document.getElementById(aID);
115 node.removeAttribute("disabled");
117 node.setAttribute("disabled", "true");