| 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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 16 matching lines...) Expand all Loading... |
| 27 const {extractHostFromFrame} = require("url"); | 27 const {extractHostFromFrame} = require("url"); |
| 28 const {port} = require("messaging"); | 28 const {port} = require("messaging"); |
| 29 | 29 |
| 30 const nonRequestTypes = ["DOCUMENT", "ELEMHIDE", "GENERICBLOCK", "GENERICHIDE"]; | 30 const nonRequestTypes = ["DOCUMENT", "ELEMHIDE", "GENERICBLOCK", "GENERICHIDE"]; |
| 31 | 31 |
| 32 // Mapping of inspected tabs to their devpanel page | 32 // Mapping of inspected tabs to their devpanel page |
| 33 // and recorded items. We can't use a PageMap here, | 33 // and recorded items. We can't use a PageMap here, |
| 34 // because data must persist after navigation/reload. | 34 // because data must persist after navigation/reload. |
| 35 let panels = new Map(); | 35 let panels = new Map(); |
| 36 | 36 |
| 37 function hasPanels() | |
| 38 { | |
| 39 return panels.size > 0; | |
| 40 } | |
| 41 | |
| 42 function isActivePanel(panel) | 37 function isActivePanel(panel) |
| 43 { | 38 { |
| 44 if (panel && !panel.reload && !panel.reloading) | 39 return panel && !panel.reload && !panel.reloading; |
| 45 return true; | |
| 46 return false; | |
| 47 } | 40 } |
| 48 | 41 |
| 49 function getActivePanel(page) | 42 function getActivePanel(page) |
| 50 { | 43 { |
| 51 let panel = panels.get(page.id); | 44 let panel = panels.get(page.id); |
| 52 if (isActivePanel(panel)) | 45 if (isActivePanel(panel)) |
| 53 return panel; | 46 return panel; |
| 54 return null; | 47 return null; |
| 55 } | 48 } |
| 56 | 49 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 request.docDomain, | 114 request.docDomain, |
| 122 request.thirdParty, | 115 request.thirdParty, |
| 123 request.sitekey, | 116 request.sitekey, |
| 124 request.specificOnly | 117 request.specificOnly |
| 125 ); | 118 ); |
| 126 } | 119 } |
| 127 | 120 |
| 128 /** | 121 /** |
| 129 * Logs a request to the devtools panel. | 122 * Logs a request to the devtools panel. |
| 130 * | 123 * |
| 131 * @param {Page} page The page the request occured on | 124 * @param {?Page} page The page the request occured on or null if |
| 125 * the request isn't associated with a page |
| 132 * @param {string} url The URL of the request | 126 * @param {string} url The URL of the request |
| 133 * @param {string} type The request type | 127 * @param {string} type The request type |
| 134 * @param {string} docDomain The IDN-decoded hostname of the document | 128 * @param {string} docDomain The IDN-decoded hostname of the document |
| 135 * @param {boolean} thirdParty Whether the origin of the request and | 129 * @param {boolean} thirdParty Whether the origin of the request and |
| 136 * document differs | 130 * document differs |
| 137 * @param {?string} sitekey The active sitekey if there is any | 131 * @param {?string} sitekey The active sitekey if there is any |
| 138 * @param {?boolean} specificOnly Whether generic filters should be ignored | 132 * @param {?boolean} specificOnly Whether generic filters should be ignored |
| 139 * @param {?BlockingFilter} filter The matched filter or null if there is no | 133 * @param {?BlockingFilter} filter The matched filter or null if there is no |
| 140 * match | 134 * match |
| 141 */ | 135 */ |
| 142 exports.logRequest = function(page, url, type, docDomain, | 136 exports.logRequest = function(page, url, type, docDomain, |
| 143 thirdParty, sitekey, | 137 thirdParty, sitekey, |
| 144 specificOnly, filter) | 138 specificOnly, filter) |
| 145 { | 139 { |
| 146 if (!hasPanels()) | 140 if (panels.size == 0) |
| 147 return; | 141 return; |
| 142 |
| 148 let request = {url, type, docDomain, thirdParty, sitekey, specificOnly}; | 143 let request = {url, type, docDomain, thirdParty, sitekey, specificOnly}; |
| 149 if (page) | 144 for (let [tabId, panel] of panels) |
| 150 { | 145 if ((!page || page.id == tabId) && isActivePanel(panel)) |
| 151 let panel = getActivePanel(page); | |
| 152 if (panel) | |
| 153 addRecord(panel, request, filter); | |
| 154 return; | |
| 155 } | |
| 156 for (let panel of panels.values()) | |
| 157 if (isActivePanel(panel)) | |
| 158 addRecord(panel, request, filter); | 146 addRecord(panel, request, filter); |
| 159 }; | 147 }; |
| 160 | 148 |
| 161 /** | 149 /** |
| 162 * Logs active element hiding filters to the devtools panel. | 150 * Logs active element hiding filters to the devtools panel. |
| 163 * | 151 * |
| 164 * @param {Page} page The page the elements were hidden on | 152 * @param {Page} page The page the elements were hidden on |
| 165 * @param {string[]} selectors The selectors of applied ElemHideFilters | 153 * @param {string[]} selectors The selectors of applied ElemHideFilters |
| 166 * @param {string[]} filters The text of applied ElemHideEmulationFilters | 154 * @param {string[]} filters The text of applied ElemHideEmulationFilters |
| 167 * @param {string} docDomain The IDN-decoded hostname of the document | 155 * @param {string} docDomain The IDN-decoded hostname of the document |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 | 345 |
| 358 chrome.webRequest.onBeforeRequest.addListener( | 346 chrome.webRequest.onBeforeRequest.addListener( |
| 359 localOnBeforeRequest, | 347 localOnBeforeRequest, |
| 360 { | 348 { |
| 361 urls: ["http://*/*", "https://*/*"], | 349 urls: ["http://*/*", "https://*/*"], |
| 362 types: ["main_frame"], | 350 types: ["main_frame"], |
| 363 tabId: inspectedTabId | 351 tabId: inspectedTabId |
| 364 } | 352 } |
| 365 ); | 353 ); |
| 366 | 354 |
| 367 if (!hasPanels()) | 355 if (panels.size == 0) |
| 368 { | 356 { |
| 369 ext.pages.onLoading.addListener(onLoading); | 357 ext.pages.onLoading.addListener(onLoading); |
| 370 FilterNotifier.on("filter.added", onFilterAdded); | 358 FilterNotifier.on("filter.added", onFilterAdded); |
| 371 FilterNotifier.on("filter.removed", onFilterRemoved); | 359 FilterNotifier.on("filter.removed", onFilterRemoved); |
| 372 FilterNotifier.on("subscription.added", onSubscriptionAdded); | 360 FilterNotifier.on("subscription.added", onSubscriptionAdded); |
| 373 } | 361 } |
| 374 | 362 |
| 375 newPort.onDisconnect.addListener(() => | 363 newPort.onDisconnect.addListener(() => |
| 376 { | 364 { |
| 377 delete panels.delete(inspectedTabId); | 365 panels.delete(inspectedTabId); |
| 378 chrome.webRequest.onBeforeRequest.removeListener(localOnBeforeRequest); | 366 chrome.webRequest.onBeforeRequest.removeListener(localOnBeforeRequest); |
| 379 | 367 |
| 380 if (!hasPanels()) | 368 if (panels.size == 0) |
| 381 { | 369 { |
| 382 ext.pages.onLoading.removeListener(onLoading); | 370 ext.pages.onLoading.removeListener(onLoading); |
| 383 FilterNotifier.off("filter.added", onFilterAdded); | 371 FilterNotifier.off("filter.added", onFilterAdded); |
| 384 FilterNotifier.off("filter.removed", onFilterRemoved); | 372 FilterNotifier.off("filter.removed", onFilterRemoved); |
| 385 FilterNotifier.off("subscription.added", onSubscriptionAdded); | 373 FilterNotifier.off("subscription.added", onSubscriptionAdded); |
| 386 } | 374 } |
| 387 }); | 375 }); |
| 388 | 376 |
| 389 panels.set(inspectedTabId, {port: newPort, records: []}); | 377 panels.set(inspectedTabId, {port: newPort, records: []}); |
| 390 }); | 378 }); |
| 391 | 379 |
| 392 port.on("devtools.traceElemHide", (message, sender) => | 380 port.on("devtools.traceElemHide", (message, sender) => |
| 393 { | 381 { |
| 394 logHiddenElements( | 382 logHiddenElements( |
| 395 sender.page, message.selectors, message.filters, | 383 sender.page, message.selectors, message.filters, |
| 396 extractHostFromFrame(sender.frame) | 384 extractHostFromFrame(sender.frame) |
| 397 ); | 385 ); |
| 398 }); | 386 }); |
| LEFT | RIGHT |