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

Side by Side Diff: lib/contentPolicy.js

Issue 6341149593698304: Issue 301 - Change for each to for .. of .. in lib/ (Closed)
Patch Set: Created April 10, 2014, 5:02 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 | « lib/antiadblockInit.js ('k') | lib/downloader.js » ('j') | 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
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 87
88 /** 88 /**
89 * Called on module startup, initializes various exported properties. 89 * Called on module startup, initializes various exported properties.
90 */ 90 */
91 init: function() 91 init: function()
92 { 92 {
93 TimeLine.enter("Entered content policy initialization"); 93 TimeLine.enter("Entered content policy initialization");
94 94
95 // type constant by type description and type description by type constant 95 // type constant by type description and type description by type constant
96 let iface = Ci.nsIContentPolicy; 96 let iface = Ci.nsIContentPolicy;
97 for each (let typeName in contentTypes) 97 for (let typeName of contentTypes)
98 { 98 {
99 if ("TYPE_" + typeName in iface) 99 if ("TYPE_" + typeName in iface)
100 { 100 {
101 let id = iface["TYPE_" + typeName]; 101 let id = iface["TYPE_" + typeName];
102 this.type[typeName] = id; 102 this.type[typeName] = id;
103 this.typeDescr[id] = typeName; 103 this.typeDescr[id] = typeName;
104 this.localizedDescr[id] = Utils.getString("type_label_" + typeName.toLow erCase()); 104 this.localizedDescr[id] = Utils.getString("type_label_" + typeName.toLow erCase());
105 } 105 }
106 } 106 }
107 107
108 this.type.ELEMHIDE = 0xFFFD; 108 this.type.ELEMHIDE = 0xFFFD;
109 this.typeDescr[0xFFFD] = "ELEMHIDE"; 109 this.typeDescr[0xFFFD] = "ELEMHIDE";
110 this.localizedDescr[0xFFFD] = Utils.getString("type_label_elemhide"); 110 this.localizedDescr[0xFFFD] = Utils.getString("type_label_elemhide");
111 111
112 this.type.POPUP = 0xFFFE; 112 this.type.POPUP = 0xFFFE;
113 this.typeDescr[0xFFFE] = "POPUP"; 113 this.typeDescr[0xFFFE] = "POPUP";
114 this.localizedDescr[0xFFFE] = Utils.getString("type_label_popup"); 114 this.localizedDescr[0xFFFE] = Utils.getString("type_label_popup");
115 115
116 for each (let type in nonVisualTypes) 116 for (let type of nonVisualTypes)
117 this.nonVisual[this.type[type]] = true; 117 this.nonVisual[this.type[type]] = true;
118 118
119 // whitelisted URL schemes 119 // whitelisted URL schemes
120 for each (let scheme in Prefs.whitelistschemes.toLowerCase().split(" ")) 120 for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" "))
121 this.whitelistSchemes[scheme] = true; 121 this.whitelistSchemes[scheme] = true;
122 122
123 TimeLine.log("done initializing types"); 123 TimeLine.log("done initializing types");
124 124
125 // Generate class identifier used to collapse node and register correspondin g 125 // Generate class identifier used to collapse node and register correspondin g
126 // stylesheet. 126 // stylesheet.
127 TimeLine.log("registering global stylesheet"); 127 TimeLine.log("registering global stylesheet");
128 128
129 let offset = "a".charCodeAt(0); 129 let offset = "a".charCodeAt(0);
130 for (let i = 0; i < 20; i++) 130 for (let i = 0; i < 20; i++)
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 335
336 /** 336 /**
337 * Asynchronously re-checks filters for given nodes. 337 * Asynchronously re-checks filters for given nodes.
338 */ 338 */
339 refilterNodes: function(/**Node[]*/ nodes, /**RequestEntry*/ entry) 339 refilterNodes: function(/**Node[]*/ nodes, /**RequestEntry*/ entry)
340 { 340 {
341 // Ignore nodes that have been blocked already 341 // Ignore nodes that have been blocked already
342 if (entry.filter && !(entry.filter instanceof WhitelistFilter)) 342 if (entry.filter && !(entry.filter instanceof WhitelistFilter))
343 return; 343 return;
344 344
345 for each (let node in nodes) 345 for (let node of nodes)
346 Utils.runAsync(refilterNode, this, node, entry); 346 Utils.runAsync(refilterNode, this, node, entry);
347 } 347 }
348 }; 348 };
349 Policy.init(); 349 Policy.init();
350 350
351 /** 351 /**
352 * Actual nsIContentPolicy and nsIChannelEventSink implementation 352 * Actual nsIContentPolicy and nsIChannelEventSink implementation
353 * @class 353 * @class
354 */ 354 */
355 let PolicyImplementation = 355 let PolicyImplementation =
(...skipping 15 matching lines...) Expand all
371 } 371 }
372 catch (e if e.result == Cr.NS_ERROR_FACTORY_EXISTS) 372 catch (e if e.result == Cr.NS_ERROR_FACTORY_EXISTS)
373 { 373 {
374 // See bug 924340 - it might be too early to init now, the old version 374 // See bug 924340 - it might be too early to init now, the old version
375 // we are replacing didn't finish removing itself yet. 375 // we are replacing didn't finish removing itself yet.
376 Utils.runAsync(this.init.bind(this)); 376 Utils.runAsync(this.init.bind(this));
377 return; 377 return;
378 } 378 }
379 379
380 let catMan = Utils.categoryManager; 380 let catMan = Utils.categoryManager;
381 for each (let category in this.xpcom_categories) 381 for (let category of this.xpcom_categories)
382 catMan.addCategoryEntry(category, this.contractID, this.contractID, false, true); 382 catMan.addCategoryEntry(category, this.contractID, this.contractID, false, true);
383 383
384 // http-on-opening-request is new in Gecko 18, http-on-modify-request can 384 // http-on-opening-request is new in Gecko 18, http-on-modify-request can
385 // be used in earlier releases. 385 // be used in earlier releases.
386 let httpTopic = "http-on-opening-request"; 386 let httpTopic = "http-on-opening-request";
387 if (Services.vc.compare(Utils.platformVersion, "18.0") < 0) 387 if (Services.vc.compare(Utils.platformVersion, "18.0") < 0)
388 httpTopic = "http-on-modify-request"; 388 httpTopic = "http-on-modify-request";
389 389
390 Services.obs.addObserver(this, httpTopic, true); 390 Services.obs.addObserver(this, httpTopic, true);
391 Services.obs.addObserver(this, "content-document-global-created", true); 391 Services.obs.addObserver(this, "content-document-global-created", true);
392 Services.obs.addObserver(this, "xpcom-category-entry-removed", true); 392 Services.obs.addObserver(this, "xpcom-category-entry-removed", true);
393 Services.obs.addObserver(this, "xpcom-category-cleared", true); 393 Services.obs.addObserver(this, "xpcom-category-cleared", true);
394 394
395 onShutdown.add(function() 395 onShutdown.add(function()
396 { 396 {
397 // Our category observers should be removed before changing category 397 // Our category observers should be removed before changing category
398 // memberships, just in case. 398 // memberships, just in case.
399 Services.obs.removeObserver(this, httpTopic); 399 Services.obs.removeObserver(this, httpTopic);
400 Services.obs.removeObserver(this, "content-document-global-created"); 400 Services.obs.removeObserver(this, "content-document-global-created");
401 Services.obs.removeObserver(this, "xpcom-category-entry-removed"); 401 Services.obs.removeObserver(this, "xpcom-category-entry-removed");
402 Services.obs.removeObserver(this, "xpcom-category-cleared"); 402 Services.obs.removeObserver(this, "xpcom-category-cleared");
403 403
404 for each (let category in this.xpcom_categories) 404 for (let category of this.xpcom_categories)
405 catMan.deleteCategoryEntry(category, this.contractID, false); 405 catMan.deleteCategoryEntry(category, this.contractID, false);
406 406
407 // This needs to run asynchronously, see bug 753687 407 // This needs to run asynchronously, see bug 753687
408 Utils.runAsync(function() 408 Utils.runAsync(function()
409 { 409 {
410 registrar.unregisterFactory(this.classID, this); 410 registrar.unregisterFactory(this.classID, this);
411 }.bind(this)); 411 }.bind(this));
412 412
413 this.previousRequest = null; 413 this.previousRequest = null;
414 }.bind(this)); 414 }.bind(this));
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 } 632 }
633 633
634 /** 634 /**
635 * Processes nodes scheduled for post-processing (typically hides them). 635 * Processes nodes scheduled for post-processing (typically hides them).
636 */ 636 */
637 function postProcessNodes() 637 function postProcessNodes()
638 { 638 {
639 let nodes = scheduledNodes; 639 let nodes = scheduledNodes;
640 scheduledNodes = null; 640 scheduledNodes = null;
641 641
642 for each (let node in nodes) 642 for (let node of nodes)
643 { 643 {
644 // adjust frameset's cols/rows for frames 644 // adjust frameset's cols/rows for frames
645 let parentNode = node.parentNode; 645 let parentNode = node.parentNode;
646 if (parentNode && parentNode instanceof Ci.nsIDOMHTMLFrameSetElement) 646 if (parentNode && parentNode instanceof Ci.nsIDOMHTMLFrameSetElement)
647 { 647 {
648 let hasCols = (parentNode.cols && parentNode.cols.indexOf(",") > 0); 648 let hasCols = (parentNode.cols && parentNode.cols.indexOf(",") > 0);
649 let hasRows = (parentNode.rows && parentNode.rows.indexOf(",") > 0); 649 let hasRows = (parentNode.rows && parentNode.rows.indexOf(",") > 0);
650 if ((hasCols || hasRows) && !(hasCols && hasRows)) 650 if ((hasCols || hasRows) && !(hasCols && hasRows))
651 { 651 {
652 let index = -1; 652 let index = -1;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 if (!wnd || wnd.closed) 755 if (!wnd || wnd.closed)
756 return; 756 return;
757 757
758 if (entry.type == Policy.type.OBJECT) 758 if (entry.type == Policy.type.OBJECT)
759 { 759 {
760 node.removeEventListener("mouseover", objectMouseEventHander, true); 760 node.removeEventListener("mouseover", objectMouseEventHander, true);
761 node.removeEventListener("mouseout", objectMouseEventHander, true); 761 node.removeEventListener("mouseout", objectMouseEventHander, true);
762 } 762 }
763 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ; 763 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ;
764 } 764 }
OLDNEW
« no previous file with comments | « lib/antiadblockInit.js ('k') | lib/downloader.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld