From e72754ef17f40595211a55bc0e58bd6ccdfb8c83 Mon Sep 17 00:00:00 2001 From: Mark Goodwin Date: Wed, 10 Jun 2015 14:18:17 +0100 Subject: [PATCH] Bug 1088141 - Add telemetry for SSL Error Reports (r=felipe) --- browser/base/content/aboutNetError.xhtml | 6 +++++ browser/base/content/browser.js | 24 ++++++++++++++++++++ browser/base/content/content.js | 21 ++++++++++++++++- toolkit/components/telemetry/Histograms.json | 6 +++++ 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/browser/base/content/aboutNetError.xhtml b/browser/base/content/aboutNetError.xhtml index c061e8cdcdb2..5bac3a79e73e 100644 --- a/browser/base/content/aboutNetError.xhtml +++ b/browser/base/content/aboutNetError.xhtml @@ -112,6 +112,12 @@ .addEventListener('click', function togglePanelVisibility() { var panel = document.getElementById('certificateErrorReportingPanel'); toggleDisplay(panel); + + if (panel.style.display == "block") { + // send event to trigger telemetry ping + var event = new CustomEvent("AboutNetErrorUIExpanded", {bubbles:true}); + document.dispatchEvent(event); + } }); } diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 7628d98f2e97..4c5f0e4d4a1b 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -2692,6 +2692,12 @@ let gMenuButtonUpdateBadge = { } }; +// Values for telemtery bins: see TLS_ERROR_REPORT_UI in Histograms.json +const TLS_ERROR_REPORT_TELEMETRY_AUTO_CHECKED = 2; +const TLS_ERROR_REPORT_TELEMETRY_AUTO_UNCHECKED = 3; +const TLS_ERROR_REPORT_TELEMETRY_MANUAL_SEND = 4; +const TLS_ERROR_REPORT_TELEMETRY_AUTO_SEND = 5; + /** * Handle command events bubbling up from error page content * or from about:newtab or from remote error pages that invoke @@ -2705,6 +2711,7 @@ let BrowserOnClick = { mm.addMessageListener("Browser:EnableOnlineMode", this); mm.addMessageListener("Browser:SendSSLErrorReport", this); mm.addMessageListener("Browser:SetSSLErrorReportAuto", this); + mm.addMessageListener("Browser:SSLErrorReportTelemetry", this); }, uninit: function () { @@ -2714,6 +2721,7 @@ let BrowserOnClick = { mm.removeMessageListener("Browser:EnableOnlineMode", this); mm.removeMessageListener("Browser:SendSSLErrorReport", this); mm.removeMessageListener("Browser:SetSSLErrorReportAuto", this); + mm.removeMessageListener("Browser:SSLErrorReportTelemetry", this); }, handleEvent: function (event) { @@ -2760,6 +2768,16 @@ let BrowserOnClick = { break; case "Browser:SetSSLErrorReportAuto": Services.prefs.setBoolPref("security.ssl.errorReporting.automatic", msg.json.automatic); + let bin = TLS_ERROR_REPORT_TELEMETRY_AUTO_UNCHECKED; + if (msg.json.automatic) { + bin = TLS_ERROR_REPORT_TELEMETRY_AUTO_CHECKED; + } + Services.telemetry.getHistogramById("TLS_ERROR_REPORT_UI").add(bin); + break; + case "Browser:SSLErrorReportTelemetry": + let reportStatus = msg.data.reportStatus; + Services.telemetry.getHistogramById("TLS_ERROR_REPORT_UI") + .add(reportStatus); break; } }, @@ -2781,6 +2799,12 @@ let BrowserOnClick = { return; } + let bin = TLS_ERROR_REPORT_TELEMETRY_MANUAL_SEND; + if (Services.prefs.getBoolPref("security.ssl.errorReporting.automatic")) { + bin = TLS_ERROR_REPORT_TELEMETRY_AUTO_SEND; + } + Services.telemetry.getHistogramById("TLS_ERROR_REPORT_UI").add(bin); + let serhelper = Cc["@mozilla.org/network/serialization-helper;1"] .getService(Ci.nsISerializationHelper); let transportSecurityInfo = serhelper.deserializeObject(securityInfo); diff --git a/browser/base/content/content.js b/browser/base/content/content.js index 61f17691cc3c..e9bbbe886619 100644 --- a/browser/base/content/content.js +++ b/browser/base/content/content.js @@ -177,11 +177,18 @@ Cc["@mozilla.org/eventlistenerservice;1"] .getService(Ci.nsIEventListenerService) .addSystemEventListener(global, "contextmenu", handleContentContextMenu, false); +// Values for telemtery bins: see TLS_ERROR_REPORT_UI in Histograms.json +const TLS_ERROR_REPORT_TELEMETRY_UI_SHOWN = 0; +const TLS_ERROR_REPORT_TELEMETRY_EXPANDED = 1; +const TLS_ERROR_REPORT_TELEMETRY_SUCCESS = 6; +const TLS_ERROR_REPORT_TELEMETRY_FAILURE = 7; + let AboutNetErrorListener = { init: function(chromeGlobal) { chromeGlobal.addEventListener('AboutNetErrorLoad', this, false, true); chromeGlobal.addEventListener('AboutNetErrorSetAutomatic', this, false, true); chromeGlobal.addEventListener('AboutNetErrorSendReport', this, false, true); + chromeGlobal.addEventListener('AboutNetErrorUIExpanded', this, false, true); }, get isAboutNetError() { @@ -203,6 +210,10 @@ let AboutNetErrorListener = { case "AboutNetErrorSendReport": this.onSendReport(aEvent); break; + case "AboutNetErrorUIExpanded": + sendAsyncMessage("Browser:SSLErrorReportTelemetry", + {reportStatus: TLS_ERROR_REPORT_TELEMETRY_EXPANDED}); + break; } }, @@ -215,6 +226,10 @@ let AboutNetErrorListener = { }) } )); + + sendAsyncMessage("Browser:SSLErrorReportTelemetry", + {reportStatus: TLS_ERROR_REPORT_TELEMETRY_UI_SHOWN}); + if (automatic) { this.onSendReport(evt); } @@ -259,11 +274,15 @@ let AboutNetErrorListener = { // show the retry button retryBtn.style.removeProperty("display"); reportSendingMsg.style.display = "none"; + sendAsyncMessage("Browser:SSLErrorReportTelemetry", + {reportStatus: TLS_ERROR_REPORT_TELEMETRY_FAILURE}); break; case "complete": // Show a success indicator reportSentMsg.style.removeProperty("display"); reportSendingMsg.style.display = "none"; + sendAsyncMessage("Browser:SSLErrorReportTelemetry", + {reportStatus: TLS_ERROR_REPORT_TELEMETRY_SUCCESS}); break; } } @@ -284,7 +303,7 @@ let AboutNetErrorListener = { sendAsyncMessage("Browser:SendSSLErrorReport", { elementId: evt.target.id, documentURI: contentDoc.documentURI, - location: contentDoc.location, + location: {hostname: contentDoc.location.hostname, port: contentDoc.location.port}, securityInfo: serializedSecurityInfo }); } diff --git a/toolkit/components/telemetry/Histograms.json b/toolkit/components/telemetry/Histograms.json index d57f87b54f51..43fe6e9edafc 100644 --- a/toolkit/components/telemetry/Histograms.json +++ b/toolkit/components/telemetry/Histograms.json @@ -7204,6 +7204,12 @@ "kind": "flag", "description": "a testing histogram; not meant to be touched" }, + "TLS_ERROR_REPORT_UI": { + "expires_in_version": "never", + "kind": "enumerated", + "n_values": 15, + "description": "User interaction with the TLS Error Reporter in about:neterror (0=Error seen, 1='auto' checked, 2='auto' unchecked, 3=Sent manually, 4=Sent automatically, 5=Send success, 6=Send failure, 7=Report section expanded)" + }, "CERT_OCSP_ENABLED": { "expires_in_version": "never", "kind": "boolean",