Index: lib/requestNotifier.js |
=================================================================== |
--- a/lib/requestNotifier.js |
+++ b/lib/requestNotifier.js |
@@ -102,17 +102,17 @@ RequestNotifier.prototype = |
notifiers.delete(this.id); |
}, |
/** |
* Notifies listener about a new request. |
* @param {Window} wnd |
* @param {Node} node |
- * @param {RequestEntry} entry |
+ * @param {Object} entry |
*/ |
notifyListener: function(wnd, node, entry) |
{ |
this.listener.call(this.listenerObj, wnd, node, entry, this.scanComplete); |
}, |
/** |
* Number of currently posted scan events (will be 0 when the scan finishes |
@@ -182,38 +182,87 @@ RequestNotifier.getSelection = function( |
* @param {String} contentType request type, e.g. "IMAGE" |
* @param {String} docDomain domain of the document that initiated the request |
* @param {Boolean} thirdParty will be true if a third-party server has been requested |
* @param {String} location the address that has been requested |
* @param {Filter} filter filter applied to the request or null if none |
*/ |
RequestNotifier.addNodeData = function(/**Node*/ node, /**Window*/ topWnd, /**String*/ contentType, /**String*/ docDomain, /**Boolean*/ thirdParty, /**String*/ location, /**Filter*/ filter) |
{ |
- return new RequestEntry(node, topWnd, contentType, docDomain, thirdParty, location, filter); |
+ let entry = { |
+ id: ++requestEntryMaxId, |
+ type: contentType, |
+ docDomain, thirdParty, location, filter |
+ } |
+ |
+ let existingData = nodeData.get(node); |
+ if (typeof existingData == "undefined") |
+ { |
+ existingData = {}; |
+ nodeData.set(node, existingData); |
+ } |
+ |
+ // Add this request to the node data |
+ existingData[contentType + " " + location] = entry; |
+ |
+ // Update window statistics |
+ if (!windowStats.has(topWnd.document)) |
+ { |
+ windowStats.set(topWnd.document, { |
+ items: 0, |
+ hidden: 0, |
+ blocked: 0, |
+ whitelisted: 0, |
+ filters: {} |
+ }); |
+ } |
+ |
+ 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++; |
+ else if (filter instanceof ElemHideFilter) |
+ stats.hidden++; |
+ |
+ if (filter.text in stats.filters) |
+ stats.filters[filter.text]++; |
+ else |
+ stats.filters[filter.text] = 1; |
+ } |
+ |
+ // Notify listeners |
+ for (let notifier of notifiers.values()) |
+ if (!notifier.window || notifier.window == topWnd) |
+ notifier.notifyListener(topWnd, node, entry); |
} |
/** |
* 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 (windowStats.has(wnd.document)) |
return windowStats.get(wnd.document); |
else |
return null; |
} |
/** |
- * Retrieves the request entry associated with a DOM node. |
+ * Retrieves the request data 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 |
* @param {Integer} [type] request type to be looking for |
* @param {String} [location] request location to be looking for |
- * @result {[Node, RequestEntry]} |
+ * @result {[Node, Object]} |
* @static |
*/ |
RequestNotifier.getDataForNode = function(node, noParent, type, location) |
{ |
while (node) |
{ |
let data = nodeData.get(node); |
if (typeof data != "undefined") |
@@ -242,104 +291,8 @@ RequestNotifier.getDataForNode = functio |
else |
{ |
node = null; |
} |
} |
return null; |
}; |
- |
-function RequestEntry(node, topWnd, contentType, docDomain, thirdParty, location, filter) |
-{ |
- this.type = contentType; |
- this.docDomain = docDomain; |
- this.thirdParty = thirdParty; |
- this.location = location; |
- this.filter = filter; |
- this.id = ++requestEntryMaxId; |
- |
- this.attachToNode(node); |
- |
- // Update window statistics |
- if (!windowStats.has(topWnd.document)) |
- { |
- windowStats.set(topWnd.document, { |
- items: 0, |
- hidden: 0, |
- blocked: 0, |
- whitelisted: 0, |
- filters: {} |
- }); |
- } |
- |
- 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++; |
- else if (filter instanceof ElemHideFilter) |
- stats.hidden++; |
- |
- if (filter.text in stats.filters) |
- stats.filters[filter.text]++; |
- else |
- stats.filters[filter.text] = 1; |
- } |
- |
- // Notify listeners |
- for (let notifier of notifiers.values()) |
- if (!notifier.window || notifier.window == topWnd) |
- notifier.notifyListener(topWnd, node, this); |
-} |
-RequestEntry.prototype = |
-{ |
- /** |
- * id of request (used to determine last entry attached to a node) |
- * @type integer |
- */ |
- id: 0, |
- /** |
- * Content type of the request, e.g. "IMAGE" |
- * @type String |
- */ |
- type: null, |
- /** |
- * Domain name of the requesting document |
- * @type String |
- */ |
- docDomain: null, |
- /** |
- * True if the request goes to a different domain than the domain of the containing document |
- * @type Boolean |
- */ |
- thirdParty: false, |
- /** |
- * Address being requested |
- * @type String |
- */ |
- location: null, |
- /** |
- * Filter that was applied to this request (if any) |
- * @type Filter |
- */ |
- filter: null, |
- |
- /** |
- * Attaches this request object to a DOM node. |
- */ |
- attachToNode: function(/**Node*/ node) |
- { |
- let existingData = nodeData.get(node); |
- if (typeof existingData == "undefined") |
- { |
- existingData = {}; |
- nodeData.set(node, existingData); |
- } |
- |
- // Add this request to the node data |
- existingData[this.type + " " + this.location] = this; |
- } |
-}; |