[tor-commits] [tor-browser/tor-browser-68.1.0esr-9.0-2] Bug 24653: merge securityLevel.properties into torbutton.dtd
gk at torproject.org
gk at torproject.org
Fri Sep 13 08:49:38 UTC 2019
commit 3b5b0d6d502d712734c2c5b7e35c0d29e5f19204
Author: Alex Catarineu <acat at torproject.org>
Date: Tue Aug 13 11:57:22 2019 +0200
Bug 24653: merge securityLevel.properties into torbutton.dtd
---
.../securitylevel/content/securityLevel.js | 89 +++++++++++++---------
1 file changed, 52 insertions(+), 37 deletions(-)
diff --git a/browser/components/securitylevel/content/securityLevel.js b/browser/components/securitylevel/content/securityLevel.js
index 25f6423bc6d3..9dc23d97855d 100644
--- a/browser/components/securitylevel/content/securityLevel.js
+++ b/browser/components/securitylevel/content/securityLevel.js
@@ -8,61 +8,76 @@ XPCOMUtils.defineLazyModuleGetters(this, {
PanelMultiView: "resource:///modules/PanelMultiView.jsm",
});
+XPCOMUtils.defineLazyGlobalGetters(this, ["DOMParser"]);
+XPCOMUtils.defineLazyGetter(this, "domParser", () => new DOMParser());
+
/*
Security Level Strings
Strings loaded from torbutton, but en-US defaults provided in case torbutton addon not enabled
*/
XPCOMUtils.defineLazyGetter(this, "SecurityLevelStrings", function() {
- let sls = null;
- try {
- sls = Services.strings.createBundle("chrome://torbutton/locale/securityLevel.properties");
- } catch(e) { }
+ // copied from testing/marionette/l10n.js
+ let localizeEntity = function(urls, id) {
+ // Build a string which contains all possible entity locations
+ let locations = [];
+ urls.forEach((url, index) => {
+ locations.push(`<!ENTITY % dtd_${index} SYSTEM "${url}">%dtd_${index};`);
+ });
+
+ // Use the DOM parser to resolve the entity and extract its real value
+ let header = `<?xml version="1.0"?><!DOCTYPE elem [${locations.join("")}]>`;
+ let elem = `<elem id="elementID">&${id};</elem>`;
+ let doc = domParser.parseFromString(header + elem, "text/xml");
+ let element = doc.querySelector("elem[id='elementID']");
+
+ if (element === null) {
+ throw new Error(`Entity with id='${id}' hasn't been found`);
+ }
+
+ return element.textContent;
+ };
- // tries to get the given key from the string bundle, return fallback on failure
let getString = function(key, fallback) {
- let retval = "";
- if (sls) {
- try {
- retval = sls.GetStringFromName(key);
- } catch(e) { }
- }
- if (retval == "") {
- retval = fallback;
- }
- return retval;
+ try {
+ return localizeEntity(
+ ['chrome://torbutton/locale/torbutton.dtd'],
+ `torbutton.prefs.sec_${key}`
+ );
+ } catch (e) { }
+ return fallback;
};
// read localized strings from torbutton; but use hard-coded en-US strings as fallbacks in case of error
let retval = {
- securityLevel : getString("securityLevel.securityLevel", "Security Level"),
- customWarning : getString("securityLevel.customWarning", "Custom"),
- overview : getString("securityLevel.overview", "Disable certain web features that can be used to attack your security and anonymity."),
+ securityLevel : getString("caption", "Security Level"),
+ customWarning : getString("custom_warning", "Custom"),
+ overview : getString("overview", "Disable certain web features that can be used to attack your security and anonymity."),
standard : {
- level : getString("securityLevel.standard.level", "Standard"),
- tooltip : getString("securityLevel.standard.tooltip", "Security Level : Standard"),
- summary : getString("securityLevel.standard.summary", "All Tor Browser and website features are enabled."),
+ level : getString("standard_label", "Standard"),
+ tooltip : getString("standard_tooltip", "Security Level : Standard"),
+ summary : getString("standard_description", "All Tor Browser and website features are enabled."),
},
safer : {
- level : getString("securityLevel.safer.level", "Safer"),
- tooltip : getString("securityLevel.safer.tooltip", "Security Level : Safer"),
- summary : getString("securityLevel.safer.summary", "Disables website features that are often dangerous, causing some sites to lose functionality."),
- description1 : getString("securityLevel.safer.description1", "JavaScript is disabled on non-HTTPS sites."),
- description2 : getString("securityLevel.safer.description2", "Some fonts and math symbols are disabled."),
- description3 : getString("securityLevel.safer.description3", "Audio and video (HTML5 media) are click-to-play."),
+ level : getString("safer_label", "Safer"),
+ tooltip : getString("safer_tooltip", "Security Level : Safer"),
+ summary : getString("safer_description", "Disables website features that are often dangerous, causing some sites to lose functionality."),
+ description1 : getString("js_on_https_sites_only", "JavaScript is disabled on non-HTTPS sites."),
+ description2 : getString("limit_typography", "Some fonts and math symbols are disabled."),
+ description3 : getString("click_to_play_media", "Audio and video (HTML5 media), and WebGL are click-to-play."),
},
safest : {
- level : getString("securityLevel.safest.level", "Safest"),
- tooltip : getString("securityLevel.safest.tooltip", "Security Level : Safest"),
- summary : getString("securityLevel.safest.summary", "Only allows website features required for static sites and basic services. These changes affect images, media, and scripts."),
- description1 : getString("securityLevel.safest.description1", "JavaScript is disabled by default on all sites."),
- description2 : getString("securityLevel.safest.description2", "Some fonts, icons, math symbols, and images are disabled."),
- description3 : getString("securityLevel.safest.description3", "Audio and video (HTML5 media) are click-to-play."),
+ level : getString("safest_label", "Safest"),
+ tooltip : getString("safest_tooltip", "Security Level : Safest"),
+ summary : getString("safest_description", "Only allows website features required for static sites and basic services. These changes affect images, media, and scripts."),
+ description1 : getString("js_disabled", "JavaScript is disabled by default on all sites."),
+ description2 : getString("limit_graphics_and_typography", "Some fonts, icons, math symbols, and images are disabled."),
+ description3 : getString("click_to_play_media", "Audio and video (HTML5 media), and WebGL are click-to-play."),
},
custom : {
- summary : getString("securityLevel.custom.summary", "Your custom browser preferences have resulted in unusual security settings. For security and privacy reasons, we recommend you choose one of the default security levels."),
+ summary : getString("custom_summary", "Your custom browser preferences have resulted in unusual security settings. For security and privacy reasons, we recommend you choose one of the default security levels."),
},
- learnMore : getString("securityLevel.learnMore", "Learn more"),
+ learnMore : getString("learn_more_label", "Learn more"),
learnMoreURL : function() {
let locale = "";
try {
@@ -77,8 +92,8 @@ XPCOMUtils.defineLazyGetter(this, "SecurityLevelStrings", function() {
return "https://tb-manual.torproject.org/" + locale + "/security-settings/";
}(),
- restoreDefaults : getString("securityLevel.restoreDefaults", "Restore Defaults"),
- advancedSecuritySettings : getString("securityLevel.advancedSecuritySettings", "Advanced Security Settings\u2026"),
+ restoreDefaults : getString("restore_defaults", "Restore Defaults"),
+ advancedSecuritySettings : getString("advanced_security_settings", "Advanced Security Settings\u2026"),
};
More information about the tor-commits
mailing list