Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/requestNotifier.js

Issue 29329742: Issue 3251 - Simplify messaging from child scripts to parent (Closed)
Patch Set: Rebased, no return value stringification Created Nov. 9, 2015, 11:01 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/elemHide.js ('k') | lib/utils.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/requestNotifier.js
===================================================================
--- a/lib/requestNotifier.js
+++ b/lib/requestNotifier.js
@@ -14,47 +14,44 @@
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @fileOverview Stores Adblock Plus data to be attached to a window.
*/
+let {Utils} = require("utils");
+
let windowSelection = new WeakMap();
let requestNotifierMaxId = 0;
/**
* Active RequestNotifier instances by their ID
* @type Map.<number,RequestNotifier>
*/
let notifiers = new Map();
let messageManager = Cc["@mozilla.org/parentprocessmessagemanager;1"]
.getService(Ci.nsIMessageListenerManager)
.QueryInterface(Ci.nsIMessageBroadcaster);
-messageManager.addMessageListener("AdblockPlus:FoundNodeData", onNodeData);
-messageManager.addMessageListener("AdblockPlus:ScanComplete", onScanComplete);
-onShutdown.add(() => {
- messageManager.removeMessageListener("AdblockPlus:FoundNodeData", onNodeData);
- messageManager.removeMessageListener("AdblockPlus:ScanComplete", onScanComplete);
-});
+Utils.addChildMessageListener("AdblockPlus:FoundNodeData", onNodeData);
+Utils.addChildMessageListener("AdblockPlus:ScanComplete", onScanComplete);
-function onNodeData(message)
+function onNodeData({notifierID, data})
{
- let {notifierID, data} = message.data;
let notifier = notifiers.get(notifierID);
if (notifier)
notifier.notifyListener(data);
}
-function onScanComplete(message)
+function onScanComplete(notifierID)
{
- let notifier = notifiers.get(message.data);
+ let notifier = notifiers.get(notifierID);
if (notifier)
notifier.onComplete();
}
/**
* Creates a notifier object for a particular window. After creation the window
* will first be scanned for previously saved requests. Once that scan is
* complete only new requests for this window will be reported.
« no previous file with comments | « lib/elemHide.js ('k') | lib/utils.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld