Bug 641781 - Port the safe mode startup window to Thunderbird. r=Standard8, sr=bienvenu, ui-r=clarkbw
authorSiddharth Agarwal <sid.bugzilla@gmail.com>
Thu, 31 Mar 2011 01:50:46 +0530
changeset 7293 765eb39e92ea1e76de4a45f70970ffeda94c41a1
parent 7292 dbb11495c869eb5980f43b53e7a26f1f282fa4fd
child 7294 0588746db118ae82055879245e289689e5af681b
push idunknown
push userunknown
push dateunknown
reviewersStandard8, bienvenu, clarkbw
bugs641781
Bug 641781 - Port the safe mode startup window to Thunderbird. r=Standard8, sr=bienvenu, ui-r=clarkbw
mail/base/content/safeMode.js
mail/base/content/safeMode.xul
mail/base/jar.mn
mail/components/Makefile.in
mail/components/mailComponents.manifest
mail/components/mailGlue.js
mail/locales/en-US/chrome/messenger/safeMode.dtd
mail/locales/jar.mn
new file mode 100644
--- /dev/null
+++ b/mail/base/content/safeMode.js
@@ -0,0 +1,110 @@
+/* -*- Mode: JavaScript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Mike Connor.
+ * Portions created by the Initial Developer are Copyright (C) 2005
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Mike Connor <mconnor@steelgryphon.com>
+ *   Asaf Romano <mano@mozilla.com>
+ *   Siddharth Agarwal <sid.bugzilla@gmail.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+Components.utils.import("resource://gre/modules/AddonManager.jsm");
+
+function restartApp() {
+  var appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"]
+                             .getService(Components.interfaces.nsIAppStartup);
+  appStartup.quit(appStartup.eForceQuit | appStartup.eRestart);
+}
+
+function deleteLocalstore() {
+  const nsIDirectoryServiceContractID = "@mozilla.org/file/directory_service;1";
+  const nsIProperties = Components.interfaces.nsIProperties;
+  var directoryService =  Components.classes[nsIDirectoryServiceContractID]
+                                    .getService(nsIProperties);
+  var localstoreFile = directoryService.get("LStoreS", Components.interfaces.nsIFile);
+  if (localstoreFile.exists())
+    localstoreFile.remove(false);
+}
+
+function disableAddons() {
+  AddonManager.getAllAddons(function(aAddons) {
+    aAddons.forEach(function(aAddon) {
+      if (aAddon.type == "theme") {
+        // Setting userDisabled to false on the default theme activates it,
+        // disables all other themes and deactivates the applied persona, if
+        // any.
+        const DEFAULT_THEME_ID = "{972ce4c6-7e08-4474-a285-3208198ce6fd}";
+        if (aAddon.id == DEFAULT_THEME_ID)
+          aAddon.userDisabled = false;
+      }
+      else {
+        aAddon.userDisabled = true;
+      }
+    });
+
+    restartApp();
+  });
+}
+
+function onOK() {
+  try {
+    if (document.getElementById("resetToolbars").checked)
+      deleteLocalstore();
+    if (document.getElementById("disableAddons").checked) {
+      disableAddons();
+      // disableAddons will asynchronously restart the application
+      return false;
+    }
+  } catch(e) {
+  }
+
+  restartApp();
+  return false;
+}
+
+function onCancel() {
+  var appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"]
+                             .getService(Components.interfaces.nsIAppStartup);
+  appStartup.quit(appStartup.eForceQuit);
+}
+
+function onLoad() {
+  document.getElementById("tasks")
+          .addEventListener("CheckboxStateChange", updateOKButtonState, false);
+}
+
+function updateOKButtonState() {
+  document.documentElement.getButton("accept").disabled = 
+    !document.getElementById("resetToolbars").checked &&
+    !document.getElementById("disableAddons").checked;
+}
new file mode 100644
--- /dev/null
+++ b/mail/base/content/safeMode.xul
@@ -0,0 +1,88 @@
+<?xml version="1.0"?>
+<!-- ***** BEGIN LICENSE BLOCK *****
+  -   Version: MPL 1.1/GPL 2.0/LGPL 2.1
+  -
+  -  The contents of this file are subject to the Mozilla Public License Version
+  -  1.1 (the "License"); you may not use this file except in compliance with
+  -  the License. You may obtain a copy of the License at
+  -  http://www.mozilla.org/MPL/
+  -
+  -  Software distributed under the License is distributed on an "AS IS" basis,
+  -  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+  -  for the specific language governing rights and limitations under the
+  -  License.
+  -
+  -  The Original Code is mozilla.org code.
+  -
+  -  The Initial Developer of the Original Code is
+  -  Mike Connor.
+  -  Portions created by the Initial Developer are Copyright (C) 2005
+  -  the Initial Developer. All Rights Reserved.
+  -
+  -  Contributor(s):
+  -    Mike Connor <mconnor@steelgryphon.com>
+  -    Siddharth Agarwal <sid.bugzilla@gmail.com>
+  -
+  -  Alternatively, the contents of this file may be used under the terms of
+  -  either the GNU General Public License Version 2 or later (the "GPL"), or
+  -  the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+  -  in which case the provisions of the GPL or the LGPL are applicable instead
+  -  of those above. If you wish to allow use of your version of this file only
+  -  under the terms of either the GPL or the LGPL, and not to allow others to
+  -  use your version of this file under the terms of the MPL, indicate your
+  -  decision by deleting the provisions above and replace them with the notice
+  -  and other provisions required by the GPL or the LGPL. If you do not delete
+  -  the provisions above, a recipient may use your version of this file under
+  -  the terms of any one of the MPL, the GPL or the LGPL.
+  -
+  -  ***** END LICENSE BLOCK ***** -->
+
+<!DOCTYPE overlay [
+<!ENTITY % brandDTD SYSTEM "chrome://branding/locale/brand.dtd">
+%brandDTD;
+<!ENTITY % safeModeDTD SYSTEM "chrome://messenger/locale/safeMode.dtd">
+%safeModeDTD;
+<!ENTITY % utilityDTD SYSTEM "chrome://communicator/locale/utilityOverlay.dtd">
+%utilityDTD;
+]>
+
+<?xml-stylesheet href="chrome://global/skin/"?>
+
+<dialog id="safeModeDialog"
+            xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+            title="&safeModeDialog.title;"
+            buttons="accept,cancel,extra1"
+            buttonlabelaccept="&changeAndRestartButton.label;"
+            buttonaccesskeyaccept="&changeAndRestartButton.accesskey;"
+#ifdef XP_WIN
+            buttonlabelcancel="&quitApplicationCmd.label;"
+            buttonaccesskeycancel="&quitApplicationCmd.accesskey;"
+#else
+            buttonlabelcancel="&quitApplicationCmdUnix.label;"
+            buttonaccesskeycancel="&quitApplicationCmdUnix.accesskey;"
+#endif
+            buttonlabelextra1="&continueButton.label;"
+            buttonaccesskeyextra1="&continueButton.accesskey;"
+            width="&window.width;"
+            ondialogaccept="return onOK()"
+            ondialogcancel="onCancel()"
+            ondialogextra1="window.close()"
+            onload="onLoad();"
+            buttondisabledaccept="true">
+
+  <script type="application/javascript" src="chrome://messenger/content/safeMode.js"/>
+
+  <stringbundle id="preferencesBundle" src="chrome://messenger/locale/preferences/preferences.properties"/>
+
+  <description>&safeModeDescription.label;</description>
+
+  <separator class="thin"/>
+
+  <label value="&safeModeDescription2.label;"/>
+  <vbox id="tasks">
+    <checkbox id="disableAddons" label="&disableAddons.label;" accesskey="&disableAddons.accesskey;"/>
+    <checkbox id="resetToolbars" label="&resetToolbars.label;" accesskey="&resetToolbars.accesskey;"/>
+  </vbox>
+     
+  <separator class="thin"/>
+</dialog>
--- a/mail/base/jar.mn
+++ b/mail/base/jar.mn
@@ -109,16 +109,18 @@ messenger.jar:
     content/messenger/glodaFacetView.css            (content/glodaFacetView.css)
     content/messenger/glodaFacetBindings.css        (content/glodaFacetBindings.css)
     content/messenger/glodaFacetBindings.xml        (content/glodaFacetBindings.xml)
     content/messenger/glodaFacetVis.js              (content/glodaFacetVis.js)
     content/messenger/quickFilterBar.xul            (content/quickFilterBar.xul)
     content/messenger/quickFilterBar.js             (content/quickFilterBar.js)
     content/messenger/quickFilterBar.css            (content/quickFilterBar.css)
     content/messenger/downloadsOverlay.xul          (content/downloadsOverlay.xul)
+*   content/messenger/safeMode.xul                  (content/safeMode.xul)
+    content/messenger/safeMode.js                   (content/safeMode.js)
 # the following files are mail-specific overrides
 *+  content/messenger/license.html                  (/mozilla/toolkit/content/license.html)
 % override chrome://global/content/license.html chrome://messenger/content/license.html
 
 comm.jar:
 % content communicator %content/communicator/
 *  content/communicator/contentAreaClick.js         (content/contentAreaClick.js)
 *  content/communicator/utilityOverlay.xul          (content/utilityOverlay.xul)
--- a/mail/components/Makefile.in
+++ b/mail/components/Makefile.in
@@ -59,16 +59,17 @@ DIRS += test
 endif
 
 DIRS += build
 
 EXTRA_COMPONENTS = \
 	nsMailDefaultHandler.js \
 	mailContentHandler.js \
 	aboutRedirector.js \
+	mailGlue.js \
 	mailComponents.manifest \
 	$(NULL)
 
 EXTRA_JS_MODULES = \
   appIdleManager.js \
   $(NULL)
 
 
--- a/mail/components/mailComponents.manifest
+++ b/mail/components/mailComponents.manifest
@@ -7,8 +7,12 @@ contract @mozilla.org/network/protocol/a
 component {44346520-c5d2-44e5-a1ec-034e04d7fac4} nsMailDefaultHandler.js
 contract @mozilla.org/mail/clh;1 {44346520-c5d2-44e5-a1ec-034e04d7fac4}
 category command-line-handler x-default @mozilla.org/mail/clh;1
 category command-line-validator b-default @mozilla.org/mail/clh;1
 
 component {1c73f03a-b817-4640-b984-18c3478a9ae3} mailContentHandler.js
 contract @mozilla.org/uriloader/content-handler;1?type=text/html {1c73f03a-b817-4640-b984-18c3478a9ae3}
 contract @mozilla.org/uriloader/content-handler;1?type=text/plain {1c73f03a-b817-4640-b984-18c3478a9ae3}
+
+component {eb239c82-fac9-431e-98d7-11cacd0f71b8} mailGlue.js
+contract @mozilla.org/mail/mailglue;1 {eb239c82-fac9-431e-98d7-11cacd0f71b8}
+category app-startup MailGlue service,@mozilla.org/mail/mailglue;1
new file mode 100644
--- /dev/null
+++ b/mail/components/mailGlue.js
@@ -0,0 +1,95 @@
+/* -*- Mode: JavaScript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * the Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Siddharth Agarwal <sid.bugzilla@gmail.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+const Ci = Components.interfaces;
+const Cc = Components.classes;
+const Cu = Components.utils;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+
+/**
+ * Glue code that should be executed before any windows are opened. Any
+ * window-independent helper methods (a la nsBrowserGlue.js) should go in
+ * MailUtils.js instead.
+ */
+
+function MailGlue() {
+  this._init();
+}
+
+MailGlue.prototype = {
+  // init (called at app startup)
+  _init: function MailGlue__init() {
+    Services.obs.addObserver(this, "xpcom-shutdown", false);
+    Services.obs.addObserver(this, "final-ui-startup", false);
+  },
+
+  // cleanup (called at shutdown)
+  _dispose: function MailGlue__dispose() {
+    Services.obs.removeObserver(this, "xpcom-shutdown");
+    Services.obs.removeObserver(this, "final-ui-startup");
+  },
+
+  // nsIObserver implementation
+  observe: function MailGlue_observe(aSubject, aTopic, aData) {
+    switch (aTopic) {
+    case "xpcom-shutdown":
+      this._dispose();
+      break;
+    case "final-ui-startup":
+      this._onProfileStartup();
+      break;
+    }
+  },
+
+  _onProfileStartup: function MailGlue__onProfileStartup() {
+    // check if we're in safe mode
+    if (Services.appinfo.inSafeMode) {
+      Services.ww.openWindow(null, "chrome://messenger/content/safeMode.xul", 
+                             "_blank", "chrome,centerscreen,modal,resizable=no", null);
+    }
+  },
+
+  // for XPCOM
+  classID: Components.ID("{eb239c82-fac9-431e-98d7-11cacd0f71b8}"),
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
+};
+
+var components = [MailGlue];
+var NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
new file mode 100644
--- /dev/null
+++ b/mail/locales/en-US/chrome/messenger/safeMode.dtd
@@ -0,0 +1,55 @@
+<!-- ***** BEGIN LICENSE BLOCK *****
+#if 0
+   - Version: MPL 1.1/GPL 2.0/LGPL 2.1
+   -
+   - The contents of this file are subject to the Mozilla Public License Version
+   - 1.1 (the "License"); you may not use this file except in compliance with
+   - the License. You may obtain a copy of the License at
+   - http://www.mozilla.org/MPL/
+   -
+   - Software distributed under the License is distributed on an "AS IS" basis,
+   - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+   - for the specific language governing rights and limitations under the
+   - License.
+   -
+   - The Original Code is mozilla.org Code.
+   -
+   - The Initial Developer of the Original Code is Mike Connor.
+   - Portions created by the Initial Developer are Copyright (C) 2005
+   - the Initial Developer. All Rights Reserved.
+   -
+   - Contributor(s):
+   -   Mike Connor <mconnor@steelgryphon.com>
+   -
+   - Alternatively, the contents of this file may be used under the terms of
+   - either the GNU General Public License Version 2 or later (the "GPL"), or
+   - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+   - in which case the provisions of the GPL or the LGPL are applicable instead
+   - of those above. If you wish to allow use of your version of this file only
+   - under the terms of either the GPL or the LGPL, and not to allow others to
+   - use your version of this file under the terms of the MPL, indicate your
+   - decision by deleting the provisions above and replace them with the notice
+   - and other provisions required by the LGPL or the GPL. If you do not delete
+   - the provisions above, a recipient may use your version of this file under
+   - the terms of any one of the MPL, the GPL or the LGPL.
+   -
+#endif
+   - ***** END LICENSE BLOCK ***** -->
+
+<!ENTITY safeModeDialog.title             "&brandShortName; Safe Mode">
+<!ENTITY window.width                     "37em">
+
+<!ENTITY safeModeDescription.label        "&brandShortName; is now running in Safe Mode, which temporarily disables your custom settings, themes, and extensions.">
+<!ENTITY safeModeDescription2.label       "You can make some or all of these changes permanent:">
+
+<!ENTITY disableAddons.label              "Disable all add-ons">
+<!ENTITY disableAddons.accesskey          "D">
+
+<!ENTITY resetToolbars.label              "Reset toolbars and controls">
+<!ENTITY resetToolbars.accesskey          "R">
+
+<!ENTITY changeAndRestartButton.label     "Make Changes and Restart">
+<!ENTITY changeAndRestartButton.accesskey "M">
+
+<!ENTITY continueButton.label             "Continue in Safe Mode">
+<!ENTITY continueButton.accesskey         "C">
--- a/mail/locales/jar.mn
+++ b/mail/locales/jar.mn
@@ -102,16 +102,17 @@
   locale/@AB_CD@/messenger/featureConfigurator.dtd                      (%chrome/messenger/featureConfigurator.dtd)
   locale/@AB_CD@/messenger/configEditorOverlay.dtd                      (%chrome/messenger/configEditorOverlay.dtd)
   locale/@AB_CD@/messenger/gloda.properties                             (%chrome/messenger/gloda.properties)
   locale/@AB_CD@/messenger/glodaComplete.properties                     (%chrome/messenger/glodaComplete.properties)
   locale/@AB_CD@/messenger/templateUtils.properties                     (%chrome/messenger/templateUtils.properties)
   locale/@AB_CD@/messenger/glodaFacetView.properties                    (%chrome/messenger/glodaFacetView.properties)
   locale/@AB_CD@/messenger/glodaFacetView.dtd                           (%chrome/messenger/glodaFacetView.dtd)
   locale/@AB_CD@/messenger/quickFilterBar.dtd                           (%chrome/messenger/quickFilterBar.dtd)
