[Pkg-mozext-commits] [requestpolicy] 144/280: update "Permissive Status" via prefBranch observer
David Prévot
taffit at moszumanska.debian.org
Sat May 2 20:30:13 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository requestpolicy.
commit 0825bbdcd069715278aa8d59de5f427a41bc374f
Author: Martin Kimmerle <dev at 256k.de>
Date: Thu Jan 15 22:40:43 2015 +0100
update "Permissive Status" via prefBranch observer
Do not call `_setPermissiveNotificationForAllWindows` anymore.
Instead, observe pref changes of "startWithAllowAllEnabled" and
update the Permissive Status (whether the flag is yellow or not)
when observed.
This fixes #570
---
src/content/lib/observer-manager.jsm | 5 -----
src/content/ui/overlay.js | 43 ++++++++++++++++++------------------
2 files changed, 21 insertions(+), 27 deletions(-)
diff --git a/src/content/lib/observer-manager.jsm b/src/content/lib/observer-manager.jsm
index 1f5c7ce..3075d10 100644
--- a/src/content/lib/observer-manager.jsm
+++ b/src/content/lib/observer-manager.jsm
@@ -163,11 +163,6 @@ function ObserverManager(aEnv) {
// shorthand for binding
let observeSinglePrefBranch = ObserverManager.prototype.observeSinglePrefBranch;
- /**
- * Observe a notification directly from nsIObserverService.
- * ==> In this case, each "ID" is a "topic".
- * https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIObserverService#addObserver%28%29
- */
ObserverManager.prototype.observeRPPref = function(aList) {
let self = this;
forEach(aList, observeSinglePrefBranch.bind(self, rpPrefBranch));
diff --git a/src/content/ui/overlay.js b/src/content/ui/overlay.js
index 255b19a..e81333e 100644
--- a/src/content/ui/overlay.js
+++ b/src/content/ui/overlay.js
@@ -138,7 +138,6 @@ requestpolicy.overlay = (function() {
RequestProcessor.addRequestObserver(self);
//self.setContextMenuEnabled(rpPrefBranch.getBoolPref("contextMenu"));
- self._setPermissiveNotification(Prefs.isBlockingDisabled());
}
} catch (e) {
Logger.severe(Logger.TYPE_ERROR,
@@ -640,30 +639,32 @@ requestpolicy.overlay = (function() {
};
/**
- * Sets the permissive status visible to the user for all windows.
+ * Update RP's "permissive" status, which is to true or false.
*/
- self._setPermissiveNotificationForAllWindows = function(isPermissive) {
- // We do it for all windows, not just the current one.
- var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
- .getService(Components.interfaces.nsIWindowMediator);
- var enumerator = wm.getEnumerator(null);
- while (enumerator.hasMoreElements()) {
- var window = enumerator.getNext();
- if ("requestpolicy" in window && "overlay" in window.requestpolicy) {
- window.requestpolicy.overlay._setPermissiveNotification(isPermissive);
- }
- }
- };
-
- /**
- * Sets the permissive status visible to the user for just this window.
- */
- self._setPermissiveNotification = function(isPermissive) {
+ function updatePermissiveStatus() {
var button = $id(toolbarButtonId);
if (button) {
+ let isPermissive = Prefs.isBlockingDisabled();
button.setAttribute("requestpolicyPermissive", isPermissive);
}
- };
+ }
+ /**
+ * register a pref observer
+ */
+ function updatePermissiveStatusOnPrefChanges() {
+ OverlayEnvironment.obMan.observeRPPref({
+ "startWithAllowAllEnabled": function(subject, topic, data) {
+ if (topic == "nsPref:changed") {
+ updatePermissiveStatus();
+ }
+ }
+ });
+ }
+ OverlayEnvironment.addStartupFunction(Environment.LEVELS.INTERFACE,
+ updatePermissiveStatusOnPrefChanges);
+ // initially set the Permissive Status
+ OverlayEnvironment.addStartupFunction(Environment.LEVELS.UI,
+ updatePermissiveStatus);
/**
* This function is called when any allowed requests happen. This must be as
@@ -1061,8 +1062,6 @@ requestpolicy.overlay = (function() {
// Change the link displayed in the menu.
$id('rp-link-enable-blocking').hidden = !disabled;
$id('rp-link-disable-blocking').hidden = disabled;
-
- self._setPermissiveNotificationForAllWindows(disabled);
};
/**
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/requestpolicy.git
More information about the Pkg-mozext-commits
mailing list