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

Delta Between Two Patch Sets: lib/requestNotifier.js

Issue 5681038109966336: issue #362 - firefox: block image broken on youtube thumbnails (recommended videos) (Closed)
Left Patch Set: Created Aug. 10, 2014, 11:52 a.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 * @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 235 * @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
235 * @param {Integer} [type] request type to be looking for 236 * @param {Integer} [type] request type to be looking for
236 * @param {String} [location] request location to be looking for 237 * @param {String} [location] request location to be looking for
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 entry = getEntry(nodeData, node); 245 let data = getEntry(nodeData, node);
245 if (typeof entry != "undefined" && 246 if (typeof data != "undefined")
246 (typeof type == "undefined" || entry.type == type) && 247 {
247 (typeof location == "undefined" || entry.location == location)) 248 let entry = null;
248 { 249 // Look for matching entry
249 return [node, entry]; 250 for (let k in data)
251 {
252 if ((!entry || entry.id < data[k].id) &&
253 (typeof type == "undefined" || data[k].type == type) &&
254 (typeof location == "undefined" || data[k].location == location))
255 {
256 entry = data[k];
257 }
258 }
259 if (entry)
260 return [node, entry];
250 } 261 }
251 262
252 // 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
253 if ((typeof noParent != "boolean" || !noParent) && 264 if ((typeof noParent != "boolean" || !noParent) &&
254 node.parentNode instanceof Ci.nsIDOMElement) 265 node.parentNode instanceof Ci.nsIDOMElement)
255 { 266 {
256 node = node.parentNode; 267 node = node.parentNode;
257 } 268 }
258 else 269 else
259 { 270 {
260 node = null; 271 node = null;
261 } 272 }
262 } 273 }
263 274
264 return null; 275 return null;
265 }; 276 };
266 277
267 function RequestEntry(node, topWnd, contentType, docDomain, thirdParty, location , filter) 278 function RequestEntry(node, topWnd, contentType, docDomain, thirdParty, location , filter)
268 { 279 {
269 this.type = contentType; 280 this.type = contentType;
270 this.docDomain = docDomain; 281 this.docDomain = docDomain;
271 this.thirdParty = thirdParty; 282 this.thirdParty = thirdParty;
272 this.location = location; 283 this.location = location;
273 this.filter = filter; 284 this.filter = filter;
285 this.id = ++requestEntryMaxId;
274 286
275 this.attachToNode(node); 287 this.attachToNode(node);
276 288
277 // Update window statistics 289 // Update window statistics
278 if (!hasEntry(windowStats, topWnd.document)) 290 if (!hasEntry(windowStats, topWnd.document))
279 { 291 {
280 setEntry(windowStats, topWnd.document, { 292 setEntry(windowStats, topWnd.document, {
281 items: 0, 293 items: 0,
282 hidden: 0, 294 hidden: 0,
283 blocked: 0, 295 blocked: 0,
(...skipping 21 matching lines...) Expand all
305 } 317 }
306 318
307 // Notify listeners 319 // Notify listeners
308 for (let notifier of activeNotifiers) 320 for (let notifier of activeNotifiers)
309 if (!notifier.window || notifier.window == topWnd) 321 if (!notifier.window || notifier.window == topWnd)
310 notifier.notifyListener(topWnd, node, this); 322 notifier.notifyListener(topWnd, node, this);
311 } 323 }
312 RequestEntry.prototype = 324 RequestEntry.prototype =
313 { 325 {
314 /** 326 /**
327 * id of request (used to determine last entry attached to a node)
328 * @type integer
329 */
330 id: 0,
331 /**
315 * Content type of the request (one of the nsIContentPolicy constants) 332 * Content type of the request (one of the nsIContentPolicy constants)
316 * @type Integer 333 * @type Integer
317 */ 334 */
318 type: null, 335 type: null,
319 /** 336 /**
320 * Domain name of the requesting document 337 * Domain name of the requesting document
321 * @type String 338 * @type String
322 */ 339 */
323 docDomain: null, 340 docDomain: null,
324 /** 341 /**
(...skipping 26 matching lines...) Expand all
351 get localizedDescr() 368 get localizedDescr()
352 { 369 {
353 return require("contentPolicy").Policy.localizedDescr[this.type]; 370 return require("contentPolicy").Policy.localizedDescr[this.type];
354 }, 371 },
355 372
356 /** 373 /**
357 * Attaches this request object to a DOM node. 374 * Attaches this request object to a DOM node.
358 */ 375 */
359 attachToNode: function(/**Node*/ node) 376 attachToNode: function(/**Node*/ node)
360 { 377 {
361 setEntry(nodeData, node, this); 378 let existingData = getEntry(nodeData, node);
Wladimir Palant 2014/08/14 20:44:57 The the list of blockable items is broken now beca
saroyanm 2014/08/17 14:25:21 Oops, Thanks for that.
362 } 379 if (typeof existingData == "undefined")
363 }; 380 {
381 existingData = {};
382 setEntry(nodeData, node, existingData);
383 }
384
385 // Add this request to the node data
386 existingData[this.type + " " + this.location] = this;
387 }
388 };
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld