[Pale-Moon] Issue #1744 - Add pref to ask for master password on application start.

This is a solution for some users having issues with multiple MP prompts due to
either a race or asynchronously-triggered features that each need password
database access (e.g. website login + sync)

Based on Interlink's similar solution by Matt A. Tobin
This commit is contained in:
Moonchild 2020-09-21 21:03:55 +00:00 • committed by roytam1
commit 093f9b4f55
2 changed files with 25 additions and 0 deletions

View file

@ -286,6 +286,7 @@ BrowserGlue.prototype = {
break;
case "profile-after-change":
this._onProfileAfterChange();
this._promptForMasterPassword();
break;
case "browser-search-engine-modified":
if (data != "engine-default" && data != "engine-current") {
@ -409,6 +410,26 @@ BrowserGlue.prototype = {
{
this._copyDefaultProfileFiles();
},
_promptForMasterPassword: function() {
if (!Services.prefs.getBoolPref("signon.startup.prompt", false))
return;
// Try to avoid the multiple master password prompts on startup scenario
// by prompting for the master password upfront.
let token = Components.classes["@mozilla.org/security/pk11tokendb;1"]
.getService(Components.interfaces.nsIPK11TokenDB)
.getInternalKeyToken();
// Only log in to the internal token if it is already initialized,
// otherwise we get a "Change Master Password" dialog.
try {
if (!token.needsUserInit)
token.login(false);
} catch (ex) {
// If user cancels an exception is expected.
}
},
_onAppDefaults: function() {
// apply distribution customizations (prefs)