| 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(); | 
 |   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  * Checks whether a request should be allowed, hides it if necessary |   85  * Checks whether a request should be allowed, hides it if necessary | 
|   59  * @param wnd {nsIDOMWindow} |   86  * @param wnd {nsIDOMWindow} | 
|   60  * @param node {nsIDOMElement} |   87  * @param node {nsIDOMElement} | 
|   61  * @param contentType {String} |   88  * @param contentType {String} | 
|   62  * @param location {String} location of the request, filter key if contentType i
     s ELEMHIDE |   89  * @param location {String} location of the request, filter key if contentType i
     s ELEMHIDE | 
|   63  * @param [callback] {Function} If present, the request will be sent |   90  * @param [callback] {Function} If present, the request will be sent | 
|   64  *                              asynchronously and callback called with the |   91  *                              asynchronously and callback called with the | 
|   65  *                              response |   92  *                              response | 
|   66  * @return {Boolean} false if the request should be blocked |   93  * @return {Boolean} false if the request should be blocked | 
|   67  */ |   94  */ | 
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  111   { |  138   { | 
|  112     sendAsyncMessage("AdblockPlus:ShouldAllow", data, (data) => { |  139     sendAsyncMessage("AdblockPlus:ShouldAllow", data, (data) => { | 
|  113       callback(processResponse(data)); |  140       callback(processResponse(data)); | 
|  114     }); |  141     }); | 
|  115   } |  142   } | 
|  116   else |  143   else | 
|  117     return processResponse(sendSyncMessage("AdblockPlus:ShouldAllow", data)); |  144     return processResponse(sendSyncMessage("AdblockPlus:ShouldAllow", data)); | 
|  118 }; |  145 }; | 
|  119  |  146  | 
|  120 /** |  147 /** | 
 |  148  * 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 | 
 |  150  * called later, otherwise the nodes will be leaked. | 
 |  151  * @param {DOMNode[]} nodes  list of nodes to be stored | 
 |  152  * @return {string}  unique ID for the nodes | 
 |  153  */ | 
 |  154 let storeNodes = exports.storeNodes = function(nodes) | 
 |  155 { | 
 |  156   let id = nodesIDPrefix + (++maxNodesID); | 
 |  157   storedNodes.set(id, nodes); | 
 |  158   return id; | 
 |  159 }; | 
 |  160  | 
 |  161 /** | 
 |  162  * Called via message whenever Policy.deleteNodes() is called in the parent. | 
 |  163  */ | 
 |  164 function onDeleteNodes(message) | 
 |  165 { | 
 |  166   storedNodes.delete(message.data); | 
 |  167 } | 
 |  168  | 
 |  169 /** | 
 |  170  * Called via message whenever Policy.refilterNodes() is called in the parent. | 
 |  171  */ | 
 |  172 function onRefilterNodes(message) | 
 |  173 { | 
 |  174   let {nodesID, entry} = message.data; | 
 |  175   let nodes = storedNodes.get(nodesID); | 
 |  176   if (nodes) | 
 |  177     for (let node of nodes) | 
 |  178       if (node.nodeType == Ci.nsIDOMNode.ELEMENT_NODE) | 
 |  179         Utils.runAsync(refilterNode.bind(this, node, entry)); | 
 |  180 } | 
 |  181  | 
 |  182 /** | 
 |  183  * Re-checks filters on an element. | 
 |  184  */ | 
 |  185 function refilterNode(/**Node*/ node, /**Object*/ entry) | 
 |  186 { | 
 |  187   let wnd = Utils.getWindow(node); | 
 |  188   if (!wnd || wnd.closed) | 
 |  189     return; | 
 |  190  | 
 |  191   if (entry.type == "OBJECT") | 
 |  192   { | 
 |  193     node.removeEventListener("mouseover", objectMouseEventHander, true); | 
 |  194     node.removeEventListener("mouseout", objectMouseEventHander, true); | 
 |  195   } | 
 |  196  | 
 |  197   shouldAllow(wnd, node, entry.type, entry.location, (allow) => { | 
 |  198     // Force node to be collapsed | 
 |  199     if (!allow) | 
 |  200       schedulePostProcess(node) | 
 |  201   }); | 
 |  202 } | 
 |  203  | 
 |  204 /** | 
|  121  * Actual nsIContentPolicy and nsIChannelEventSink implementation |  205  * Actual nsIContentPolicy and nsIChannelEventSink implementation | 
|  122  * @class |  206  * @class | 
|  123  */ |  207  */ | 
|  124 var PolicyImplementation = |  208 var PolicyImplementation = | 
|  125 { |  209 { | 
|  126   classDescription: "Adblock Plus content policy", |  210   classDescription: "Adblock Plus content policy", | 
|  127   classID: Components.ID("cfeaabe6-1dd1-11b2-a0c6-cb5c268894c9"), |  211   classID: Components.ID("cfeaabe6-1dd1-11b2-a0c6-cb5c268894c9"), | 
|  128   contractID: "@adblockplus.org/abp/policy;1", |  212   contractID: "@adblockplus.org/abp/policy;1", | 
|  129   xpcom_categories: ["content-policy", "net-channel-event-sinks"], |  213   xpcom_categories: ["content-policy", "net-channel-event-sinks"], | 
|  130  |  214  | 
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  364         let property = (hasCols ? "cols" : "rows"); |  448         let property = (hasCols ? "cols" : "rows"); | 
|  365         let weights = parentNode[property].split(","); |  449         let weights = parentNode[property].split(","); | 
|  366         weights[index] = "0"; |  450         weights[index] = "0"; | 
|  367         parentNode[property] = weights.join(","); |  451         parentNode[property] = weights.join(","); | 
|  368       } |  452       } | 
|  369     } |  453     } | 
|  370     else |  454     else | 
|  371       node.classList.add(collapsedClass); |  455       node.classList.add(collapsedClass); | 
|  372   } |  456   } | 
|  373 } |  457 } | 
| OLD | NEW |