From 2533f8da772d61a9bf37706b19c2ada3b60ff653 Mon Sep 17 00:00:00 2001 From: Erica Wright Date: Wed, 27 May 2020 22:33:02 +0000 Subject: [PATCH] Bug 1636962 - Add telemetry for all page load errors r=johannh,xeonchen,nika Differential Revision: https://phabricator.services.mozilla.com/D75873 --- docshell/base/moz.build | 1 + docshell/base/nsDocShell.cpp | 27 +-- docshell/base/nsDocShellTelemetryUtils.cpp | 210 ++++++++++++++++++ docshell/base/nsDocShellTelemetryUtils.h | 22 ++ .../manager/ssl/nsISecurityUITelemetry.idl | 2 +- toolkit/components/telemetry/Histograms.json | 65 +++++- 6 files changed, 303 insertions(+), 24 deletions(-) create mode 100644 docshell/base/nsDocShellTelemetryUtils.cpp create mode 100644 docshell/base/nsDocShellTelemetryUtils.h diff --git a/docshell/base/moz.build b/docshell/base/moz.build index ef2ca57774bc..89b041213852 100644 --- a/docshell/base/moz.build +++ b/docshell/base/moz.build @@ -93,6 +93,7 @@ UNIFIED_SOURCES += [ 'nsDocShellEditorData.cpp', 'nsDocShellEnumerator.cpp', 'nsDocShellLoadState.cpp', + 'nsDocShellTelemetryUtils.cpp', 'nsDocShellTreeOwner.cpp', 'nsDSURIContentListener.cpp', 'nsPingListener.cpp', diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 059c13488c6e..d0fdf7fc36cb 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -220,6 +220,7 @@ #include "URIUtils.h" #include "timeline/JavascriptTimelineMarker.h" +#include "nsDocShellTelemetryUtils.h" #ifdef MOZ_PLACES # include "nsIFaviconService.h" @@ -3494,36 +3495,14 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI* aURI, errorPage.Assign(alternateErrorPage); } - uint32_t bucketId; - bool sendTelemetry = false; if (NS_ERROR_PHISHING_URI == aError) { - sendTelemetry = true; error = "deceptiveBlocked"; - bucketId = IsFrame() - ? IUrlClassifierUITelemetry::WARNING_PHISHING_PAGE_FRAME - : IUrlClassifierUITelemetry::WARNING_PHISHING_PAGE_TOP; } else if (NS_ERROR_MALWARE_URI == aError) { - sendTelemetry = true; error = "malwareBlocked"; - bucketId = IsFrame() - ? IUrlClassifierUITelemetry::WARNING_MALWARE_PAGE_FRAME - : IUrlClassifierUITelemetry::WARNING_MALWARE_PAGE_TOP; } else if (NS_ERROR_UNWANTED_URI == aError) { - sendTelemetry = true; error = "unwantedBlocked"; - bucketId = IsFrame() - ? IUrlClassifierUITelemetry::WARNING_UNWANTED_PAGE_FRAME - : IUrlClassifierUITelemetry::WARNING_UNWANTED_PAGE_TOP; } else if (NS_ERROR_HARMFUL_URI == aError) { - sendTelemetry = true; error = "harmfulBlocked"; - bucketId = IsFrame() - ? IUrlClassifierUITelemetry::WARNING_HARMFUL_PAGE_FRAME - : IUrlClassifierUITelemetry::WARNING_HARMFUL_PAGE_TOP; - } - - if (sendTelemetry && errorPage.EqualsIgnoreCase("blocked")) { - Telemetry::Accumulate(Telemetry::URLCLASSIFIER_UI_EVENTS, bucketId); } cssClass.AssignLiteral("blacklist"); @@ -3686,6 +3665,10 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI* aURI, errorDescriptionID = error; } + Telemetry::AccumulateCategoricalKeyed( + IsFrame() ? NS_LITERAL_CSTRING("frame") : NS_LITERAL_CSTRING("top"), + mozilla::dom::LoadErrorToTelemetryLabel(aError)); + // Test if the error needs to be formatted if (!messageStr.IsEmpty()) { // already obtained message diff --git a/docshell/base/nsDocShellTelemetryUtils.cpp b/docshell/base/nsDocShellTelemetryUtils.cpp new file mode 100644 index 000000000000..5d0600903640 --- /dev/null +++ b/docshell/base/nsDocShellTelemetryUtils.cpp @@ -0,0 +1,210 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsDocShellTelemetryUtils.h" + +namespace { + +using ErrorLabel = mozilla::Telemetry::LABELS_PAGE_LOAD_ERROR; + +struct LoadErrorTelemetryResult { + nsresult mValue; + ErrorLabel mLabel; +}; + +static const LoadErrorTelemetryResult sResult[] = { + { + NS_ERROR_UNKNOWN_PROTOCOL, + ErrorLabel::UNKNOWN_PROTOCOL, + }, + { + NS_ERROR_FILE_NOT_FOUND, + ErrorLabel::FILE_NOT_FOUND, + }, + { + NS_ERROR_FILE_ACCESS_DENIED, + ErrorLabel::FILE_ACCESS_DENIED, + }, + { + NS_ERROR_UNKNOWN_HOST, + ErrorLabel::UNKNOWN_HOST, + }, + { + NS_ERROR_CONNECTION_REFUSED, + ErrorLabel::CONNECTION_REFUSED, + }, + { + NS_ERROR_PROXY_BAD_GATEWAY, + ErrorLabel::PROXY_BAD_GATEWAY, + }, + { + NS_ERROR_NET_INTERRUPT, + ErrorLabel::NET_INTERRUPT, + }, + { + NS_ERROR_NET_TIMEOUT, + ErrorLabel::NET_TIMEOUT, + }, + { + NS_ERROR_PROXY_GATEWAY_TIMEOUT, + ErrorLabel::P_GATEWAY_TIMEOUT, + }, + { + NS_ERROR_CSP_FRAME_ANCESTOR_VIOLATION, + ErrorLabel::CSP_FRAME_ANCEST, + }, + { + NS_ERROR_CSP_FORM_ACTION_VIOLATION, + ErrorLabel::CSP_FORM_ACTION, + }, + { + NS_ERROR_CSP_NAVIGATE_TO_VIOLATION, + ErrorLabel::CSP_NAVIGATE_TO, + }, + { + NS_ERROR_XFO_VIOLATION, + ErrorLabel::XFO_VIOLATION, + }, + { + NS_ERROR_PHISHING_URI, + ErrorLabel::PHISHING_URI, + }, + { + NS_ERROR_MALWARE_URI, + ErrorLabel::MALWARE_URI, + }, + { + NS_ERROR_UNWANTED_URI, + ErrorLabel::UNWANTED_URI, + }, + { + NS_ERROR_HARMFUL_URI, + ErrorLabel::HARMFUL_URI, + }, + { + NS_ERROR_CONTENT_CRASHED, + ErrorLabel::CONTENT_CRASHED, + }, + { + NS_ERROR_FRAME_CRASHED, + ErrorLabel::FRAME_CRASHED, + }, + { + NS_ERROR_BUILDID_MISMATCH, + ErrorLabel::BUILDID_MISMATCH, + }, + { + NS_ERROR_NET_RESET, + ErrorLabel::NET_RESET, + }, + { + NS_ERROR_MALFORMED_URI, + ErrorLabel::MALFORMED_URI, + }, + { + NS_ERROR_REDIRECT_LOOP, + ErrorLabel::REDIRECT_LOOP, + }, + { + NS_ERROR_UNKNOWN_SOCKET_TYPE, + ErrorLabel::UNKNOWN_SOCKET, + }, + { + NS_ERROR_DOCUMENT_NOT_CACHED, + ErrorLabel::DOCUMENT_N_CACHED, + }, + { + NS_ERROR_OFFLINE, + ErrorLabel::OFFLINE, + }, + { + NS_ERROR_DOCUMENT_IS_PRINTMODE, + ErrorLabel::DOC_PRINTMODE, + }, + { + NS_ERROR_PORT_ACCESS_NOT_ALLOWED, + ErrorLabel::PORT_ACCESS, + }, + { + NS_ERROR_UNKNOWN_PROXY_HOST, + ErrorLabel::UNKNOWN_PROXY_HOST, + }, + { + NS_ERROR_PROXY_CONNECTION_REFUSED, + ErrorLabel::PROXY_CONNECTION, + }, + { + NS_ERROR_PROXY_FORBIDDEN, + ErrorLabel::PROXY_FORBIDDEN, + }, + { + NS_ERROR_PROXY_NOT_IMPLEMENTED, + ErrorLabel::P_NOT_IMPLEMENTED, + }, + { + NS_ERROR_PROXY_AUTHENTICATION_FAILED, + ErrorLabel::PROXY_AUTH, + }, + { + NS_ERROR_PROXY_TOO_MANY_REQUESTS, + ErrorLabel::PROXY_TOO_MANY, + }, + { + NS_ERROR_INVALID_CONTENT_ENCODING, + ErrorLabel::CONTENT_ENCODING, + }, + { + NS_ERROR_REMOTE_XUL, + ErrorLabel::REMOTE_XUL, + }, + { + NS_ERROR_UNSAFE_CONTENT_TYPE, + ErrorLabel::UNSAFE_CONTENT, + }, + { + NS_ERROR_CORRUPTED_CONTENT, + ErrorLabel::CORRUPTED_CONTENT, + }, + { + NS_ERROR_INTERCEPTION_FAILED, + ErrorLabel::INTERCEPTION_FAIL, + }, + { + NS_ERROR_NET_INADEQUATE_SECURITY, + ErrorLabel::INADEQUATE_SEC, + }, + { + NS_ERROR_BLOCKED_BY_POLICY, + ErrorLabel::BLOCKED_BY_POLICY, + }, + { + NS_ERROR_NET_HTTP2_SENT_GOAWAY, + ErrorLabel::HTTP2_SENT_GOAWAY, + }, + { + NS_ERROR_NET_HTTP3_PROTOCOL_ERROR, + ErrorLabel::HTTP3_PROTOCOL, + }, + { + NS_BINDING_FAILED, + ErrorLabel::BINDING_FAILED, + }, +}; +} // anonymous namespace + +namespace mozilla { +namespace dom { +mozilla::Telemetry::LABELS_PAGE_LOAD_ERROR LoadErrorToTelemetryLabel( + nsresult aRv) { + MOZ_ASSERT(aRv != NS_OK); + + for (const auto& p : sResult) { + if (p.mValue == aRv) { + return p.mLabel; + } + } + return ErrorLabel::otherError; +} +} // namespace dom +} // namespace mozilla diff --git a/docshell/base/nsDocShellTelemetryUtils.h b/docshell/base/nsDocShellTelemetryUtils.h new file mode 100644 index 000000000000..4e0097caecea --- /dev/null +++ b/docshell/base/nsDocShellTelemetryUtils.h @@ -0,0 +1,22 @@ +//* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef nsDocShellTelemetryUtils_h__ +#define nsDocShellTelemetryUtils_h__ + +#include "mozilla/Telemetry.h" + +namespace mozilla { +namespace dom { +/** + * Convert page load errors to telemetry labels + * Only select nsresults are converted, otherwise this function + * will return "errorOther", view the list of errors at + * docshell/base/nsDocShellTelemetryUtils.cpp. + */ +Telemetry::LABELS_PAGE_LOAD_ERROR LoadErrorToTelemetryLabel(nsresult aRv); +} // namespace dom +} // namespace mozilla +#endif // nsDocShellTelemetryUtils_h__ diff --git a/security/manager/ssl/nsISecurityUITelemetry.idl b/security/manager/ssl/nsISecurityUITelemetry.idl index dcd563bf29eb..e29657c422fb 100644 --- a/security/manager/ssl/nsISecurityUITelemetry.idl +++ b/security/manager/ssl/nsISecurityUITelemetry.idl @@ -134,5 +134,5 @@ const uint32_t WARNING_BAD_CERT_TOP_CONFIRM_ADD_EXCEPTION_FLAG_TIME = 4; // const uint32_t WARNING_UNWANTED_PAGE_FRAME_IGNORE_WARNING = 99; // All the buckets are used so the safebrowsing-related buckets were -// moved under URLCLASSIFIER_UI_EVENTS probe. See bug 1375277 for more information. +// moved under PAGE_LOAD_ERROR probe. See bug 1636962 for more information. }; diff --git a/toolkit/components/telemetry/Histograms.json b/toolkit/components/telemetry/Histograms.json index c314b9599c53..4c3e7263d5f5 100644 --- a/toolkit/components/telemetry/Histograms.json +++ b/toolkit/components/telemetry/Histograms.json @@ -11878,6 +11878,69 @@ "alert_emails": ["mobile-frontend@mozilla.com"], "bug_numbers": [1235061] }, + "PAGE_LOAD_ERROR" : { + "record_in_processes": ["main", "content"], + "products": ["firefox", "fennec", "geckoview"], + "expires_in_version": "never", + "releaseChannelCollection": "opt-out", + "kind": "categorical", + "keyed": true, + "keys": [ + "top", + "frame" + ], + "n_values": 45, + "labels": [ + "UNKNOWN_PROTOCOL", + "FILE_NOT_FOUND", + "FILE_ACCESS_DENIED", + "UNKNOWN_HOST", + "CONNECTION_REFUSED", + "PROXY_BAD_GATEWAY", + "NET_INTERRUPT", + "NET_TIMEOUT", + "P_GATEWAY_TIMEOUT", + "CSP_FRAME_ANCEST", + "CSP_FORM_ACTION", + "CSP_NAVIGATE_TO", + "XFO_VIOLATION", + "PHISHING_URI", + "MALWARE_URI", + "UNWANTED_URI", + "HARMFUL_URI", + "CONTENT_CRASHED", + "FRAME_CRASHED", + "BUILDID_MISMATCH", + "NET_RESET", + "MALFORMED_URI", + "REDIRECT_LOOP", + "UNKNOWN_SOCKET", + "DOCUMENT_N_CACHED", + "OFFLINE", + "DOC_PRINTMODE", + "PORT_ACCESS", + "UNKNOWN_PROXY_HOST", + "PROXY_CONNECTION", + "PROXY_FORBIDDEN", + "P_NOT_IMPLEMENTED", + "PROXY_AUTH", + "PROXY_TOO_MANY", + "CONTENT_ENCODING", + "REMOTE_XUL", + "UNSAFE_CONTENT", + "CORRUPTED_CONTENT", + "INTERCEPTION_FAIL", + "INADEQUATE_SEC", + "BLOCKED_BY_POLICY", + "HTTP2_SENT_GOAWAY", + "HTTP3_PROTOCOL", + "BINDING_FAILED", + "otherError" + ], + "description": "Page load errors. Match values with type of error in nsDocShellTelemetryUtils.cpp", + "alert_emails": ["seceng-telemetry@mozilla.com"], + "bug_numbers": [1636962] + }, "COOKIE_BEHAVIOR": { "record_in_processes": ["main"], "products": ["firefox"], @@ -14343,7 +14406,7 @@ "record_in_processes": ["main", "content"], "products": ["firefox", "fennec", "geckoview"], "alert_emails": ["seceng-telemetry@mozilla.com", "dlee@mozilla.com"], - "bug_numbers": [1375277, 1531034], + "bug_numbers": [1375277, 1531034, 1636962], "expires_in_version": "never", "kind": "enumerated", "n_values": 64,