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

Side by Side Diff: lib/abp2blocklist.js

Issue 29502555: Issue 5464 - Ignore and whitelist WebRTC if not supported (Closed) Base URL: https://hg.adblockplus.org/abp2blocklist
Patch Set: Created Aug. 1, 2017, 8:14 a.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 | no next file » | 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 return "^https?://([^/:]*\\.)?" + escapeRegExp(domain).toLowerCase() + "[/:]"; 135 return "^https?://([^/:]*\\.)?" + escapeRegExp(domain).toLowerCase() + "[/:]";
136 } 136 }
137 137
138 function getURLSchemes(contentType) 138 function getURLSchemes(contentType)
139 { 139 {
140 // If the given content type includes all supported URL schemes, simply 140 // If the given content type includes all supported URL schemes, simply
141 // return a single generic URL scheme pattern. This minimizes the size of the 141 // return a single generic URL scheme pattern. This minimizes the size of the
142 // generated rule set. The downside to this is that it will also match 142 // generated rule set. The downside to this is that it will also match
143 // schemes that we do not want to match (e.g. "ftp://"), but this can be 143 // schemes that we do not want to match (e.g. "ftp://"), but this can be
144 // mitigated by adding exceptions for those schemes. 144 // mitigated by adding exceptions for those schemes.
145 if (contentType & typeMap.WEBSOCKET && contentType & typeMap.WEBRTC && 145 if (contentType & typeMap.WEBSOCKET &&
146 (!typeMap.WEBRTC || contentType & typeMap.WEBRTC) &&
146 contentType & httpRequestTypes) 147 contentType & httpRequestTypes)
147 return ["[^:]+:(//)?"]; 148 return ["[^:]+:(//)?"];
148 149
149 let urlSchemes = []; 150 let urlSchemes = [];
150 151
151 if (contentType & typeMap.WEBSOCKET) 152 if (contentType & typeMap.WEBSOCKET)
152 urlSchemes.push("wss?://"); 153 urlSchemes.push("wss?://");
153 154
154 if (contentType & typeMap.WEBRTC) 155 if (contentType & typeMap.WEBRTC)
155 urlSchemes.push("stuns?:", "turns?:"); 156 urlSchemes.push("stuns?:", "turns?:");
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 contentType = filter.contentType; 413 contentType = filter.contentType;
413 414
414 // If WebSocket or WebRTC are given along with other options but not 415 // If WebSocket or WebRTC are given along with other options but not
415 // including all three of WebSocket, WebRTC, and at least one HTTP raw type, 416 // including all three of WebSocket, WebRTC, and at least one HTTP raw type,
416 // we must generate multiple rules. For example, for the filter 417 // we must generate multiple rules. For example, for the filter
417 // "foo$websocket,image", we must generate one rule with "^wss?://" and "raw" 418 // "foo$websocket,image", we must generate one rule with "^wss?://" and "raw"
418 // and another rule with "^https?://" and "image". If we merge the two, we 419 // and another rule with "^https?://" and "image". If we merge the two, we
419 // end up blocking requests of all HTTP raw types (e.g. XMLHttpRequest) 420 // end up blocking requests of all HTTP raw types (e.g. XMLHttpRequest)
420 // inadvertently. 421 // inadvertently.
421 if ((contentType & typeMap.WEBSOCKET && contentType != typeMap.WEBSOCKET && 422 if ((contentType & typeMap.WEBSOCKET && contentType != typeMap.WEBSOCKET &&
422 !(contentType & typeMap.WEBRTC && 423 !((!typeMap.WEBRTC || contentType & typeMap.WEBRTC) &&
423 contentType & rawRequestTypes & httpRequestTypes)) || 424 contentType & rawRequestTypes & httpRequestTypes)) ||
424 (contentType & typeMap.WEBRTC && contentType != typeMap.WEBRTC && 425 (contentType & typeMap.WEBRTC && contentType != typeMap.WEBRTC &&
425 !(contentType & typeMap.WEBSOCKET && 426 !(contentType & typeMap.WEBSOCKET &&
426 contentType & rawRequestTypes & httpRequestTypes))) 427 contentType & rawRequestTypes & httpRequestTypes)))
427 { 428 {
428 if (contentType & typeMap.WEBSOCKET) 429 if (contentType & typeMap.WEBSOCKET)
429 { 430 {
430 convertFilterAddRules(rules, filter, action, withResourceTypes, 431 convertFilterAddRules(rules, filter, action, withResourceTypes,
431 exceptionDomains, typeMap.WEBSOCKET); 432 exceptionDomains, typeMap.WEBSOCKET);
432 } 433 }
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 1224
1224 /** 1225 /**
1225 * Generate content blocker list for all filters that were added 1226 * Generate content blocker list for all filters that were added
1226 */ 1227 */
1227 ContentBlockerList.prototype.generateRules = function() 1228 ContentBlockerList.prototype.generateRules = function()
1228 { 1229 {
1229 let cssRules = []; 1230 let cssRules = [];
1230 let cssExceptionRules = []; 1231 let cssExceptionRules = [];
1231 let blockingRules = []; 1232 let blockingRules = [];
1232 let blockingExceptionRules = []; 1233 let blockingExceptionRules = [];
1234 let urlSchemeExceptionRules = [];
1233 1235
1234 let ruleGroups = [cssRules, cssExceptionRules, 1236 let ruleGroups = [cssRules, cssExceptionRules,
1235 blockingRules, blockingExceptionRules]; 1237 blockingRules, blockingExceptionRules,
1238 urlSchemeExceptionRules];
1236 1239
1237 let genericSelectors = []; 1240 let genericSelectors = [];
1238 let groupedElemhideFilters = new Map(); 1241 let groupedElemhideFilters = new Map();
1239 1242
1240 for (let filter of this.elemhideFilters) 1243 for (let filter of this.elemhideFilters)
1241 { 1244 {
1242 let result = convertElemHideFilter(filter, this.elemhideSelectorExceptions); 1245 let result = convertElemHideFilter(filter, this.elemhideSelectorExceptions);
1243 if (!result) 1246 if (!result)
1244 continue; 1247 continue;
1245 1248
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 convertFilterAddRules(blockingRules, filter, "block", true, 1307 convertFilterAddRules(blockingRules, filter, "block", true,
1305 requestFilterExceptionDomains); 1308 requestFilterExceptionDomains);
1306 } 1309 }
1307 1310
1308 for (let filter of this.requestExceptions) 1311 for (let filter of this.requestExceptions)
1309 { 1312 {
1310 convertFilterAddRules(blockingExceptionRules, filter, 1313 convertFilterAddRules(blockingExceptionRules, filter,
1311 "ignore-previous-rules", true); 1314 "ignore-previous-rules", true);
1312 } 1315 }
1313 1316
1317 if (!typeMap.WEBRTC)
1318 {
1319 urlSchemeExceptionRules.push([
1320 {
1321 trigger: {"url-filter": "^stuns?:"},
1322 action: {type: "ignore-previous-rules"}
1323 },
1324 {
1325 trigger: {"url-filter": "^turns?:"},
1326 action: {type: "ignore-previous-rules"}
1327 }
1328 ]);
1329 }
1330
1314 return async(ruleGroups, (group, index) => () => 1331 return async(ruleGroups, (group, index) => () =>
1315 { 1332 {
1316 let next = () => 1333 let next = () =>
1317 { 1334 {
1318 if (index == ruleGroups.length - 1) 1335 if (index == ruleGroups.length - 1)
1319 return ruleGroups.reduce((all, rules) => all.concat(rules), []); 1336 return ruleGroups.reduce((all, rules) => all.concat(rules), []);
1320 }; 1337 };
1321 1338
1322 if (this.options.merge == "all" || 1339 if (this.options.merge == "all" ||
1323 (this.options.merge == "auto" && 1340 (this.options.merge == "auto" &&
1324 ruleGroups.reduce((n, group) => n + group.length, 0) > 50000)) 1341 ruleGroups.reduce((n, group) => n + group.length, 0) > 50000))
1325 { 1342 {
1326 return mergeRules(ruleGroups[index], this.options.merge == "all") 1343 return mergeRules(ruleGroups[index], this.options.merge == "all")
1327 .then(rules => 1344 .then(rules =>
1328 { 1345 {
1329 ruleGroups[index] = rules; 1346 ruleGroups[index] = rules;
1330 return next(); 1347 return next();
1331 }); 1348 });
1332 } 1349 }
1333 1350
1334 return next(); 1351 return next();
1335 }); 1352 });
1336 }; 1353 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld