1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 /* import-globals-from pippki.js */
7 document.addEventListener("dialogaccept", onDialogAccept);
10 * @file Implements the functionality of load_device.xhtml: a dialog that allows
11 * a PKCS #11 module to be loaded into Firefox.
14 async function onBrowseBtnPress() {
15 let fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
16 let [loadPK11ModuleFilePickerTitle] = await document.l10n.formatValues([
17 { id: "load-pk11-module-file-picker-title" },
20 window.browsingContext,
21 loadPK11ModuleFilePickerTitle,
22 Ci.nsIFilePicker.modeOpen
24 fp.appendFilters(Ci.nsIFilePicker.filterAll);
26 if (rv == Ci.nsIFilePicker.returnOK) {
27 document.getElementById("device_path").value = fp.file.path;
30 // This notification gets sent solely for test purposes. It should not be
31 // used by production code.
32 Services.obs.notifyObservers(window, "LoadPKCS11Module:FilePickHandled");
37 * ondialogaccept() handler.
39 * @param {object} event
40 * The event causing this handler function to be called.
42 function onDialogAccept(event) {
43 let nameBox = document.getElementById("device_name");
44 let pathBox = document.getElementById("device_path");
45 let pkcs11ModuleDB = Cc["@mozilla.org/security/pkcs11moduledb;1"].getService(
50 pkcs11ModuleDB.addModule(nameBox.value, pathBox.value, 0, 0);
52 addModuleFailure("add-module-failure");
53 event.preventDefault();
57 async function addModuleFailure(l10nID) {
58 let [AddModuleFailure] = await document.l10n.formatValues([{ id: l10nID }]);
59 alertPromptService(null, AddModuleFailure);
62 function validateModuleName() {
63 let name = document.getElementById("device_name").value;
64 let helpText = document.getElementById("helpText");
66 let dialogNode = document.querySelector("dialog");
67 dialogNode.removeAttribute("buttondisabledaccept");
69 document.l10n.setAttributes(helpText, "load-module-help-empty-module-name");
70 dialogNode.setAttribute("buttondisabledaccept", true);
72 if (name == "Root Certs") {
73 document.l10n.setAttributes(
75 "load-module-help-root-certs-module-name"
77 dialogNode.setAttribute("buttondisabledaccept", true);