Bug 381269 Workaround for multiple master password prompts on startup r+sr=Neil a=IanN
authorJens Hatlak <jh@junetz.de>
Wed, 07 Oct 2009 00:37:37 +0100
changeset 4062 0e28d1ce1aeb
parent 4061 71d3504685ab
child 4063 82a189244d8c
push id3174
push userneil@parkwaycc.co.uk
push date2009-10-06 23:37 +0000
treeherdercomm-central@0e28d1ce1aeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersIanN
bugs381269
Bug 381269 Workaround for multiple master password prompts on startup r+sr=Neil a=IanN
suite/browser/browser-prefs.js
suite/common/src/nsSuiteGlue.js
--- a/suite/browser/browser-prefs.js
+++ b/suite/browser/browser-prefs.js
@@ -42,16 +42,19 @@
  */
 
 pref("startup.homepage_override_url","chrome://navigator-region/locale/region.properties");
 pref("general.skins.selectedSkin", "classic/1.0");
 
 pref("browser.chromeURL","chrome://navigator/content/navigator.xul");
 pref("browser.hiddenWindowChromeURL", "chrome://navigator/content/hiddenWindow.xul");
 
+// prompt for Master Password on startup
+pref("signon.startup.prompt",               true);
+
 pref("general.startup.browser",             true);
 pref("general.startup.mail",                false);
 pref("general.startup.news",                false);
 pref("general.startup.editor",              false);
 pref("general.startup.compose",             false);
 pref("general.startup.addressbook",         false);
 
 pref("general.open_location.last_url",      "");
--- a/suite/common/src/nsSuiteGlue.js
+++ b/suite/common/src/nsSuiteGlue.js
@@ -65,16 +65,17 @@ SuiteGlue.prototype = {
   observe: function(subject, topic, data)
   {
     switch(topic) {
       case "xpcom-shutdown":
         this._dispose();
         break;
       case "final-ui-startup":
         this._onProfileStartup();
+        this._promptForMasterPassword();
         this._checkForNewAddons();
         break;
       case "browser:purge-session-history":
         // reset the console service's error buffer
         const cs = Components.classes["@mozilla.org/consoleservice;1"]
                              .getService(Components.interfaces.nsIConsoleService);
         cs.logStringMessage(null); // clear the console (in case it's open)
         cs.reset();
@@ -168,16 +169,39 @@ SuiteGlue.prototype = {
   },
 
   // profile shutdown handler (contains profile cleanup routines)
   _onProfileShutdown: function()
   {
     Sanitizer.checkAndSanitize();
   },
 
+  _promptForMasterPassword: function()
+  {
+    var prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
+                               .getService(Components.interfaces.nsIPrefBranch);
+    if (!prefBranch.getBoolPref("signon.startup.prompt"))
+      return;
+
+    // Look to see if a master password is set, if so prompt for it to try
+    // and avoid the multiple master password prompts on startup scenario.
+    let token = Components.classes["@mozilla.org/security/pk11tokendb;1"]
+                          .getService(Components.interfaces.nsIPK11TokenDB)
+                          .getInternalKeyToken();
+
+    // If an empty string is valid for the internal token, then we don't
+    // have a master password, else, if it does, then try to login.
+    try {
+      if (!token.checkPassword(""))
+        token.login(false);
+    } catch (ex) {
+      // If user cancels an exception is expected.
+    }
+  },
+
   // If new add-ons were installed during startup, open the add-ons manager.
   _checkForNewAddons: function()
   {
     const PREF_EM_NEW_ADDONS_LIST = "extensions.newAddons";
 
     const prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
                                  .getService(Components.interfaces.nsIPrefBranch);
     if (!prefBranch.prefHasUserValue(PREF_EM_NEW_ADDONS_LIST))