Skip to content

Commit

Permalink
Don't put prefs and observerObj in global scope
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacSchemm committed Dec 7, 2017
1 parent d4c741e commit 892864d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
21 changes: 9 additions & 12 deletions chrome/content/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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);
Expand All @@ -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");
Expand All @@ -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 = {
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 892864d

Please sign in to comment.