| 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-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 18 matching lines...) Expand all Loading... | |
| 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 isActivePanel(panel) | 37 function isActivePanel(panel) |
| 38 { | 38 { |
| 39 if (panel && !panel.reload && !panel.reloading) | 39 return panel && !panel.reload && !panel.reloading; |
|
Sebastian Noack
2017/05/30 11:10:49
The if/else is redundant, You can just return the
Jon Sonesen
2017/05/31 08:28:17
Acknowledged.
| |
| 40 return true; | |
| 41 return false; | |
| 42 } | 40 } |
| 43 | 41 |
| 44 function getActivePanel(page) | 42 function getActivePanel(page) |
| 45 { | 43 { |
| 46 let panel = panels.get(page.id); | 44 let panel = panels.get(page.id); |
| 47 if (isActivePanel(panel)) | 45 if (isActivePanel(panel)) |
| 48 return panel; | 46 return panel; |
| 49 return null; | 47 return null; |
| 50 } | 48 } |
| 51 | 49 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 request.docDomain, | 114 request.docDomain, |
| 117 request.thirdParty, | 115 request.thirdParty, |
| 118 request.sitekey, | 116 request.sitekey, |
| 119 request.specificOnly | 117 request.specificOnly |
| 120 ); | 118 ); |
| 121 } | 119 } |
| 122 | 120 |
| 123 /** | 121 /** |
| 124 * Logs a request to the devtools panel. | 122 * Logs a request to the devtools panel. |
| 125 * | 123 * |
| 126 * @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 | |
| 127 * @param {string} url The URL of the request | 126 * @param {string} url The URL of the request |
| 128 * @param {string} type The request type | 127 * @param {string} type The request type |
| 129 * @param {string} docDomain The IDN-decoded hostname of the document | 128 * @param {string} docDomain The IDN-decoded hostname of the document |
| 130 * @param {boolean} thirdParty Whether the origin of the request and | 129 * @param {boolean} thirdParty Whether the origin of the request and |
| 131 * document differs | 130 * document differs |
| 132 * @param {?string} sitekey The active sitekey if there is any | 131 * @param {?string} sitekey The active sitekey if there is any |
| 133 * @param {?boolean} specificOnly Whether generic filters should be ignored | 132 * @param {?boolean} specificOnly Whether generic filters should be ignored |
| 134 * @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 |
| 135 * match | 134 * match |
| 136 */ | 135 */ |
| 137 exports.logRequest = function(page, url, type, docDomain, | 136 exports.logRequest = function(page, url, type, docDomain, |
| 138 thirdParty, sitekey, | 137 thirdParty, sitekey, |
| 139 specificOnly, filter) | 138 specificOnly, filter) |
| 140 { | 139 { |
| 141 if (panels.size == 0) | 140 if (panels.size == 0) |
| 142 return; | 141 return; |
| 142 | |
| 143 let request = {url, type, docDomain, thirdParty, sitekey, specificOnly}; | 143 let request = {url, type, docDomain, thirdParty, sitekey, specificOnly}; |
| 144 if (page) | 144 for (let [tabId, panel] of panels) |
| 145 { | 145 if ((!page || page.id == tabId) && isActivePanel(panel)) |
| 146 let panel = getActivePanel(page); | |
| 147 if (panel) | |
| 148 addRecord(panel, request, filter); | |
| 149 return; | |
| 150 } | |
| 151 for (let panel of panels.values()) | |
| 152 if (isActivePanel(panel)) | |
| 153 addRecord(panel, request, filter); | 146 addRecord(panel, request, filter); |
|
Sebastian Noack
2017/05/30 11:10:49
This would be somewhat less efficient, in case you
Jon Sonesen
2017/05/31 08:28:18
Yeah I like this, will do. Thanks.
| |
| 154 }; | 147 }; |
| 155 | 148 |
| 156 /** | 149 /** |
| 157 * Logs active element hiding filters to the devtools panel. | 150 * Logs active element hiding filters to the devtools panel. |
| 158 * | 151 * |
| 159 * @param {Page} page The page the elements were hidden on | 152 * @param {Page} page The page the elements were hidden on |
| 160 * @param {string[]} selectors The selectors of applied ElemHideFilters | 153 * @param {string[]} selectors The selectors of applied ElemHideFilters |
| 161 * @param {string[]} filters The text of applied ElemHideEmulationFilters | 154 * @param {string[]} filters The text of applied ElemHideEmulationFilters |
| 162 * @param {string} docDomain The IDN-decoded hostname of the document | 155 * @param {string} docDomain The IDN-decoded hostname of the document |
| 163 */ | 156 */ |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 panels.set(inspectedTabId, {port: newPort, records: []}); | 377 panels.set(inspectedTabId, {port: newPort, records: []}); |
| 385 }); | 378 }); |
| 386 | 379 |
| 387 port.on("devtools.traceElemHide", (message, sender) => | 380 port.on("devtools.traceElemHide", (message, sender) => |
| 388 { | 381 { |
| 389 logHiddenElements( | 382 logHiddenElements( |
| 390 sender.page, message.selectors, message.filters, | 383 sender.page, message.selectors, message.filters, |
| 391 extractHostFromFrame(sender.frame) | 384 extractHostFromFrame(sender.frame) |
| 392 ); | 385 ); |
| 393 }); | 386 }); |
| LEFT | RIGHT |