| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 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} = | 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 |
| 34 function isActivePanel(panel) | 34 function isActivePanel(panel) |
| 35 { | 35 { |
| (...skipping 114 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 = subscription ? | |
|
Manish Jethani
2018/12/18 17:12:16
It seems the parentheses are not required.
For in
Jon Sonesen
2018/12/19 10:05:20
Done.
Manish Jethani
2018/12/19 10:25:16
It should be aligned with the "b" in "subscription
| |
| 163 (filter => subscription.searchFilter(filter) != -1) : | |
| 164 filters.includes.bind(filters); | |
| 165 | |
| 162 for (let panel of panels.values()) | 166 for (let panel of panels.values()) |
| 163 { | 167 { |
| 164 for (let i = 0; i < panel.records.length; i++) | 168 for (let i = 0; i < panel.records.length; i++) |
| 165 { | 169 { |
| 166 let record = panel.records[i]; | 170 let record = panel.records[i]; |
| 167 | 171 |
| 168 // 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, |
| 169 // 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 |
| 170 // 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 |
| 171 // 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 |
| 172 // filters, we also wouldn't know if any new element matches. | 176 // filters, we also wouldn't know if any new element matches. |
| 173 if (added) | 177 if (added) |
| 174 { | 178 { |
| 175 if (nonRequestTypes.includes(record.request.type)) | 179 if (nonRequestTypes.includes(record.request.type)) |
| 176 continue; | 180 continue; |
| 177 | 181 |
| 178 let filter = matchRequest(record.request); | 182 let filter = matchRequest(record.request); |
| 179 if (!filters.includes(filter)) | 183 |
| 180 continue; | 184 if (filter) |
|
kzar
2018/12/18 11:29:57
Nit: Please add braces since the body spans more t
| |
| 185 if (!includes(filter)) | |
|
kzar
2018/12/18 11:29:57
Woudln't it make more sense to do this:
if (filte
Manish Jethani
2018/12/18 17:12:16
This would have to be:
if (!filter || !includes
Jon Sonesen
2018/12/19 10:05:20
Done.
| |
| 186 continue; | |
| 181 | 187 |
| 182 record.filter = filter; | 188 record.filter = filter; |
| 183 } | 189 } |
| 184 | 190 |
| 185 // If a filter shown in the devtools panel got removed, update that | 191 // If a filter shown in the devtools panel got removed, update that |
| 186 // record to show the filter that matches now, or none, instead. | 192 // record to show the filter that matches now, or none, instead. |
| 187 // For filters that aren't associated with any sub-resource request, | 193 // For filters that aren't associated with any sub-resource request, |
| 188 // just remove the record. We wouldn't know whether another filter | 194 // just remove the record. We wouldn't know whether another filter |
| 189 // matches instead until the page is reloaded. | 195 // matches instead until the page is reloaded. |
| 190 else | 196 else |
| 191 { | 197 { |
| 192 if (!filters.includes(record.filter)) | 198 if (!includes(record.filter)) |
| 193 continue; | 199 continue; |
| 194 | 200 |
| 195 if (nonRequestTypes.includes(record.request.type)) | 201 if (nonRequestTypes.includes(record.request.type)) |
| 196 { | 202 { |
| 197 panel.port.postMessage({ | 203 panel.port.postMessage({ |
| 198 type: "remove-record", | 204 type: "remove-record", |
| 199 index: i | 205 index: i |
| 200 }); | 206 }); |
| 201 panel.records.splice(i--, 1); | 207 panel.records.splice(i--, 1); |
| 202 continue; | 208 continue; |
| 203 } | 209 } |
| 204 | 210 |
| 205 record.filter = matchRequest(record.request); | 211 record.filter = matchRequest(record.request); |
| 206 } | 212 } |
| 207 | 213 |
| 208 panel.port.postMessage({ | 214 panel.port.postMessage({ |
| 209 type: "update-record", | 215 type: "update-record", |
| 210 index: i, | 216 index: i, |
| 211 request: record.request, | 217 request: record.request, |
| 212 filter: getFilterInfo(record.filter) | 218 filter: getFilterInfo(record.filter) |
| 213 }); | 219 }); |
| 214 } | 220 } |
| 215 } | 221 } |
| 216 } | 222 } |
| 217 | 223 |
| 218 function onFilterAdded(filter) | 224 function onFilterAdded(filter, subscription) |
|
kzar
2018/12/18 11:29:57
It seems weird to add the `subscription` parameter
Jon Sonesen
2018/12/19 10:05:20
Done.
kzar
2018/12/19 10:16:52
Thanks, but why did you add it in the first place?
| |
| 219 { | 225 { |
| 220 updateFilters([filter], true); | 226 updateFilters(null, [filter], true); |
| 221 } | 227 } |
| 222 | 228 |
| 223 function onFilterRemoved(filter) | 229 function onFilterRemoved(filter, subscription) |
| 224 { | 230 { |
| 225 updateFilters([filter], false); | 231 updateFilters(null, [filter], false); |
| 226 } | 232 } |
| 227 | 233 |
| 228 function onSubscriptionAdded(subscription) | 234 function onSubscriptionAdded(subscription) |
| 229 { | 235 { |
| 230 if (subscription instanceof SpecialSubscription) | 236 if (subscription instanceof SpecialSubscription) |
| 231 updateFilters(subscription.filters, true); | 237 updateFilters(subscription, null, true); |
| 232 } | 238 } |
| 233 | 239 |
| 234 browser.runtime.onConnect.addListener(newPort => | 240 browser.runtime.onConnect.addListener(newPort => |
| 235 { | 241 { |
| 236 let match = newPort.name.match(/^devtools-(\d+)$/); | 242 let match = newPort.name.match(/^devtools-(\d+)$/); |
| 237 if (!match) | 243 if (!match) |
| 238 return; | 244 return; |
| 239 | 245 |
| 240 let inspectedTabId = parseInt(match[1], 10); | 246 let inspectedTabId = parseInt(match[1], 10); |
| 241 let localOnBeforeRequest = onBeforeRequest.bind(); | 247 let localOnBeforeRequest = onBeforeRequest.bind(); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 270 ext.pages.onLoading.removeListener(onLoading); | 276 ext.pages.onLoading.removeListener(onLoading); |
| 271 filterNotifier.off("filter.added", onFilterAdded); | 277 filterNotifier.off("filter.added", onFilterAdded); |
| 272 filterNotifier.off("filter.removed", onFilterRemoved); | 278 filterNotifier.off("filter.removed", onFilterRemoved); |
| 273 filterNotifier.off("subscription.added", onSubscriptionAdded); | 279 filterNotifier.off("subscription.added", onSubscriptionAdded); |
| 274 } | 280 } |
| 275 }); | 281 }); |
| 276 | 282 |
| 277 HitLogger.addListener(inspectedTabId, hitListener); | 283 HitLogger.addListener(inspectedTabId, hitListener); |
| 278 panels.set(inspectedTabId, panel); | 284 panels.set(inspectedTabId, panel); |
| 279 }); | 285 }); |
| OLD | NEW |