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

Delta Between Two Patch Sets: lib/requestBlocker.js

Issue 29421712: Issue 5184 - Support Firefox-specific webRequest types (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Left Patch Set: Simplify logic a little bit Created May 19, 2017, 4:50 p.m.
Right Patch Set: Use for..in Created May 20, 2017, 6:54 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « ext/background.js ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 15 matching lines...) Expand all
26 const {Prefs} = require("prefs"); 26 const {Prefs} = require("prefs");
27 const {checkWhitelisted, getKey} = require("whitelisting"); 27 const {checkWhitelisted, getKey} = require("whitelisting");
28 const {stringifyURL, extractHostFromFrame, isThirdParty} = require("url"); 28 const {stringifyURL, extractHostFromFrame, isThirdParty} = require("url");
29 const {port} = require("messaging"); 29 const {port} = require("messaging");
30 const devtools = require("devtools"); 30 const devtools = require("devtools");
31 31
32 // Chrome and Firefox (WebExtensions) can't distinguish between 32 // Chrome and Firefox (WebExtensions) can't distinguish between
33 // OBJECT_SUBREQUEST and OBJECT requests. 33 // OBJECT_SUBREQUEST and OBJECT requests.
34 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; 34 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT;
35 35
36 let resourceTypes = new Map( 36 // Map of content types reported by the browser to the respecitve content types
37 Object.keys(RegExpFilter.typeMap).map(type => [type.toLowerCase(), type]) 37 // used by Adblock Plus. Other content types are simply mapped to OTHER.
38 .concat([ 38 let resourceTypes = new Map(function*()
39 // Map unsupported resource types to types we support. Anything that isn't 39 {
Sebastian Noack 2017/05/19 17:47:41 I wouldn't consider these resource types "unsuppor
Manish Jethani 2017/05/19 23:44:15 OK, I've just copied that comment over and changed
Sebastian Noack 2017/05/20 06:42:37 As I said, I don't have a strong opinion. So if yo
Manish Jethani 2017/05/20 18:50:47 Acknowledged.
40 // mapped here is implicitly mapped to "OTHER". 40 for (let type in RegExpFilter.typeMap)
41 ["beacon", "PING"], 41 yield [type.toLowerCase(), type];
42 ["imageset", "IMAGE"], 42
43 ["sub_frame", "SUBDOCUMENT"] 43 yield ["sub_frame", "SUBDOCUMENT"];
44 ]) 44
45 ); 45 // Treat navigator.sendBeacon() the same as <a ping>, it's essentially the
46 // same concept - merely generalized.
47 yield ["beacon", "PING"];
48
49 // Treat <img srcset> and <picture> the same as other images.
50 yield ["imageset", "IMAGE"];
51 }());
46 52
47 function onBeforeRequestAsync(page, url, type, docDomain, 53 function onBeforeRequestAsync(page, url, type, docDomain,
48 thirdParty, sitekey, 54 thirdParty, sitekey,
49 specificOnly, filter) 55 specificOnly, filter)
50 { 56 {
51 if (filter) 57 if (filter)
52 FilterNotifier.emit("filter.hitCount", filter, 0, 0, page); 58 FilterNotifier.emit("filter.hitCount", filter, 0, 0, page);
53 59
54 if (devtools) 60 if (devtools)
55 { 61 {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 if (msg.requestType in chrome.webRequest.ResourceType) 182 if (msg.requestType in chrome.webRequest.ResourceType)
177 return false; 183 return false;
178 184
179 return ext.webRequest.onBeforeRequest._dispatch( 185 return ext.webRequest.onBeforeRequest._dispatch(
180 new URL(msg.url), 186 new URL(msg.url),
181 msg.requestType, 187 msg.requestType,
182 sender.page, 188 sender.page,
183 sender.frame 189 sender.frame
184 ).includes(false); 190 ).includes(false);
185 }); 191 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld