| 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * @fileOverview Hit counts for element hiding. | 19 * @fileOverview Hit counts for element hiding. |
| 20 */ | 20 */ |
| 21 | 21 |
| 22 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); | 22 try |
| 23 { |
| 24 // Hack: SDK loader masks our Components object with a getter. |
| 25 let proto = Object.getPrototypeOf(this); |
| 26 let property = Object.getOwnPropertyDescriptor(proto, "Components"); |
| 27 if (property && property.get) |
| 28 delete proto.Components; |
| 29 } |
| 30 catch (e) |
| 31 { |
| 32 Cu.reportError(e); |
| 33 } |
| 34 |
| 35 let {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {}); |
| 36 let {PrivateBrowsingUtils} = Cu.import("resource://gre/modules/PrivateBrowsingUt
ils.jsm") |
| 23 | 37 |
| 24 let {Utils} = require("utils"); | 38 let {Utils} = require("utils"); |
| 25 | 39 |
| 40 let messageID = 0; |
| 41 |
| 42 // The allowXBL binding below won't have any effect on the element. For elements |
| 43 // that should be hidden however we don't return any binding at all, this makes |
| 44 // Gecko stop constructing the node - it cannot be shown. |
| 45 const allowXBL = "<bindings xmlns='http://www.mozilla.org/xbl'><binding id='dumm
y' bindToUntrustedContent='true'/></bindings>"; |
| 46 const hideXBL = "<bindings xmlns='http://www.mozilla.org/xbl'/>"; |
| 47 |
| 48 function getFrames(window) |
| 49 { |
| 50 let frames = []; |
| 51 while (window) |
| 52 { |
| 53 let frame = { |
| 54 location: window.location.href, |
| 55 sitekey: null |
| 56 }; |
| 57 |
| 58 let documentElement = window.document && window.document.documentElement; |
| 59 if (documentElement) |
| 60 frame.sitekey = documentElement.getAttribute("data-adblockkey") |
| 61 |
| 62 if (window == window.parent) |
| 63 frame.privateBrowsing = PrivateBrowsingUtils.isWindowPrivate(window); |
| 64 |
| 65 frames.push(frame); |
| 66 window = (window != window.parent ? window.parent : null); |
| 67 } |
| 68 return frames; |
| 69 } |
| 70 |
| 26 /** | 71 /** |
| 27 * about: URL module used to count hits. | 72 * about: URL module used to count hits. |
| 28 * @class | 73 * @class |
| 29 */ | 74 */ |
| 30 let AboutHandler = exports.AboutHandler = | 75 let AboutHandler = |
| 31 { | 76 { |
| 32 classID: Components.ID("{55fb7be0-1dd2-11b2-98e6-9e97caf8ba67}"), | 77 classID: Components.ID("{55fb7be0-1dd2-11b2-98e6-9e97caf8ba67}"), |
| 33 classDescription: "Element hiding hit registration protocol handler", | 78 classDescription: "Element hiding hit registration protocol handler", |
| 34 aboutPrefix: "abp-elemhidehit", | 79 aboutPrefix: "abp-elemhidehit", |
| 35 | 80 |
| 36 /** | 81 /** |
| 37 * Registers handler on startup. | 82 * Registers handler on startup. |
| 38 */ | 83 */ |
| 39 init: function() | 84 init: function() |
| 40 { | 85 { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 owner: Utils.systemPrincipal, | 146 owner: Utils.systemPrincipal, |
| 102 securityInfo: null, | 147 securityInfo: null, |
| 103 notificationCallbacks: null, | 148 notificationCallbacks: null, |
| 104 loadFlags: 0, | 149 loadFlags: 0, |
| 105 loadGroup: null, | 150 loadGroup: null, |
| 106 name: null, | 151 name: null, |
| 107 status: Cr.NS_OK, | 152 status: Cr.NS_OK, |
| 108 | 153 |
| 109 asyncOpen: function(listener, context) | 154 asyncOpen: function(listener, context) |
| 110 { | 155 { |
| 111 let stream = this.open(); | 156 let responseMessage = "AdblockPlus:ElemHideHit:Response" + (++messageID); |
| 112 Utils.runAsync(() => | 157 |
| 158 let processResponse = (message) => |
| 113 { | 159 { |
| 160 removeMessageListener(responseMessage, processResponse); |
| 161 |
| 162 let data = (message.data ? hideXBL : allowXBL); |
| 163 let stream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(Ci
.nsIStringInputStream); |
| 164 stream.setData(data, data.length); |
| 165 |
| 114 try { | 166 try { |
| 115 listener.onStartRequest(this, context); | 167 listener.onStartRequest(this, context); |
| 116 } catch(e) {} | 168 } catch(e) {} |
| 117 try { | 169 try { |
| 118 listener.onDataAvailable(this, context, stream, 0, stream.available()); | 170 listener.onDataAvailable(this, context, stream, 0, stream.available()); |
| 119 } catch(e) {} | 171 } catch(e) {} |
| 120 try { | 172 try { |
| 121 listener.onStopRequest(this, context, Cr.NS_OK); | 173 listener.onStopRequest(this, context, Cr.NS_OK); |
| 122 } catch(e) {} | 174 } catch(e) {} |
| 175 }; |
| 176 |
| 177 addMessageListener(responseMessage, processResponse); |
| 178 sendAsyncMessage("AdblockPlus:ElemHideHit", { |
| 179 responseMessage, |
| 180 key: this.key, |
| 181 frames: getFrames(Utils.getRequestWindow(this)) |
| 123 }); | 182 }); |
| 124 }, | 183 }, |
| 125 | 184 |
| 126 asyncOpen2: function(listener) | 185 asyncOpen2: function(listener) |
| 127 { | 186 { |
| 128 if (!this.loadInfo.triggeringPrincipal.equals(Utils.systemPrincipal)) | 187 if (!this.loadInfo.triggeringPrincipal.equals(Utils.systemPrincipal)) |
| 129 throw Cr.NS_ERROR_FAILURE; | 188 throw Cr.NS_ERROR_FAILURE; |
| 130 this.asyncOpen(listener, null); | 189 this.asyncOpen(listener, null); |
| 131 }, | 190 }, |
| 132 | 191 |
| 133 open: function() | 192 open: function() |
| 134 { | 193 { |
| 135 let {Policy} = require("contentPolicy"); | 194 throw Cr.NS_ERROR_NOT_IMPLEMENTED; |
| 136 let {ElemHide} = require("elemHide"); | |
| 137 | |
| 138 // This dummy binding below won't have any effect on the element. For | |
| 139 // elements that should be hidden however we don't return any binding at | |
| 140 // all, this makes Gecko stop constructing the node - it cannot be shown. | |
| 141 let data = "<bindings xmlns='http://www.mozilla.org/xbl'><binding id='dummy'
bindToUntrustedContent='true'/></bindings>"; | |
| 142 let filter = ElemHide.getFilterByKey(this.key); | |
| 143 if (filter) | |
| 144 { | |
| 145 let wnd = Utils.getRequestWindow(this); | |
| 146 if (wnd && wnd.document && !Policy.processNode(wnd, wnd.document, Policy.t
ype.ELEMHIDE, filter)) | |
| 147 data = "<bindings xmlns='http://www.mozilla.org/xbl'/>"; | |
| 148 } | |
| 149 | |
| 150 let stream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(Ci.n
sIStringInputStream); | |
| 151 stream.setData(data, data.length); | |
| 152 return stream; | |
| 153 }, | 195 }, |
| 154 isPending: function() | 196 isPending: function() |
| 155 { | 197 { |
| 156 return false; | 198 return false; |
| 157 }, | 199 }, |
| 158 cancel: function() | 200 cancel: function() |
| 159 { | 201 { |
| 160 throw Cr.NS_ERROR_NOT_IMPLEMENTED; | 202 throw Cr.NS_ERROR_NOT_IMPLEMENTED; |
| 161 }, | 203 }, |
| 162 suspend: function() | 204 suspend: function() |
| 163 { | 205 { |
| 164 throw Cr.NS_ERROR_NOT_IMPLEMENTED; | 206 throw Cr.NS_ERROR_NOT_IMPLEMENTED; |
| 165 }, | 207 }, |
| 166 resume: function() | 208 resume: function() |
| 167 { | 209 { |
| 168 throw Cr.NS_ERROR_NOT_IMPLEMENTED; | 210 throw Cr.NS_ERROR_NOT_IMPLEMENTED; |
| 169 }, | 211 }, |
| 170 | 212 |
| 171 QueryInterface: XPCOMUtils.generateQI([Ci.nsIChannel, Ci.nsIRequest]) | 213 QueryInterface: XPCOMUtils.generateQI([Ci.nsIChannel, Ci.nsIRequest]) |
| 172 }; | 214 }; |
| OLD | NEW |