[Pkg-mozext-commits] [requestpolicy] 205/280: OberverManager.observe*() - array instead of obj
David Prévot
taffit at moszumanska.debian.org
Sat May 2 20:30:27 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 ec3b48333b0908baf78079f7fd0c9ab3d54aafbe
Author: Martin Kimmerle <dev at 256k.de>
Date: Wed Feb 4 19:24:30 2015 +0100
OberverManager.observe*() - array instead of obj
The OberverManager's observe* functions now take an array
instead of an object. This way it's possible to pass "dynamic"
topics more easily. -- Computed property names are available
starting with Gecko 34, see
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Operators/Object_initializer#Computed_property_names
This also fixes a bug of a incorrectly created object, regarding
the SUBSCRIPTION_*_TOPIC constants in rpService.
---
src/content/lib/logger.jsm | 14 ++++-----
src/content/lib/observer-manager.jsm | 42 +++++++++-----------------
src/content/lib/prefs.jsm | 10 +++---
src/content/lib/request-processor.jsm | 5 ++-
src/content/lib/request-processor.redirects.js | 20 ++++++------
src/content/main/requestpolicy-service.jsm | 14 ++++-----
src/content/settings/subscriptions.js | 8 ++---
src/content/settings/yourpolicy.js | 8 ++---
src/content/ui/overlay.js | 14 ++++-----
9 files changed, 61 insertions(+), 74 deletions(-)
diff --git a/src/content/lib/logger.jsm b/src/content/lib/logger.jsm
index b315d25..0705a33 100644
--- a/src/content/lib/logger.jsm
+++ b/src/content/lib/logger.jsm
@@ -107,13 +107,13 @@ let Logger = (function() {
}
// rpPrefBranch is available now.
- ProcessEnvironment.obMan.observeRPPref({
- "log": function(subject, topic, data) {
- if (topic == "nsPref:changed") {
- updateLoggingSettings();
- }
- }
- });
+ ProcessEnvironment.obMan.observeRPPref(
+ ["log"],
+ function(subject, topic) {
+ if (topic === "nsPref:changed") {
+ updateLoggingSettings();
+ }
+ });
updateLoggingSettings();
// don't call init() anymore when doLog() is called
diff --git a/src/content/lib/observer-manager.jsm b/src/content/lib/observer-manager.jsm
index ba98868..74c4166 100644
--- a/src/content/lib/observer-manager.jsm
+++ b/src/content/lib/observer-manager.jsm
@@ -90,19 +90,6 @@ function ObserverManager(aEnv) {
* The "ID" for each function might be something different.
*/
{
- /**
- * Call aCallback for each of the object's entries, (key, value) being the
- * parameters.
- */
- let forEach = function(obj, aCallback) {
- for (let key in obj) {
- if (obj.hasOwnProperty(key)) {
- aCallback(key, obj[key]);
- }
- }
- };
-
-
//
// functions using nsIObserverService
//
@@ -119,18 +106,18 @@ function ObserverManager(aEnv) {
self.observers.push(new SingleTopicObserver(aTopic, aCallback));
};
- // shorthand for binding
- let observeSingleTopic = ObserverManager.prototype.observeSingleTopic;
-
/**
* Observe multiple topics.
*
- * @param {Object} aList - A list whereas a key is a "topic" to be observed
- * and a value is the function to be called when the topic is observed.
+ * @param {Array} aTopics - A list of topics to be observed.
+ * @param {function} aCallback - the function to be called when one of the
+ * the topics is observed.
*/
- ObserverManager.prototype.observe = function(aList) {
+ ObserverManager.prototype.observe = function(aTopics, aCallback) {
let self = this;
- forEach(aList, observeSingleTopic.bind(self));
+ aTopics.forEach(function(topic) {
+ self.observeSingleTopic(topic, aCallback);
+ });
};
/**
@@ -160,16 +147,17 @@ function ObserverManager(aEnv) {
self.observers.push(obs);
};
- // shorthand for binding
- let observeSinglePrefBranch = ObserverManager.prototype.observeSinglePrefBranch;
-
- ObserverManager.prototype.observeRPPref = function(aList) {
+ ObserverManager.prototype.observeRPPref = function(aDomains, aCallback) {
let self = this;
- forEach(aList, observeSinglePrefBranch.bind(self, rpPrefBranch));
+ aDomains.forEach(function(domain) {
+ self.observeSinglePrefBranch(rpPrefBranch, domain, aCallback);
+ });
};
- ObserverManager.prototype.observeRootPref = function(aList) {
+ ObserverManager.prototype.observeRootPref = function(aDomains, aCallback) {
let self = this;
- forEach(aList, observeSinglePrefBranch.bind(self, rootPrefBranch));
+ aDomains.forEach(function(domain) {
+ self.observeSinglePrefBranch(rootPrefBranch, domain, aCallback);
+ });
};
}
diff --git a/src/content/lib/prefs.jsm b/src/content/lib/prefs.jsm
index 8d9d754..fe103a0 100644
--- a/src/content/lib/prefs.jsm
+++ b/src/content/lib/prefs.jsm
@@ -134,13 +134,13 @@ let Prefs = (function() {
function registerPrefObserver() {
// observe everything on RP's pref branch
- ProcessEnvironment.obMan.observeRPPref({"": observePref});
+ ProcessEnvironment.obMan.observeRPPref([""], observePref);
// observe what is needed else
- ProcessEnvironment.obMan.observeRootPref({
- "network.prefetch-next": observePref,
- "network.dns.disablePrefetch": observePref
- });
+ ProcessEnvironment.obMan.observeRootPref([
+ "network.prefetch-next",
+ "network.dns.disablePrefetch"
+ ], observePref);
}
ProcessEnvironment.addStartupFunction(Environment.LEVELS.INTERFACE,
registerPrefObserver);
diff --git a/src/content/lib/request-processor.jsm b/src/content/lib/request-processor.jsm
index 03d832a..c01bd1d 100644
--- a/src/content/lib/request-processor.jsm
+++ b/src/content/lib/request-processor.jsm
@@ -885,9 +885,8 @@ let RequestProcessor = (function(self) {
}
};
- ProcessEnvironment.obMan.observe({
- "http-on-modify-request": examineHttpRequest
- });
+ ProcessEnvironment.obMan.observe(["http-on-modify-request"],
+ examineHttpRequest);
diff --git a/src/content/lib/request-processor.redirects.js b/src/content/lib/request-processor.redirects.js
index 8e76b5f..a6ea9e4 100644
--- a/src/content/lib/request-processor.redirects.js
+++ b/src/content/lib/request-processor.redirects.js
@@ -61,14 +61,16 @@ let RequestProcessor = (function(self) {
- ProcessEnvironment.obMan.observe({
- "http-on-examine-response": function(subject) {
- examineHttpResponse(subject);
- },
- HTTPS_EVERYWHERE_REWRITE_TOPIC: function(subject, topic, data) {
- handleHttpsEverywhereUriRewrite(subject, data);
- }
- });
+ ProcessEnvironment.obMan.observe(
+ ["http-on-examine-response"],
+ function(subject) {
+ examineHttpResponse(subject);
+ });
+ ProcessEnvironment.obMan.observe(
+ [HTTPS_EVERYWHERE_REWRITE_TOPIC],
+ function(subject, topic, data) {
+ handleHttpsEverywhereUriRewrite(subject, data);
+ });
@@ -337,7 +339,7 @@ let RequestProcessor = (function(self) {
* available on the channel. The response can be accessed and modified via
* nsITraceableChannel.
*/
- let examineHttpResponse = function(aSubject) {
+ function examineHttpResponse(aSubject) {
// Currently, if a user clicks a link to download a file and that link
// redirects and is subsequently blocked, the user will see the blocked
// destination in the menu. However, after they have allowed it from
diff --git a/src/content/main/requestpolicy-service.jsm b/src/content/main/requestpolicy-service.jsm
index 212b962..b6ab26e 100644
--- a/src/content/main/requestpolicy-service.jsm
+++ b/src/content/main/requestpolicy-service.jsm
@@ -131,17 +131,17 @@ let rpService = (function() {
loadConfigAndRules);
function registerObservers() {
- ProcessEnvironment.obMan.observe({
- "sessionstore-windows-restored": self.observe,
- SUBSCRIPTION_UPDATED_TOPIC: self.observe,
- SUBSCRIPTION_ADDED_TOPIC: self.observe,
- SUBSCRIPTION_REMOVED_TOPIC: self.observe,
+ ProcessEnvironment.obMan.observe([
+ "sessionstore-windows-restored",
+ SUBSCRIPTION_UPDATED_TOPIC,
+ SUBSCRIPTION_ADDED_TOPIC,
+ SUBSCRIPTION_REMOVED_TOPIC,
// support for old browsers (Firefox <20)
// TODO: support per-window temporary rules
// see https://github.com/RequestPolicyContinued/requestpolicy/issues/533#issuecomment-68851396
- "private-browsing": self.observe
- });
+ "private-browsing"
+ ], self.observe);
}
ProcessEnvironment.addStartupFunction(Environment.LEVELS.INTERFACE,
registerObservers);
diff --git a/src/content/settings/subscriptions.js b/src/content/settings/subscriptions.js
index 2aabbc5..fc625b0 100644
--- a/src/content/settings/subscriptions.js
+++ b/src/content/settings/subscriptions.js
@@ -133,8 +133,8 @@ function onload() {
}
// call updateDisplay() every time a subscription is added or removed
- WinEnv.obMan.observe({
- SUBSCRIPTION_ADDED_TOPIC: updateDisplay,
- SUBSCRIPTION_REMOVED_TOPIC: updateDisplay
- });
+ WinEnv.obMan.observe([
+ SUBSCRIPTION_ADDED_TOPIC,
+ SUBSCRIPTION_REMOVED_TOPIC
+ ], updateDisplay);
}
diff --git a/src/content/settings/yourpolicy.js b/src/content/settings/yourpolicy.js
index 4ae4c71..6523e6d 100644
--- a/src/content/settings/yourpolicy.js
+++ b/src/content/settings/yourpolicy.js
@@ -230,10 +230,8 @@ function onload() {
}
// observe rule changes and update the table then
- WinEnv.obMan.observe({
- "requestpolicy-rules-changed": function(subject, topic, data) {
- var search = $id('rulesearch');
- populateRuleTable(search.value);
- }
+ WinEnv.obMan.observe(["requestpolicy-rules-changed"], function() {
+ var search = $id('rulesearch');
+ populateRuleTable(search.value);
});
}
diff --git a/src/content/ui/overlay.js b/src/content/ui/overlay.js
index 02c892a..5776118 100644
--- a/src/content/ui/overlay.js
+++ b/src/content/ui/overlay.js
@@ -663,13 +663,13 @@ requestpolicy.overlay = (function() {
* register a pref observer
*/
function updatePermissiveStatusOnPrefChanges() {
- OverlayEnvironment.obMan.observeRPPref({
- "startWithAllowAllEnabled": function(subject, topic, data) {
- if (topic == "nsPref:changed") {
- updatePermissiveStatus();
- }
- }
- });
+ OverlayEnvironment.obMan.observeRPPref(
+ ["startWithAllowAllEnabled"],
+ function(subject, topic, data) {
+ if (topic === "nsPref:changed") {
+ updatePermissiveStatus();
+ }
+ });
}
OverlayEnvironment.addStartupFunction(Environment.LEVELS.INTERFACE,
updatePermissiveStatusOnPrefChanges);
--
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