summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/preferences
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /toolkit/mozapps/preferences
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'toolkit/mozapps/preferences')
-rw-r--r--toolkit/mozapps/preferences/changemp.js237
-rw-r--r--toolkit/mozapps/preferences/changemp.xul67
-rw-r--r--toolkit/mozapps/preferences/fontbuilder.js126
-rw-r--r--toolkit/mozapps/preferences/jar.mn11
-rw-r--r--toolkit/mozapps/preferences/moz.build7
-rw-r--r--toolkit/mozapps/preferences/removemp.js56
-rw-r--r--toolkit/mozapps/preferences/removemp.xul46
7 files changed, 550 insertions, 0 deletions
diff --git a/toolkit/mozapps/preferences/changemp.js b/toolkit/mozapps/preferences/changemp.js
new file mode 100644
index 000000000..82dd20128
--- /dev/null
+++ b/toolkit/mozapps/preferences/changemp.js
@@ -0,0 +1,237 @@
+// -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*-
+
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const nsPK11TokenDB = "@mozilla.org/security/pk11tokendb;1";
+const nsIPK11TokenDB = Components.interfaces.nsIPK11TokenDB;
+const nsIDialogParamBlock = Components.interfaces.nsIDialogParamBlock;
+const nsPKCS11ModuleDB = "@mozilla.org/security/pkcs11moduledb;1";
+const nsIPKCS11ModuleDB = Components.interfaces.nsIPKCS11ModuleDB;
+const nsIPKCS11Slot = Components.interfaces.nsIPKCS11Slot;
+const nsIPK11Token = Components.interfaces.nsIPK11Token;
+
+
+var params;
+var tokenName="";
+var pw1;
+
+function init()
+{
+ pw1 = document.getElementById("pw1");
+
+ process();
+}
+
+
+function process()
+{
+ var secmoddb = Components.classes[nsPKCS11ModuleDB].getService(nsIPKCS11ModuleDB);
+ var bundle = document.getElementById("bundlePreferences");
+
+ // If the token is unitialized, don't use the old password box.
+ // Otherwise, do.
+
+ var slot = secmoddb.findSlotByName(tokenName);
+ if (slot) {
+ var oldpwbox = document.getElementById("oldpw");
+ var msgBox = document.getElementById("message");
+ var status = slot.status;
+ if (status == nsIPKCS11Slot.SLOT_UNINITIALIZED
+ || status == nsIPKCS11Slot.SLOT_READY) {
+
+ oldpwbox.setAttribute("hidden", "true");
+ msgBox.setAttribute("value", bundle.getString("password_not_set"));
+ msgBox.setAttribute("hidden", "false");
+
+ if (status == nsIPKCS11Slot.SLOT_READY) {
+ oldpwbox.setAttribute("inited", "empty");
+ } else {
+ oldpwbox.setAttribute("inited", "true");
+ }
+
+ // Select first password field
+ document.getElementById('pw1').focus();
+
+ } else {
+ // Select old password field
+ oldpwbox.setAttribute("hidden", "false");
+ msgBox.setAttribute("hidden", "true");
+ oldpwbox.setAttribute("inited", "false");
+ oldpwbox.focus();
+ }
+ }
+
+ if (params) {
+ // Return value 0 means "canceled"
+ params.SetInt(1, 0);
+ }
+
+ checkPasswords();
+}
+
+function setPassword()
+{
+ var pk11db = Components.classes[nsPK11TokenDB].getService(nsIPK11TokenDB);
+ var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
+ .getService(Components.interfaces.nsIPromptService);
+ var token = pk11db.findTokenByName(tokenName);
+ dump("*** TOKEN!!!! (name = |" + token + "|\n");
+
+ var oldpwbox = document.getElementById("oldpw");
+ var initpw = oldpwbox.getAttribute("inited");
+ var bundle = document.getElementById("bundlePreferences");
+
+ var success = false;
+
+ if (initpw == "false" || initpw == "empty") {
+ try {
+ var oldpw = "";
+ var passok = 0;
+
+ if (initpw == "empty") {
+ passok = 1;
+ } else {
+ oldpw = oldpwbox.value;
+ passok = token.checkPassword(oldpw);
+ }
+
+ if (passok) {
+ if (initpw == "empty" && pw1.value == "") {
+ // This makes no sense that we arrive here,
+ // we reached a case that should have been prevented by checkPasswords.
+ } else {
+ if (pw1.value == "") {
+ var secmoddb = Components.classes[nsPKCS11ModuleDB].getService(nsIPKCS11ModuleDB);
+ if (secmoddb.isFIPSEnabled) {
+ // empty passwords are not allowed in FIPS mode
+ promptService.alert(window,
+ bundle.getString("pw_change_failed_title"),
+ bundle.getString("pw_change2empty_in_fips_mode"));
+ passok = 0;
+ }
+ }
+ if (passok) {
+ token.changePassword(oldpw, pw1.value);
+ if (pw1.value == "") {
+ promptService.alert(window,
+ bundle.getString("pw_change_success_title"),
+ bundle.getString("pw_erased_ok")
+ + " " + bundle.getString("pw_empty_warning"));
+ } else {
+ promptService.alert(window,
+ bundle.getString("pw_change_success_title"),
+ bundle.getString("pw_change_ok"));
+ }
+ success = true;
+ }
+ }
+ } else {
+ oldpwbox.focus();
+ oldpwbox.setAttribute("value", "");
+ promptService.alert(window,
+ bundle.getString("pw_change_failed_title"),
+ bundle.getString("incorrect_pw"));
+ }
+ } catch (e) {
+ promptService.alert(window,
+ bundle.getString("pw_change_failed_title"),
+ bundle.getString("failed_pw_change"));
+ }
+ } else {
+ token.initPassword(pw1.value);
+ if (pw1.value == "") {
+ promptService.alert(window,
+ bundle.getString("pw_change_success_title"),
+ bundle.getString("pw_not_wanted")
+ + " " + bundle.getString("pw_empty_warning"));
+ }
+ success = true;
+ }
+
+ // Terminate dialog
+ if (success)
+ window.close();
+}
+
+function setPasswordStrength()
+{
+// Here is how we weigh the quality of the password
+// number of characters
+// numbers
+// non-alpha-numeric chars
+// upper and lower case characters
+
+ var pw=document.getElementById('pw1').value;
+
+// length of the password
+ var pwlength=(pw.length);
+ if (pwlength>5)
+ pwlength=5;
+
+
+// use of numbers in the password
+ var numnumeric = pw.replace (/[0-9]/g, "");
+ var numeric=(pw.length - numnumeric.length);
+ if (numeric>3)
+ numeric=3;
+
+// use of symbols in the password
+ var symbols = pw.replace (/\W/g, "");
+ var numsymbols=(pw.length - symbols.length);
+ if (numsymbols>3)
+ numsymbols=3;
+
+// use of uppercase in the password
+ var numupper = pw.replace (/[A-Z]/g, "");
+ var upper=(pw.length - numupper.length);
+ if (upper>3)
+ upper=3;
+
+
+ var pwstrength=((pwlength*10)-20) + (numeric*10) + (numsymbols*15) + (upper*10);
+
+ // make sure we're give a value between 0 and 100
+ if ( pwstrength < 0 ) {
+ pwstrength = 0;
+ }
+
+ if ( pwstrength > 100 ) {
+ pwstrength = 100;
+ }
+
+ var mymeter=document.getElementById('pwmeter');
+ mymeter.value = pwstrength;
+
+ return;
+}
+
+function checkPasswords()
+{
+ var pw1=document.getElementById('pw1').value;
+ var pw2=document.getElementById('pw2').value;
+ var ok=document.documentElement.getButton("accept");
+
+ var oldpwbox = document.getElementById("oldpw");
+ if (oldpwbox) {
+ var initpw = oldpwbox.getAttribute("inited");
+
+ if (initpw == "empty" && pw1 == "") {
+ // The token has already been initialized, therefore this dialog
+ // was called with the intention to change the password.
+ // The token currently uses an empty password.
+ // We will not allow changing the password from empty to empty.
+ ok.setAttribute("disabled", "true");
+ return;
+ }
+ }
+
+ if (pw1 == pw2) {
+ ok.setAttribute("disabled", "false");
+ } else
+ {
+ ok.setAttribute("disabled", "true");
+ }
+
+}
diff --git a/toolkit/mozapps/preferences/changemp.xul b/toolkit/mozapps/preferences/changemp.xul
new file mode 100644
index 000000000..14d02295e
--- /dev/null
+++ b/toolkit/mozapps/preferences/changemp.xul
@@ -0,0 +1,67 @@
+<?xml version="1.0"?>
+
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
+
+<!DOCTYPE dialog [
+<!ENTITY % brandDTD SYSTEM "chrome://branding/locale/brand.dtd" >
+<!ENTITY % changempDTD SYSTEM "chrome://mozapps/locale/preferences/changemp.dtd" >
+%brandDTD;
+%changempDTD;
+]>
+
+<dialog id="changemp" title="&setPassword.title;"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ style="width: 40em;"
+ ondialogaccept="setPassword();"
+ onload="init()">
+
+ <script type="application/javascript" src="chrome://mozapps/content/preferences/changemp.js"/>
+
+ <stringbundle id="bundlePreferences" src="chrome://mozapps/locale/preferences/preferences.properties"/>
+
+ <description control="pw1">&masterPasswordDescription.label;</description>
+
+ <groupbox>
+ <grid>
+ <columns>
+ <column flex="1"/>
+ <column/>
+ </columns>
+ <rows>
+ <row>
+ <label control="oldpw">&setPassword.oldPassword.label;</label>
+ <textbox id="oldpw" type="password"/>
+ <!-- This textbox is inserted as a workaround to the fact that making the 'type'
+ & 'disabled' property of the 'oldpw' textbox toggle between ['password' &
+ 'false'] and ['text' & 'true'] - as would be necessary if the menu has more
+ than one tokens, some initialized and some not - does not work properly. So,
+ either the textbox 'oldpw' or the textbox 'message' would be displayed,
+ depending on the state of the token selected
+ -->
+ <textbox id="message" disabled="true" />
+ </row>
+ <row>
+ <label control="pw1">&setPassword.newPassword.label;</label>
+ <textbox id="pw1" type="password"
+ oninput="setPasswordStrength(); checkPasswords();"/>
+ </row>
+ <row>
+ <label control="pw2">&setPassword.reenterPassword.label;</label>
+ <textbox id="pw2" type="password" oninput="checkPasswords();"/>
+ </row>
+ </rows>
+ </grid>
+ </groupbox>
+
+ <groupbox>
+ <caption label="&setPassword.meter.label;"/>
+ <progressmeter id="pwmeter" mode="determined" value="0"/>
+ </groupbox>
+
+ <description control="pw2" class="header">&masterPasswordWarning.label;</description>
+
+</dialog>
diff --git a/toolkit/mozapps/preferences/fontbuilder.js b/toolkit/mozapps/preferences/fontbuilder.js
new file mode 100644
index 000000000..a76ce6b25
--- /dev/null
+++ b/toolkit/mozapps/preferences/fontbuilder.js
@@ -0,0 +1,126 @@
+// -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
+
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var FontBuilder = {
+ _enumerator: null,
+ get enumerator ()
+ {
+ if (!this._enumerator) {
+ this._enumerator = Components.classes["@mozilla.org/gfx/fontenumerator;1"]
+ .createInstance(Components.interfaces.nsIFontEnumerator);
+ }
+ return this._enumerator;
+ },
+
+ _allFonts: null,
+ _langGroupSupported: false,
+ buildFontList: function (aLanguage, aFontType, aMenuList)
+ {
+ // Reset the list
+ while (aMenuList.hasChildNodes())
+ aMenuList.removeChild(aMenuList.firstChild);
+
+ var defaultFont = null;
+ // Load Font Lists
+ var fonts = this.enumerator.EnumerateFonts(aLanguage, aFontType, { } );
+ if (fonts.length > 0)
+ defaultFont = this.enumerator.getDefaultFont(aLanguage, aFontType);
+ else {
+ fonts = this.enumerator.EnumerateFonts(aLanguage, "", { });
+ if (fonts.length > 0)
+ defaultFont = this.enumerator.getDefaultFont(aLanguage, "");
+ }
+
+ if (!this._allFonts)
+ this._allFonts = this.enumerator.EnumerateAllFonts({});
+
+ // Build the UI for the Default Font and Fonts for this CSS type.
+ var popup = document.createElement("menupopup");
+ var separator;
+ if (fonts.length > 0) {
+ if (defaultFont) {
+ var bundlePreferences = document.getElementById("bundlePreferences");
+ var label = bundlePreferences.getFormattedString("labelDefaultFont", [defaultFont]);
+ var menuitem = document.createElement("menuitem");
+ menuitem.setAttribute("label", label);
+ menuitem.setAttribute("value", ""); // Default Font has a blank value
+ popup.appendChild(menuitem);
+
+ separator = document.createElement("menuseparator");
+ popup.appendChild(separator);
+ }
+
+ for (var i = 0; i < fonts.length; ++i) {
+ menuitem = document.createElement("menuitem");
+ menuitem.setAttribute("value", fonts[i]);
+ menuitem.setAttribute("label", fonts[i]);
+ popup.appendChild(menuitem);
+ }
+ }
+
+ // Build the UI for the remaining fonts.
+ if (this._allFonts.length > fonts.length) {
+ this._langGroupSupported = true;
+ // Both lists are sorted, and the Fonts-By-Type list is a subset of the
+ // All-Fonts list, so walk both lists side-by-side, skipping values we've
+ // already created menu items for.
+ var builtItem = separator ? separator.nextSibling : popup.firstChild;
+ var builtItemValue = builtItem ? builtItem.getAttribute("value") : null;
+
+ separator = document.createElement("menuseparator");
+ popup.appendChild(separator);
+
+ for (i = 0; i < this._allFonts.length; ++i) {
+ if (this._allFonts[i] != builtItemValue) {
+ menuitem = document.createElement("menuitem");
+ menuitem.setAttribute("value", this._allFonts[i]);
+ menuitem.setAttribute("label", this._allFonts[i]);
+ popup.appendChild(menuitem);
+ }
+ else {
+ builtItem = builtItem.nextSibling;
+ builtItemValue = builtItem ? builtItem.getAttribute("value") : null;
+ }
+ }
+ }
+ aMenuList.appendChild(popup);
+ },
+
+ readFontSelection(aElement)
+ {
+ // Determine the appropriate value to select, for the following cases:
+ // - there is no setting
+ // - the font selected by the user is no longer present (e.g. deleted from
+ // fonts folder)
+ let preference = document.getElementById(aElement.getAttribute("preference"));
+ if (preference.value) {
+ let fontItems = aElement.getElementsByAttribute("value", preference.value);
+
+ // There is a setting that actually is in the list. Respect it.
+ if (fontItems.length)
+ return undefined;
+ }
+
+ // The first item will be a reasonable choice only if the font backend
+ // supports language-specific enumaration.
+ let defaultValue = this._langGroupSupported ?
+ aElement.firstChild.firstChild.getAttribute("value") : "";
+ let fontNameList = preference.name.replace(".name.", ".name-list.");
+ let prefFontNameList = document.getElementById(fontNameList);
+ if (!prefFontNameList || !prefFontNameList.value)
+ return defaultValue;
+
+ let fontNames = prefFontNameList.value.split(",");
+
+ for (let i = 0; i < fontNames.length; ++i) {
+ let fontName = this.enumerator.getStandardFamilyName(fontNames[i].trim());
+ let fontItems = aElement.getElementsByAttribute("value", fontName);
+ if (fontItems.length)
+ return fontItems[0].getAttribute("value");
+ }
+ return defaultValue;
+ }
+};
diff --git a/toolkit/mozapps/preferences/jar.mn b/toolkit/mozapps/preferences/jar.mn
new file mode 100644
index 000000000..3ebdff5da
--- /dev/null
+++ b/toolkit/mozapps/preferences/jar.mn
@@ -0,0 +1,11 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+toolkit.jar:
+% content mozapps %content/mozapps/
+ content/mozapps/preferences/fontbuilder.js
+ content/mozapps/preferences/changemp.js
+ content/mozapps/preferences/changemp.xul
+ content/mozapps/preferences/removemp.js
+ content/mozapps/preferences/removemp.xul
diff --git a/toolkit/mozapps/preferences/moz.build b/toolkit/mozapps/preferences/moz.build
new file mode 100644
index 000000000..eb4454d28
--- /dev/null
+++ b/toolkit/mozapps/preferences/moz.build
@@ -0,0 +1,7 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+JAR_MANIFESTS += ['jar.mn'] \ No newline at end of file
diff --git a/toolkit/mozapps/preferences/removemp.js b/toolkit/mozapps/preferences/removemp.js
new file mode 100644
index 000000000..1f6356eac
--- /dev/null
+++ b/toolkit/mozapps/preferences/removemp.js
@@ -0,0 +1,56 @@
+// -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
+
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var gRemovePasswordDialog = {
+ _token : null,
+ _bundle : null,
+ _prompt : null,
+ _okButton : null,
+ _password : null,
+ init: function ()
+ {
+ this._prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
+ .getService(Components.interfaces.nsIPromptService);
+ this._bundle = document.getElementById("bundlePreferences");
+
+ this._okButton = document.documentElement.getButton("accept");
+ this._okButton.label = this._bundle.getString("pw_remove_button");
+
+ this._password = document.getElementById("password");
+
+ var pk11db = Components.classes["@mozilla.org/security/pk11tokendb;1"]
+ .getService(Components.interfaces.nsIPK11TokenDB);
+ this._token = pk11db.getInternalKeyToken();
+
+ // Initialize the enabled state of the Remove button by checking the
+ // initial value of the password ("" should be incorrect).
+ this.validateInput();
+ },
+
+ validateInput: function ()
+ {
+ this._okButton.disabled = !this._token.checkPassword(this._password.value);
+ },
+
+ removePassword: function ()
+ {
+ if (this._token.checkPassword(this._password.value)) {
+ this._token.changePassword(this._password.value, "");
+ this._prompt.alert(window,
+ this._bundle.getString("pw_change_success_title"),
+ this._bundle.getString("pw_erased_ok")
+ + " " + this._bundle.getString("pw_empty_warning"));
+ }
+ else {
+ this._password.value = "";
+ this._password.focus();
+ this._prompt.alert(window,
+ this._bundle.getString("pw_change_failed_title"),
+ this._bundle.getString("incorrect_pw"));
+ }
+ },
+};
+
diff --git a/toolkit/mozapps/preferences/removemp.xul b/toolkit/mozapps/preferences/removemp.xul
new file mode 100644
index 000000000..17ab48e39
--- /dev/null
+++ b/toolkit/mozapps/preferences/removemp.xul
@@ -0,0 +1,46 @@
+<?xml version="1.0"?>
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+
+<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
+
+<!DOCTYPE dialog [
+<!ENTITY % brandDTD SYSTEM "chrome://branding/locale/brand.dtd" >
+<!ENTITY % removempDTD SYSTEM "chrome://mozapps/locale/preferences/removemp.dtd" >
+%brandDTD;
+%removempDTD;
+]>
+
+<dialog id="removemp" title="&removePassword.title;"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ style="width: 35em;"
+ ondialogaccept="gRemovePasswordDialog.removePassword();"
+ onload="gRemovePasswordDialog.init()">
+
+ <script type="application/javascript" src="chrome://mozapps/content/preferences/removemp.js"/>
+
+ <stringbundle id="bundlePreferences" src="chrome://mozapps/locale/preferences/preferences.properties"/>
+
+ <vbox id="warnings">
+ <description>&removeWarning1.label;</description>
+ <description class="header">&removeWarning2.label;</description>
+ </vbox>
+
+ <separator class="thin"/>
+
+ <groupbox>
+ <caption label="&removeInfo.label;"/>
+
+ <hbox align="center">
+ <label control="password" value="&setPassword.oldPassword.label;"/>
+ <textbox id="password" type="password"
+ oninput="gRemovePasswordDialog.validateInput();"
+ aria-describedby="warnings"/>
+ </hbox>
+ </groupbox>
+
+ <separator/>
+
+</dialog>