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

Side by Side Diff: lib/requestBlocker.js

Issue 29753574: Issue 6565 - Ignore requests sent by Chrome's new tab page (Closed)
Patch Set: Created April 16, 2018, 1:03 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 the browser 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 // * On Chromium >=63, requests that don't relate to any document or extension 167 if (originUrl && (originUrl.protocol == extensionProtocol ||
168 // have no "initiator". But since on older Chromium versions, no request 168 originUrl.protocol == "chrome:"))
169 // has an "initiator", we have to check for the tabId as well.
170 if (originUrl)
171 {
172 if (originUrl.protocol == extensionProtocol ||
173 originUrl.protocol == "chrome:")
174 return;
175 }
176 else if (details.tabId == -1)
177 return; 169 return;
178 170
179 let page = null; 171 let page = new ext.Page({id: details.tabId});
180 let frame = null; 172 let frame = ext.getFrame(
181 if (details.tabId != -1) 173 details.tabId,
182 { 174 // We are looking for the frame that contains the element which
183 page = new ext.Page({id: details.tabId}); 175 // has triggered this request. For most requests (e.g. images) we
184 frame = ext.getFrame( 176 // can just use the request's frame ID, but for subdocument requests
185 details.tabId, 177 // (e.g. iframes) we must instead use the request's parent frame ID.
186 // We are looking for the frame that contains the element which 178 details.type == "sub_frame" ? details.parentFrameId : details.frameId
187 // has triggered this request. For most requests (e.g. images) we 179 );
188 // can just use the request's frame ID, but for subdocument requests
189 // (e.g. iframes) we must instead use the request's parent frame ID.
190 details.type == "sub_frame" ? details.parentFrameId : details.frameId
191 );
192 }
193 180
194 if (checkWhitelisted(page, frame, originUrl)) 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
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).
185 if ((!frame && !originUrl) || checkWhitelisted(page, 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.
195 return; 186 return;
196 187
197 let type = resourceTypes.get(details.type) || "OTHER"; 188 let type = resourceTypes.get(details.type) || "OTHER";
198 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame, 189 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame,
199 originUrl); 190 originUrl);
200 let [filter, urlString, thirdParty] = matchRequest(url, type, docDomain, 191 let [filter, urlString, thirdParty] = matchRequest(url, type, docDomain,
201 sitekey, specificOnly); 192 sitekey, specificOnly);
202 193
203 getRelatedTabIds(details).then(tabIds => 194 getRelatedTabIds(details).then(tabIds =>
204 { 195 {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 } 306 }
316 307
317 FilterNotifier.on("subscription.added", onFilterChange); 308 FilterNotifier.on("subscription.added", onFilterChange);
318 FilterNotifier.on("subscription.removed", onFilterChange); 309 FilterNotifier.on("subscription.removed", onFilterChange);
319 FilterNotifier.on("subscription.updated", onFilterChange); 310 FilterNotifier.on("subscription.updated", onFilterChange);
320 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); 311 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true));
321 FilterNotifier.on("filter.added", onFilterChange); 312 FilterNotifier.on("filter.added", onFilterChange);
322 FilterNotifier.on("filter.removed", onFilterChange); 313 FilterNotifier.on("filter.removed", onFilterChange);
323 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); 314 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true));
324 FilterNotifier.on("load", onFilterChange); 315 FilterNotifier.on("load", onFilterChange);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld