Bug 1642725 - use sets of known message identifiers to limit possible error titles and messages instead of consulting fluent, r=zbraniecki,prathiksha,fluent-reviewers,Pike

Differential Revision: https://phabricator.services.mozilla.com/D82135
This commit is contained in:
Gijs Kruitbosch 2020-07-06 11:12:08 +00:00
parent 875c3dcf70
commit 8909e119d0
6 changed files with 94 additions and 21 deletions

View File

@ -11,6 +11,47 @@ const TLS_ERROR_REPORT_TELEMETRY_AUTO_CHECKED = 2;
const TLS_ERROR_REPORT_TELEMETRY_AUTO_UNCHECKED = 3;
const TLS_ERROR_REPORT_TELEMETRY_UI_SHOWN = 0;
// Used to check if we have a specific localized message for an error.
const KNOWN_ERROR_TITLE_IDS = new Set([
// Error titles:
"connectionFailure-title",
"deniedPortAccess-title",
"dnsNotFound-title",
"fileNotFound-title",
"fileAccessDenied-title",
"generic-title",
"captivePortal-title",
"malformedURI-title",
"netInterrupt-title",
"notCached-title",
"netOffline-title",
"contentEncodingError-title",
"unsafeContentType-title",
"netReset-title",
"netTimeout-title",
"unknownProtocolFound-title",
"proxyConnectFailure-title",
"proxyResolveFailure-title",
"redirectLoop-title",
"unknownSocketType-title",
"nssFailure2-title",
"csp-xfo-error-title",
"corruptedContentError-title",
"remoteXUL-title",
"sslv3Used-title",
"inadequateSecurityError-title",
"blockedByPolicy-title",
"clockSkewError-title",
"networkProtocolError-title",
"nssBadCert-title",
"nssBadCert-sts-title",
"certerror-mitm-title",
]);
/* The error message IDs from nsserror.ftl get processed into
* aboutNetErrorCodes.js which is loaded before we are: */
/* global KNOWN_ERROR_MESSAGE_IDS */
// The following parameters are parsed from the error URL:
// e - the error code
// s - custom CSS class to allow alternate styling/favicons
@ -163,7 +204,7 @@ function disallowCertOverridesIfNeeded() {
}
}
async function setErrorPageStrings(err) {
function setErrorPageStrings(err) {
let title = err + "-title";
let isCertError = err == "nssBadCert";
@ -177,19 +218,12 @@ async function setErrorPageStrings(err) {
title = "csp-xfo-error-title";
}
let [errorCodeTitle] = await document.l10n.formatValues([
{
id: title,
},
]);
let titleElement = document.querySelector(".title-text");
if (!errorCodeTitle) {
console.error("No strings exist for this error type");
document.l10n.setAttributes(titleElement, "generic-title");
return;
}
if (!KNOWN_ERROR_TITLE_IDS.has(title)) {
console.error("No strings exist for error:", title);
title = "generic-title";
}
document.l10n.setAttributes(titleElement, title);
}
@ -452,16 +486,14 @@ async function setNetErrorMessageFromCode() {
let desc = document.getElementById("errorShortDescText");
let errorCodeStr = securityInfo.errorCodeString || "";
let errorCodeStrId = errorCodeStr
.split("_")
.join("-")
.toLowerCase();
let errorCodeMsg = "";
if (errorCodeStr) {
[errorCodeMsg] = await document.l10n.formatValues([
{
id: errorCodeStr
.split("_")
.join("-")
.toLowerCase(),
},
]);
if (KNOWN_ERROR_MESSAGE_IDS.has(errorCodeStrId)) {
[errorCodeMsg] = await document.l10n.formatValues([errorCodeStrId]);
}
if (!errorCodeMsg) {

View File

@ -208,5 +208,6 @@
</div>
</div>
</body>
<script src="chrome://browser/content/aboutNetErrorCodes.js"/>
<script src="chrome://browser/content/aboutNetError.js"/>
</html>

View File

@ -0,0 +1,30 @@
#!/usr/bin/env python3
# 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/.
from __future__ import absolute_import
from fluent.syntax import parse
from fluent.syntax.ast import Message
import sys
def find_error_ids(filename, known_strings):
with open(filename, 'r', encoding="utf-8") as f:
known_strings += [m.id.name for m in parse(f.read()).body if isinstance(m, Message)]
def main(output, *filenames):
known_strings = []
for filename in filenames:
find_error_ids(filename, known_strings)
output.write('const KNOWN_ERROR_MESSAGE_IDS = new Set([\n')
for known_string in known_strings:
output.write(' "{}",\n'.format(known_string))
output.write(']);\n')
if __name__ == '__main__':
sys.exit(main(sys.stdout, *sys.argv[1:]))

View File

@ -22,6 +22,7 @@ browser.jar:
content/browser/logos/send.svg (content/logos/send.svg)
content/browser/logos/tracking-protection.svg (content/logos/tracking-protection.svg)
content/browser/logos/tracking-protection-dark-theme.svg (content/logos/tracking-protection-dark-theme.svg)
content/browser/aboutNetErrorCodes.js (content/aboutNetErrorCodes.js)
content/browser/aboutNetError.xhtml (content/aboutNetError.xhtml)
content/browser/aboutNetError.js (content/aboutNetError.js)
content/browser/aboutRobots-icon.png (content/aboutRobots-icon.png)

View File

@ -72,3 +72,7 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('windows', 'gtk'):
DEFINES['MENUBAR_CAN_AUTOHIDE'] = 1
JAR_MANIFESTS += ['jar.mn']
GeneratedFile('content/aboutNetErrorCodes.js', script='gen_aboutneterror_codes.py',
inputs=['/browser/locales/en-US/browser/nsserrors.ftl'])

View File

@ -2,6 +2,11 @@
# 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/.
# DO NOT ADD THINGS OTHER THAN ERROR MESSAGES HERE.
# This file gets parsed into a JS dictionary of all known error message ids in
# gen_aboutneterror_codes.py . If we end up needing fluent attributes or
# refactoring them in some way, the script will need updating.
# Variables:
# $hostname (String) - Hostname of the website with SSL error.
# $errorMessage (String) - Error message corresponding to the type of error we are experiencing.