Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/abp2blocklist.js

Issue 29441592: Issue 4329 - Add $genericblock support (Closed) Base URL: https://hg.adblockplus.org/abp2blocklist
Patch Set: Add $genericblock domains after filter-specific exception domains Created May 20, 2017, 7:28 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/abp2blocklist.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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);
Sebastian Noack 2017/05/21 20:44:35 I wonder whether it would be better to avoid conca
Manish Jethani 2017/05/21 21:03:57 JSHydra does not support the spread operator. It's
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 * Create a new Adblock Plus filter to content blocker list converter 359 * Create a new Adblock Plus filter to content blocker list converter
356 * 360 *
357 * @constructor 361 * @constructor
358 */ 362 */
359 exports.ContentBlockerList = function () 363 exports.ContentBlockerList = function ()
360 { 364 {
361 this.requestFilters = []; 365 this.requestFilters = [];
362 this.requestExceptions = []; 366 this.requestExceptions = [];
363 this.elemhideFilters = []; 367 this.elemhideFilters = [];
364 this.elemhideExceptions = []; 368 this.elemhideExceptions = [];
369 this.genericblockExceptions = [];
365 this.elemhideSelectorExceptions = new Map(); 370 this.elemhideSelectorExceptions = new Map();
366 }; 371 };
367 372
368 /** 373 /**
369 * Add Adblock Plus filter to be converted 374 * Add Adblock Plus filter to be converted
370 * 375 *
371 * @param {Filter} filter Filter to convert 376 * @param {Filter} filter Filter to convert
372 */ 377 */
373 ContentBlockerList.prototype.addFilter = function(filter) 378 ContentBlockerList.prototype.addFilter = function(filter)
374 { 379 {
375 if (filter.sitekeys) 380 if (filter.sitekeys)
376 return; 381 return;
377 if (filter instanceof filterClasses.RegExpFilter && 382 if (filter instanceof filterClasses.RegExpFilter &&
378 filter.regexpSource == null) 383 filter.regexpSource == null)
379 return; 384 return;
380 385
381 if (filter instanceof filterClasses.BlockingFilter) 386 if (filter instanceof filterClasses.BlockingFilter)
382 this.requestFilters.push(filter); 387 this.requestFilters.push(filter);
383 388
384 if (filter instanceof filterClasses.WhitelistFilter) 389 if (filter instanceof filterClasses.WhitelistFilter)
385 { 390 {
386 if (filter.contentType & (typeMap.DOCUMENT | whitelistableRequestTypes)) 391 if (filter.contentType & (typeMap.DOCUMENT | whitelistableRequestTypes))
387 this.requestExceptions.push(filter); 392 this.requestExceptions.push(filter);
388 393
389 if (filter.contentType & typeMap.ELEMHIDE) 394 if (filter.contentType & typeMap.ELEMHIDE)
390 this.elemhideExceptions.push(filter); 395 this.elemhideExceptions.push(filter);
396
397 if (filter.contentType & typeMap.GENERICBLOCK)
398 this.genericblockExceptions.push(filter);
391 } 399 }
392 400
393 if (filter instanceof filterClasses.ElemHideFilter) 401 if (filter instanceof filterClasses.ElemHideFilter)
394 this.elemhideFilters.push(filter); 402 this.elemhideFilters.push(filter);
395 403
396 if (filter instanceof filterClasses.ElemHideException) 404 if (filter instanceof filterClasses.ElemHideException)
397 { 405 {
398 let domains = this.elemhideSelectorExceptions[filter.selector]; 406 let domains = this.elemhideSelectorExceptions[filter.selector];
399 if (!domains) 407 if (!domains)
400 domains = this.elemhideSelectorExceptions[filter.selector] = []; 408 domains = this.elemhideSelectorExceptions[filter.selector] = [];
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 trigger: {"url-filter": matchDomain, 452 trigger: {"url-filter": matchDomain,
445 "url-filter-is-case-sensitive": true}, 453 "url-filter-is-case-sensitive": true},
446 action: {type: "css-display-none", 454 action: {type: "css-display-none",
447 selector: selector} 455 selector: selector}
448 }); 456 });
449 } 457 }
450 }); 458 });
451 459
452 for (let filter of this.elemhideExceptions) 460 for (let filter of this.elemhideExceptions)
453 convertFilterAddRules(rules, filter, "ignore-previous-rules", false); 461 convertFilterAddRules(rules, filter, "ignore-previous-rules", false);
462
463 let requestFilterExceptionDomains = [];
464 for (let filter of this.genericblockExceptions)
465 {
466 let parsed = parseFilterRegexpSource(filter.regexpSource);
467 if (parsed.hostname)
468 requestFilterExceptionDomains.push(parsed.hostname);
469 }
470
454 for (let filter of this.requestFilters) 471 for (let filter of this.requestFilters)
455 convertFilterAddRules(rules, filter, "block", true); 472 {
473 convertFilterAddRules(rules, filter, "block", true,
474 requestFilterExceptionDomains);
475 }
476
456 for (let filter of this.requestExceptions) 477 for (let filter of this.requestExceptions)
457 convertFilterAddRules(rules, filter, "ignore-previous-rules", true); 478 convertFilterAddRules(rules, filter, "ignore-previous-rules", true);
458 479
459 return rules.filter(rule => !hasNonASCI(rule)); 480 return rules.filter(rule => !hasNonASCI(rule));
460 }; 481 };
OLDNEW
« no previous file with comments | « no previous file | test/abp2blocklist.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld