From aa0976835b949e3b01f2afdb7de54b50ede43b90 Mon Sep 17 00:00:00 2001 From: Ian Neal Date: Fri, 28 Oct 2011 17:29:34 +0100 Subject: [PATCH] Bug 682580 - Remove suite's dependency on nsTryToClose.js r=neil a=CLOSED TREE --- suite/common/src/nsSuiteGlue.js | 6 ---- suite/installer/package-manifest.in | 2 -- suite/mailnews/compose/MsgComposeCommands.js | 38 +++++++++++++------- suite/mailnews/msgMail3PaneWindow.js | 16 +++++++-- suite/mailnews/search/FilterListDialog.js | 19 +++++++--- 5 files changed, 53 insertions(+), 28 deletions(-) diff --git a/suite/common/src/nsSuiteGlue.js b/suite/common/src/nsSuiteGlue.js index 9c69b2f191..acee18f47a 100644 --- a/suite/common/src/nsSuiteGlue.js +++ b/suite/common/src/nsSuiteGlue.js @@ -211,12 +211,6 @@ SuiteGlue.prototype = { this._isPlacesLockedObserver = true; Services.obs.addObserver(this, "places-shutdown", false); this._isPlacesShutdownObserver = true; - try { - tryToClose = Components.classes["@mozilla.org/appshell/trytoclose;1"] - .getService(Components.interfaces.nsIObserver); - Services.obs.removeObserver(tryToClose, "quit-application-requested"); - Services.obs.addObserver(tryToClose, "quit-application-requested", true); - } catch (e) {} }, // cleanup (called on application shutdown) diff --git a/suite/installer/package-manifest.in b/suite/installer/package-manifest.in index fb591cfae1..8d650ec8b7 100644 --- a/suite/installer/package-manifest.in +++ b/suite/installer/package-manifest.in @@ -383,8 +383,6 @@ @BINPATH@/components/nsSetDefault.manifest #endif @BINPATH@/components/nsTaggingService.js -@BINPATH@/components/nsTryToClose.js -@BINPATH@/components/nsTryToClose.manifest @BINPATH@/components/nsTypeAheadFind.js #ifdef MOZ_UPDATER @BINPATH@/components/nsUpdateService.js diff --git a/suite/mailnews/compose/MsgComposeCommands.js b/suite/mailnews/compose/MsgComposeCommands.js index cf8c724c11..3a7e7191c9 100644 --- a/suite/mailnews/compose/MsgComposeCommands.js +++ b/suite/mailnews/compose/MsgComposeCommands.js @@ -654,34 +654,46 @@ function updateOptionItems() goUpdateCommand("cmd_quoteMessage"); } -var messageComposeOfflineObserver = { - observe: function(subject, topic, state) { +var messageComposeOfflineQuitObserver = { + observe: function(aSubject, aTopic, aState) { // sanity checks - if (topic != "network:offline-status-changed") return; - MessageComposeOfflineStateChanged(state == "offline"); + if (aTopic == "network:offline-status-changed") + { + MessageComposeOfflineStateChanged(aState == "offline"); - try { + try { setupLdapAutocompleteSession(); - } catch (ex) { + } catch (ex) { // catch the exception and ignore it, so that if LDAP setup // fails, the entire compose window stuff doesn't get aborted + } } + // check whether to veto the quit request (unless another observer already + // did) + else if (aTopic == "quit-application-requested" && + aSubject instanceof Components.interfaces.nsISupportsPRBool && + !aSubject.data) + aSubject.data = !ComposeCanClose(); } } -function AddMessageComposeOfflineObserver() +function AddMessageComposeOfflineQuitObserver() { - Services.obs.addObserver(messageComposeOfflineObserver, + Services.obs.addObserver(messageComposeOfflineQuitObserver, "network:offline-status-changed", false); + Services.obs.addObserver(messageComposeOfflineQuitObserver, + "quit-application-requested", false); // set the initial state of the send button MessageComposeOfflineStateChanged(Services.io.offline); } -function RemoveMessageComposeOfflineObserver() +function RemoveMessageComposeOfflineQuitObserver() { - Services.obs.removeObserver(messageComposeOfflineObserver, + Services.obs.removeObserver(messageComposeOfflineQuitObserver, "network:offline-status-changed"); + Services.obs.removeObserver(messageComposeOfflineQuitObserver, + "quit-application-requested"); } function MessageComposeOfflineStateChanged(goingOffline) @@ -1494,7 +1506,7 @@ function ComposeLoad() dump("failed to get RDF\n"); } - AddMessageComposeOfflineObserver(); + AddMessageComposeOfflineQuitObserver(); AddDirectoryServerObserver(true); if (gLogComposePerformance) @@ -1524,7 +1536,6 @@ function ComposeLoad() MsgComposeCloseWindow(false); // Don't try to recycle a bogus window return; } - window.tryToClose=ComposeCanClose; if (gLogComposePerformance) sMsgComposeService.TimeStamp("Done with the initialization (ComposeLoad). Waiting on editor to load about:blank", false); @@ -1546,8 +1557,9 @@ function ComposeUnload() EditorCleanup(); - RemoveMessageComposeOfflineObserver(); + RemoveMessageComposeOfflineQuitObserver(); RemoveDirectoryServerObserver(null); + if (gCurrentIdentity) RemoveDirectoryServerObserver("mail.identity." + gCurrentIdentity.key); if (gCurrentAutocompleteDirectory) diff --git a/suite/mailnews/msgMail3PaneWindow.js b/suite/mailnews/msgMail3PaneWindow.js index 433608c01c..30783e5d32 100644 --- a/suite/mailnews/msgMail3PaneWindow.js +++ b/suite/mailnews/msgMail3PaneWindow.js @@ -717,7 +717,8 @@ function OnLoadMessenger() let tabmail = GetTabMail(); tabmail.registerTabType(gMailNewsTabsType); tabmail.openFirstTab(); - window.tryToClose = MailWindowIsClosing; + Services.obs.addObserver(MailWindowIsClosing, + "quit-application-requested", false); InitMsgWindow(); messenger.setWindow(window, msgWindow); @@ -819,6 +820,8 @@ function OnUnloadMessenger() pref.removeObserver("mail.pane_config.dynamic", MailPrefObserver, false); pref.removeObserver("mail.showCondensedAddresses", MailPrefObserver, false); window.removeEventListener("AppCommand", HandleAppCommandEvent, true); + Services.obs.removeObserver(MailWindowIsClosing, + "quit-application-requested"); OnLeavingFolder(gMsgFolderSelected); // mark all read in current folder accountManager.removeIncomingServerListener(gThreePaneIncomingServerListener); @@ -831,8 +834,13 @@ function OnUnloadMessenger() } // we probably want to warn if more than one tab is closed -function MailWindowIsClosing() +function MailWindowIsClosing(aCancelQuit, aTopic, aData) { + if (aTopic == "quit-application-requested" && + aCancelQuit instanceof Components.interfaces.nsISupportsPRBool && + aCancelQuit.data) + return false; + let reallyClose = true; let numtabs = GetTabMail().tabInfo.length; if (numtabs > 1) @@ -859,6 +867,10 @@ function MailWindowIsClosing() pref.setBoolPref("browser.tabs.warnOnClose", false); } } + + if (!reallyClose && aTopic == "quit-application-requested") + aCancelQuit.data = true; + return reallyClose; } diff --git a/suite/mailnews/search/FilterListDialog.js b/suite/mailnews/search/FilterListDialog.js index 87a9094dbe..77ed9b5e22 100644 --- a/suite/mailnews/search/FilterListDialog.js +++ b/suite/mailnews/search/FilterListDialog.js @@ -202,7 +202,8 @@ function onLoad() // Focus the list. gFilterTree.focus(); - window.tryToClose = onFilterClose; + Services.obs.addObserver(onFilterClose, + "quit-application-requested", false); top.controllers.insertControllerAt(0, gFilterController); } @@ -448,11 +449,17 @@ function onFilterUnload() if (filterList) filterList.saveToDefaultFile(); + Services.obs.removeObserver(onFilterClose, "quit-application-requested"); top.controllers.removeController(gFilterController); } -function onFilterClose() +function onFilterClose(aCancelQuit, aTopic, aData) { + if (aTopic == "quit-application-requested" && + aCancelQuit instanceof Components.interfaces.nsISupportsPRBool && + aCancelQuit.data) + return false; + if (gRunFiltersButton.getAttribute("label") == gRunFiltersButton.getAttribute("stoplabel")) { var promptTitle = gFilterBundle.getString("promptTitle"); var promptMsg = gFilterBundle.getString("promptMsg");; @@ -463,10 +470,12 @@ function onFilterClose() (Services.prompt.BUTTON_TITLE_IS_STRING * Services.prompt.BUTTON_POS_0) + (Services.prompt.BUTTON_TITLE_IS_STRING * Services.prompt.BUTTON_POS_1), - continueButtonLabel, stopButtonLabel, null, null, {value:0})) - gFilterListMsgWindow.StopUrls(); - else + continueButtonLabel, stopButtonLabel, null, null, {value:0}) == 0) { + if (aTopic == "quit-application-requested") + aCancelQuit.data = true; return false; + } + gFilterListMsgWindow.StopUrls(); } return true;