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 downloadcert.xhtml: a dialog that allows
9 * a user to confirm whether to import a certificate, and if so what trust
11 * @param {nsISupports} window.arguments.0
12 * Certificate to confirm import of, queryable to nsIX509Cert.
13 * @param {nsISupports} window.arguments.1
14 * Object to set the return values of calling the dialog on, queryable
15 * to the underlying type of DownloadCertReturnValues.
19 * @typedef DownloadCertReturnValues
20 * @type {nsIWritablePropertyBag2}
21 * @property {boolean} importConfirmed
22 * Set to true if the user confirmed import of the cert and accepted
23 * the dialog, false otherwise.
24 * @property {boolean} trustForSSL
25 * Set to true if the cert should be trusted for SSL, false otherwise.
26 * Undefined value if |importConfirmed| is not true.
27 * @property {boolean} trustForEmail
28 * Set to true if the cert should be trusted for e-mail, false
29 * otherwise. Undefined value if |importConfirmed| is not true.
33 * The cert to potentially import.
43 gCert = window.arguments[0].QueryInterface(Ci.nsIX509Cert);
45 document.addEventListener("dialogaccept", onDialogAccept);
46 document.addEventListener("dialogcancel", onDialogCancel);
48 let bundle = document.getElementById("pippki_bundle");
49 let caName = gCert.commonName;
51 caName = bundle.getString("unnamedCA");
54 setText("trustHeader", bundle.getFormattedString("newCAMessage1", [caName]));
58 * Handler for the "View Cert" button.
61 viewCertHelper(window, gCert, "window");
65 * ondialogaccept() handler.
67 function onDialogAccept() {
68 let checkSSL = document.getElementById("trustSSL");
69 let checkEmail = document.getElementById("trustEmail");
71 let retVals = window.arguments[1].QueryInterface(Ci.nsIWritablePropertyBag2);
72 retVals.setPropertyAsBool("importConfirmed", true);
73 retVals.setPropertyAsBool("trustForSSL", checkSSL.checked);
74 retVals.setPropertyAsBool("trustForEmail", checkEmail.checked);
78 * ondialogcancel() handler.
80 function onDialogCancel() {
81 let retVals = window.arguments[1].QueryInterface(Ci.nsIWritablePropertyBag2);
82 retVals.setPropertyAsBool("importConfirmed", false);