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: Fix bug Created Aug. 1, 2017, 8:48 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 WebRTC is not supported, we still end up generating a lot of rules with
1318 // a generic URL scheme pattern that covers WebRTC anyway. In order to avoid
1319 // inadvertently blocking any WebRTC requests, we must add exceptions here
1320 // for WebRTC URLs. This is not required when WebRTC is supported, because in
1321 // that case we explicitly check if the filter covers WebRTC.
1322 if (!typeMap.WEBRTC)
1323 {
1324 urlSchemeExceptionRules.push(
1325 {
1326 trigger: {"url-filter": "^stuns?:"},
1327 action: {type: "ignore-previous-rules"}
1328 },
1329 {
1330 trigger: {"url-filter": "^turns?:"},
1331 action: {type: "ignore-previous-rules"}
1332 }
1333 );
1334 }
1335
1314 return async(ruleGroups, (group, index) => () => 1336 return async(ruleGroups, (group, index) => () =>
1315 { 1337 {
1316 let next = () => 1338 let next = () =>
1317 { 1339 {
1318 if (index == ruleGroups.length - 1) 1340 if (index == ruleGroups.length - 1)
1319 return ruleGroups.reduce((all, rules) => all.concat(rules), []); 1341 return ruleGroups.reduce((all, rules) => all.concat(rules), []);
1320 }; 1342 };
1321 1343
1322 if (this.options.merge == "all" || 1344 if (this.options.merge == "all" ||
1323 (this.options.merge == "auto" && 1345 (this.options.merge == "auto" &&
1324 ruleGroups.reduce((n, group) => n + group.length, 0) > 50000)) 1346 ruleGroups.reduce((n, group) => n + group.length, 0) > 50000))
1325 { 1347 {
1326 return mergeRules(ruleGroups[index], this.options.merge == "all") 1348 return mergeRules(ruleGroups[index], this.options.merge == "all")
1327 .then(rules => 1349 .then(rules =>
1328 { 1350 {
1329 ruleGroups[index] = rules; 1351 ruleGroups[index] = rules;
1330 return next(); 1352 return next();
1331 }); 1353 });
1332 } 1354 }
1333 1355
1334 return next(); 1356 return next();
1335 }); 1357 });
1336 }; 1358 };
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