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: 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:
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:
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 180
189 // (e.g. iframes) we must instead use the request's parent frame ID. 181 // On Chromium >= 63, if both the frame is unknown and we haven't get
190 details.type == "sub_frame" ? details.parentFrameId : details.frameId 182 // an "initator", this implies a request sent by the browser itself
191 ); 183 // (on older versions of Chromium, due to the lack of "initator",
192 } 184 // this can also indicate a request sent by a Shared/Service Worker).
185 if (!frame && !originUrl)
186 return;
193 187
194 if (checkWhitelisted(page, frame, originUrl)) 188 if (checkWhitelisted(page, frame, originUrl))
195 return; 189 return;
196 190
197 let type = resourceTypes.get(details.type) || "OTHER"; 191 let type = resourceTypes.get(details.type) || "OTHER";
198 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame, 192 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame,
199 originUrl); 193 originUrl);
200 let [filter, urlString, thirdParty] = matchRequest(url, type, docDomain, 194 let [filter, urlString, thirdParty] = matchRequest(url, type, docDomain,
201 sitekey, specificOnly); 195 sitekey, specificOnly);
202 196
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 } 309 }
316 310
317 FilterNotifier.on("subscription.added", onFilterChange); 311 FilterNotifier.on("subscription.added", onFilterChange);
318 FilterNotifier.on("subscription.removed", onFilterChange); 312 FilterNotifier.on("subscription.removed", onFilterChange);
319 FilterNotifier.on("subscription.updated", onFilterChange); 313 FilterNotifier.on("subscription.updated", onFilterChange);
320 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); 314 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true));
321 FilterNotifier.on("filter.added", onFilterChange); 315 FilterNotifier.on("filter.added", onFilterChange);
322 FilterNotifier.on("filter.removed", onFilterChange); 316 FilterNotifier.on("filter.removed", onFilterChange);
323 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); 317 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true));
324 FilterNotifier.on("load", onFilterChange); 318 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