| Index: lib/requestBlocker.js |
| =================================================================== |
| --- a/lib/requestBlocker.js |
| +++ b/lib/requestBlocker.js |
| @@ -1,6 +1,6 @@ |
| /* |
| * This file is part of Adblock Plus <https://adblockplus.org/>, |
| - * Copyright (C) 2006-2016 Eyeo GmbH |
| + * Copyright (C) 2006-2017 eyeo GmbH |
| * |
| * Adblock Plus is free software: you can redistribute it and/or modify |
| * it under the terms of the GNU General Public License version 3 as |
| @@ -29,9 +29,27 @@ |
| const {port} = require("messaging"); |
| const devtools = require("devtools"); |
| -// Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests. |
| +// Chrome and Firefox (WebExtensions) can't distinguish between |
| +// OBJECT_SUBREQUEST and OBJECT requests. |
| RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; |
| +// Map of content types reported by the browser to the respecitve content types |
| +// used by Adblock Plus. Other content types are simply mapped to OTHER. |
| +let resourceTypes = new Map(function*() |
| +{ |
| + for (let type in RegExpFilter.typeMap) |
| + yield [type.toLowerCase(), type]; |
| + |
| + yield ["sub_frame", "SUBDOCUMENT"]; |
| + |
| + // Treat navigator.sendBeacon() the same as <a ping>, it's essentially the |
| + // same concept - merely generalized. |
| + yield ["beacon", "PING"]; |
| + |
| + // Treat <img srcset> and <picture> the same as other images. |
| + yield ["imageset", "IMAGE"]; |
| +}()); |
| + |
| function onBeforeRequestAsync(page, url, type, docDomain, |
| thirdParty, sitekey, |
| specificOnly, filter) |
| @@ -40,11 +58,13 @@ |
| FilterNotifier.emit("filter.hitCount", filter, 0, 0, page); |
| if (devtools) |
| + { |
| devtools.logRequest( |
| page, url, type, docDomain, |
| thirdParty, sitekey, |
| specificOnly, filter |
| ); |
| + } |
| } |
| ext.webRequest.onBeforeRequest.addListener((url, type, page, frame) => |
| @@ -61,13 +81,15 @@ |
| page, frame, RegExpFilter.typeMap.GENERICBLOCK |
| ); |
| + let mappedType = resourceTypes.get(type) || "OTHER"; |
| + |
| let filter = defaultMatcher.matchesAny( |
| - urlString, RegExpFilter.typeMap[type], |
| + urlString, RegExpFilter.typeMap[mappedType], |
| docDomain, thirdParty, sitekey, specificOnly |
| ); |
| setTimeout(onBeforeRequestAsync, 0, page, urlString, |
| - type, docDomain, |
| + mappedType, docDomain, |
| thirdParty, sitekey, |
| specificOnly, filter); |
| @@ -152,12 +174,18 @@ |
| FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); |
| FilterNotifier.on("load", onFilterChange); |
| -port.on("request.websocket", (msg, sender) => |
| +port.on("request.blockedByWrapper", (msg, sender) => |
| { |
| + // Chrome 58 onwards directly supports WebSocket blocking, so we can ignore |
| + // messages from the wrapper here (see https://crbug.com/129353). Hopefully |
| + // WebRTC will be supported soon too (see https://crbug.com/707683). |
| + if (msg.requestType.toUpperCase() in chrome.webRequest.ResourceType) |
| + return false; |
| + |
| return ext.webRequest.onBeforeRequest._dispatch( |
| - new URL(msg.url), |
| - "WEBSOCKET", |
| - sender.page, |
| - sender.frame |
| - ).indexOf(false) != -1; |
| + new URL(msg.url), |
| + msg.requestType, |
| + sender.page, |
| + sender.frame |
| + ).includes(false); |
| }); |