Bug 1206842 - check we have a failedChannel and securityInfo before serializing, extract to helper, original patch by YF (Yang), r?fkiefer
MozReview-Commit-ID: 9isfRHExX4H
--- a/browser/base/content/content.js
+++ b/browser/base/content/content.js
@@ -271,16 +271,30 @@ const PREF_BLOCKLIST_CLOCK_SKEW_SECONDS
const PREF_SSL_IMPACT_ROOTS = ["security.tls.version.", "security.ssl3."];
const PREF_SSL_IMPACT = PREF_SSL_IMPACT_ROOTS.reduce((prefs, root) => {
return prefs.concat(Services.prefs.getChildList(root));
}, []);
+function getSerializedSecurityInfo(docShell) {
+ let serhelper = Cc["@mozilla.org/network/serialization-helper;1"]
+ .getService(Ci.nsISerializationHelper);
+
+ let securityInfo = docShell.failedChannel && docShell.failedChannel.securityInfo;
+ if (!securityInfo) {
+ return "";
+ }
+ securityInfo.QueryInterface(Ci.nsITransportSecurityInfo)
+ .QueryInterface(Ci.nsISerializable);
+
+ return serhelper.serializeToString(securityInfo);
+}
+
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);
chromeGlobal.addEventListener('AboutNetErrorResetPreferences', this, false, true);
},
@@ -412,29 +426,20 @@ var AboutNetAndCertErrorListener = {
onSetAutomatic: function(evt) {
sendAsyncMessage("Browser:SetSSLErrorReportAuto", {
automatic: evt.detail
});
// if we're enabling reports, send a report for this failure
if (evt.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
+ securityInfo: getSerializedSecurityInfo(docShell),
});
}
},
onOverride: function(evt) {
let {host, port} = content.document.mozDocumentURIIfNotForErrorPages;
sendAsyncMessage("Browser:OverrideWeakCrypto", { uri: {host, port} });
@@ -537,36 +542,24 @@ var ClickEventHandler = {
// This might be middle mouse navigation.
if (event.button == 1) {
sendAsyncMessage("Content:Click", json);
}
},
onCertError: function (targetElement, ownerDoc) {
- let docshell = ownerDoc.defaultView.QueryInterface(Ci.nsIInterfaceRequestor)
+ let docShell = ownerDoc.defaultView.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell);
- let serhelper = Cc["@mozilla.org/network/serialization-helper;1"]
- .getService(Ci.nsISerializationHelper);
- let serializedSecurityInfo = "";
-
- try {
- let serializable = docShell.failedChannel.securityInfo
- .QueryInterface(Ci.nsITransportSecurityInfo)
- .QueryInterface(Ci.nsISerializable);
-
- serializedSecurityInfo = serhelper.serializeToString(serializable);
- } catch (e) { }
-
sendAsyncMessage("Browser:CertExceptionError", {
location: ownerDoc.location.href,
elementId: targetElement.getAttribute("id"),
isTopFrame: (ownerDoc.defaultView.parent === ownerDoc.defaultView),
- securityInfoAsString: serializedSecurityInfo
+ securityInfoAsString: getSerializedSecurityInfo(docShell),
});
},
onAboutBlocked: function (targetElement, ownerDoc) {
var reason = 'phishing';
if (/e=malwareBlocked/.test(ownerDoc.documentURI)) {
reason = 'malware';
} else if (/e=unwantedBlocked/.test(ownerDoc.documentURI)) {