Bug 1240594 - Deduplicate certerror and neterror message passing code. r=Gijs

MozReview-Commit-ID: 3M8caW1Zqsv

--HG--
extra : rebase_source : d64c4ba26878d702aec5f74283cb6d84327a532e
This commit is contained in:
Nihanth Subramanya 2016-03-15 02:36:21 -07:00
parent 87f70a9bc2
commit 5105f59732
2 changed files with 38 additions and 99 deletions

View File

@ -2664,9 +2664,9 @@ var BrowserOnClick = {
receiveMessage: function (msg) {
switch (msg.name) {
case "Browser:CertExceptionError":
this.onAboutCertError(msg.target, msg.data.elementId,
msg.data.isTopFrame, msg.data.location,
msg.data.securityInfoAsString);
this.onCertError(msg.target, msg.data.elementId,
msg.data.isTopFrame, msg.data.location,
msg.data.securityInfoAsString);
break;
case "Browser:SiteBlockedError":
this.onAboutBlocked(msg.data.elementId, msg.data.reason,
@ -2727,7 +2727,7 @@ var BrowserOnClick = {
uri.host, uri.port);
},
onAboutCertError: function (browser, elementId, isTopFrame, location, securityInfoAsString) {
onCertError: function (browser, elementId, isTopFrame, location, securityInfoAsString) {
let secHistogram = Services.telemetry.getHistogramById("SECURITY_UI");
switch (elementId) {
@ -2778,7 +2778,7 @@ var BrowserOnClick = {
let errorInfo = getDetailedCertErrorInfo(location,
securityInfoAsString);
browser.messageManager.sendAsyncMessage("AboutCertErrorDetails",
browser.messageManager.sendAsyncMessage("CertErrorDetails",
{ info: errorInfo });
break;

View File

@ -212,98 +212,10 @@ const TLS_ERROR_REPORT_TELEMETRY_EXPANDED = 1;
const TLS_ERROR_REPORT_TELEMETRY_SUCCESS = 6;
const TLS_ERROR_REPORT_TELEMETRY_FAILURE = 7;
var AboutCertErrorListener = {
init(chromeGlobal) {
addMessageListener("AboutCertErrorDetails", this);
chromeGlobal.addEventListener("AboutCertErrorLoad", this, false, true);
chromeGlobal.addEventListener("AboutCertErrorSetAutomatic", this, false, true);
},
get isAboutCertError() {
return content.document.documentURI.startsWith("about:certerror");
},
handleEvent(event) {
if (!this.isAboutCertError) {
return;
}
switch (event.type) {
case "AboutCertErrorLoad":
this.onLoad(event);
break;
case "AboutCertErrorSetAutomatic":
this.onSetAutomatic(event);
break;
}
},
receiveMessage(msg) {
if (!this.isAboutCertError) {
return;
}
switch (msg.name) {
case "AboutCertErrorDetails":
this.onDetails(msg);
break;
}
},
onLoad(event) {
let originalTarget = event.originalTarget;
let ownerDoc = originalTarget.ownerDocument;
ClickEventHandler.onAboutCertError(originalTarget, ownerDoc);
// Set up the TLS Error Reporting UI - reports are sent automatically
// (from nsHttpChannel::OnStopRequest) if the user has previously enabled
// automatic sending of reports. The UI ensures that a report is sent
// for the certificate error currently displayed if the user enables it
// here.
let automatic = Services.prefs.getBoolPref("security.ssl.errorReporting.automatic");
content.dispatchEvent(new content.CustomEvent("AboutCertErrorOptions", {
detail: JSON.stringify({
enabled: Services.prefs.getBoolPref("security.ssl.errorReporting.enabled"),
automatic,
})
}));
},
onDetails(msg) {
let div = content.document.getElementById("certificateErrorText");
div.textContent = msg.data.info;
},
onSetAutomatic(event) {
sendAsyncMessage("Browser:SetSSLErrorReportAuto", {
automatic: event.detail
});
// if we're enabling reports, send a report for this failure
if (event.detail) {
let serhelper = Cc["@mozilla.org/network/serialization-helper;1"]
.getService(Ci.nsISerializationHelper);
let serializable = docShell.failedChannel.securityInfo
.QueryInterface(Ci.nsITransportSecurityInfo)
.QueryInterface(Ci.nsISerializable);
let serializedSecurityInfo = serhelper.serializeToString(serializable);
let {host, port} = content.document.mozDocumentURIIfNotForErrorPages;
sendAsyncMessage("Browser:SendSSLErrorReport", {
uri: { host, port },
securityInfo: serializedSecurityInfo
});
}
},
};
AboutCertErrorListener.init(this);
var AboutNetErrorListener = {
var AboutNetAndCertErrorListener = {
init: function(chromeGlobal) {
addMessageListener("CertErrorDetails", this);
chromeGlobal.addEventListener('AboutNetErrorLoad', this, false, true);
chromeGlobal.addEventListener('AboutNetErrorSetAutomatic', this, false, true);
chromeGlobal.addEventListener('AboutNetErrorOverride', this, false, true);
@ -313,8 +225,29 @@ var AboutNetErrorListener = {
return content.document.documentURI.startsWith("about:neterror");
},
get isAboutCertError() {
return content.document.documentURI.startsWith("about:certerror");
},
receiveMessage: function(msg) {
if (!this.isAboutCertError) {
return;
}
switch (msg.name) {
case "CertErrorDetails":
this.onCertErrorDetails(msg);
break;
}
},
onCertErrorDetails(msg) {
let div = content.document.getElementById("certificateErrorText");
div.textContent = msg.data.info;
},
handleEvent: function(aEvent) {
if (!this.isAboutNetError) {
if (!this.isAboutNetError && !this.isAboutCertError) {
return;
}
@ -332,6 +265,12 @@ var AboutNetErrorListener = {
},
onPageLoad: function(evt) {
if (this.isAboutCertError) {
let originalTarget = evt.originalTarget;
let ownerDoc = originalTarget.ownerDocument;
ClickEventHandler.onCertError(originalTarget, ownerDoc);
}
let automatic = Services.prefs.getBoolPref("security.ssl.errorReporting.automatic");
content.dispatchEvent(new content.CustomEvent("AboutNetErrorOptions", {
detail: JSON.stringify({
@ -375,7 +314,7 @@ var AboutNetErrorListener = {
}
}
AboutNetErrorListener.init(this);
AboutNetAndCertErrorListener.init(this);
var ClickEventHandler = {
@ -398,7 +337,7 @@ var ClickEventHandler = {
// Handle click events from about pages
if (ownerDoc.documentURI.startsWith("about:certerror")) {
this.onAboutCertError(originalTarget, ownerDoc);
this.onCertError(originalTarget, ownerDoc);
return;
} else if (ownerDoc.documentURI.startsWith("about:blocked")) {
this.onAboutBlocked(originalTarget, ownerDoc);
@ -458,7 +397,7 @@ var ClickEventHandler = {
}
},
onAboutCertError: function (targetElement, ownerDoc) {
onCertError: function (targetElement, ownerDoc) {
let docshell = ownerDoc.defaultView.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell);