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 = null; | 165 let nogeneric = false; |
166 let generichide = null; | |
167 | 166 |
168 if (!match && Prefs.enabled) | 167 if (!match && Prefs.enabled) |
169 { | 168 { |
170 let testWnd = wnd; | 169 let testWnd = wnd; |
171 let testSitekey = sitekey; | 170 let testSitekey = sitekey; |
172 let testSitekeyWnd = sitekeyWnd; | 171 let testSitekeyWnd = sitekeyWnd; |
173 let parentWndLocation = getWindowLocation(testWnd); | 172 let parentWndLocation = getWindowLocation(testWnd); |
174 while (true) | 173 while (true) |
175 { | 174 { |
176 let testWndLocation = parentWndLocation; | 175 let testWndLocation = parentWndLocation; |
177 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); | 176 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); |
178 match = Policy.isWhitelisted(testWndLocation, parentWndLocation, testSit ekey); | 177 match = Policy.isWhitelisted(testWndLocation, parentWndLocation, testSit ekey); |
179 | 178 |
180 if (match instanceof WhitelistFilter) | 179 if (match instanceof WhitelistFilter) |
181 { | 180 { |
182 FilterStorage.increaseHitCount(match, wnd); | 181 FilterStorage.increaseHitCount(match, wnd); |
183 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); |
184 return true; | 183 return true; |
185 } | 184 } |
186 else if (contentType != Policy.type.ELEMHIDE) | 185 |
Thomas Greiner
2015/08/28 10:28:24
Detail: The "else" keyword is redundant here due t
kzar
2015/09/03 12:37:02
Done.
| |
187 { | 186 let genericType = (contentType == Policy.type.ELEMHIDE ? |
188 let parentDocDomain = getHostname(parentWndLocation); | 187 RegExpFilter.typeMap.GENERICHIDE : |
189 let genericblockMatch = defaultMatcher.matchesAny( | 188 RegExpFilter.typeMap.GENERICBLOCK); |
190 testWndLocation, RegExpFilter.typeMap.GENERICBLOCK, | 189 let parentDocDomain = getHostname(parentWndLocation); |
191 parentDocDomain, false, testSitekey | 190 let nogenericMatch = defaultMatcher.matchesAny( |
192 ); | 191 testWndLocation, genericType, parentDocDomain, false, testSitekey |
193 if (genericblockMatch instanceof WhitelistFilter) | 192 ); |
194 { | 193 if (nogenericMatch instanceof WhitelistFilter) |
195 genericblock = { | 194 { |
196 match: genericblockMatch, | 195 nogeneric = true; |
197 parentDocDomain: parentDocDomain, | 196 |
198 testWnd: testWnd, | 197 FilterStorage.increaseHitCount(nogenericMatch, wnd); |
199 testWndLocation: testWndLocation | 198 RequestNotifier.addNodeData(testWnd.document, topWnd, contentType, |
200 }; | 199 parentDocDomain, false, testWndLocation, |
201 } | 200 nogenericMatch); |
202 } | 201 } |
203 | 202 |
204 if (testWnd.parent == testWnd) | 203 if (testWnd.parent == testWnd) |
205 break; | 204 break; |
206 | 205 |
207 if (testWnd == testSitekeyWnd) | 206 if (testWnd == testSitekeyWnd) |
208 [testSitekey, testSitekeyWnd] = getSitekey(testWnd.parent); | 207 [testSitekey, testSitekeyWnd] = getSitekey(testWnd.parent); |
209 testWnd = testWnd.parent; | 208 testWnd = testWnd.parent; |
210 } | 209 } |
211 } | 210 } |
212 | 211 |
213 // Data loaded by plugins should be attached to the document | 212 // Data loaded by plugins should be attached to the document |
214 if (contentType == Policy.type.OBJECT_SUBREQUEST && node instanceof Ci.nsIDO MElement) | 213 if (contentType == Policy.type.OBJECT_SUBREQUEST && node instanceof Ci.nsIDO MElement) |
215 node = node.ownerDocument; | 214 node = node.ownerDocument; |
216 | 215 |
217 // Fix type for objects misrepresented as frames or images | 216 // Fix type for objects misrepresented as frames or images |
218 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)) |
219 contentType = Policy.type.OBJECT; | 218 contentType = Policy.type.OBJECT; |
220 | 219 |
221 let locationText = location.spec; | 220 let locationText = location.spec; |
222 if (!match && contentType == Policy.type.ELEMHIDE) | 221 if (!match && contentType == Policy.type.ELEMHIDE) |
223 { | 222 { |
224 let testWnd = wnd; | 223 let testWnd = wnd; |
225 let parentWndLocation = getWindowLocation(testWnd); | 224 let parentWndLocation = getWindowLocation(testWnd); |
226 while (true) | 225 while (true) |
227 { | 226 { |
228 let testWndLocation = parentWndLocation; | 227 let testWndLocation = parentWndLocation; |
229 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); | 228 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); |
230 let parentDocDomain = getHostname(parentWndLocation); | 229 let parentDocDomain = getHostname(parentWndLocation); |
231 | |
232 match = defaultMatcher.matchesAny(testWndLocation, RegExpFilter.typeMap. ELEMHIDE, parentDocDomain, false, sitekey); | 230 match = defaultMatcher.matchesAny(testWndLocation, RegExpFilter.typeMap. ELEMHIDE, parentDocDomain, false, sitekey); |
233 | |
234 if (match instanceof WhitelistFilter) | 231 if (match instanceof WhitelistFilter) |
235 { | 232 { |
236 FilterStorage.increaseHitCount(match, wnd); | 233 FilterStorage.increaseHitCount(match, wnd); |
237 RequestNotifier.addNodeData(testWnd.document, topWnd, contentType, par entDocDomain, false, testWndLocation, match); | 234 RequestNotifier.addNodeData(testWnd.document, topWnd, contentType, par entDocDomain, false, testWndLocation, match); |
238 return true; | 235 return true; |
239 } | |
240 | |
241 let generichideMatch = defaultMatcher.matchesAny( | |
242 testWndLocation, RegExpFilter.typeMap.GENERICHIDE, | |
243 parentDocDomain, false, sitekey | |
244 ); | |
245 if (generichideMatch instanceof WhitelistFilter) | |
246 { | |
247 generichide = { | |
248 match: generichideMatch, | |
249 parentDocDomain: parentDocDomain, | |
250 testWnd: testWnd, | |
251 testWndLocation: testWndLocation | |
252 }; | |
253 } | 236 } |
254 | 237 |
255 if (testWnd.parent == testWnd) | 238 if (testWnd.parent == testWnd) |
256 break; | 239 break; |
257 else | 240 else |
258 testWnd = testWnd.parent; | 241 testWnd = testWnd.parent; |
259 } | 242 } |
260 | 243 |
261 match = location; | 244 match = location; |
262 locationText = match.text.replace(/^.*?#/, '#'); | 245 locationText = match.text.replace(/^.*?#/, '#'); |
263 location = locationText; | 246 location = locationText; |
264 | 247 |
265 if (!match.isActiveOnDomain(docDomain)) | 248 if (!match.isActiveOnDomain(docDomain)) |
266 return true; | 249 return true; |
267 | 250 |
268 let exception = ElemHide.getException(match, docDomain); | 251 let exception = ElemHide.getException(match, docDomain); |
269 if (exception) | 252 if (exception) |
270 { | 253 { |
271 FilterStorage.increaseHitCount(exception, wnd); | 254 FilterStorage.increaseHitCount(exception, wnd); |
272 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, false, locationText, exception); | 255 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, false, locationText, exception); |
273 return true; | 256 return true; |
274 } | 257 } |
275 | 258 |
276 if (match && match.isGeneric() && generichide) | 259 if (nogeneric && match.isGeneric()) |
Thomas Greiner
2015/08/28 10:28:24
I'd assume that checking for "generichide" first w
kzar
2015/09/03 12:37:02
Done.
| |
277 { | |
278 FilterStorage.increaseHitCount(generichide.match, wnd); | |
279 RequestNotifier.addNodeData( | |
280 generichide.testWnd.document, | |
281 topWnd, contentType, | |
282 generichide.parentDocDomain, | |
283 false, generichide.testWndLocation, | |
284 generichide.match | |
285 ); | |
286 return true; | 260 return true; |
287 } | |
288 } | 261 } |
289 | 262 |
290 let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty (location, docDomain)); | 263 let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty (location, docDomain)); |
291 | 264 |
292 if (!match && Prefs.enabled && contentType in Policy.typeMask) | 265 if (!match && Prefs.enabled && contentType in Policy.typeMask) |
293 { | 266 { |
294 match = defaultMatcher.matchesAny(locationText, Policy.typeMask[contentTyp e], docDomain, thirdParty, sitekey); | 267 match = defaultMatcher.matchesAny(locationText, Policy.typeMask[contentTyp e], |
295 if (match instanceof BlockingFilter) | 268 docDomain, thirdParty, sitekey, nogeneri c); |
296 { | 269 if (match instanceof BlockingFilter && node.ownerDocument && !(contentType in Policy.nonVisual)) |
297 if (match.isGeneric() && genericblock) | 270 { |
298 { | 271 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fas tcollapse); |
299 FilterStorage.increaseHitCount(genericblock.match, wnd); | 272 if (collapse || prefCollapse) |
300 RequestNotifier.addNodeData( | 273 schedulePostProcess(node); |
301 genericblock.testWnd.document, | |
302 topWnd, contentType, | |
303 genericblock.parentDocDomain, | |
304 false, genericblock.testWndLocation, | |
305 genericblock.match | |
306 ); | |
307 return true; | |
308 } | |
309 | |
310 if (node.ownerDocument && !(contentType in Policy.nonVisual)) | |
311 { | |
312 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.f astcollapse); | |
313 if (collapse || prefCollapse) | |
314 schedulePostProcess(node); | |
315 } | |
316 } | 274 } |
317 | 275 |
318 // Track mouse events for objects | 276 // Track mouse events for objects |
319 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) |
320 { | 278 { |
321 node.addEventListener("mouseover", objectMouseEventHander, true); | 279 node.addEventListener("mouseover", objectMouseEventHander, true); |
322 node.addEventListener("mouseout", objectMouseEventHander, true); | 280 node.addEventListener("mouseout", objectMouseEventHander, true); |
323 } | 281 } |
324 } | 282 } |
325 | 283 |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
860 if (!wnd || wnd.closed) | 818 if (!wnd || wnd.closed) |
861 return; | 819 return; |
862 | 820 |
863 if (entry.type == Policy.type.OBJECT) | 821 if (entry.type == Policy.type.OBJECT) |
864 { | 822 { |
865 node.removeEventListener("mouseover", objectMouseEventHander, true); | 823 node.removeEventListener("mouseover", objectMouseEventHander, true); |
866 node.removeEventListener("mouseout", objectMouseEventHander, true); | 824 node.removeEventListener("mouseout", objectMouseEventHander, true); |
867 } | 825 } |
868 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ; | 826 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ; |
869 } | 827 } |
LEFT | RIGHT |