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

Delta Between Two Patch Sets: lib/requestBlocker.js

Issue 29739603: Issue 6544 - Prevent requests sent by Chrome or Adblock Plus from being blocked (Closed)
Left Patch Set: Rebased Created April 9, 2018, 9:30 p.m.
Right Patch Set: Made logic more verbose Created April 9, 2018, 9:33 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 | « lib/devtools.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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 13 matching lines...) Expand all
24 const {Subscription} = require("../adblockpluscore/lib/subscriptionClasses"); 24 const {Subscription} = require("../adblockpluscore/lib/subscriptionClasses");
25 const {defaultMatcher} = require("../adblockpluscore/lib/matcher"); 25 const {defaultMatcher} = require("../adblockpluscore/lib/matcher");
26 const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier"); 26 const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier");
27 const {Prefs} = require("./prefs"); 27 const {Prefs} = require("./prefs");
28 const {checkWhitelisted, getKey} = require("./whitelisting"); 28 const {checkWhitelisted, getKey} = require("./whitelisting");
29 const {stringifyURL, extractHostFromFrame, isThirdParty} = require("./url"); 29 const {stringifyURL, extractHostFromFrame, isThirdParty} = require("./url");
30 const {port} = require("./messaging"); 30 const {port} = require("./messaging");
31 const devtools = require("./devtools"); 31 const devtools = require("./devtools");
32 32
33 const extensionProtocol = new URL(browser.extension.getURL("")).protocol; 33 const extensionProtocol = new URL(browser.extension.getURL("")).protocol;
34 const ignoredOrigins = new Set([extensionProtocol, "chrome:"]);
35 34
36 // Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests. 35 // Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests.
37 if (!browser.webRequest.ResourceType || 36 if (!browser.webRequest.ResourceType ||
38 !("OBJECT_SUBREQUEST" in browser.webRequest.ResourceType)) 37 !("OBJECT_SUBREQUEST" in browser.webRequest.ResourceType))
39 { 38 {
40 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; 39 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT;
41 } 40 }
42 41
43 // Map of content types reported by the browser to the respecitve content types 42 // Map of content types reported by the browser to the respecitve content types
44 // used by Adblock Plus. Other content types are simply mapped to OTHER. 43 // used by Adblock Plus. Other content types are simply mapped to OTHER.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // Ignore requests sent by extensions or by the browser itself: 140 // Ignore requests sent by extensions or by the browser itself:
142 // * Firefox intercepts requests sent by any extensions, indicated with 141 // * Firefox intercepts requests sent by any extensions, indicated with
143 // an "originURL" starting with "moz-extension:". 142 // an "originURL" starting with "moz-extension:".
144 // * Chromium intercepts requests sent by this extension only, indicated 143 // * Chromium intercepts requests sent by this extension only, indicated
145 // on Chromium >=63 with an "initiator" starting with "chrome-extension:". 144 // on Chromium >=63 with an "initiator" starting with "chrome-extension:".
146 // * On Firefox, requests that don't relate to any document or extension are 145 // * On Firefox, requests that don't relate to any document or extension are
147 // indicated with an "originUrl" starting with "chrome:". 146 // indicated with an "originUrl" starting with "chrome:".
148 // * On Chromium >=63, requests that don't relate to any document or extension 147 // * On Chromium >=63, requests that don't relate to any document or extension
149 // have no "initiator". But since on older Chromium versions, no request 148 // have no "initiator". But since on older Chromium versions, no request
150 // has an "initiator", we have to check for the tabId as well. 149 // has an "initiator", we have to check for the tabId as well.
151 if (originUrl ? ignoredOrigins.has(originUrl.protocol) : details.tabId == -1) 150 if (originUrl)
151 {
152 if (originUrl.protocol == extensionProtocol ||
153 originUrl.protocol == "chrome:")
154 return;
155 }
156 else if (details.tabId == -1)
152 return; 157 return;
153 158
154 let page = null; 159 let page = null;
155 let frame = null; 160 let frame = null;
156 if (details.tabId != -1) 161 if (details.tabId != -1)
157 { 162 {
158 page = new ext.Page({id: details.tabId}); 163 page = new ext.Page({id: details.tabId});
159 frame = ext.getFrame( 164 frame = ext.getFrame(
160 details.tabId, 165 details.tabId,
161 // We are looking for the frame that contains the element which 166 // We are looking for the frame that contains the element which
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 274
270 port.on("request.blockedByRTCWrapper", (msg, sender) => 275 port.on("request.blockedByRTCWrapper", (msg, sender) =>
271 { 276 {
272 return ext.webRequest.onBeforeRequest._dispatch( 277 return ext.webRequest.onBeforeRequest._dispatch(
273 new URL(msg.url), 278 new URL(msg.url),
274 "webrtc", 279 "webrtc",
275 sender.page, 280 sender.page,
276 sender.frame 281 sender.frame
277 ).includes(false); 282 ).includes(false);
278 }); 283 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld