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

Delta Between Two Patch Sets: lib/requestBlocker.js

Issue 29753574: Issue 6565 - Ignore requests sent by Chrome's new tab page (Closed)
Left Patch Set: Created April 16, 2018, 1:03 p.m.
Right Patch Set: Separate checks Created April 16, 2018, 4:35 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 | « no previous file | 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 if (url.protocol != "http:" && url.protocol != "https:" && 150 if (url.protocol != "http:" && url.protocol != "https:" &&
151 url.protocol != "ws:" && url.protocol != "wss:") 151 url.protocol != "ws:" && url.protocol != "wss:")
152 return; 152 return;
153 153
154 // Firefox provides us with the full origin URL, while Chromium (>=63) 154 // Firefox provides us with the full origin URL, while Chromium (>=63)
155 // provides only the protocol + host of the (top-level) document which 155 // provides only the protocol + host of the (top-level) document which
156 // the request originates from through the "initiator" property. 156 // the request originates from through the "initiator" property.
157 let originUrl = details.originUrl ? new URL(details.originUrl) : 157 let originUrl = details.originUrl ? new URL(details.originUrl) :
158 details.initiator ? new URL(details.initiator) : null; 158 details.initiator ? new URL(details.initiator) : null;
159 159
160 // Ignore requests sent by extensions or by Firefox itself: 160 // Ignore requests sent by extensions or by Firefox itself:
kzar 2018/04/16 15:53:38 I feel it's kind of confusing how we both make the
Sebastian Noack 2018/04/16 16:42:21 Well, the logic is generic (and covers more than j
161 // * Firefox intercepts requests sent by any extensions, indicated with 161 // * Firefox intercepts requests sent by any extensions, indicated with
162 // an "originURL" starting with "moz-extension:". 162 // an "originURL" starting with "moz-extension:".
163 // * Chromium intercepts requests sent by this extension only, indicated 163 // * Chromium intercepts requests sent by this extension only, indicated
164 // on Chromium >=63 with an "initiator" starting with "chrome-extension:". 164 // on Chromium >=63 with an "initiator" starting with "chrome-extension:".
165 // * On Firefox, requests that don't relate to any document or extension are 165 // * On Firefox, requests that don't relate to any document or extension are
166 // indicated with an "originUrl" starting with "chrome:". 166 // indicated with an "originUrl" starting with "chrome:".
167 if (originUrl && (originUrl.protocol == extensionProtocol || 167 if (originUrl && (originUrl.protocol == extensionProtocol ||
168 originUrl.protocol == "chrome:")) 168 originUrl.protocol == "chrome:"))
169 return; 169 return;
170 170
171 let page = new ext.Page({id: details.tabId}); 171 let page = new ext.Page({id: details.tabId});
172 let frame = ext.getFrame( 172 let frame = ext.getFrame(
173 details.tabId, 173 details.tabId,
174 // We are looking for the frame that contains the element which 174 // We are looking for the frame that contains the element which
175 // has triggered this request. For most requests (e.g. images) we 175 // has triggered this request. For most requests (e.g. images) we
176 // can just use the request's frame ID, but for subdocument requests 176 // can just use the request's frame ID, but for subdocument requests
177 // (e.g. iframes) we must instead use the request's parent frame ID. 177 // (e.g. iframes) we must instead use the request's parent frame ID.
178 details.type == "sub_frame" ? details.parentFrameId : details.frameId 178 details.type == "sub_frame" ? details.parentFrameId : details.frameId
179 ); 179 );
180 180
181 // On Chromium >= 63, if both the frame is unknown and we haven't get 181 // On Chromium >= 63, if both the frame is unknown and we haven't get
182 // an "initator", this implies a request sent by the browser itself 182 // an "initator", this implies a request sent by the browser itself
183 // (on older versions of Chromium, due to the lack of "initator", 183 // (on older versions of Chromium, due to the lack of "initator",
184 // this can also indicate a request sent by a Shared/Service Worker). 184 // this can also indicate a request sent by a Shared/Service Worker).
185 if ((!frame && !originUrl) || checkWhitelisted(page, frame, originUrl)) 185 if (!frame && !originUrl)
kzar 2018/04/16 15:53:38 I'd rather not mix new check with the whitelisting
Sebastian Noack 2018/04/16 16:42:21 Done.
186 return;
187
188 if (checkWhitelisted(page, frame, originUrl))
186 return; 189 return;
187 190
188 let type = resourceTypes.get(details.type) || "OTHER"; 191 let type = resourceTypes.get(details.type) || "OTHER";
189 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame, 192 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame,
190 originUrl); 193 originUrl);
191 let [filter, urlString, thirdParty] = matchRequest(url, type, docDomain, 194 let [filter, urlString, thirdParty] = matchRequest(url, type, docDomain,
192 sitekey, specificOnly); 195 sitekey, specificOnly);
193 196
194 getRelatedTabIds(details).then(tabIds => 197 getRelatedTabIds(details).then(tabIds =>
195 { 198 {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 } 309 }
307 310
308 FilterNotifier.on("subscription.added", onFilterChange); 311 FilterNotifier.on("subscription.added", onFilterChange);
309 FilterNotifier.on("subscription.removed", onFilterChange); 312 FilterNotifier.on("subscription.removed", onFilterChange);
310 FilterNotifier.on("subscription.updated", onFilterChange); 313 FilterNotifier.on("subscription.updated", onFilterChange);
311 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); 314 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true));
312 FilterNotifier.on("filter.added", onFilterChange); 315 FilterNotifier.on("filter.added", onFilterChange);
313 FilterNotifier.on("filter.removed", onFilterChange); 316 FilterNotifier.on("filter.removed", onFilterChange);
314 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); 317 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true));
315 FilterNotifier.on("load", onFilterChange); 318 FilterNotifier.on("load", onFilterChange);
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld