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

Side by Side Diff: lib/requestNotifier.js

Issue 5681038109966336: issue #362 - firefox: block image broken on youtube thumbnails (recommended videos) (Closed)
Patch Set: Created Aug. 17, 2014, 2:11 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /** 18 /**
19 * @fileOverview Stores Adblock Plus data to be attached to a window. 19 * @fileOverview Stores Adblock Plus data to be attached to a window.
20 */ 20 */
21 21
22 Cu.import("resource://gre/modules/Services.jsm"); 22 Cu.import("resource://gre/modules/Services.jsm");
23 23
24 let {Utils} = require("utils"); 24 let {Utils} = require("utils");
25 let {BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter, ElemHideExce ption} = require("filterClasses"); 25 let {BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter, ElemHideExce ption} = require("filterClasses");
26 26
27 let nodeData = new WeakMap(); 27 let nodeData = new WeakMap();
28 let windowStats = new WeakMap(); 28 let windowStats = new WeakMap();
29 let windowSelection = new WeakMap(); 29 let windowSelection = new WeakMap();
30 let requestEntryMaxId = 0;
30 31
31 let setEntry, hasEntry, getEntry; 32 let setEntry, hasEntry, getEntry;
32 // Last issue(Bug 982561) preventing us from using WeakMap fixed for FF version 32 33 // Last issue(Bug 982561) preventing us from using WeakMap fixed for FF version 32
33 if (Services.vc.compare(Utils.platformVersion, "32.0a1") >= 0) 34 if (Services.vc.compare(Utils.platformVersion, "32.0a1") >= 0)
34 { 35 {
35 setEntry = (map, key, value) => map.set(key, value); 36 setEntry = (map, key, value) => map.set(key, value);
36 hasEntry = (map, key) => map.has(key); 37 hasEntry = (map, key) => map.has(key);
37 getEntry = (map, key) => map.get(key); 38 getEntry = (map, key) => map.get(key);
38 } 39 }
39 else 40 else
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 * @result {[Node, RequestEntry]} 238 * @result {[Node, RequestEntry]}
238 * @static 239 * @static
239 */ 240 */
240 RequestNotifier.getDataForNode = function(node, noParent, type, location) 241 RequestNotifier.getDataForNode = function(node, noParent, type, location)
241 { 242 {
242 while (node) 243 while (node)
243 { 244 {
244 let data = getEntry(nodeData, node); 245 let data = getEntry(nodeData, node);
245 if (typeof data != "undefined") 246 if (typeof data != "undefined")
246 { 247 {
248 let entry = null;
247 // Look for matching entry 249 // Look for matching entry
248 for (let k in data) 250 for (let k in data)
249 { 251 {
250 let entry = data[k]; 252 if ((!entry || entry.id < data[k].id) &&
251 if ((typeof type == "undefined" || entry.type == type) && 253 (typeof type == "undefined" || data[k].type == type) &&
252 (typeof location == "undefined" || entry.location == location)) 254 (typeof location == "undefined" || data[k].location == location))
253 { 255 {
254 return [node, entry]; 256 entry = data[k];
255 } 257 }
256 } 258 }
259 if (entry)
260 return [node, entry];
257 } 261 }
258 262
259 // If we don't have any match on this node then maybe its parent will do 263 // If we don't have any match on this node then maybe its parent will do
260 if ((typeof noParent != "boolean" || !noParent) && 264 if ((typeof noParent != "boolean" || !noParent) &&
261 node.parentNode instanceof Ci.nsIDOMElement) 265 node.parentNode instanceof Ci.nsIDOMElement)
262 { 266 {
263 node = node.parentNode; 267 node = node.parentNode;
264 } 268 }
265 else 269 else
266 { 270 {
267 node = null; 271 node = null;
268 } 272 }
269 } 273 }
270 274
271 return null; 275 return null;
272 }; 276 };
273 277
274 function RequestEntry(node, topWnd, contentType, docDomain, thirdParty, location , filter) 278 function RequestEntry(node, topWnd, contentType, docDomain, thirdParty, location , filter)
275 { 279 {
276 this.type = contentType; 280 this.type = contentType;
277 this.docDomain = docDomain; 281 this.docDomain = docDomain;
278 this.thirdParty = thirdParty; 282 this.thirdParty = thirdParty;
279 this.location = location; 283 this.location = location;
280 this.filter = filter; 284 this.filter = filter;
285 this.id = ++requestEntryMaxId;
281 286
282 this.attachToNode(node); 287 this.attachToNode(node);
283 288
284 // Update window statistics 289 // Update window statistics
285 if (!hasEntry(windowStats, topWnd.document)) 290 if (!hasEntry(windowStats, topWnd.document))
286 { 291 {
287 setEntry(windowStats, topWnd.document, { 292 setEntry(windowStats, topWnd.document, {
288 items: 0, 293 items: 0,
289 hidden: 0, 294 hidden: 0,
290 blocked: 0, 295 blocked: 0,
(...skipping 21 matching lines...) Expand all
312 } 317 }
313 318
314 // Notify listeners 319 // Notify listeners
315 for (let notifier of activeNotifiers) 320 for (let notifier of activeNotifiers)
316 if (!notifier.window || notifier.window == topWnd) 321 if (!notifier.window || notifier.window == topWnd)
317 notifier.notifyListener(topWnd, node, this); 322 notifier.notifyListener(topWnd, node, this);
318 } 323 }
319 RequestEntry.prototype = 324 RequestEntry.prototype =
320 { 325 {
321 /** 326 /**
327 * id of request (used to determine last entry attached to a node)
328 * @type integer
329 */
330 id: 0,
331 /**
322 * Content type of the request (one of the nsIContentPolicy constants) 332 * Content type of the request (one of the nsIContentPolicy constants)
323 * @type Integer 333 * @type Integer
324 */ 334 */
325 type: null, 335 type: null,
326 /** 336 /**
327 * Domain name of the requesting document 337 * Domain name of the requesting document
328 * @type String 338 * @type String
329 */ 339 */
330 docDomain: null, 340 docDomain: null,
331 /** 341 /**
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 if (typeof existingData == "undefined") 379 if (typeof existingData == "undefined")
370 { 380 {
371 existingData = {}; 381 existingData = {};
372 setEntry(nodeData, node, existingData); 382 setEntry(nodeData, node, existingData);
373 } 383 }
374 384
375 // Add this request to the node data 385 // Add this request to the node data
376 existingData[this.type + " " + this.location] = this; 386 existingData[this.type + " " + this.location] = this;
377 } 387 }
378 }; 388 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld