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

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

Issue 29329884: Issue 3224 - Unbreak filter assistant (Closed)
Left Patch Set: Created Nov. 9, 2015, 1:45 p.m.
Right Patch Set: Rebased Created Nov. 12, 2015, 3:10 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 | « chrome/content/ui/sidebar.js ('k') | lib/child/objectTabs.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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 /** 51 /**
52 * Maps numerical content type IDs to strings. 52 * Maps numerical content type IDs to strings.
53 * @type Map.<number,string> 53 * @type Map.<number,string>
54 */ 54 */
55 let types = new Map(); 55 let types = new Map();
56 56
57 /** 57 /**
58 * Contains nodes stored by storeNodes() mapped by their IDs. 58 * Contains nodes stored by storeNodes() mapped by their IDs.
59 * @type Map.<string,DOMNode[]> 59 * @type Map.<string,DOMNode[]>
60 */ 60 */
61 let storedNodes = new Map(); 61 let storedNodes = new Map();
tschuster 2015/12/01 16:42:40 So, this is cleaned up by DeleteNodes, which is ca
Wladimir Palant 2015/12/01 19:15:31 Nodes can be removed without navigating away (yes,
62 62
63 /** 63 /**
64 * Process-dependent prefix to be used for unique nodes identifiers returned 64 * Process-dependent prefix to be used for unique nodes identifiers returned
65 * by storeNodes(). 65 * by storeNodes().
66 * @type string 66 * @type string
67 */ 67 */
68 let nodesIDPrefix = Services.appinfo.processID + " "; 68 let nodesIDPrefix = Services.appinfo.processID + " ";
69 69
70 /** 70 /**
71 * Counter used to generate unique nodes identifiers in storeNodes(). 71 * Counter used to generate unique nodes identifiers in storeNodes().
72 * @type number 72 * @type number
73 */ 73 */
74 let maxNodesID = 0; 74 let maxNodesID = 0;
75 75
76 addMessageListener("AdblockPlus:DeleteNodes", onDeleteNodes); 76 addMessageListener("AdblockPlus:DeleteNodes", onDeleteNodes);
77 addMessageListener("AdblockPlus:RefilterNodes", onRefilterNodes); 77 addMessageListener("AdblockPlus:RefilterNodes", onRefilterNodes);
78 78
79 onShutdown.add(() => { 79 onShutdown.add(() => {
80 removeMessageListener("AdblockPlus:DeleteNodes", onDeleteNodes); 80 removeMessageListener("AdblockPlus:DeleteNodes", onDeleteNodes);
81 removeMessageListener("AdblockPlus:RefilterNodes", onRefilterNodes); 81 removeMessageListener("AdblockPlus:RefilterNodes", onRefilterNodes);
82 }); 82 });
83 83
84 /** 84 /**
85 * Processes parent's response to the ShouldAllow message.
86 * @param {nsIDOMWindow} window window that the request is associated with
87 * @param {nsIDOMElement} node DOM element that the request is associated with
88 * @param {Object|undefined} response object received as response
89 * @return {Boolean} false if the request should be blocked
90 */
91 function processPolicyResponse(window, node, response)
92 {
93 if (typeof response == "undefined")
94 return true;
95
96 let {allow, collapse, hits} = response;
97 let isObject = false;
98 for (let hit of hits)
99 {
100 if (hit.contentType == "OBJECT")
101 isObject = true;
102
103 let context = node;
104 if (typeof hit.frameIndex == "number")
105 {
106 context = window;
107 for (let i = 0; i < hit.frameIndex; i++)
108 context = context.parent;
109 context = context.document;
110 }
111 RequestNotifier.addNodeData(context, window.top, hit);
112 }
113
114 if (node.nodeType == Ci.nsIDOMNode.ELEMENT_NODE)
115 {
116 // Track mouse events for objects
117 if (allow && isObject)
118 {
119 node.addEventListener("mouseover", objectMouseEventHander, true);
120 node.addEventListener("mouseout", objectMouseEventHander, true);
121 }
122
123 if (collapse)
124 schedulePostProcess(node);
125 }
126 return allow;
127 }
128
129 /**
85 * Checks whether a request should be allowed, hides it if necessary 130 * Checks whether a request should be allowed, hides it if necessary
86 * @param wnd {nsIDOMWindow} 131 * @param {nsIDOMWindow} window
87 * @param node {nsIDOMElement} 132 * @param {nsIDOMElement} node
88 * @param contentType {String} 133 * @param {String} contentType
89 * @param location {String} location of the request, filter key if contentType i s ELEMHIDE 134 * @param {String} location location of the request, filter key if contentType i s ELEMHIDE
90 * @param [callback] {Function} If present, the request will be sent
91 * asynchronously and callback called with the
92 * response
93 * @return {Boolean} false if the request should be blocked 135 * @return {Boolean} false if the request should be blocked
94 */ 136 */
95 let shouldAllow = exports.shouldAllow = function(window, node, contentType, loca tion, callback) 137 let shouldAllow = exports.shouldAllow = function(window, node, contentType, loca tion)
96 { 138 {
97 function processResponse(response) 139 return processPolicyResponse(window, node, sendSyncMessage("AdblockPlus:Should Allow", {
98 { 140 contentType,
99 if (typeof response == "undefined") 141 location,
100 return true;
101
102 let {allow, collapse, hits} = response;
103 for (let hit of hits)
104 {
105 let context = node;
106 if (typeof hit.frameIndex == "number")
107 {
108 context = window;
109 for (let i = 0; i < hit.frameIndex; i++)
110 context = context.parent;
111 context = context.document;
112 }
113 RequestNotifier.addNodeData(context, window.top, hit);
114 }
115
116 if (node.nodeType == Ci.nsIDOMNode.ELEMENT_NODE)
117 {
118 // Track mouse events for objects
119 if (allow && contentType == "OBJECT")
120 {
121 node.addEventListener("mouseover", objectMouseEventHander, true);
122 node.addEventListener("mouseout", objectMouseEventHander, true);
123 }
124
125 if (collapse)
126 schedulePostProcess(node);
127 }
128 return allow;
129 }
130
131 let data = {
132 contentType: contentType,
133 location: location,
134 frames: getFrames(window), 142 frames: getFrames(window),
135 isPrivate: isPrivate(window) 143 isPrivate: isPrivate(window)
136 }; 144 }));
137 if (typeof callback == "function") 145 };
138 { 146
139 sendAsyncMessage("AdblockPlus:ShouldAllow", data, (data) => { 147 /**
140 callback(processResponse(data)); 148 * Asynchronously checks whether a request should be allowed.
141 }); 149 * @param {nsIDOMWindow} window
142 } 150 * @param {nsIDOMElement} node
143 else 151 * @param {String} contentType
144 return processResponse(sendSyncMessage("AdblockPlus:ShouldAllow", data)); 152 * @param {String} location location of the request, filter key if contentType i s ELEMHIDE
153 * @param {Function} callback callback to be called with a boolean value, if
154 * false the request should be blocked
155 */
156 let shouldAllowAsync = exports.shouldAllowAsync = function(window, node, content Type, location, callback)
157 {
158 sendAsyncMessage("AdblockPlus:ShouldAllow", {
159 contentType,
160 location,
161 frames: getFrames(window),
162 isPrivate: isPrivate(window)
163 }, response => callback(processPolicyResponse(window, node, response)));
145 }; 164 };
146 165
147 /** 166 /**
148 * Stores nodes and generates a unique ID for them that can be used for 167 * Stores nodes and generates a unique ID for them that can be used for
149 * Policy.refilterNodes() later. It's important that Policy.deleteNodes() is 168 * Policy.refilterNodes() later. It's important that Policy.deleteNodes() is
150 * called later, otherwise the nodes will be leaked. 169 * called later, otherwise the nodes will be leaked.
151 * @param {DOMNode[]} nodes list of nodes to be stored 170 * @param {DOMNode[]} nodes list of nodes to be stored
152 * @return {string} unique ID for the nodes 171 * @return {string} unique ID for the nodes
153 */ 172 */
154 let storeNodes = exports.storeNodes = function(nodes) 173 let storeNodes = exports.storeNodes = function(nodes)
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 // Special treatment for pop-up windows - this will close the window 373 // Special treatment for pop-up windows - this will close the window
355 // rather than preventing the redirect. Note that we might not have 374 // rather than preventing the redirect. Note that we might not have
356 // seen the original channel yet because the redirect happened before 375 // seen the original channel yet because the redirect happened before
357 // the async code in observe() had a chance to run. 376 // the async code in observe() had a chance to run.
358 this.observe(wnd, "content-document-global-created", null, oldChannel. URI.spec); 377 this.observe(wnd, "content-document-global-created", null, oldChannel. URI.spec);
359 this.observe(wnd, "content-document-global-created", null, newChannel. URI.spec); 378 this.observe(wnd, "content-document-global-created", null, newChannel. URI.spec);
360 } 379 }
361 return; 380 return;
362 } 381 }
363 382
364 shouldAllow(wnd, wnd.document, types.get(contentType), newChannel.URI.spec , function(allow) 383 shouldAllowAsync(wnd, wnd.document, types.get(contentType), newChannel.URI .spec, function(allow)
365 { 384 {
366 callback.onRedirectVerifyCallback(allow ? Cr.NS_OK : Cr.NS_BINDING_ABORT ED); 385 callback.onRedirectVerifyCallback(allow ? Cr.NS_OK : Cr.NS_BINDING_ABORT ED);
367 }); 386 });
368 async = true; 387 async = true;
369 } 388 }
370 catch (e) 389 catch (e)
371 { 390 {
372 // We shouldn't throw exceptions here - this will prevent the redirect. 391 // We shouldn't throw exceptions here - this will prevent the redirect.
373 Cu.reportError(e); 392 Cu.reportError(e);
374 } 393 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 Utils.runAsync(postProcessNodes); 430 Utils.runAsync(postProcessNodes);
412 } 431 }
413 } 432 }
414 433
415 /** 434 /**
416 * Processes nodes scheduled for post-processing (typically hides them). 435 * Processes nodes scheduled for post-processing (typically hides them).
417 */ 436 */
418 function postProcessNodes() 437 function postProcessNodes()
419 { 438 {
420 if (!collapsedClass) 439 if (!collapsedClass)
421 {
422 collapsedClass = sendSyncMessage("AdblockPlus:GetCollapsedClass"); 440 collapsedClass = sendSyncMessage("AdblockPlus:GetCollapsedClass");
423 if (!collapsedClass)
424 {
425 Utils.runAsync(postProcessNodes);
426 return;
427 }
428 }
429 441
430 let nodes = scheduledNodes; 442 let nodes = scheduledNodes;
431 scheduledNodes = null; 443 scheduledNodes = null;
444
445 if (!collapsedClass)
446 return;
432 447
433 for (let node of nodes) 448 for (let node of nodes)
434 { 449 {
435 // adjust frameset's cols/rows for frames 450 // adjust frameset's cols/rows for frames
436 let parentNode = node.parentNode; 451 let parentNode = node.parentNode;
437 if (parentNode && parentNode instanceof Ci.nsIDOMHTMLFrameSetElement) 452 if (parentNode && parentNode instanceof Ci.nsIDOMHTMLFrameSetElement)
438 { 453 {
439 let hasCols = (parentNode.cols && parentNode.cols.indexOf(",") > 0); 454 let hasCols = (parentNode.cols && parentNode.cols.indexOf(",") > 0);
440 let hasRows = (parentNode.rows && parentNode.rows.indexOf(",") > 0); 455 let hasRows = (parentNode.rows && parentNode.rows.indexOf(",") > 0);
441 if ((hasCols || hasRows) && !(hasCols && hasRows)) 456 if ((hasCols || hasRows) && !(hasCols && hasRows))
442 { 457 {
443 let index = -1; 458 let index = -1;
444 for (let frame = node; frame; frame = frame.previousSibling) 459 for (let frame = node; frame; frame = frame.previousSibling)
445 if (frame instanceof Ci.nsIDOMHTMLFrameElement || frame instanceof Ci. nsIDOMHTMLFrameSetElement) 460 if (frame instanceof Ci.nsIDOMHTMLFrameElement || frame instanceof Ci. nsIDOMHTMLFrameSetElement)
446 index++; 461 index++;
447 462
448 let property = (hasCols ? "cols" : "rows"); 463 let property = (hasCols ? "cols" : "rows");
449 let weights = parentNode[property].split(","); 464 let weights = parentNode[property].split(",");
450 weights[index] = "0"; 465 weights[index] = "0";
451 parentNode[property] = weights.join(","); 466 parentNode[property] = weights.join(",");
452 } 467 }
453 } 468 }
454 else 469 else
455 node.classList.add(collapsedClass); 470 node.classList.add(collapsedClass);
456 } 471 }
457 } 472 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld