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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 typeMap.OBJECT_SUBREQUEST | | 207 typeMap.OBJECT_SUBREQUEST | |
208 typeMap.PING | | 208 typeMap.PING | |
209 typeMap.OTHER)) | 209 typeMap.OTHER)) |
210 types.push("raw"); | 210 types.push("raw"); |
211 if (filter.contentType & typeMap.SUBDOCUMENT) | 211 if (filter.contentType & typeMap.SUBDOCUMENT) |
212 types.push("document"); | 212 types.push("document"); |
213 | 213 |
214 return types; | 214 return types; |
215 } | 215 } |
216 | 216 |
217 function convertFilterAddRules(rules, filter, action, withResourceTypes) | 217 function convertFilterAddRules(rules, filter, action, withResourceTypes, |
| 218 exceptionDomains) |
218 { | 219 { |
219 let parsed = parseFilterRegexpSource(filter.regexpSource); | 220 let parsed = parseFilterRegexpSource(filter.regexpSource); |
220 | 221 |
221 // For the special case of $document whitelisting filters with just a domain | 222 // For the special case of $document whitelisting filters with just a domain |
222 // we can generate an equivalent blocking rule exception using if-domain. | 223 // we can generate an equivalent blocking rule exception using if-domain. |
223 if (filter instanceof filterClasses.WhitelistFilter && | 224 if (filter instanceof filterClasses.WhitelistFilter && |
224 filter.contentType & typeMap.DOCUMENT && | 225 filter.contentType & typeMap.DOCUMENT && |
225 parsed.justHostname) | 226 parsed.justHostname) |
226 { | 227 { |
227 rules.push({ | 228 rules.push({ |
(...skipping 21 matching lines...) Expand all Loading... |
249 trigger["url-filter"] = trigger["url-filter"].toLowerCase(); | 250 trigger["url-filter"] = trigger["url-filter"].toLowerCase(); |
250 | 251 |
251 if (parsed.canSafelyMatchAsLowercase || filter.matchCase) | 252 if (parsed.canSafelyMatchAsLowercase || filter.matchCase) |
252 trigger["url-filter-is-case-sensitive"] = true; | 253 trigger["url-filter-is-case-sensitive"] = true; |
253 | 254 |
254 let included = []; | 255 let included = []; |
255 let excluded = []; | 256 let excluded = []; |
256 | 257 |
257 parseDomains(filter.domains, included, excluded); | 258 parseDomains(filter.domains, included, excluded); |
258 | 259 |
| 260 if (exceptionDomains) |
| 261 excluded = excluded.concat(exceptionDomains); |
| 262 |
259 if (withResourceTypes) | 263 if (withResourceTypes) |
260 { | 264 { |
261 trigger["resource-type"] = getResourceTypes(filter); | 265 trigger["resource-type"] = getResourceTypes(filter); |
262 | 266 |
263 if (trigger["resource-type"].length == 0) | 267 if (trigger["resource-type"].length == 0) |
264 return; | 268 return; |
265 } | 269 } |
266 | 270 |
267 if (filter.thirdParty != null) | 271 if (filter.thirdParty != null) |
268 trigger["load-type"] = [filter.thirdParty ? "third-party" : "first-party"]; | 272 trigger["load-type"] = [filter.thirdParty ? "third-party" : "first-party"]; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 * Create a new Adblock Plus filter to content blocker list converter | 378 * Create a new Adblock Plus filter to content blocker list converter |
375 * | 379 * |
376 * @constructor | 380 * @constructor |
377 */ | 381 */ |
378 exports.ContentBlockerList = function () | 382 exports.ContentBlockerList = function () |
379 { | 383 { |
380 this.requestFilters = []; | 384 this.requestFilters = []; |
381 this.requestExceptions = []; | 385 this.requestExceptions = []; |
382 this.elemhideFilters = []; | 386 this.elemhideFilters = []; |
383 this.elemhideExceptions = []; | 387 this.elemhideExceptions = []; |
| 388 this.genericblockExceptions = []; |
384 this.generichideExceptions = []; | 389 this.generichideExceptions = []; |
385 this.elemhideSelectorExceptions = new Map(); | 390 this.elemhideSelectorExceptions = new Map(); |
386 }; | 391 }; |
387 | 392 |
388 /** | 393 /** |
389 * Add Adblock Plus filter to be converted | 394 * Add Adblock Plus filter to be converted |
390 * | 395 * |
391 * @param {Filter} filter Filter to convert | 396 * @param {Filter} filter Filter to convert |
392 */ | 397 */ |
393 ContentBlockerList.prototype.addFilter = function(filter) | 398 ContentBlockerList.prototype.addFilter = function(filter) |
394 { | 399 { |
395 if (filter.sitekeys) | 400 if (filter.sitekeys) |
396 return; | 401 return; |
397 if (filter instanceof filterClasses.RegExpFilter && | 402 if (filter instanceof filterClasses.RegExpFilter && |
398 filter.regexpSource == null) | 403 filter.regexpSource == null) |
399 return; | 404 return; |
400 | 405 |
401 if (filter instanceof filterClasses.BlockingFilter) | 406 if (filter instanceof filterClasses.BlockingFilter) |
402 this.requestFilters.push(filter); | 407 this.requestFilters.push(filter); |
403 | 408 |
404 if (filter instanceof filterClasses.WhitelistFilter) | 409 if (filter instanceof filterClasses.WhitelistFilter) |
405 { | 410 { |
406 if (filter.contentType & (typeMap.DOCUMENT | whitelistableRequestTypes)) | 411 if (filter.contentType & (typeMap.DOCUMENT | whitelistableRequestTypes)) |
407 this.requestExceptions.push(filter); | 412 this.requestExceptions.push(filter); |
408 | 413 |
| 414 if (filter.contentType & typeMap.GENERICBLOCK) |
| 415 this.genericblockExceptions.push(filter); |
| 416 |
409 if (filter.contentType & typeMap.ELEMHIDE) | 417 if (filter.contentType & typeMap.ELEMHIDE) |
410 this.elemhideExceptions.push(filter); | 418 this.elemhideExceptions.push(filter); |
411 else if (filter.contentType & typeMap.GENERICHIDE) | 419 else if (filter.contentType & typeMap.GENERICHIDE) |
412 this.generichideExceptions.push(filter); | 420 this.generichideExceptions.push(filter); |
413 } | 421 } |
414 | 422 |
415 if (filter instanceof filterClasses.ElemHideFilter) | 423 if (filter instanceof filterClasses.ElemHideFilter) |
416 this.elemhideFilters.push(filter); | 424 this.elemhideFilters.push(filter); |
417 | 425 |
418 if (filter instanceof filterClasses.ElemHideException) | 426 if (filter instanceof filterClasses.ElemHideException) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 for (let filter of this.generichideExceptions) | 473 for (let filter of this.generichideExceptions) |
466 convertFilterAddRules(rules, filter, "ignore-previous-rules", false); | 474 convertFilterAddRules(rules, filter, "ignore-previous-rules", false); |
467 | 475 |
468 groupedElemhideFilters.forEach((selectors, matchDomain) => | 476 groupedElemhideFilters.forEach((selectors, matchDomain) => |
469 { | 477 { |
470 addCSSRules(rules, selectors, matchDomain); | 478 addCSSRules(rules, selectors, matchDomain); |
471 }); | 479 }); |
472 | 480 |
473 for (let filter of this.elemhideExceptions) | 481 for (let filter of this.elemhideExceptions) |
474 convertFilterAddRules(rules, filter, "ignore-previous-rules", false); | 482 convertFilterAddRules(rules, filter, "ignore-previous-rules", false); |
| 483 |
| 484 let requestFilterExceptionDomains = []; |
| 485 for (let filter of this.genericblockExceptions) |
| 486 { |
| 487 let parsed = parseFilterRegexpSource(filter.regexpSource); |
| 488 if (parsed.hostname) |
| 489 requestFilterExceptionDomains.push(parsed.hostname); |
| 490 } |
| 491 |
475 for (let filter of this.requestFilters) | 492 for (let filter of this.requestFilters) |
476 convertFilterAddRules(rules, filter, "block", true); | 493 { |
| 494 convertFilterAddRules(rules, filter, "block", true, |
| 495 requestFilterExceptionDomains); |
| 496 } |
| 497 |
477 for (let filter of this.requestExceptions) | 498 for (let filter of this.requestExceptions) |
478 convertFilterAddRules(rules, filter, "ignore-previous-rules", true); | 499 convertFilterAddRules(rules, filter, "ignore-previous-rules", true); |
479 | 500 |
480 return rules.filter(rule => !hasNonASCI(rule)); | 501 return rules.filter(rule => !hasNonASCI(rule)); |
481 }; | 502 }; |
OLD | NEW |