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

Delta Between Two Patch Sets: lib/child/contentPolicy.js

Issue 29338279: Issue 3499 - Use new messaging API in the content policy implementation (Closed)
Left Patch Set: Created March 15, 2016, 10:57 a.m.
Right Patch Set: More obvious logic in postProcessNodes Created March 16, 2016, 10:10 a.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 | lib/contentPolicy.js » ('j') | 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 <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 27 matching lines...) Expand all
38 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); 38 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
39 39
40 let {port} = require("messaging"); 40 let {port} = require("messaging");
41 let {Utils} = require("utils"); 41 let {Utils} = require("utils");
42 let {getFrames, isPrivate} = require("child/utils"); 42 let {getFrames, isPrivate} = require("child/utils");
43 let {objectMouseEventHander} = require("child/objectTabs"); 43 let {objectMouseEventHander} = require("child/objectTabs");
44 let {RequestNotifier} = require("child/requestNotifier"); 44 let {RequestNotifier} = require("child/requestNotifier");
45 45
46 /** 46 /**
47 * Randomly generated class name, to be applied to collapsed nodes. 47 * Randomly generated class name, to be applied to collapsed nodes.
48 * @type string 48 * @type Promise.<string>
49 */ 49 */
50 let collapsedClass = null; 50 let collapsedClass = port.emitWithResponse("getCollapsedClass");
51 51
52 /** 52 /**
53 * Maps numerical content type IDs to strings. 53 * Maps numerical content type IDs to strings.
54 * @type Map.<number,string> 54 * @type Map.<number,string>
55 */ 55 */
56 let types = new Map(); 56 let types = new Map();
57 57
58 /** 58 /**
59 * Contains nodes stored by storeNodes() mapped by their IDs. 59 * Contains nodes stored by storeNodes() mapped by their IDs.
60 * @type Map.<string,DOMNode[]> 60 * @type Map.<string,DOMNode[]>
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 scheduledNodes = [node]; 449 scheduledNodes = [node];
450 Utils.runAsync(postProcessNodes); 450 Utils.runAsync(postProcessNodes);
451 } 451 }
452 } 452 }
453 453
454 /** 454 /**
455 * Processes nodes scheduled for post-processing (typically hides them). 455 * Processes nodes scheduled for post-processing (typically hides them).
456 */ 456 */
457 function postProcessNodes() 457 function postProcessNodes()
458 { 458 {
459 if (!collapsedClass) 459 collapsedClass.then(cls =>
Thomas Greiner 2016/03/23 18:47:59 Detail: Anything wrong with calling it "collapsedC
Wladimir Palant 2016/03/24 07:27:26 They are not the same thing however. I would consi
460 { 460 {
461 port.emitWithResponse("getCollapsedClass").then(cls => 461 let nodes = scheduledNodes;
462 { 462 scheduledNodes = null;
463 // We might have sent this message multiple times, ignore response if a 463
464 // previous response was already processed. 464 // Resolving class is async initially so the nodes might have already been
465 if (collapsedClass) 465 // processed in the meantime.
466 return; 466 if (!nodes)
467 467 return;
468 collapsedClass = cls; 468
469 postProcessNodes(); 469 for (let node of nodes)
470 }); 470 {
471 return; 471 // adjust frameset's cols/rows for frames
472 } 472 let parentNode = node.parentNode;
473 473 if (parentNode && parentNode instanceof Ci.nsIDOMHTMLFrameSetElement)
474 let nodes = scheduledNodes;
475 scheduledNodes = null;
Erik 2016/03/15 20:57:41 It appears that `postProcessNodes` is run twice no
Wladimir Palant 2016/03/16 10:13:00 No, we don't run this code multiple times (return
476
477 for (let node of nodes)
478 {
479 // adjust frameset's cols/rows for frames
480 let parentNode = node.parentNode;
481 if (parentNode && parentNode instanceof Ci.nsIDOMHTMLFrameSetElement)
482 {
483 let hasCols = (parentNode.cols && parentNode.cols.indexOf(",") > 0);
484 let hasRows = (parentNode.rows && parentNode.rows.indexOf(",") > 0);
485 if ((hasCols || hasRows) && !(hasCols && hasRows))
486 { 474 {
487 let index = -1; 475 let hasCols = (parentNode.cols && parentNode.cols.indexOf(",") > 0);
488 for (let frame = node; frame; frame = frame.previousSibling) 476 let hasRows = (parentNode.rows && parentNode.rows.indexOf(",") > 0);
489 if (frame instanceof Ci.nsIDOMHTMLFrameElement || frame instanceof Ci. nsIDOMHTMLFrameSetElement) 477 if ((hasCols || hasRows) && !(hasCols && hasRows))
490 index++; 478 {
491 479 let index = -1;
492 let property = (hasCols ? "cols" : "rows"); 480 for (let frame = node; frame; frame = frame.previousSibling)
493 let weights = parentNode[property].split(","); 481 if (frame instanceof Ci.nsIDOMHTMLFrameElement || frame instanceof C i.nsIDOMHTMLFrameSetElement)
494 weights[index] = "0"; 482 index++;
495 parentNode[property] = weights.join(","); 483
484 let property = (hasCols ? "cols" : "rows");
485 let weights = parentNode[property].split(",");
486 weights[index] = "0";
487 parentNode[property] = weights.join(",");
488 }
496 } 489 }
497 } 490 else
498 else 491 node.classList.add(cls);
499 node.classList.add(collapsedClass); 492 }
500 } 493 });
501 } 494 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld