From 892864d7e1daea7dfbbfdc252e98f76a668ffc9b Mon Sep 17 00:00:00 2001 From: Isaac Schemm Date: Thu, 7 Dec 2017 14:53:45 -0600 Subject: [PATCH] Don't put prefs and observerObj in global scope --- chrome/content/button.js | 21 +++++++++------------ install.rdf | 2 +- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/chrome/content/button.js b/chrome/content/button.js index b39f696..8ba89d8 100644 --- a/chrome/content/button.js +++ b/chrome/content/button.js @@ -2,11 +2,8 @@ * 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/. */ -var prefs = null; -var observerObj = null; - this.addEventListener("load", function () { - prefs = Services.prefs.getBranch("media.navigator.permission."); + WebRTCPermissionsButtons.prefs = Services.prefs.getBranch("media.navigator.permission."); var toolbarbutton = document.getElementById("webrtc-permissions-ui-toggle-1"); var menuItem = document.getElementById("webRTCOverrideToolsMenuToggle"); @@ -15,7 +12,7 @@ this.addEventListener("load", function () { .getBoolPref("show-in-menu"); if (!showInMenu) menuItem.hidden = true; - observerObj = { + WebRTCPermissionsButtons.observerObj = { observe: function (aSubject, aTopic, aData) { if ("nsPref:changed" == aTopic) { var newValue = aSubject.getBoolPref(aData); @@ -33,9 +30,9 @@ this.addEventListener("load", function () { } }; - prefs.addObserver("", observerObj, false); + WebRTCPermissionsButtons.prefs.addObserver("", WebRTCPermissionsButtons.observerObj, false); - var value = prefs.getBoolPref("disabled"); + var value = WebRTCPermissionsButtons.prefs.getBoolPref("disabled"); if (value) { toolbarbutton.label = toolbarbutton.tooltipText = WebRTCPermissionsButtons.GetString("overrideOn"); toolbarbutton.classList.add("setting-true"); @@ -45,14 +42,14 @@ this.addEventListener("load", function () { .getBranch("extensions.webrtc-permissions-ui-toggle.") .getBoolPref("reset-on-new-window"); if (r) { - prefs.setBoolPref("disabled", false); + WebRTCPermissionsButtons.prefs.setBoolPref("disabled", false); } } else { toolbarbutton.label = toolbarbutton.tooltipText = WebRTCPermissionsButtons.GetString("overrideOff"); } }); this.addEventListener("unload", function () { - prefs.removeObserver("", observerObj); + WebRTCPermissionsButtons.prefs.removeObserver("", WebRTCPermissionsButtons.observerObj); }); WebRTCPermissionsButtons = { @@ -76,13 +73,13 @@ WebRTCPermissionsButtons = { if (addon.pendingOperations & (AddonManager.PENDING_DISABLE | AddonManager.PENDING_UNINSTALL)) { promptService.alert(this.window, title, WebRTCPermissionsButtons.GetString("enableOrReinstallRequired")); } else { - var actualValue = prefs.getBoolPref("disabled"); + var actualValue = WebRTCPermissionsButtons.prefs.getBoolPref("disabled"); if (actualValue) { - prefs.setBoolPref("disabled", false); + WebRTCPermissionsButtons.prefs.setBoolPref("disabled", false); Services.prefs.getBranch("media.navigator.").clearUserPref("enabled"); Services.prefs.getBranch("media.peerconnection.").clearUserPref("enabled"); } else if (promptService.confirm(this.window, title, WebRTCPermissionsButtons.GetString("confirmationPromptMessage"))) { - prefs.setBoolPref("disabled", true); + WebRTCPermissionsButtons.prefs.setBoolPref("disabled", true); Services.prefs.getBranch("media.navigator.").setBoolPref("enabled", true); Services.prefs.getBranch("media.peerconnection.").setBoolPref("enabled", true); } diff --git a/install.rdf b/install.rdf index 309cd46..127046d 100644 --- a/install.rdf +++ b/install.rdf @@ -11,7 +11,7 @@ em:creator="Isaac Schemm" em:id="webrtc-permissions-ui-toggle@lakora.us" - em:version="1.3.0" + em:version="1.3.1" em:homepageURL="https://github.com/IsaacSchemm/webrtc-permissions-ui-toggle" em:iconURL="chrome://webrtc-permissions-ui-toggle/content/icon.png"