| 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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 // previous URL. | 250 // previous URL. |
| 251 if (panel && panel.reload) | 251 if (panel && panel.reload) |
| 252 { | 252 { |
| 253 chrome.tabs.reload(tabId, {bypassCache: true}); | 253 chrome.tabs.reload(tabId, {bypassCache: true}); |
| 254 | 254 |
| 255 panel.reload = false; | 255 panel.reload = false; |
| 256 panel.reloading = true; | 256 panel.reloading = true; |
| 257 } | 257 } |
| 258 } | 258 } |
| 259 | 259 |
| 260 function onFilterChange(action, arg) | 260 function updateFilters(filters, added) |
| 261 { | 261 { |
| 262 let added, filters; | |
| 263 switch (action) | |
| 264 { | |
| 265 case "filter.added": | |
| 266 added = true; | |
| 267 filters = [arg]; | |
| 268 break; | |
| 269 | |
| 270 case "filter.removed": | |
| 271 added = false; | |
| 272 filters = [arg]; | |
| 273 break; | |
| 274 | |
| 275 // When there haven't ever been any user filters before, the subscription is | |
| 276 // added, triggering a "subscription.added" instead of a "filter.added" even
t. | |
| 277 case "subscription.added": | |
| 278 if (arg instanceof SpecialSubscription) | |
| 279 { | |
| 280 added = true; | |
| 281 filters = arg.filters; | |
| 282 break; | |
| 283 } | |
| 284 | |
| 285 default: | |
| 286 return; | |
| 287 } | |
| 288 | |
| 289 for (let tabId in panels) | 262 for (let tabId in panels) |
| 290 { | 263 { |
| 291 let panel = panels[tabId]; | 264 let panel = panels[tabId]; |
| 292 | 265 |
| 293 for (let i = 0; i < panel.records.length; i++) | 266 for (let i = 0; i < panel.records.length; i++) |
| 294 { | 267 { |
| 295 let record = panel.records[i]; | 268 let record = panel.records[i]; |
| 296 | 269 |
| 297 // If an added filter matches a request shown in the devtools panel, | 270 // If an added filter matches a request shown in the devtools panel, |
| 298 // update that record to show the new filter. Ignore filters that aren't | 271 // update that record to show the new filter. Ignore filters that aren't |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 panel.port.postMessage({ | 310 panel.port.postMessage({ |
| 338 type: "update-record", | 311 type: "update-record", |
| 339 index: i, | 312 index: i, |
| 340 request: record.request, | 313 request: record.request, |
| 341 filter: getFilterInfo(record.filter) | 314 filter: getFilterInfo(record.filter) |
| 342 }); | 315 }); |
| 343 } | 316 } |
| 344 } | 317 } |
| 345 } | 318 } |
| 346 | 319 |
| 320 function onFilterAdded(filter) |
| 321 { |
| 322 updateFilters([filter], true); |
| 323 } |
| 324 |
| 325 function onFilterRemoved(filter) |
| 326 { |
| 327 updateFilters([filter], false); |
| 328 } |
| 329 |
| 330 function onSubscriptionAdded(subscription) |
| 331 { |
| 332 if (subscription instanceof SpecialSubscription) |
| 333 updateFilters(subscription.filters, true); |
| 334 } |
| 335 |
| 347 chrome.runtime.onConnect.addListener(port => | 336 chrome.runtime.onConnect.addListener(port => |
| 348 { | 337 { |
| 349 let match = port.name.match(/^devtools-(\d+)$/); | 338 let match = port.name.match(/^devtools-(\d+)$/); |
| 350 if (!match) | 339 if (!match) |
| 351 return; | 340 return; |
| 352 | 341 |
| 353 let inspectedTabId = parseInt(match[1], 10); | 342 let inspectedTabId = parseInt(match[1], 10); |
| 354 let localOnBeforeRequest = onBeforeRequest.bind(); | 343 let localOnBeforeRequest = onBeforeRequest.bind(); |
| 355 | 344 |
| 356 chrome.webRequest.onBeforeRequest.addListener( | 345 chrome.webRequest.onBeforeRequest.addListener( |
| 357 localOnBeforeRequest, | 346 localOnBeforeRequest, |
| 358 { | 347 { |
| 359 urls: ["<all_urls>"], | 348 urls: ["<all_urls>"], |
| 360 types: ["main_frame"], | 349 types: ["main_frame"], |
| 361 tabId: inspectedTabId | 350 tabId: inspectedTabId |
| 362 } | 351 } |
| 363 ); | 352 ); |
| 364 | 353 |
| 365 if (!hasPanels()) | 354 if (!hasPanels()) |
| 366 { | 355 { |
| 367 ext.pages.onLoading.addListener(onLoading); | 356 ext.pages.onLoading.addListener(onLoading); |
| 368 FilterNotifier.addListener(onFilterChange); | 357 FilterNotifier.on("filter.added", onFilterAdded); |
| 358 FilterNotifier.on("filter.removed", onFilterRemoved); |
| 359 FilterNotifier.on("subscription.added", onSubscriptionAdded); |
| 369 } | 360 } |
| 370 | 361 |
| 371 port.onDisconnect.addListener(() => | 362 port.onDisconnect.addListener(() => |
| 372 { | 363 { |
| 373 delete panels[inspectedTabId]; | 364 delete panels[inspectedTabId]; |
| 374 chrome.webRequest.onBeforeRequest.removeListener(localOnBeforeRequest); | 365 chrome.webRequest.onBeforeRequest.removeListener(localOnBeforeRequest); |
| 375 | 366 |
| 376 if (!hasPanels()) | 367 if (!hasPanels()) |
| 377 { | 368 { |
| 378 FilterNotifier.removeListener(onFilterChange); | |
| 379 ext.pages.onLoading.removeListener(onLoading); | 369 ext.pages.onLoading.removeListener(onLoading); |
| 370 FilterNotifier.off("filter.added", onFilterAdded); |
| 371 FilterNotifier.off("filter.removed", onFilterRemoved); |
| 372 FilterNotifier.off("subscription.added", onSubscriptionAdded); |
| 380 } | 373 } |
| 381 }); | 374 }); |
| 382 | 375 |
| 383 panels[inspectedTabId] = {port: port, records: []}; | 376 panels[inspectedTabId] = {port: port, records: []}; |
| 384 }); | 377 }); |
| 385 | 378 |
| 386 port.on("devtools.traceElemHide", (message, sender) => | 379 port.on("devtools.traceElemHide", (message, sender) => |
| 387 { | 380 { |
| 388 logHiddenElements( | 381 logHiddenElements( |
| 389 message.page, message.selectors, | 382 message.page, message.selectors, |
| 390 extractHostFromFrame(sender.frame) | 383 extractHostFromFrame(sender.frame) |
| 391 ); | 384 ); |
| 392 }); | 385 }); |
| OLD | NEW |