From af719f1186fca9d7e46428feb9ee9b9cae4fae49 Mon Sep 17 00:00:00 2001 From: Richard Pospesel Date: Mon, 4 Mar 2019 16:09:51 -0800 Subject: [PATCH] Bug 25658: Replace security slider with security level UI This patch adds a new 'securitylevel' component to Tor Browser intended to replace the torbutton 'Security Slider'. This component adds a new Security Level toolbar button which visually indicates the current global security level via icon (as defined by the extensions.torbutton.security_slider pref), a drop-down hanger with a short description of the current security level, and a new section in the about:preferences#privacy page where users can change their current security level. In addition, the hanger and the preferences page will show a visual warning when the user has modified prefs associated with the security level and provide a one-click 'Restore Defaults' button to get the user back on recommended settings. Strings used by this patch are pulled from the torbutton extension, but en-US defaults are provided if there is an error loading from the extension. With this patch applied, the usual work-flow of "./mach build && ./mach run" work as expected, even if the torbutton extension is disabled. --- browser/app/profile/000-tor-browser.js | 2 +- browser/base/content/browser.js | 10 + browser/base/content/browser.xul | 5 + browser/components/moz.build | 1 + .../preferences/in-content/preferences.xul | 1 + .../preferences/in-content/privacy.js | 18 + .../preferences/in-content/privacy.xul | 2 + .../securitylevel/content/securityLevel.js | 528 ++++++++++++++++++ .../content/securityLevelButton.css | 9 + .../content/securityLevelButton.inc.xul | 5 + .../content/securityLevelButton.svg | 21 + .../content/securityLevelPanel.css | 82 +++ .../content/securityLevelPanel.inc.xul | 33 ++ .../content/securityLevelPreferences.css | 26 + .../content/securityLevelPreferences.inc.xul | 66 +++ browser/components/securitylevel/jar.mn | 6 + browser/components/securitylevel/moz.build | 1 + 17 files changed, 815 insertions(+), 1 deletion(-) create mode 100644 browser/components/securitylevel/content/securityLevel.js create mode 100644 browser/components/securitylevel/content/securityLevelButton.css create mode 100644 browser/components/securitylevel/content/securityLevelButton.inc.xul create mode 100644 browser/components/securitylevel/content/securityLevelButton.svg create mode 100644 browser/components/securitylevel/content/securityLevelPanel.css create mode 100644 browser/components/securitylevel/content/securityLevelPanel.inc.xul create mode 100644 browser/components/securitylevel/content/securityLevelPreferences.css create mode 100644 browser/components/securitylevel/content/securityLevelPreferences.inc.xul create mode 100644 browser/components/securitylevel/jar.mn create mode 100644 browser/components/securitylevel/moz.build diff --git a/browser/app/profile/000-tor-browser.js b/browser/app/profile/000-tor-browser.js index f41d6d48b6f8b..74c7f35b98cd5 100644 --- a/browser/app/profile/000-tor-browser.js +++ b/browser/app/profile/000-tor-browser.js @@ -250,7 +250,7 @@ pref("extensions.webextensions.ExtensionStorageIDB.enabled", false); pref("extensions.allowPrivateBrowsingByDefault", true); // Toolbar layout -pref("browser.uiCustomization.state", "{\"placements\":{\"widget-overflow-fixed-list\":[],\"PersonalToolbar\":[\"personal-bookmarks\"],\"nav-bar\":[\"torbutton-button\",\"back-button\",\"forward-button\",\"stop-reload-button\",\"urlbar-container\",\"downloads-button\",\"_73a6fe31-595d-460b-a920-fcc0f8843232_-browser-action\"],\"TabsToolbar\":[\"tabbrowser-tabs\",\"new-tab-button\",\"alltabs-button\"],\"toolbar-menubar\":[\"menubar-items\"],\"PanelUI-contents\":[\"home-button\",\"edit-controls\",\"zoom-controls\",\"new-window-button\",\"save-page-button\",\"print-button\",\"bookmarks-menu-button\",\"history-panelmenu\",\"find-button\",\"preferences-button\",\"add-ons-button\",\"developer-button\",\"https-everywhere-button\"],\"addon-bar\":[\"addonbar-closebutton\",\"status-bar\"]},\"seen\":[\"developer-button\",\"https-everywhere_eff_org-browser-action\",\"_73a6fe31-595d-460b-a920-fcc0f8843232_-browser-action\"],\"dirtyAreaCache\":[\"PersonalToolbar\",\"nav-bar\",\"TabsToolbar\",\"toolbar-menubar\"],\"currentVersion\":14,\"newElementCount\":1}"); +pref("browser.uiCustomization.state", "{\"placements\":{\"widget-overflow-fixed-list\":[],\"PersonalToolbar\":[\"personal-bookmarks\"],\"nav-bar\":[\"back-button\",\"forward-button\",\"stop-reload-button\",\"urlbar-container\",\"torbutton-button\",\"security-level-button\",\"downloads-button\"],\"TabsToolbar\":[\"tabbrowser-tabs\",\"new-tab-button\",\"alltabs-button\"],\"toolbar-menubar\":[\"menubar-items\"],\"PanelUI-contents\":[\"home-button\",\"edit-controls\",\"zoom-controls\",\"new-window-button\",\"save-page-button\",\"print-button\",\"bookmarks-menu-button\",\"history-panelmenu\",\"find-button\",\"preferences-button\",\"add-ons-button\",\"developer-button\"],\"addon-bar\":[\"addonbar-closebutton\",\"status-bar\"]},\"seen\":[\"developer-button\",\"https-everywhere-eff_eff_org-browser-action\",\"_73a6fe31-595d-460b-a920-fcc0f8843232_-browser-action\"],\"dirtyAreaCache\":[\"PersonalToolbar\",\"nav-bar\",\"TabsToolbar\",\"toolbar-menubar\"],\"currentVersion\":14,\"newElementCount\":1}"); // Putting the search engine prefs into this file to fix #11236. // Default search engine diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index a0ed38f36f557..5cebc4ccacafa 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -209,6 +209,11 @@ XPCOMUtils.defineLazyScriptGetter( ["DownloadsButton", "DownloadsIndicatorView"], "chrome://browser/content/downloads/indicator.js" ); +XPCOMUtils.defineLazyScriptGetter( + this, + ["SecurityLevelButton"], + "chrome://browser/content/securitylevel/securityLevel.js" +); XPCOMUtils.defineLazyScriptGetter( this, "gEditItemOverlay", @@ -1847,6 +1852,9 @@ var gBrowserInit = { // doesn't flicker as the window is being shown. DownloadsButton.init(); + // Init the SecuritySettingsButton + SecurityLevelButton.init(); + // Certain kinds of automigration rely on this notification to complete // their tasks BEFORE the browser window is shown. SessionStore uses it to // restore tabs into windows AFTER important parts like gMultiProcessBrowser @@ -2482,6 +2490,8 @@ var gBrowserInit = { DownloadsButton.uninit(); + SecurityLevelButton.uninit(); + gAccessibilityServiceIndicator.uninit(); AccessibilityRefreshBlocker.uninit(); diff --git a/browser/base/content/browser.xul b/browser/base/content/browser.xul index f5bdf818c1718..42c0d2d47397a 100644 --- a/browser/base/content/browser.xul +++ b/browser/base/content/browser.xul @@ -20,6 +20,8 @@ + + @@ -620,6 +622,7 @@ #include ../../components/controlcenter/content/identityPanel.inc.xul #include ../../components/controlcenter/content/protectionsPanel.inc.xul #include ../../components/downloads/content/downloadsPanel.inc.xul +#include ../../components/securitylevel/content/securityLevelPanel.inc.xul #include browser-allTabsMenu.inc.xul @@ -1057,6 +1060,8 @@ +#include ../../components/securitylevel/content/securityLevelButton.inc.xul + + diff --git a/browser/components/preferences/in-content/privacy.js b/browser/components/preferences/in-content/privacy.js index 140842d8884ff..7583d4e66290f 100644 --- a/browser/components/preferences/in-content/privacy.js +++ b/browser/components/preferences/in-content/privacy.js @@ -62,6 +62,12 @@ XPCOMUtils.defineLazyGetter(this, "AlertsServiceDND", function() { } }); +XPCOMUtils.defineLazyScriptGetter( + this, + ["SecurityLevelPreferences"], + "chrome://browser/content/securitylevel/securityLevel.js" +); + XPCOMUtils.defineLazyServiceGetter( this, "listManager", @@ -225,6 +231,17 @@ function dataCollectionCheckboxHandler({ var gPrivacyPane = { _pane: null, + /** + * Show the Security Level UI + */ + _initSecurityLevel() { + SecurityLevelPreferences.init(); + let unload = () => { + window.removeEventListener("unload", unload); + SecurityLevelPreferences.uninit(); + }; + }, + /** * Whether the prompt to restart Firefox should appear when changing the autostart pref. */ @@ -350,6 +367,7 @@ var gPrivacyPane = { this.trackingProtectionReadPrefs(); this.networkCookieBehaviorReadPrefs(); this._initTrackingProtectionExtensionControl(); + this._initSecurityLevel(); Services.telemetry.setEventRecordingEnabled("pwmgr", true); diff --git a/browser/components/preferences/in-content/privacy.xul b/browser/components/preferences/in-content/privacy.xul index d7c91810fdff3..013fe147bc82b 100644 --- a/browser/components/preferences/in-content/privacy.xul +++ b/browser/components/preferences/in-content/privacy.xul @@ -870,6 +870,8 @@ +#include ../../securitylevel/content/securityLevelPreferences.inc.xul +