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

Unified Diff: lib/abp2blocklist.js

Issue 29492555: Issue 5283 - Combine other raw types with WebSocket and WebRTC when possible (Closed) Base URL: https://hg.adblockplus.org/abp2blocklist
Patch Set: Created July 19, 2017, 10:26 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/abp2blocklist.js
===================================================================
--- a/lib/abp2blocklist.js
+++ b/lib/abp2blocklist.js
@@ -19,30 +19,38 @@
"use strict";
let filterClasses = require("filterClasses");
let punycode = require("punycode");
const selectorLimit = 5000;
const typeMap = filterClasses.RegExpFilter.typeMap;
-const whitelistableRequestTypes = (typeMap.IMAGE
- | typeMap.STYLESHEET
- | typeMap.SCRIPT
- | typeMap.FONT
- | typeMap.MEDIA
- | typeMap.POPUP
- | typeMap.OBJECT
- | typeMap.OBJECT_SUBREQUEST
- | typeMap.XMLHTTPREQUEST
- | typeMap.WEBSOCKET
- | typeMap.WEBRTC
- | typeMap.PING
- | typeMap.SUBDOCUMENT
- | typeMap.OTHER);
+
+const httpRequestTypes = typeMap.IMAGE |
+ typeMap.STYLESHEET |
+ typeMap.SCRIPT |
+ typeMap.FONT |
+ typeMap.MEDIA |
+ typeMap.POPUP |
+ typeMap.OBJECT |
+ typeMap.OBJECT_SUBREQUEST |
+ typeMap.XMLHTTPREQUEST |
+ typeMap.PING |
+ typeMap.SUBDOCUMENT |
+ typeMap.OTHER;
+const rawRequestTypes = typeMap.XMLHTTPREQUEST |
+ typeMap.WEBSOCKET |
+ typeMap.WEBRTC |
+ typeMap.OBJECT_SUBREQUEST |
+ typeMap.PING |
+ typeMap.OTHER;
+const whitelistableRequestTypes = httpRequestTypes |
+ typeMap.WEBSOCKET |
+ typeMap.WEBRTC;
function parseDomains(domains, included, excluded)
{
for (let domain in domains)
{
if (domain != "")
{
let enabled = domains[domain];
@@ -69,28 +77,28 @@
function getURLSchemes(contentType)
{
// If the given content type includes all supported URL schemes, simply
// return a single generic URL scheme pattern. This minimizes the size of the
// generated rule set. The downside to this is that it will also match
// schemes that we do not want to match (e.g. "ftp://"), but this can be
// mitigated by adding exceptions for those schemes.
if (contentType & typeMap.WEBSOCKET && contentType & typeMap.WEBRTC &&
- contentType & ~(typeMap.WEBSOCKET | typeMap.WEBRTC))
+ contentType & httpRequestTypes)
return ["[^:]+:(//)?"];
let urlSchemes = [];
if (contentType & typeMap.WEBSOCKET)
urlSchemes.push("wss?://");
if (contentType & typeMap.WEBRTC)
urlSchemes.push("stuns?:", "turns?:");
- if (contentType & ~(typeMap.WEBSOCKET | typeMap.WEBRTC))
+ if (contentType & httpRequestTypes)
urlSchemes.push("https?://");
return urlSchemes;
}
function findSubdomainsInList(domain, list)
{
let subdomains = [];
@@ -283,25 +291,18 @@
if (contentType & typeMap.SCRIPT)
types.push("script");
if (contentType & typeMap.FONT)
types.push("font");
if (contentType & (typeMap.MEDIA | typeMap.OBJECT))
types.push("media");
if (contentType & typeMap.POPUP)
types.push("popup");
- if (contentType & (typeMap.XMLHTTPREQUEST |
- typeMap.WEBSOCKET |
- typeMap.WEBRTC |
- typeMap.OBJECT_SUBREQUEST |
- typeMap.PING |
- typeMap.OTHER))
- {
+ if (contentType & rawRequestTypes)
types.push("raw");
- }
if (contentType & typeMap.SUBDOCUMENT)
types.push("document");
return types;
}
function makeRuleCopies(trigger, action, urlSchemes)
{
@@ -346,27 +347,28 @@
function convertFilterAddRules(rules, filter, action, withResourceTypes,
exceptionDomains, contentType)
{
if (!contentType)
contentType = filter.contentType;
// If WebSocket or WebRTC are given along with other options but not
- // including all three of WebSocket, WebRTC, and XMLHttpRequest, we must
- // generate multiple rules. For example, for the filter
+ // including all three of WebSocket, WebRTC, and at least one HTTP raw type,
+ // we must generate multiple rules. For example, for the filter
// "foo$websocket,image", we must generate one rule with "^wss?://" and "raw"
// and another rule with "^https?://" and "image". If we merge the two, we
- // end up blocking requests of type XMLHttpRequest inadvertently.
+ // end up blocking requests of all HTTP raw types (e.g. XMLHttpRequest)
+ // inadvertently.
if ((contentType & typeMap.WEBSOCKET && contentType != typeMap.WEBSOCKET &&
!(contentType & typeMap.WEBRTC &&
- contentType & typeMap.XMLHTTPREQUEST)) ||
+ contentType & rawRequestTypes & httpRequestTypes)) ||
(contentType & typeMap.WEBRTC && contentType != typeMap.WEBRTC &&
!(contentType & typeMap.WEBSOCKET &&
- contentType & typeMap.XMLHTTPREQUEST)))
+ contentType & rawRequestTypes & httpRequestTypes)))
{
if (contentType & typeMap.WEBSOCKET)
{
convertFilterAddRules(rules, filter, action, withResourceTypes,
exceptionDomains, typeMap.WEBSOCKET);
}
if (contentType & typeMap.WEBRTC)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld