Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 { | 155 { |
156 let topWnd = wnd.top; | 156 let topWnd = wnd.top; |
157 if (!topWnd || !topWnd.location || !topWnd.location.href) | 157 if (!topWnd || !topWnd.location || !topWnd.location.href) |
158 return true; | 158 return true; |
159 | 159 |
160 let originWindow = Utils.getOriginWindow(wnd); | 160 let originWindow = Utils.getOriginWindow(wnd); |
161 let wndLocation = originWindow.location.href; | 161 let wndLocation = originWindow.location.href; |
162 let docDomain = getHostname(wndLocation); | 162 let docDomain = getHostname(wndLocation); |
163 let match = null; | 163 let match = null; |
164 let [sitekey, sitekeyWnd] = getSitekey(wnd); | 164 let [sitekey, sitekeyWnd] = getSitekey(wnd); |
165 let genericblock = { match: null }; | 165 let nogeneric = false; |
Sebastian Noack
2015/07/14 17:23:33
Also it might be a bad idea performance-wise to cr
Sebastian Noack
2015/07/14 17:23:33
Nit: We don't add spaces at the beginning/end of a
kzar
2015/07/15 11:56:20
Acknowledged.
| |
166 | |
166 if (!match && Prefs.enabled) | 167 if (!match && Prefs.enabled) |
167 { | 168 { |
168 let testWnd = wnd; | 169 let testWnd = wnd; |
169 let testSitekey = sitekey; | 170 let testSitekey = sitekey; |
170 let testSitekeyWnd = sitekeyWnd; | 171 let testSitekeyWnd = sitekeyWnd; |
171 let parentWndLocation = getWindowLocation(testWnd); | 172 let parentWndLocation = getWindowLocation(testWnd); |
172 while (true) | 173 while (true) |
173 { | 174 { |
174 let testWndLocation = parentWndLocation; | 175 let testWndLocation = parentWndLocation; |
175 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); | 176 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); |
176 match = Policy.isWhitelisted(testWndLocation, parentWndLocation, testSit ekey); | 177 match = Policy.isWhitelisted(testWndLocation, parentWndLocation, testSit ekey); |
177 | 178 |
178 if (match instanceof WhitelistFilter) | 179 if (match instanceof WhitelistFilter) |
179 { | 180 { |
180 FilterStorage.increaseHitCount(match, wnd); | 181 FilterStorage.increaseHitCount(match, wnd); |
181 RequestNotifier.addNodeData(testWnd.document, topWnd, Policy.type.DOCU MENT, getHostname(parentWndLocation), false, testWndLocation, match); | 182 RequestNotifier.addNodeData(testWnd.document, topWnd, Policy.type.DOCU MENT, getHostname(parentWndLocation), false, testWndLocation, match); |
182 return true; | 183 return true; |
183 } | 184 } |
184 else if (!(genericblock.match instanceof WhitelistFilter) && contentType != Policy.type.ELEMHIDE) | 185 |
Sebastian Noack
2015/07/14 17:23:33
Wouldn't genericblock.match alway be null here, he
kzar
2015/07/15 11:56:21
You're right, I think I was emulating some of the
| |
185 { | 186 let genericType = (contentType == Policy.type.ELEMHIDE ? |
186 let parentDocDomain = getHostname(parentWndLocation); | 187 RegExpFilter.typeMap.GENERICHIDE : |
187 genericblock.match = defaultMatcher.matchesAny(testWndLocation, RegExp Filter.typeMap.GENERICBLOCK, parentDocDomain, false); | 188 RegExpFilter.typeMap.GENERICBLOCK); |
188 if (genericblock.match instanceof WhitelistFilter) | 189 let parentDocDomain = getHostname(parentWndLocation); |
189 { | 190 let nogenericMatch = defaultMatcher.matchesAny( |
190 genericblock.parentDocDomain = parentDocDomain; | 191 testWndLocation, genericType, parentDocDomain, false, testSitekey |
191 genericblock.testWnd = testWnd; | 192 ); |
192 genericblock.testWndLocation = testWndLocation; | 193 if (nogenericMatch instanceof WhitelistFilter) |
193 } | 194 { |
195 nogeneric = true; | |
196 | |
197 FilterStorage.increaseHitCount(nogenericMatch, wnd); | |
198 RequestNotifier.addNodeData(testWnd.document, topWnd, contentType, | |
199 parentDocDomain, false, testWndLocation, | |
200 nogenericMatch); | |
194 } | 201 } |
195 | 202 |
196 if (testWnd.parent == testWnd) | 203 if (testWnd.parent == testWnd) |
197 break; | 204 break; |
198 | 205 |
199 if (testWnd == testSitekeyWnd) | 206 if (testWnd == testSitekeyWnd) |
200 [testSitekey, testSitekeyWnd] = getSitekey(testWnd.parent); | 207 [testSitekey, testSitekeyWnd] = getSitekey(testWnd.parent); |
201 testWnd = testWnd.parent; | 208 testWnd = testWnd.parent; |
202 } | 209 } |
203 } | 210 } |
204 | 211 |
205 // Data loaded by plugins should be attached to the document | 212 // Data loaded by plugins should be attached to the document |
206 if (contentType == Policy.type.OBJECT_SUBREQUEST && node instanceof Ci.nsIDO MElement) | 213 if (contentType == Policy.type.OBJECT_SUBREQUEST && node instanceof Ci.nsIDO MElement) |
207 node = node.ownerDocument; | 214 node = node.ownerDocument; |
208 | 215 |
209 // Fix type for objects misrepresented as frames or images | 216 // Fix type for objects misrepresented as frames or images |
210 if (contentType != Policy.type.OBJECT && (node instanceof Ci.nsIDOMHTMLObjec tElement || node instanceof Ci.nsIDOMHTMLEmbedElement)) | 217 if (contentType != Policy.type.OBJECT && (node instanceof Ci.nsIDOMHTMLObjec tElement || node instanceof Ci.nsIDOMHTMLEmbedElement)) |
211 contentType = Policy.type.OBJECT; | 218 contentType = Policy.type.OBJECT; |
212 | 219 |
213 let locationText = location.spec; | 220 let locationText = location.spec; |
214 if (!match && contentType == Policy.type.ELEMHIDE) | 221 if (!match && contentType == Policy.type.ELEMHIDE) |
215 { | 222 { |
216 let testWnd = wnd; | 223 let testWnd = wnd; |
217 let parentWndLocation = getWindowLocation(testWnd); | 224 let parentWndLocation = getWindowLocation(testWnd); |
218 while (true) | 225 while (true) |
219 { | 226 { |
220 let testWndLocation = parentWndLocation; | 227 let testWndLocation = parentWndLocation; |
221 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); | 228 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); |
222 let parentDocDomain = getHostname(parentWndLocation); | 229 let parentDocDomain = getHostname(parentWndLocation); |
223 | |
224 match = defaultMatcher.matchesAny(testWndLocation, RegExpFilter.typeMap. ELEMHIDE, parentDocDomain, false, sitekey); | 230 match = defaultMatcher.matchesAny(testWndLocation, RegExpFilter.typeMap. ELEMHIDE, parentDocDomain, false, sitekey); |
225 | |
226 if (!(match instanceof WhitelistFilter) && (!location.domains || locatio n.domains[""])) | |
227 match = defaultMatcher.matchesAny(testWndLocation, RegExpFilter.typeMa p.GENERICHIDE, parentDocDomain, false); | |
228 | |
229 if (match instanceof WhitelistFilter) | 231 if (match instanceof WhitelistFilter) |
230 { | 232 { |
231 FilterStorage.increaseHitCount(match, wnd); | 233 FilterStorage.increaseHitCount(match, wnd); |
232 RequestNotifier.addNodeData(testWnd.document, topWnd, contentType, par entDocDomain, false, testWndLocation, match); | 234 RequestNotifier.addNodeData(testWnd.document, topWnd, contentType, par entDocDomain, false, testWndLocation, match); |
233 return true; | 235 return true; |
234 } | 236 } |
235 | 237 |
236 if (testWnd.parent == testWnd) | 238 if (testWnd.parent == testWnd) |
237 break; | 239 break; |
238 else | 240 else |
239 testWnd = testWnd.parent; | 241 testWnd = testWnd.parent; |
240 } | 242 } |
241 | 243 |
242 match = location; | 244 match = location; |
243 locationText = match.text.replace(/^.*?#/, '#'); | 245 locationText = match.text.replace(/^.*?#/, '#'); |
244 location = locationText; | 246 location = locationText; |
245 | 247 |
246 if (!match.isActiveOnDomain(docDomain)) | 248 if (!match.isActiveOnDomain(docDomain)) |
247 return true; | 249 return true; |
248 | 250 |
249 let exception = ElemHide.getException(match, docDomain); | 251 let exception = ElemHide.getException(match, docDomain); |
250 if (exception) | 252 if (exception) |
251 { | 253 { |
252 FilterStorage.increaseHitCount(exception, wnd); | 254 FilterStorage.increaseHitCount(exception, wnd); |
253 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, false, locationText, exception); | 255 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, false, locationText, exception); |
254 return true; | 256 return true; |
255 } | 257 } |
258 | |
259 if (nogeneric && match.isGeneric()) | |
260 return true; | |
256 } | 261 } |
257 | 262 |
258 let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty (location, docDomain)); | 263 let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty (location, docDomain)); |
259 | 264 |
260 if (!match && Prefs.enabled && contentType in Policy.typeMask) | 265 if (!match && Prefs.enabled && contentType in Policy.typeMask) |
261 { | 266 { |
262 match = defaultMatcher.matchesAny(locationText, Policy.typeMask[contentTyp e], docDomain, thirdParty, sitekey); | 267 match = defaultMatcher.matchesAny(locationText, Policy.typeMask[contentTyp e], |
263 if (match instanceof BlockingFilter) | 268 docDomain, thirdParty, sitekey, nogeneri c); |
264 { | 269 if (match instanceof BlockingFilter && node.ownerDocument && !(contentType in Policy.nonVisual)) |
265 if ((!match.domains || match.domains[""]) && genericblock.match instance of WhitelistFilter) | 270 { |
266 { | 271 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fas tcollapse); |
267 FilterStorage.increaseHitCount(genericblock.match, wnd); | 272 if (collapse || prefCollapse) |
268 RequestNotifier.addNodeData( | 273 schedulePostProcess(node); |
269 genericblock.testWnd.document, | |
270 topWnd, contentType, | |
271 genericblock.parentDocDomain, | |
272 false, genericblock.testWndLocation, | |
273 genericblock.match | |
274 ); | |
275 return true; | |
276 } | |
277 | |
278 if (node.ownerDocument && !(contentType in Policy.nonVisual)) | |
279 { | |
280 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.f astcollapse); | |
281 if (collapse || prefCollapse) | |
282 schedulePostProcess(node); | |
283 } | |
284 } | 274 } |
285 | 275 |
286 // Track mouse events for objects | 276 // Track mouse events for objects |
287 if (!match && contentType == Policy.type.OBJECT && node.nodeType == Ci.nsI DOMNode.ELEMENT_NODE) | 277 if (!match && contentType == Policy.type.OBJECT && node.nodeType == Ci.nsI DOMNode.ELEMENT_NODE) |
288 { | 278 { |
289 node.addEventListener("mouseover", objectMouseEventHander, true); | 279 node.addEventListener("mouseover", objectMouseEventHander, true); |
290 node.addEventListener("mouseout", objectMouseEventHander, true); | 280 node.addEventListener("mouseout", objectMouseEventHander, true); |
291 } | 281 } |
292 } | 282 } |
293 | 283 |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
828 if (!wnd || wnd.closed) | 818 if (!wnd || wnd.closed) |
829 return; | 819 return; |
830 | 820 |
831 if (entry.type == Policy.type.OBJECT) | 821 if (entry.type == Policy.type.OBJECT) |
832 { | 822 { |
833 node.removeEventListener("mouseover", objectMouseEventHander, true); | 823 node.removeEventListener("mouseover", objectMouseEventHander, true); |
834 node.removeEventListener("mouseout", objectMouseEventHander, true); | 824 node.removeEventListener("mouseout", objectMouseEventHander, true); |
835 } | 825 } |
836 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ; | 826 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ; |
837 } | 827 } |
LEFT | RIGHT |