| 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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 let included = []; | 269 let included = []; |
| 270 let excluded = []; | 270 let excluded = []; |
| 271 | 271 |
| 272 parseDomains(filter.domains, included, excluded); | 272 parseDomains(filter.domains, included, excluded); |
| 273 | 273 |
| 274 if (exceptionDomains) | 274 if (exceptionDomains) |
| 275 excluded = excluded.concat(exceptionDomains); | 275 excluded = excluded.concat(exceptionDomains); |
| 276 | 276 |
| 277 if (withResourceTypes) | 277 if (withResourceTypes) |
| 278 { | 278 { |
| 279 trigger["resource-type"] = getResourceTypes(filter); | 279 let resourceTypes = getResourceTypes(filter); |
| 280 | 280 |
| 281 if (trigger["resource-type"].length == 0) | 281 // Content blocker rules can't differentiate between sub-document requests |
| 282 // (iframes) and top-level document requests. To avoid too many false |
| 283 // positives, we prevent rules with no hostname part from blocking document |
| 284 // requests. |
| 285 // |
| 286 // Once Safari 11 becomes our minimum supported version, we could change |
| 287 // our approach here to use the new "unless-top-url" property instead. |
| 288 if (filter instanceof filterClasses.BlockingFilter && !parsed.hostname) |
| 289 resourceTypes = resourceTypes.filter(type => type != "document"); |
| 290 |
| 291 if (resourceTypes.length == 0) |
| 282 return; | 292 return; |
| 293 |
| 294 trigger["resource-type"] = resourceTypes; |
| 283 } | 295 } |
| 284 | 296 |
| 285 if (filter.thirdParty != null) | 297 if (filter.thirdParty != null) |
| 286 trigger["load-type"] = [filter.thirdParty ? "third-party" : "first-party"]; | 298 trigger["load-type"] = [filter.thirdParty ? "third-party" : "first-party"]; |
| 287 | 299 |
| 288 if (included.length > 0) | 300 if (included.length > 0) |
| 289 { | 301 { |
| 290 trigger["if-domain"] = []; | 302 trigger["if-domain"] = []; |
| 291 | 303 |
| 292 for (let name of included) | 304 for (let name of included) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 308 { | 320 { |
| 309 trigger["if-domain"].push("*" + name); | 321 trigger["if-domain"].push("*" + name); |
| 310 } | 322 } |
| 311 } | 323 } |
| 312 } | 324 } |
| 313 else if (excluded.length > 0) | 325 else if (excluded.length > 0) |
| 314 { | 326 { |
| 315 trigger["unless-domain"] = excluded.map(name => "*" + name); | 327 trigger["unless-domain"] = excluded.map(name => "*" + name); |
| 316 } | 328 } |
| 317 else if (filter instanceof filterClasses.BlockingFilter && | 329 else if (filter instanceof filterClasses.BlockingFilter && |
| 318 filter.contentType & typeMap.SUBDOCUMENT) | 330 filter.contentType & typeMap.SUBDOCUMENT && parsed.hostname) |
| 319 { | 331 { |
| 332 // Rules with a hostname part are still allowed to block document requests, |
| 333 // but we add an exception for top-level documents. |
| 334 // |
| 335 // Note that we can only do this if there's no "unless-domain" property for |
| 336 // now. This also only works in Safari 11 onwards, while older versions |
| 337 // simply ignore this property. Once Safari 11 becomes our minimum |
| 338 // supported version, we can merge "unless-domain" into "unless-top-url". |
| 320 trigger["unless-top-url"] = [trigger["url-filter"]]; | 339 trigger["unless-top-url"] = [trigger["url-filter"]]; |
| 321 if (trigger["url-filter-is-case-sensitive"]) | 340 if (trigger["url-filter-is-case-sensitive"]) |
| 322 trigger["top-url-filter-is-case-sensitive"] = true; | 341 trigger["top-url-filter-is-case-sensitive"] = true; |
| 323 } | 342 } |
| 324 | 343 |
| 325 rules.push({trigger: trigger, action: {type: action}}); | 344 rules.push({trigger: trigger, action: {type: action}}); |
| 326 } | 345 } |
| 327 | 346 |
| 328 function hasNonASCI(obj) | 347 function hasNonASCI(obj) |
| 329 { | 348 { |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 { | 558 { |
| 540 convertFilterAddRules(rules, filter, "block", true, | 559 convertFilterAddRules(rules, filter, "block", true, |
| 541 requestFilterExceptionDomains); | 560 requestFilterExceptionDomains); |
| 542 } | 561 } |
| 543 | 562 |
| 544 for (let filter of this.requestExceptions) | 563 for (let filter of this.requestExceptions) |
| 545 convertFilterAddRules(rules, filter, "ignore-previous-rules", true); | 564 convertFilterAddRules(rules, filter, "ignore-previous-rules", true); |
| 546 | 565 |
| 547 return rules.filter(rule => !hasNonASCI(rule)); | 566 return rules.filter(rule => !hasNonASCI(rule)); |
| 548 }; | 567 }; |
| OLD | NEW |