Bug 1422811 - Move reportTLS functionality for cert error pages into content.js. r=Gijs,mgoodwin
This also ensures that we consider certificate error pages in frames as well as top-level.
MozReview-Commit-ID: IA4vT8yZnuN
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -2910,32 +2910,30 @@ const PREF_SSL_IMPACT_ROOTS = ["security
*/
var BrowserOnClick = {
init() {
let mm = window.messageManager;
mm.addMessageListener("Browser:CertExceptionError", this);
mm.addMessageListener("Browser:OpenCaptivePortalPage", this);
mm.addMessageListener("Browser:SiteBlockedError", this);
mm.addMessageListener("Browser:EnableOnlineMode", this);
- mm.addMessageListener("Browser:SendSSLErrorReport", this);
mm.addMessageListener("Browser:SetSSLErrorReportAuto", this);
mm.addMessageListener("Browser:ResetSSLPreferences", this);
mm.addMessageListener("Browser:SSLErrorReportTelemetry", this);
mm.addMessageListener("Browser:SSLErrorGoBack", this);
Services.obs.addObserver(this, "captive-portal-login-abort");
Services.obs.addObserver(this, "captive-portal-login-success");
},
uninit() {
let mm = window.messageManager;
mm.removeMessageListener("Browser:CertExceptionError", this);
mm.removeMessageListener("Browser:SiteBlockedError", this);
mm.removeMessageListener("Browser:EnableOnlineMode", this);
- mm.removeMessageListener("Browser:SendSSLErrorReport", this);
mm.removeMessageListener("Browser:SetSSLErrorReportAuto", this);
mm.removeMessageListener("Browser:ResetSSLPreferences", this);
mm.removeMessageListener("Browser:SSLErrorReportTelemetry", this);
mm.removeMessageListener("Browser:SSLErrorGoBack", this);
Services.obs.removeObserver(this, "captive-portal-login-abort");
Services.obs.removeObserver(this, "captive-portal-login-success");
},
@@ -2968,21 +2966,16 @@ var BrowserOnClick = {
break;
case "Browser:EnableOnlineMode":
if (Services.io.offline) {
// Reset network state and refresh the page.
Services.io.offline = false;
msg.target.reload();
}
break;
- case "Browser:SendSSLErrorReport":
- this.onSSLErrorReport(msg.target,
- msg.data.uri,
- msg.data.securityInfo);
- break;
case "Browser:ResetSSLPreferences":
let prefSSLImpact = PREF_SSL_IMPACT_ROOTS.reduce((prefs, root) => {
return prefs.concat(Services.prefs.getChildList(root));
}, []);
for (let prefName of prefSSLImpact) {
Services.prefs.clearUserPref(prefName);
}
msg.target.reload();
@@ -3001,33 +2994,16 @@ var BrowserOnClick = {
.add(reportStatus);
break;
case "Browser:SSLErrorGoBack":
goBackFromErrorPage();
break;
}
},
- onSSLErrorReport(browser, uri, securityInfo) {
- if (!Services.prefs.getBoolPref("security.ssl.errorReporting.enabled")) {
- Cu.reportError("User requested certificate error report sending, but certificate error reporting is disabled");
- return;
- }
-
- let serhelper = Cc["@mozilla.org/network/serialization-helper;1"]
- .getService(Ci.nsISerializationHelper);
- let transportSecurityInfo = serhelper.deserializeObject(securityInfo);
- transportSecurityInfo.QueryInterface(Ci.nsITransportSecurityInfo);
-
- let errorReporter = Cc["@mozilla.org/securityreporter;1"]
- .getService(Ci.nsISecurityReporter);
- errorReporter.reportTLSError(transportSecurityInfo,
- uri.host, uri.port);
- },
-
onCertError(browser, elementId, isTopFrame, location, securityInfoAsString) {
let secHistogram = Services.telemetry.getHistogramById("SECURITY_UI");
let securityInfo;
switch (elementId) {
case "exceptionDialogButton":
if (isTopFrame) {
secHistogram.add(Ci.nsISecurityUITelemetry.WARNING_BAD_CERT_TOP_CLICK_ADD_EXCEPTION);
--- a/browser/base/content/content.js
+++ b/browser/base/content/content.js
@@ -437,24 +437,30 @@ var AboutNetAndCertErrorListener = {
sendAsyncMessage("Browser:ResetSSLPreferences");
},
onSetAutomatic(evt) {
sendAsyncMessage("Browser:SetSSLErrorReportAuto", {
automatic: evt.detail
});
- // if we're enabling reports, send a report for this failure
+ // If we're enabling reports, send a report for this failure.
if (evt.detail) {
- let {host, port} = content.document.mozDocumentURIIfNotForErrorPages;
- sendAsyncMessage("Browser:SendSSLErrorReport", {
- uri: { host, port },
- securityInfo: getSerializedSecurityInfo(docShell),
- });
+ let win = evt.originalTarget.ownerGlobal;
+ let docShell = win.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIWebNavigation)
+ .QueryInterface(Ci.nsIDocShell);
+ let {securityInfo} = docShell.failedChannel;
+ securityInfo.QueryInterface(Ci.nsITransportSecurityInfo);
+ let {host, port} = win.document.mozDocumentURIIfNotForErrorPages;
+
+ let errorReporter = Cc["@mozilla.org/securityreporter;1"]
+ .getService(Ci.nsISecurityReporter);
+ errorReporter.reportTLSError(securityInfo, host, port);
}
},
};
AboutNetAndCertErrorListener.init(this);
AboutBlockedSiteListener.init(this);
var ClickEventHandler = {