Clean up exceptionDialog.js.

This commit is contained in:
Fedor 2019-12-25 15:45:14 +03:00
parent a59ad20972
commit f92331676b

View File

@ -57,7 +57,7 @@ function initExceptionDialog() {
if (args[0].location) { if (args[0].location) {
// We were pre-seeded with a location. // We were pre-seeded with a location.
document.getElementById("locationTextBox").value = args[0].location; document.getElementById("locationTextBox").value = args[0].location;
document.getElementById('checkCertButton').disabled = false; document.getElementById("checkCertButton").disabled = false;
if (args[0].sslStatus) { if (args[0].sslStatus) {
gSSLStatus = args[0].sslStatus; gSSLStatus = args[0].sslStatus;
@ -128,15 +128,17 @@ function checkCert() {
/** /**
* Build and return a URI, based on the information supplied in the * Build and return a URI, based on the information supplied in the
* Certificate Location fields * Certificate Location fields
*
* @returns {nsIURI}
* URI constructed from the information supplied on success, null
* otherwise.
*/ */
function getURI() { function getURI() {
// Use fixup service instead of just ioservice's newURI since it's quite // Use fixup service instead of just ioservice's newURI since it's quite
// likely that the host will be supplied without a protocol prefix, resulting // likely that the host will be supplied without a protocol prefix, resulting
// in malformed uri exceptions being thrown. // in malformed uri exceptions being thrown.
let fus = Components.classes["@mozilla.org/docshell/urifixup;1"]
.getService(Components.interfaces.nsIURIFixup);
let locationTextBox = document.getElementById("locationTextBox"); let locationTextBox = document.getElementById("locationTextBox");
let uri = fus.createFixupURI(locationTextBox.value, 0); let uri = Services.uriFixup.createFixupURI(locationTextBox.value, 0);
if (!uri) { if (!uri) {
return null; return null;
@ -170,7 +172,7 @@ function resetDialog() {
* Called by input textboxes to manage UI state * Called by input textboxes to manage UI state
*/ */
function handleTextChange() { function handleTextChange() {
var checkCertButton = document.getElementById('checkCertButton'); var checkCertButton = document.getElementById("checkCertButton");
checkCertButton.disabled = !(document.getElementById("locationTextBox").value); checkCertButton.disabled = !(document.getElementById("locationTextBox").value);
if (gNeedReset) { if (gNeedReset) {
gNeedReset = false; gNeedReset = false;
@ -238,8 +240,7 @@ function updateCertStatus() {
pe.checked = !inPrivateBrowsing; pe.checked = !inPrivateBrowsing;
setText("headerDescription", gPKIBundle.getString("addExceptionInvalidHeader")); setText("headerDescription", gPKIBundle.getString("addExceptionInvalidHeader"));
} } else {
else {
shortDesc = "addExceptionValidShort"; shortDesc = "addExceptionValidShort";
longDesc = "addExceptionValidLong"; longDesc = "addExceptionValidLong";
gDialog.getButton("extra1").disabled = true; gDialog.getButton("extra1").disabled = true;
@ -251,11 +252,8 @@ function updateCertStatus() {
document.getElementById("viewCertButton").disabled = false; document.getElementById("viewCertButton").disabled = false;
// Notify observers about the availability of the certificate // Notify observers about the availability of the certificate
Components.classes["@mozilla.org/observer-service;1"] Services.obs.notifyObservers(null, "cert-exception-ui-ready");
.getService(Components.interfaces.nsIObserverService) } else if (gChecking) {
.notifyObservers(null, "cert-exception-ui-ready", null);
}
else if (gChecking) {
shortDesc = "addExceptionCheckingShort"; shortDesc = "addExceptionCheckingShort";
longDesc = "addExceptionCheckingLong2"; longDesc = "addExceptionCheckingLong2";
// We're checking the certificate, so we disable the Get Certificate // We're checking the certificate, so we disable the Get Certificate
@ -265,8 +263,7 @@ function updateCertStatus() {
document.getElementById("viewCertButton").disabled = true; document.getElementById("viewCertButton").disabled = true;
gDialog.getButton("extra1").disabled = true; gDialog.getButton("extra1").disabled = true;
document.getElementById("permanent").disabled = true; document.getElementById("permanent").disabled = true;
} } else {
else {
shortDesc = "addExceptionNoCertShort"; shortDesc = "addExceptionNoCertShort";
longDesc = "addExceptionNoCertLong2"; longDesc = "addExceptionNoCertLong2";
// We're done checking the certificate, so allow the user to check it again. // We're done checking the certificate, so allow the user to check it again.