+  locale/@AB_CD@/messenger/safeMode.dtd                                 (%chrome/messenger/safeMode.dtd)
   locale/@AB_CD@/messenger/addressbook/abMainWindow.dtd                 (%chrome/messenger/addressbook/abMainWindow.dtd)
   locale/@AB_CD@/messenger/addressbook/abNewCardDialog.dtd              (%chrome/messenger/addressbook/abNewCardDialog.dtd)
   locale/@AB_CD@/messenger/addressbook/abContactsPanel.dtd              (%chrome/messenger/addressbook/abContactsPanel.dtd)
   locale/@AB_CD@/messenger/addressbook/abAddressBookNameDialog.dtd      (%chrome/messenger/addressbook/abAddressBookNameDialog.dtd)
   locale/@AB_CD@/messenger/addressbook/abCardOverlay.dtd                (%chrome/messenger/addressbook/abCardOverlay.dtd)
   locale/@AB_CD@/messenger/addressbook/abCardViewOverlay.dtd            (%chrome/messenger/addressbook/abCardViewOverlay.dtd)
   locale/@AB_CD@/messenger/addressbook/abDirTreeOverlay.dtd             (%chrome/messenger/addressbook/abDirTreeOverlay.dtd)
   locale/@AB_CD@/messenger/addressbook/abResultsPaneOverlay.dtd         (%chrome/messenger/addressbook/abResultsPaneOverlay.dtd)