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

Unified Diff: lib/requestBlocker.js

Issue 29421712: Issue 5184 - Support Firefox-specific webRequest types (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Use for..in Created May 20, 2017, 6:54 p.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 | « ext/background.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/requestBlocker.js
===================================================================
--- a/lib/requestBlocker.js
+++ b/lib/requestBlocker.js
@@ -24,19 +24,37 @@
const {defaultMatcher} = require("matcher");
const {FilterNotifier} = require("filterNotifier");
const {Prefs} = require("prefs");
const {checkWhitelisted, getKey} = require("whitelisting");
const {stringifyURL, extractHostFromFrame, isThirdParty} = require("url");
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)
{
if (filter)
FilterNotifier.emit("filter.hitCount", filter, 0, 0, page);
if (devtools)
@@ -58,23 +76,25 @@
let docDomain = extractHostFromFrame(frame);
let thirdParty = isThirdParty(url, docDomain);
let sitekey = getKey(page, frame);
let specificOnly = !!checkWhitelisted(
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);
return !(filter instanceof BlockingFilter);
});
port.on("filters.collapse", (message, sender) =>
{
« no previous file with comments | « ext/background.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld