Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 "use strict"; | 18 "use strict"; |
19 | 19 |
20 const {RegExpFilter, | 20 const {RegExpFilter, |
21 WhitelistFilter, | 21 WhitelistFilter, |
22 ElemHideFilter} = require("../adblockpluscore/lib/filterClasses"); | 22 ElemHideFilter} = require("../adblockpluscore/lib/filterClasses"); |
23 const {SpecialSubscription, Subscription} = | 23 const {SpecialSubscription} = |
24 require("../adblockpluscore/lib/subscriptionClasses"); | 24 require("../adblockpluscore/lib/subscriptionClasses"); |
25 const {filterStorage} = require("../adblockpluscore/lib/filterStorage"); | 25 const {filterStorage} = require("../adblockpluscore/lib/filterStorage"); |
26 const {defaultMatcher} = require("../adblockpluscore/lib/matcher"); | 26 const {defaultMatcher} = require("../adblockpluscore/lib/matcher"); |
27 const {filterNotifier} = require("../adblockpluscore/lib/filterNotifier"); | 27 const {filterNotifier} = require("../adblockpluscore/lib/filterNotifier"); |
28 const {extractHostFromFrame} = require("./url"); | 28 const {extractHostFromFrame} = require("./url"); |
29 const {port} = require("./messaging"); | 29 const {port} = require("./messaging"); |
30 const {HitLogger, nonRequestTypes} = require("./hitLogger"); | 30 const {HitLogger, nonRequestTypes} = require("./hitLogger"); |
31 | 31 |
32 let panels = new Map(); | 32 let panels = new Map(); |
33 | 33 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 // previous URL. | 150 // previous URL. |
151 if (panel && panel.reload) | 151 if (panel && panel.reload) |
152 { | 152 { |
153 browser.tabs.reload(tabId, {bypassCache: true}); | 153 browser.tabs.reload(tabId, {bypassCache: true}); |
154 | 154 |
155 panel.reload = false; | 155 panel.reload = false; |
156 panel.reloading = true; | 156 panel.reloading = true; |
157 } | 157 } |
158 } | 158 } |
159 | 159 |
160 function updateFilters(filters, added) | 160 function updateFilters(subscription, filters, added) |
161 { | 161 { |
162 let includes = filters.includes.bind(filters); | 162 let includes = subscription ? |
Manish Jethani
2018/12/07 09:14:47
Sorry about my slightly misleading example earlier
Manish Jethani
2018/12/07 09:14:47
We also need to pass the `Subscription` object to
Manish Jethani
2018/12/07 09:18:22
On second thoughts, I think we should just add a n
Jon Sonesen
2018/12/09 15:52:09
What do you think about making it an optional para
Manish Jethani
2018/12/10 07:48:27
That would be fine but not very useful since the l
| |
163 | 163 filter => filter && subscription.searchfilter(filter) != -1 : |
164 if (filters instanceof Subscription) | 164 filters.includes.bind(filters); |
165 includes = filter => filters.searchFilter(filter) != -1; | |
166 | 165 |
167 for (let panel of panels.values()) | 166 for (let panel of panels.values()) |
168 { | 167 { |
169 for (let i = 0; i < panel.records.length; i++) | 168 for (let i = 0; i < panel.records.length; i++) |
170 { | 169 { |
171 let record = panel.records[i]; | 170 let record = panel.records[i]; |
172 | 171 |
173 // If an added filter matches a request shown in the devtools panel, | 172 // If an added filter matches a request shown in the devtools panel, |
174 // update that record to show the new filter. Ignore filters that aren't | 173 // update that record to show the new filter. Ignore filters that aren't |
175 // associated with any sub-resource request. There is no record for these | 174 // associated with any sub-resource request. There is no record for these |
176 // if they don't already match. In particular, in case of element hiding | 175 // if they don't already match. In particular, in case of element hiding |
177 // filters, we also wouldn't know if any new element matches. | 176 // filters, we also wouldn't know if any new element matches. |
178 if (added) | 177 if (added) |
179 { | 178 { |
180 if (includes(record.request.type)) | 179 if (nonRequestTypes.includes(record.request.type)) |
Manish Jethani
2018/12/07 09:14:47
This appears to be incorrect.
Jon Sonesen
2018/12/09 15:52:09
Acknowledged.
| |
181 continue; | 180 continue; |
182 | 181 |
183 let filter = matchRequest(record.request); | 182 let filter = matchRequest(record.request); |
183 | |
184 if (!includes(filter)) | 184 if (!includes(filter)) |
185 continue; | 185 continue; |
186 | 186 |
187 record.filter = filter; | 187 record.filter = filter; |
188 } | 188 } |
189 | 189 |
190 // If a filter shown in the devtools panel got removed, update that | 190 // If a filter shown in the devtools panel got removed, update that |
191 // record to show the filter that matches now, or none, instead. | 191 // record to show the filter that matches now, or none, instead. |
192 // For filters that aren't associated with any sub-resource request, | 192 // For filters that aren't associated with any sub-resource request, |
193 // just remove the record. We wouldn't know whether another filter | 193 // just remove the record. We wouldn't know whether another filter |
194 // matches instead until the page is reloaded. | 194 // matches instead until the page is reloaded. |
195 else | 195 else |
196 { | 196 { |
197 if (!includes(record.filter)) | 197 if (!includes(record.filter)) |
198 continue; | 198 continue; |
199 | 199 |
200 if (includes(record.request.type)) | 200 if (nonRequestTypes.includes(record.request.type)) |
Manish Jethani
2018/12/07 09:14:47
This too appears to be incorrect.
Jon Sonesen
2018/12/09 15:52:09
Acknowledged.
| |
201 { | 201 { |
202 panel.port.postMessage({ | 202 panel.port.postMessage({ |
203 type: "remove-record", | 203 type: "remove-record", |
204 index: i | 204 index: i |
205 }); | 205 }); |
206 panel.records.splice(i--, 1); | 206 panel.records.splice(i--, 1); |
207 continue; | 207 continue; |
208 } | 208 } |
209 | 209 |
210 record.filter = matchRequest(record.request); | 210 record.filter = matchRequest(record.request); |
211 } | 211 } |
212 | 212 |
213 panel.port.postMessage({ | 213 panel.port.postMessage({ |
214 type: "update-record", | 214 type: "update-record", |
215 index: i, | 215 index: i, |
216 request: record.request, | 216 request: record.request, |
217 filter: getFilterInfo(record.filter) | 217 filter: getFilterInfo(record.filter) |
218 }); | 218 }); |
219 } | 219 } |
220 } | 220 } |
221 } | 221 } |
222 | 222 |
223 function onFilterAdded(filter) | 223 function onFilterAdded(filter) |
224 { | 224 { |
225 updateFilters([filter], true); | 225 updateFilters(null, [filter], true); |
226 } | 226 } |
227 | 227 |
228 function onFilterRemoved(filter) | 228 function onFilterRemoved(filter) |
229 { | 229 { |
230 updateFilters([filter], false); | 230 updateFilters(null, [filter], false); |
231 } | 231 } |
232 | 232 |
233 function onSubscriptionAdded(subscription) | 233 function onSubscriptionAdded(subscription) |
234 { | 234 { |
235 if (subscription instanceof SpecialSubscription) | 235 if (subscription instanceof SpecialSubscription) |
236 updateFilters(subscription.filters, true); | 236 updateFilters(subscription, null, true); |
237 } | 237 } |
238 | 238 |
239 browser.runtime.onConnect.addListener(newPort => | 239 browser.runtime.onConnect.addListener(newPort => |
240 { | 240 { |
241 let match = newPort.name.match(/^devtools-(\d+)$/); | 241 let match = newPort.name.match(/^devtools-(\d+)$/); |
242 if (!match) | 242 if (!match) |
243 return; | 243 return; |
244 | 244 |
245 let inspectedTabId = parseInt(match[1], 10); | 245 let inspectedTabId = parseInt(match[1], 10); |
246 let localOnBeforeRequest = onBeforeRequest.bind(); | 246 let localOnBeforeRequest = onBeforeRequest.bind(); |
(...skipping 28 matching lines...) Expand all Loading... | |
275 ext.pages.onLoading.removeListener(onLoading); | 275 ext.pages.onLoading.removeListener(onLoading); |
276 filterNotifier.off("filter.added", onFilterAdded); | 276 filterNotifier.off("filter.added", onFilterAdded); |
277 filterNotifier.off("filter.removed", onFilterRemoved); | 277 filterNotifier.off("filter.removed", onFilterRemoved); |
278 filterNotifier.off("subscription.added", onSubscriptionAdded); | 278 filterNotifier.off("subscription.added", onSubscriptionAdded); |
279 } | 279 } |
280 }); | 280 }); |
281 | 281 |
282 HitLogger.addListener(inspectedTabId, hitListener); | 282 HitLogger.addListener(inspectedTabId, hitListener); |
283 panels.set(inspectedTabId, panel); | 283 panels.set(inspectedTabId, panel); |
284 }); | 284 }); |
LEFT | RIGHT |