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 */
8 * @file Implements the functionality of deletecert.xhtml: a dialog that allows a
9 * user to confirm whether to delete certain certificates.
10 * @param {string} window.arguments.0
11 * One of the tab IDs listed in certManager.xhtml.
12 * @param {object[]} window.arguments.1
13 * An array of objects representing the certs to delete.
14 * Each must have a 'cert' property or a 'hostPort' property.
15 * @param {DeleteCertReturnValues} window.arguments.2
16 * Object holding the return values of calling the dialog.
20 * @typedef DeleteCertReturnValues
22 * @property {boolean} deleteConfirmed
23 * Set to true if the user confirmed deletion of the given certs,
28 * Returns the element to represent the given cert to delete.
30 * @param {object} certToDelete
31 * The item to represent.
33 * A element of each cert tree item.
35 function getLabelForCertToDelete(certToDelete) {
36 let element = document.createXULElement("label");
37 let cert = certToDelete.cert;
39 element.setAttribute("value", certToDelete.hostPort);
45 cert.organizationalUnit,
49 for (let attribute of attributes) {
51 element.setAttribute("value", attribute);
56 document.l10n.setAttributes(element, "cert-with-serial", {
57 serialNumber: cert.serialNumber,
66 let typeFlag = window.arguments[0];
67 let confirm = document.getElementById("confirm");
68 let impact = document.getElementById("impact");
72 prefixForType = "delete-user-cert-";
75 prefixForType = "delete-ssl-override-";
78 prefixForType = "delete-ca-cert-";
81 prefixForType = "delete-email-cert-";
87 document.l10n.setAttributes(
88 document.documentElement,
89 prefixForType + "title"
91 document.l10n.setAttributes(confirm, prefixForType + "confirm");
92 document.l10n.setAttributes(impact, prefixForType + "impact");
94 document.addEventListener("dialogaccept", onDialogAccept);
95 document.addEventListener("dialogcancel", onDialogCancel);
97 let box = document.getElementById("certlist");
98 let certsToDelete = window.arguments[1];
99 for (let certToDelete of certsToDelete) {
100 let listItem = document.createXULElement("richlistitem");
101 let label = getLabelForCertToDelete(certToDelete);
102 listItem.appendChild(label);
103 box.appendChild(listItem);
108 * ondialogaccept() handler.
110 function onDialogAccept() {
111 let retVals = window.arguments[2];
112 retVals.deleteConfirmed = true;
116 * ondialogcancel() handler.
118 function onDialogCancel() {
119 let retVals = window.arguments[2];
120 retVals.deleteConfirmed = false;