diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /security/manager/pki/resources/content/load_device.js | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'security/manager/pki/resources/content/load_device.js')
-rw-r--r-- | security/manager/pki/resources/content/load_device.js | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/security/manager/pki/resources/content/load_device.js b/security/manager/pki/resources/content/load_device.js new file mode 100644 index 0000000000..0f77e1f1bd --- /dev/null +++ b/security/manager/pki/resources/content/load_device.js @@ -0,0 +1,75 @@ +/* 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/. */ +/* import-globals-from pippki.js */ +"use strict"; + +document.addEventListener("dialogaccept", onDialogAccept); + +/** + * @file Implements the functionality of load_device.xhtml: a dialog that allows + * a PKCS #11 module to be loaded into Firefox. + */ + +async function onBrowseBtnPress() { + let fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker); + let [loadPK11ModuleFilePickerTitle] = await document.l10n.formatValues([ + { id: "load-pk11-module-file-picker-title" }, + ]); + fp.init(window, loadPK11ModuleFilePickerTitle, Ci.nsIFilePicker.modeOpen); + fp.appendFilters(Ci.nsIFilePicker.filterAll); + fp.open(rv => { + if (rv == Ci.nsIFilePicker.returnOK) { + document.getElementById("device_path").value = fp.file.path; + } + + // This notification gets sent solely for test purposes. It should not be + // used by production code. + Services.obs.notifyObservers(window, "LoadPKCS11Module:FilePickHandled"); + }); +} + +/** + * ondialogaccept() handler. + * + * @param {object} event + * The event causing this handler function to be called. + */ +function onDialogAccept(event) { + let nameBox = document.getElementById("device_name"); + let pathBox = document.getElementById("device_path"); + let pkcs11ModuleDB = Cc["@mozilla.org/security/pkcs11moduledb;1"].getService( + Ci.nsIPKCS11ModuleDB + ); + + try { + pkcs11ModuleDB.addModule(nameBox.value, pathBox.value, 0, 0); + } catch (e) { + addModuleFailure("add-module-failure"); + event.preventDefault(); + } +} + +async function addModuleFailure(l10nID) { + let [AddModuleFailure] = await document.l10n.formatValues([{ id: l10nID }]); + alertPromptService(null, AddModuleFailure); +} + +function validateModuleName() { + let name = document.getElementById("device_name").value; + let helpText = document.getElementById("helpText"); + helpText.value = ""; + let dialogNode = document.querySelector("dialog"); + dialogNode.removeAttribute("buttondisabledaccept"); + if (name == "") { + document.l10n.setAttributes(helpText, "load-module-help-empty-module-name"); + dialogNode.setAttribute("buttondisabledaccept", true); + } + if (name == "Root Certs") { + document.l10n.setAttributes( + helpText, + "load-module-help-root-certs-module-name" + ); + dialogNode.setAttribute("buttondisabledaccept", true); + } +} |