| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 */ | 48 */ |
| 49 let collapsedClass = null; | 49 let collapsedClass = null; |
| 50 | 50 |
| 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. | |
| 59 * @type Map.<string,DOMNode[]> | |
| 60 */ | |
| 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 | |
| 63 /** | |
| 64 * Process-dependent prefix to be used for unique nodes identifiers returned | |
| 65 * by storeNodes(). | |
| 66 * @type string | |
| 67 */ | |
| 68 let nodesIDPrefix = Services.appinfo.processID + " "; | |
| 69 | |
| 70 /** | |
| 71 * Counter used to generate unique nodes identifiers in storeNodes(). | |
| 72 * @type number | |
| 73 */ | |
| 74 let maxNodesID = 0; | |
| 75 | |
| 76 addMessageListener("AdblockPlus:DeleteNodes", onDeleteNodes); | |
| 77 addMessageListener("AdblockPlus:RefilterNodes", onRefilterNodes); | |
| 78 | |
| 79 onShutdown.add(() => { | |
| 80 removeMessageListener("AdblockPlus:DeleteNodes", onDeleteNodes); | |
| 81 removeMessageListener("AdblockPlus:RefilterNodes", onRefilterNodes); | |
| 82 }); | |
| 83 | |
| 84 /** | |
| 58 * Processes parent's response to the ShouldAllow message. | 85 * Processes parent's response to the ShouldAllow message. |
| 59 * @param {nsIDOMWindow} window window that the request is associated with | 86 * @param {nsIDOMWindow} window window that the request is associated with |
| 60 * @param {nsIDOMElement} node DOM element that the request is associated with | 87 * @param {nsIDOMElement} node DOM element that the request is associated with |
| 61 * @param {Object|undefined} response object received as response | 88 * @param {Object|undefined} response object received as response |
| 62 * @return {Boolean} false if the request should be blocked | 89 * @return {Boolean} false if the request should be blocked |
| 63 */ | 90 */ |
| 64 function processPolicyResponse(window, node, response) | 91 function processPolicyResponse(window, node, response) |
| 65 { | 92 { |
| 66 if (typeof response == "undefined") | 93 if (typeof response == "undefined") |
| 67 return true; | 94 return true; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 { | 157 { |
| 131 sendAsyncMessage("AdblockPlus:ShouldAllow", { | 158 sendAsyncMessage("AdblockPlus:ShouldAllow", { |
| 132 contentType, | 159 contentType, |
| 133 location, | 160 location, |
| 134 frames: getFrames(window), | 161 frames: getFrames(window), |
| 135 isPrivate: isPrivate(window) | 162 isPrivate: isPrivate(window) |
| 136 }, response => callback(processPolicyResponse(window, node, response))); | 163 }, response => callback(processPolicyResponse(window, node, response))); |
| 137 }; | 164 }; |
| 138 | 165 |
| 139 /** | 166 /** |
| 167 * Stores nodes and generates a unique ID for them that can be used for | |
| 168 * Policy.refilterNodes() later. It's important that Policy.deleteNodes() is | |
| 169 * called later, otherwise the nodes will be leaked. | |
| 170 * @param {DOMNode[]} nodes list of nodes to be stored | |
| 171 * @return {string} unique ID for the nodes | |
| 172 */ | |
| 173 let storeNodes = exports.storeNodes = function(nodes) | |
| 174 { | |
| 175 let id = nodesIDPrefix + (++maxNodesID); | |
| 176 storedNodes.set(id, nodes); | |
| 177 return id; | |
| 178 }; | |
| 179 | |
| 180 /** | |
| 181 * Called via message whenever Policy.deleteNodes() is called in the parent. | |
| 182 */ | |
| 183 function onDeleteNodes(message) | |
| 184 { | |
| 185 storedNodes.delete(message.data); | |
| 186 } | |
| 187 | |
| 188 /** | |
| 189 * Called via message whenever Policy.refilterNodes() is called in the parent. | |
| 190 */ | |
| 191 function onRefilterNodes(message) | |
| 192 { | |
| 193 let {nodesID, entry} = message.data; | |
| 194 let nodes = storedNodes.get(nodesID); | |
| 195 if (nodes) | |
| 196 for (let node of nodes) | |
| 197 if (node.nodeType == Ci.nsIDOMNode.ELEMENT_NODE) | |
| 198 Utils.runAsync(refilterNode.bind(this, node, entry)); | |
| 199 } | |
| 200 | |
| 201 /** | |
| 202 * Re-checks filters on an element. | |
| 203 */ | |
| 204 function refilterNode(/**Node*/ node, /**Object*/ entry) | |
| 205 { | |
| 206 let wnd = Utils.getWindow(node); | |
| 207 if (!wnd || wnd.closed) | |
| 208 return; | |
| 209 | |
| 210 if (entry.type == "OBJECT") | |
| 211 { | |
| 212 node.removeEventListener("mouseover", objectMouseEventHander, true); | |
| 213 node.removeEventListener("mouseout", objectMouseEventHander, true); | |
| 214 } | |
| 215 | |
| 216 shouldAllow(wnd, node, entry.type, entry.location, (allow) => { | |
| 217 // Force node to be collapsed | |
| 218 if (!allow) | |
| 219 schedulePostProcess(node) | |
| 220 }); | |
| 221 } | |
| 222 | |
| 223 /** | |
| 140 * Actual nsIContentPolicy and nsIChannelEventSink implementation | 224 * Actual nsIContentPolicy and nsIChannelEventSink implementation |
| 141 * @class | 225 * @class |
| 142 */ | 226 */ |
| 143 var PolicyImplementation = | 227 var PolicyImplementation = |
| 144 { | 228 { |
| 145 classDescription: "Adblock Plus content policy", | 229 classDescription: "Adblock Plus content policy", |
| 146 classID: Components.ID("cfeaabe6-1dd1-11b2-a0c6-cb5c268894c9"), | 230 classID: Components.ID("cfeaabe6-1dd1-11b2-a0c6-cb5c268894c9"), |
| 147 contractID: "@adblockplus.org/abp/policy;1", | 231 contractID: "@adblockplus.org/abp/policy;1", |
| 148 xpcom_categories: ["content-policy", "net-channel-event-sinks"], | 232 xpcom_categories: ["content-policy", "net-channel-event-sinks"], |
| 149 | 233 |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 let property = (hasCols ? "cols" : "rows"); | 463 let property = (hasCols ? "cols" : "rows"); |
| 380 let weights = parentNode[property].split(","); | 464 let weights = parentNode[property].split(","); |
| 381 weights[index] = "0"; | 465 weights[index] = "0"; |
| 382 parentNode[property] = weights.join(","); | 466 parentNode[property] = weights.join(","); |
| 383 } | 467 } |
| 384 } | 468 } |
| 385 else | 469 else |
| 386 node.classList.add(collapsedClass); | 470 node.classList.add(collapsedClass); |
| 387 } | 471 } |
| 388 } | 472 } |
| OLD | NEW |