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

Side by Side Diff: lib/requestBlocker.js

Issue 29777646: Issue 6586 - Handle intiator of "null" on Chrome >=66 (Closed)
Patch Set: Created May 10, 2018, 3:39 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 // If tabId is -1, its not (e.g. the request was sent by 105 // If tabId is -1, its not (e.g. the request was sent by
106 // a Service/Shared Worker) and we have to identify the related tabs. 106 // a Service/Shared Worker) and we have to identify the related tabs.
107 if (details.tabId != -1) 107 if (details.tabId != -1)
108 return Promise.resolve([details.tabId]); 108 return Promise.resolve([details.tabId]);
109 109
110 let url; // Firefox provides "originUrl" indicating the 110 let url; // Firefox provides "originUrl" indicating the
111 if (details.originUrl) // URL of the tab that caused this request. 111 if (details.originUrl) // URL of the tab that caused this request.
112 url = details.originUrl; // In case of Service/Shared Worker, this is the 112 url = details.originUrl; // In case of Service/Shared Worker, this is the
113 // URL of the tab that caused the worker to spawn. 113 // URL of the tab that caused the worker to spawn.
114 114
115 else if (details.initiator) // Chromium >=63 provides "intiator" which 115 else if (details.initiator && details.initiator != "null")
kzar 2018/05/11 12:50:17 Why are you comparing it to the string "null" inst
Sebastian Noack 2018/05/11 12:52:40 Because that is what Chrome >=66 sets the value to
kzar 2018/05/11 12:58:56 Weird, that sounds like a bug, did you report it?
Sebastian Noack 2018/05/11 13:04:44 Well, that behavior matches the documentation: htt
116 url = details.initiator + "/*"; // is equivalent to "originUrl" on Firefox 116 url = details.initiator + "/*"; // Chromium >=63 provides "intiator" which
117 // is equivalent to "originUrl" on Firefox
117 // except that its not a full URL but just 118 // except that its not a full URL but just
118 // an origin (proto + host). 119 // an origin (proto + host).
119 else 120 else
120 return Promise.resolve([]); 121 return Promise.resolve([]);
121 122
122 return browser.tabs.query({url}).then(tabs => tabs.map(tab => tab.id)); 123 return browser.tabs.query({url}).then(tabs => tabs.map(tab => tab.id));
123 } 124 }
124 125
125 function logRequest(tabIds, url, type, docDomain, thirdParty, 126 function logRequest(tabIds, url, type, docDomain, thirdParty,
126 sitekey, specificOnly, filter) 127 sitekey, specificOnly, filter)
(...skipping 20 matching lines...) Expand all
147 // listener. But unfortunately, Chrome <=57 doesn't support the WebSocket 148 // listener. But unfortunately, Chrome <=57 doesn't support the WebSocket
148 // protocol and is causing an error if it is given. 149 // protocol and is causing an error if it is given.
149 let url = new URL(details.url); 150 let url = new URL(details.url);
150 if (url.protocol != "http:" && url.protocol != "https:" && 151 if (url.protocol != "http:" && url.protocol != "https:" &&
151 url.protocol != "ws:" && url.protocol != "wss:") 152 url.protocol != "ws:" && url.protocol != "wss:")
152 return; 153 return;
153 154
154 // Firefox provides us with the full origin URL, while Chromium (>=63) 155 // Firefox provides us with the full origin URL, while Chromium (>=63)
155 // provides only the protocol + host of the (top-level) document which 156 // provides only the protocol + host of the (top-level) document which
156 // the request originates from through the "initiator" property. 157 // the request originates from through the "initiator" property.
157 let originUrl = details.originUrl ? new URL(details.originUrl) : 158 let originUrl = null;
158 details.initiator ? new URL(details.initiator) : null; 159 if (details.originUrl)
160 originUrl = new URL(details.originUrl);
161 else if (details.initiator && details.initiator != "null")
162 originUrl = new URL(details.initiator);
159 163
160 // Ignore requests sent by extensions or by Firefox itself: 164 // Ignore requests sent by extensions or by Firefox itself:
161 // * Firefox intercepts requests sent by any extensions, indicated with 165 // * Firefox intercepts requests sent by any extensions, indicated with
162 // an "originURL" starting with "moz-extension:". 166 // an "originURL" starting with "moz-extension:".
163 // * Chromium intercepts requests sent by this extension only, indicated 167 // * Chromium intercepts requests sent by this extension only, indicated
164 // on Chromium >=63 with an "initiator" starting with "chrome-extension:". 168 // on Chromium >=63 with an "initiator" starting with "chrome-extension:".
165 // * On Firefox, requests that don't relate to any document or extension are 169 // * On Firefox, requests that don't relate to any document or extension are
166 // indicated with an "originUrl" starting with "chrome:". 170 // indicated with an "originUrl" starting with "chrome:".
167 if (originUrl && (originUrl.protocol == extensionProtocol || 171 if (originUrl && (originUrl.protocol == extensionProtocol ||
168 originUrl.protocol == "chrome:")) 172 originUrl.protocol == "chrome:"))
169 return; 173 return;
170 174
171 let page = new ext.Page({id: details.tabId}); 175 let page = new ext.Page({id: details.tabId});
172 let frame = ext.getFrame( 176 let frame = ext.getFrame(
173 details.tabId, 177 details.tabId,
174 // We are looking for the frame that contains the element which 178 // We are looking for the frame that contains the element which
175 // has triggered this request. For most requests (e.g. images) we 179 // has triggered this request. For most requests (e.g. images) we
176 // can just use the request's frame ID, but for subdocument requests 180 // 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. 181 // (e.g. iframes) we must instead use the request's parent frame ID.
178 details.type == "sub_frame" ? details.parentFrameId : details.frameId 182 details.type == "sub_frame" ? details.parentFrameId : details.frameId
179 ); 183 );
180 184
181 // On Chromium >= 63, if both the frame is unknown and we haven't get 185 // 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 186 // an "initiator", this implies a request sent by the browser itself
Sebastian Noack 2018/05/10 15:41:40 Just fixed a typo here.
kzar 2018/05/11 12:50:17 Acknowledged.
183 // (on older versions of Chromium, due to the lack of "initator", 187 // (on older versions of Chromium, due to the lack of "initiator",
184 // this can also indicate a request sent by a Shared/Service Worker). 188 // this can also indicate a request sent by a Shared/Service Worker).
185 if (!frame && !originUrl) 189 if (!frame && !originUrl)
186 return; 190 return;
187 191
188 if (checkWhitelisted(page, frame, originUrl)) 192 if (checkWhitelisted(page, frame, originUrl))
189 return; 193 return;
190 194
191 let type = resourceTypes.get(details.type) || "OTHER"; 195 let type = resourceTypes.get(details.type) || "OTHER";
192 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame, 196 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame,
193 originUrl); 197 originUrl);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 } 313 }
310 314
311 FilterNotifier.on("subscription.added", onFilterChange); 315 FilterNotifier.on("subscription.added", onFilterChange);
312 FilterNotifier.on("subscription.removed", onFilterChange); 316 FilterNotifier.on("subscription.removed", onFilterChange);
313 FilterNotifier.on("subscription.updated", onFilterChange); 317 FilterNotifier.on("subscription.updated", onFilterChange);
314 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); 318 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true));
315 FilterNotifier.on("filter.added", onFilterChange); 319 FilterNotifier.on("filter.added", onFilterChange);
316 FilterNotifier.on("filter.removed", onFilterChange); 320 FilterNotifier.on("filter.removed", onFilterChange);
317 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); 321 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true));
318 FilterNotifier.on("load", onFilterChange); 322 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