| 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 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; | |
| 166 let generichide = null; | |
|
Wladimir Palant
2015/09/03 13:09:42
It's either a blocking rule or hiding rule - so at
kzar
2015/09/05 14:39:58
Done.
| |
| 167 | |
| 165 if (!match && Prefs.enabled) | 168 if (!match && Prefs.enabled) |
| 166 { | 169 { |
| 167 let testWnd = wnd; | 170 let testWnd = wnd; |
| 168 let testSitekey = sitekey; | 171 let testSitekey = sitekey; |
| 169 let testSitekeyWnd = sitekeyWnd; | 172 let testSitekeyWnd = sitekeyWnd; |
| 170 let parentWndLocation = getWindowLocation(testWnd); | 173 let parentWndLocation = getWindowLocation(testWnd); |
| 171 while (true) | 174 while (true) |
| 172 { | 175 { |
| 173 let testWndLocation = parentWndLocation; | 176 let testWndLocation = parentWndLocation; |
| 174 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); | 177 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); |
| 175 match = Policy.isWhitelisted(testWndLocation, parentWndLocation, testSit ekey); | 178 match = Policy.isWhitelisted(testWndLocation, parentWndLocation, testSit ekey); |
| 176 | 179 |
| 177 if (match instanceof WhitelistFilter) | 180 if (match instanceof WhitelistFilter) |
| 178 { | 181 { |
| 179 FilterStorage.increaseHitCount(match, wnd); | 182 FilterStorage.increaseHitCount(match, wnd); |
| 180 RequestNotifier.addNodeData(testWnd.document, topWnd, Policy.type.DOCU MENT, getHostname(parentWndLocation), false, testWndLocation, match); | 183 RequestNotifier.addNodeData(testWnd.document, topWnd, Policy.type.DOCU MENT, getHostname(parentWndLocation), false, testWndLocation, match); |
| 181 return true; | 184 return true; |
| 182 } | 185 } |
| 183 | 186 |
| 187 if (contentType != Policy.type.ELEMHIDE) | |
| 188 { | |
| 189 let parentDocDomain = getHostname(parentWndLocation); | |
| 190 let genericblockMatch = defaultMatcher.matchesAny( | |
| 191 testWndLocation, RegExpFilter.typeMap.GENERICBLOCK, | |
| 192 parentDocDomain, false, testSitekey | |
| 193 ); | |
| 194 if (genericblockMatch instanceof WhitelistFilter) | |
| 195 { | |
| 196 genericblock = { | |
| 197 match: genericblockMatch, | |
| 198 parentDocDomain: parentDocDomain, | |
| 199 testWnd: testWnd, | |
| 200 testWndLocation: testWndLocation | |
| 201 }; | |
| 202 } | |
| 203 } | |
| 204 | |
| 184 if (testWnd.parent == testWnd) | 205 if (testWnd.parent == testWnd) |
| 185 break; | 206 break; |
| 186 | 207 |
| 187 if (testWnd == testSitekeyWnd) | 208 if (testWnd == testSitekeyWnd) |
| 188 [testSitekey, testSitekeyWnd] = getSitekey(testWnd.parent); | 209 [testSitekey, testSitekeyWnd] = getSitekey(testWnd.parent); |
| 189 testWnd = testWnd.parent; | 210 testWnd = testWnd.parent; |
| 190 } | 211 } |
| 191 } | 212 } |
| 192 | 213 |
| 193 // Data loaded by plugins should be attached to the document | 214 // Data loaded by plugins should be attached to the document |
| 194 if (contentType == Policy.type.OBJECT_SUBREQUEST && node instanceof Ci.nsIDO MElement) | 215 if (contentType == Policy.type.OBJECT_SUBREQUEST && node instanceof Ci.nsIDO MElement) |
| 195 node = node.ownerDocument; | 216 node = node.ownerDocument; |
| 196 | 217 |
| 197 // Fix type for objects misrepresented as frames or images | 218 // Fix type for objects misrepresented as frames or images |
| 198 if (contentType != Policy.type.OBJECT && (node instanceof Ci.nsIDOMHTMLObjec tElement || node instanceof Ci.nsIDOMHTMLEmbedElement)) | 219 if (contentType != Policy.type.OBJECT && (node instanceof Ci.nsIDOMHTMLObjec tElement || node instanceof Ci.nsIDOMHTMLEmbedElement)) |
| 199 contentType = Policy.type.OBJECT; | 220 contentType = Policy.type.OBJECT; |
| 200 | 221 |
| 201 let locationText = location.spec; | 222 let locationText = location.spec; |
| 202 if (!match && contentType == Policy.type.ELEMHIDE) | 223 if (!match && contentType == Policy.type.ELEMHIDE) |
| 203 { | 224 { |
| 204 let testWnd = wnd; | 225 let testWnd = wnd; |
| 205 let parentWndLocation = getWindowLocation(testWnd); | 226 let parentWndLocation = getWindowLocation(testWnd); |
| 206 while (true) | 227 while (true) |
| 207 { | 228 { |
| 208 let testWndLocation = parentWndLocation; | 229 let testWndLocation = parentWndLocation; |
| 209 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); | 230 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi ndowLocation(testWnd.parent)); |
| 210 let parentDocDomain = getHostname(parentWndLocation); | 231 let parentDocDomain = getHostname(parentWndLocation); |
| 232 | |
| 211 match = defaultMatcher.matchesAny(testWndLocation, RegExpFilter.typeMap. ELEMHIDE, parentDocDomain, false, sitekey); | 233 match = defaultMatcher.matchesAny(testWndLocation, RegExpFilter.typeMap. ELEMHIDE, parentDocDomain, false, sitekey); |
| 234 | |
| 212 if (match instanceof WhitelistFilter) | 235 if (match instanceof WhitelistFilter) |
| 213 { | 236 { |
| 214 FilterStorage.increaseHitCount(match, wnd); | 237 FilterStorage.increaseHitCount(match, wnd); |
| 215 RequestNotifier.addNodeData(testWnd.document, topWnd, contentType, par entDocDomain, false, testWndLocation, match); | 238 RequestNotifier.addNodeData(testWnd.document, topWnd, contentType, par entDocDomain, false, testWndLocation, match); |
| 216 return true; | 239 return true; |
| 217 } | 240 } |
| 218 | 241 |
| 242 let generichideMatch = defaultMatcher.matchesAny( | |
| 243 testWndLocation, RegExpFilter.typeMap.GENERICHIDE, | |
| 244 parentDocDomain, false, sitekey | |
| 245 ); | |
| 246 if (generichideMatch instanceof WhitelistFilter) | |
| 247 { | |
| 248 generichide = { | |
| 249 match: generichideMatch, | |
| 250 parentDocDomain: parentDocDomain, | |
| 251 testWnd: testWnd, | |
| 252 testWndLocation: testWndLocation | |
| 253 }; | |
| 254 } | |
|
Wladimir Palant
2015/09/03 13:09:42
This is simply duplicating the logic from above. I
kzar
2015/09/05 14:39:58
Done.
| |
| 255 | |
| 219 if (testWnd.parent == testWnd) | 256 if (testWnd.parent == testWnd) |
| 220 break; | 257 break; |
| 221 else | 258 else |
| 222 testWnd = testWnd.parent; | 259 testWnd = testWnd.parent; |
| 223 } | 260 } |
| 224 | 261 |
| 225 match = location; | 262 match = location; |
| 226 locationText = match.text.replace(/^.*?#/, '#'); | 263 locationText = match.text.replace(/^.*?#/, '#'); |
| 227 location = locationText; | 264 location = locationText; |
| 228 | 265 |
| 229 if (!match.isActiveOnDomain(docDomain)) | 266 if (!match.isActiveOnDomain(docDomain)) |
| 230 return true; | 267 return true; |
| 231 | 268 |
| 232 let exception = ElemHide.getException(match, docDomain); | 269 let exception = ElemHide.getException(match, docDomain); |
| 233 if (exception) | 270 if (exception) |
| 234 { | 271 { |
| 235 FilterStorage.increaseHitCount(exception, wnd); | 272 FilterStorage.increaseHitCount(exception, wnd); |
| 236 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, false, locationText, exception); | 273 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, false, locationText, exception); |
| 237 return true; | 274 return true; |
| 238 } | 275 } |
| 276 | |
| 277 if (generichide && match && match.isGeneric()) | |
| 278 { | |
| 279 FilterStorage.increaseHitCount(generichide.match, wnd); | |
| 280 RequestNotifier.addNodeData( | |
| 281 generichide.testWnd.document, | |
| 282 topWnd, contentType, | |
| 283 generichide.parentDocDomain, | |
| 284 false, generichide.testWndLocation, | |
| 285 generichide.match | |
| 286 ); | |
| 287 return true; | |
| 288 } | |
| 239 } | 289 } |
| 240 | 290 |
| 241 let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty (location, docDomain)); | 291 let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty (location, docDomain)); |
| 242 | 292 |
| 243 if (!match && Prefs.enabled && contentType in Policy.typeMask) | 293 if (!match && Prefs.enabled && contentType in Policy.typeMask) |
| 244 { | 294 { |
| 245 match = defaultMatcher.matchesAny(locationText, Policy.typeMask[contentTyp e], docDomain, thirdParty, sitekey); | 295 match = defaultMatcher.matchesAny(locationText, Policy.typeMask[contentTyp e], docDomain, thirdParty, sitekey); |
| 246 if (match instanceof BlockingFilter && node.ownerDocument && !(contentType in Policy.nonVisual)) | 296 if (match instanceof BlockingFilter) |
| 247 { | 297 { |
| 248 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fas tcollapse); | 298 if (genericblock && match.isGeneric()) |
|
Wladimir Palant
2015/09/03 13:09:43
What if there are multiple filters potentially mat
kzar
2015/09/04 15:49:10
Hmm good point, any suggestions? In the other revi
Wladimir Palant
2015/09/04 16:16:23
Why another search? Just pass specificOnly and be
kzar
2015/09/05 14:39:58
Oh, of course! Done.
| |
| 249 if (collapse || prefCollapse) | 299 { |
| 250 schedulePostProcess(node); | 300 FilterStorage.increaseHitCount(genericblock.match, wnd); |
| 301 RequestNotifier.addNodeData( | |
| 302 genericblock.testWnd.document, | |
| 303 topWnd, contentType, | |
| 304 genericblock.parentDocDomain, | |
| 305 false, genericblock.testWndLocation, | |
| 306 genericblock.match | |
| 307 ); | |
| 308 return true; | |
| 309 } | |
| 310 | |
| 311 if (node.ownerDocument && !(contentType in Policy.nonVisual)) | |
| 312 { | |
| 313 let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.f astcollapse); | |
| 314 if (collapse || prefCollapse) | |
| 315 schedulePostProcess(node); | |
| 316 } | |
| 251 } | 317 } |
| 252 | 318 |
| 253 // Track mouse events for objects | 319 // Track mouse events for objects |
| 254 if (!match && contentType == Policy.type.OBJECT && node.nodeType == Ci.nsI DOMNode.ELEMENT_NODE) | 320 if (!match && contentType == Policy.type.OBJECT && node.nodeType == Ci.nsI DOMNode.ELEMENT_NODE) |
| 255 { | 321 { |
| 256 node.addEventListener("mouseover", objectMouseEventHander, true); | 322 node.addEventListener("mouseover", objectMouseEventHander, true); |
| 257 node.addEventListener("mouseout", objectMouseEventHander, true); | 323 node.addEventListener("mouseout", objectMouseEventHander, true); |
| 258 } | 324 } |
| 259 } | 325 } |
| 260 | 326 |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 795 if (!wnd || wnd.closed) | 861 if (!wnd || wnd.closed) |
| 796 return; | 862 return; |
| 797 | 863 |
| 798 if (entry.type == Policy.type.OBJECT) | 864 if (entry.type == Policy.type.OBJECT) |
| 799 { | 865 { |
| 800 node.removeEventListener("mouseover", objectMouseEventHander, true); | 866 node.removeEventListener("mouseover", objectMouseEventHander, true); |
| 801 node.removeEventListener("mouseout", objectMouseEventHander, true); | 867 node.removeEventListener("mouseout", objectMouseEventHander, true); |
| 802 } | 868 } |
| 803 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ; | 869 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true) ; |
| 804 } | 870 } |
| OLD | NEW |