[tbb-commits] [tor-browser] 02/02: fixup! Bug 40925: Implemented the Security Level component

gitolite role git at cupani.torproject.org
Mon Sep 19 23:00:09 UTC 2022


This is an automated email from the git hooks/post-receive script.

richard pushed a commit to branch tor-browser-102.2.0esr-12.0-3
in repository tor-browser.

commit cd000078e5f919eac673b9f193c5fb90c3fb5390
Author: Henry Wilkes <henry at torproject.org>
AuthorDate: Thu Sep 8 17:39:07 2022 +0100

    fixup! Bug 40925: Implemented the Security Level component
    
    Provide a label attribute for #security-level-button on load.
    
    Also tidy up the code so that the button is properly initialized whether
    it starts in the toolbar or not.
---
 .../securitylevel/content/securityLevel.js         | 58 ++++++++++------------
 1 file changed, 27 insertions(+), 31 deletions(-)

diff --git a/browser/components/securitylevel/content/securityLevel.js b/browser/components/securitylevel/content/securityLevel.js
index 11e63aa37945c..4b27ddbde5920 100644
--- a/browser/components/securitylevel/content/securityLevel.js
+++ b/browser/components/securitylevel/content/securityLevel.js
@@ -127,7 +127,8 @@ const SecurityLevelPrefs = {
 const SecurityLevelButton = {
   _securityPrefsBranch: null,
 
-  _configUIFromPrefs(securityLevelButton) {
+  _configUIFromPrefs() {
+    const securityLevelButton = this.button;
     if (securityLevelButton != null) {
       const level = SecurityLevelPrefs.securitySliderLevel;
       if (!level) {
@@ -142,42 +143,53 @@ const SecurityLevelButton = {
     }
   },
 
+  /**
+   * The node for this button.
+   *
+   * Note, the returned element may be part of the DOM or may live in the
+   * toolbox palette, where it may be added later to the DOM through
+   * customization.
+   *
+   * @type {MozToolbarbutton}
+   */
   get button() {
-    let button = document.getElementById("security-level-button");
-    if (!button) {
-      return null;
-    }
-    return button;
+    // We first search in the DOM for the security level button. If it does not
+    // exist it may be in the toolbox palette. We still want to return the
+    // button in the latter case to allow it to be initialized or adjusted in
+    // case it is added back through customization.
+    return (
+      document.getElementById("security-level-button") ||
+      window.gNavToolbox.palette.querySelector("#security-level-button")
+    );
   },
 
   get anchor() {
-    let anchor = this.button.icon;
+    let button = this.button;
+    let anchor = button?.icon;
     if (!anchor) {
       return null;
     }
 
-    anchor.setAttribute("consumeanchor", SecurityLevelButton.button.id);
+    anchor.setAttribute("consumeanchor", button.id);
     return anchor;
   },
 
   init() {
+    // Set a label to be be used as the accessible name, and to be shown in the
+    // overflow menu and during customization.
+    this.button?.setAttribute("label", SecurityLevelStrings.security_level);
     // set the initial class based off of the current pref
-    let button = this.button;
-    this._configUIFromPrefs(button);
+    this._configUIFromPrefs();
 
     this._securityPrefsBranch = Services.prefs.getBranch(
       "extensions.torbutton."
     );
     this._securityPrefsBranch.addObserver("", this);
 
-    CustomizableUI.addListener(this);
-
     SecurityLevelPanel.init();
   },
 
   uninit() {
-    CustomizableUI.removeListener(this);
-
     this._securityPrefsBranch.removeObserver("", this);
     this._securityPrefsBranch = null;
 
@@ -188,28 +200,12 @@ const SecurityLevelButton = {
     switch (topic) {
       case "nsPref:changed":
         if (data === "security_slider" || data === "security_custom") {
-          this._configUIFromPrefs(this.button);
+          this._configUIFromPrefs();
         }
         break;
     }
   },
 
-  // callback for entering the 'Customize Firefox' screen to set icon
-  onCustomizeStart(window) {
-    let navigatorToolbox = document.getElementById("navigator-toolbox");
-    let button = navigatorToolbox.palette.querySelector(
-      "#security-level-button"
-    );
-    this._configUIFromPrefs(button);
-  },
-
-  // callback when CustomizableUI modifies DOM
-  onWidgetAfterDOMChange(aNode, aNextNode, aContainer, aWasRemoval) {
-    if (aNode.id == "security-level-button" && !aWasRemoval) {
-      this._configUIFromPrefs(aNode);
-    }
-  },
-
   // for when the toolbar button needs to be activated and displays the Security Level panel
   //
   // In the toolbarbutton xul you'll notice we register this callback for both onkeypress and

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the tbb-commits mailing list