Commit 80a3bbcf authored by Richard Pospesel's avatar Richard Pospesel Committed by Matthew Finkel
Browse files

Bug 31920: Fix Security Level panel when its toolbar button moves to overflow

Simply removed the 'clever' caching of the underlying toolbar button
element. Now, each time the button is needed it is queried from the
underlying document.

A correct, but more complicated, fix would be to determine when the
toolbar button had been moved to the overflow menu and then update our
cached reference. However, this would be super brittle and would
break once another way to move the toolbar button is added in the
future.

In the end, caching something so infrequently queried is not worth the
complexity.
parent 6d5ea44d
Loading
Loading
Loading
Loading
+5 −18
Original line number Diff line number Diff line
@@ -62,8 +62,6 @@ const SecurityLevelPrefs = {

const SecurityLevelButton = {
  _securityPrefsBranch : null,
  _button : null,
  _anchor : null,

  _populateXUL : function(securityLevelButton) {
    if (securityLevelButton != null) {
@@ -95,23 +93,14 @@ const SecurityLevelButton = {
  },

  get button() {
    if (this._button) {
      return this._button;
    }

    let button = document.getElementById("security-level-button");
    if (!button) {
      return null;
    }

    return this._button = button;
    return button;
  },

  get anchor() {
    if (this._anchor) {
      return this._anchor;
    }

    let anchor = document.getAnonymousElementByAttribute(this.button, "class",
                                                   "toolbarbutton-icon");
    if (!anchor) {
@@ -119,13 +108,14 @@ const SecurityLevelButton = {
    }

    anchor.setAttribute("consumeanchor", SecurityLevelButton.button.id);
    return this._anchor = anchor;
    return anchor;
  },

  init : function() {
    // set the initial class based off of the current pref
    this._populateXUL(this.button);
    this._configUIFromPrefs(this.button);
    let button = this.button;
    this._populateXUL(button);
    this._configUIFromPrefs(button);

    this._securityPrefsBranch = Services.prefs.getBranch("extensions.torbutton.");
    this._securityPrefsBranch.addObserver("", this, false);
@@ -167,9 +157,6 @@ const SecurityLevelButton = {
    if (aNode.id == "security-level-button" && !aWasRemoval) {
      this._populateXUL(aNode);
      this._configUIFromPrefs(aNode);
      // clear out our cached elements as they seem to be recreated when the UI is customized
      delete this._button;
      delete this._anchor;
    }
  },