diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /security/manager/pki/resources/content/deletecert.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'security/manager/pki/resources/content/deletecert.js')
-rw-r--r-- | security/manager/pki/resources/content/deletecert.js | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/security/manager/pki/resources/content/deletecert.js b/security/manager/pki/resources/content/deletecert.js new file mode 100644 index 0000000000..7d926863ed --- /dev/null +++ b/security/manager/pki/resources/content/deletecert.js @@ -0,0 +1,121 @@ +/* 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"; + +/** + * @file Implements the functionality of deletecert.xhtml: a dialog that allows a + * user to confirm whether to delete certain certificates. + * @param {string} window.arguments.0 + * One of the tab IDs listed in certManager.xhtml. + * @param {object[]} window.arguments.1 + * An array of objects representing the certs to delete. + * Each must have a 'cert' property or a 'hostPort' property. + * @param {DeleteCertReturnValues} window.arguments.2 + * Object holding the return values of calling the dialog. + */ + +/** + * @typedef DeleteCertReturnValues + * @type {object} + * @property {boolean} deleteConfirmed + * Set to true if the user confirmed deletion of the given certs, + * false otherwise. + */ + +/** + * Returns the element to represent the given cert to delete. + * + * @param {object} certToDelete + * The item to represent. + * @returns {Element} + * A element of each cert tree item. + */ +function getLabelForCertToDelete(certToDelete) { + let element = document.createXULElement("label"); + let cert = certToDelete.cert; + if (!cert) { + element.setAttribute("value", certToDelete.hostPort); + return element; + } + + const attributes = [ + cert.commonName, + cert.organizationalUnit, + cert.organization, + cert.subjectName, + ]; + for (let attribute of attributes) { + if (attribute) { + element.setAttribute("value", attribute); + return element; + } + } + + document.l10n.setAttributes(element, "cert-with-serial", { + serialNumber: cert.serialNumber, + }); + return element; +} + +/** + * onload() handler. + */ +function onLoad() { + let typeFlag = window.arguments[0]; + let confirm = document.getElementById("confirm"); + let impact = document.getElementById("impact"); + let prefixForType; + switch (typeFlag) { + case "mine_tab": + prefixForType = "delete-user-cert-"; + break; + case "websites_tab": + prefixForType = "delete-ssl-override-"; + break; + case "ca_tab": + prefixForType = "delete-ca-cert-"; + break; + case "others_tab": + prefixForType = "delete-email-cert-"; + break; + default: + return; + } + + document.l10n.setAttributes( + document.documentElement, + prefixForType + "title" + ); + document.l10n.setAttributes(confirm, prefixForType + "confirm"); + document.l10n.setAttributes(impact, prefixForType + "impact"); + + document.addEventListener("dialogaccept", onDialogAccept); + document.addEventListener("dialogcancel", onDialogCancel); + + let box = document.getElementById("certlist"); + let certsToDelete = window.arguments[1]; + for (let certToDelete of certsToDelete) { + let listItem = document.createXULElement("richlistitem"); + let label = getLabelForCertToDelete(certToDelete); + listItem.appendChild(label); + box.appendChild(listItem); + } +} + +/** + * ondialogaccept() handler. + */ +function onDialogAccept() { + let retVals = window.arguments[2]; + retVals.deleteConfirmed = true; +} + +/** + * ondialogcancel() handler. + */ +function onDialogCancel() { + let retVals = window.arguments[2]; + retVals.deleteConfirmed = false; +} |