Index: lib/requestNotifier.js |
=================================================================== |
--- a/lib/requestNotifier.js |
+++ b/lib/requestNotifier.js |
@@ -24,51 +24,16 @@ Cu.import("resource://gre/modules/Servic |
let {Utils} = require("utils"); |
let {BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter, ElemHideException} = require("filterClasses"); |
let nodeData = new WeakMap(); |
let windowStats = new WeakMap(); |
let windowSelection = new WeakMap(); |
let requestEntryMaxId = 0; |
-let setEntry, hasEntry, getEntry; |
-// Last issue(Bug 982561) preventing us from using WeakMap fixed for FF version 32 |
-if (Services.vc.compare(Utils.platformVersion, "32.0a1") >= 0) |
-{ |
- setEntry = (map, key, value) => map.set(key, value); |
- hasEntry = (map, key) => map.has(key); |
- getEntry = (map, key) => map.get(key); |
-} |
-else |
-{ |
- // Fall back to user data |
- let dataSeed = Math.random(); |
- let nodeDataProp = "abpNodeData" + dataSeed; |
- let windowStatsProp = "abpWindowStats" + dataSeed; |
- let windowSelectionProp = "abpWindowSelection" + dataSeed; |
- let getProp = function(map) |
- { |
- switch (map) |
- { |
- case nodeData: |
- return nodeDataProp; |
- case windowStats: |
- return windowStatsProp; |
- case windowSelection: |
- return windowSelectionProp; |
- default: |
- return null; |
- } |
- }; |
- |
- setEntry = (map, key, value) => key.setUserData(getProp(map), value, null); |
- hasEntry = (map, key) => key.getUserData(getProp(map)); |
- getEntry = (map, key) => key.getUserData(getProp(map)) || undefined; |
-} |
- |
/** |
* List of notifiers in use - these notifiers need to receive notifications on |
* new requests. |
* @type RequestNotifier[] |
*/ |
let activeNotifiers = []; |
/** |
@@ -160,17 +125,17 @@ RequestNotifier.prototype = |
let walker = doc.createTreeWalker(doc, Ci.nsIDOMNodeFilter.SHOW_ELEMENT, null, false); |
let process = function() |
{ |
if (!this.listener) |
return; |
let node = walker.currentNode; |
- let data = getEntry(nodeData, node); |
+ let data = nodeData.get(node); |
if (typeof data != "undefined") |
for (let k in data) |
this.notifyListener(wnd, node, data[k]); |
if (walker.nextNode()) |
Utils.runAsync(process); |
else |
{ |
@@ -190,22 +155,22 @@ RequestNotifier.prototype = |
// Process each node in a separate event to allow other events to process |
this.eventsPosted++; |
Utils.runAsync(process); |
} |
}; |
RequestNotifier.storeSelection = function(/**Window*/ wnd, /**String*/ selection) |
{ |
- setEntry(windowSelection, wnd.document, selection); |
+ windowSelection.set(wnd.document, selection); |
}; |
RequestNotifier.getSelection = function(/**Window*/ wnd) /**String*/ |
{ |
- if (hasEntry(windowSelection, wnd.document)) |
- return getEntry(windowSelection, wnd.document); |
+ if (windowSelection.has(wnd.document)) |
+ return windowSelection.get(wnd.document); |
else |
return null; |
}; |
/** |
* Attaches request data to a DOM node. |
* @param {Node} node node to attach data to |
* @param {Window} topWnd top-level window the node belongs to |
@@ -221,18 +186,18 @@ RequestNotifier.addNodeData = function(/ |
} |
/** |
* Retrieves the statistics for a window. |
* @result {Object} Object with the properties items, blocked, whitelisted, hidden, filters containing statistics for the window (might be null) |
*/ |
RequestNotifier.getWindowStatistics = function(/**Window*/ wnd) |
{ |
- if (hasEntry(windowStats, wnd.document)) |
- return getEntry(windowStats, wnd.document); |
+ if (windowStats.has(wnd.document)) |
+ return windowStats.get(wnd.document); |
else |
return null; |
} |
/** |
* Retrieves the request entry associated with a DOM node. |
* @param {Node} node |
* @param {Boolean} noParent if missing or false, the search will extend to the parent nodes until one is found that has data associated with it |
@@ -240,17 +205,17 @@ RequestNotifier.getWindowStatistics = fu |
* @param {String} [location] request location to be looking for |
* @result {[Node, RequestEntry]} |
* @static |
*/ |
RequestNotifier.getDataForNode = function(node, noParent, type, location) |
{ |
while (node) |
{ |
- let data = getEntry(nodeData, node); |
+ let data = nodeData.get(node); |
if (typeof data != "undefined") |
{ |
let entry = null; |
// Look for matching entry |
for (let k in data) |
{ |
if ((!entry || entry.id < data[k].id) && |
(typeof type == "undefined" || data[k].type == type) && |
@@ -285,28 +250,28 @@ function RequestEntry(node, topWnd, cont |
this.thirdParty = thirdParty; |
this.location = location; |
this.filter = filter; |
this.id = ++requestEntryMaxId; |
this.attachToNode(node); |
// Update window statistics |
- if (!hasEntry(windowStats, topWnd.document)) |
+ if (!windowStats.has(topWnd.document)) |
{ |
- setEntry(windowStats, topWnd.document, { |
+ windowStats.set(topWnd.document, { |
items: 0, |
hidden: 0, |
blocked: 0, |
whitelisted: 0, |
filters: {} |
}); |
} |
- let stats = getEntry(windowStats, topWnd.document); |
+ let stats = windowStats.get(topWnd.document); |
if (!filter || !(filter instanceof ElemHideBase)) |
stats.items++; |
if (filter) |
{ |
if (filter instanceof BlockingFilter) |
stats.blocked++; |
else if (filter instanceof WhitelistFilter || filter instanceof ElemHideException) |
stats.whitelisted++; |
@@ -357,19 +322,19 @@ RequestEntry.prototype = |
*/ |
filter: null, |
/** |
* Attaches this request object to a DOM node. |
*/ |
attachToNode: function(/**Node*/ node) |
{ |
- let existingData = getEntry(nodeData, node); |
+ let existingData = nodeData.get(node); |
if (typeof existingData == "undefined") |
{ |
existingData = {}; |
- setEntry(nodeData, node, existingData); |
+ nodeData.set(node, existingData); |
} |
// Add this request to the node data |
existingData[this.type + " " + this.location] = this; |
} |
}; |