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-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 isActivePanel(panel) | |
38 { | |
39 return panel && !panel.reload && !panel.reloading; | |
40 } | |
41 | |
37 function getActivePanel(page) | 42 function getActivePanel(page) |
38 { | 43 { |
39 let panel = panels.get(page.id); | 44 let panel = panels.get(page.id); |
40 if (panel && !panel.reload && !panel.reloading) | 45 if (isActivePanel(panel)) |
41 return panel; | 46 return panel; |
42 return null; | 47 return null; |
43 } | 48 } |
44 | 49 |
45 function getFilterInfo(filter) | 50 function getFilterInfo(filter) |
46 { | 51 { |
47 if (!filter) | 52 if (!filter) |
48 return null; | 53 return null; |
49 | 54 |
50 let userDefined = false; | 55 let userDefined = false; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 request.docDomain, | 114 request.docDomain, |
110 request.thirdParty, | 115 request.thirdParty, |
111 request.sitekey, | 116 request.sitekey, |
112 request.specificOnly | 117 request.specificOnly |
113 ); | 118 ); |
114 } | 119 } |
115 | 120 |
116 /** | 121 /** |
117 * Logs a request to the devtools panel. | 122 * Logs a request to the devtools panel. |
118 * | 123 * |
119 * @param {Page} page The page the request occured on | 124 * @param {?Page} page The page the request occured on |
Sebastian Noack
2017/06/01 17:32:21
Please describe the scenario in which Page is null
Jon Sonesen
2017/06/02 05:02:57
Acknowledged.
| |
120 * @param {string} url The URL of the request | 125 * @param {string} url The URL of the request |
121 * @param {string} type The request type | 126 * @param {string} type The request type |
122 * @param {string} docDomain The IDN-decoded hostname of the document | 127 * @param {string} docDomain The IDN-decoded hostname of the document |
123 * @param {boolean} thirdParty Whether the origin of the request and | 128 * @param {boolean} thirdParty Whether the origin of the request and |
124 * document differs | 129 * document differs |
125 * @param {?string} sitekey The active sitekey if there is any | 130 * @param {?string} sitekey The active sitekey if there is any |
126 * @param {?boolean} specificOnly Whether generic filters should be ignored | 131 * @param {?boolean} specificOnly Whether generic filters should be ignored |
127 * @param {?BlockingFilter} filter The matched filter or null if there is no | 132 * @param {?BlockingFilter} filter The matched filter or null if there is no |
128 * match | 133 * match |
129 */ | 134 */ |
130 exports.logRequest = function(page, url, type, docDomain, | 135 exports.logRequest = function(page, url, type, docDomain, |
131 thirdParty, sitekey, | 136 thirdParty, sitekey, |
132 specificOnly, filter) | 137 specificOnly, filter) |
133 { | 138 { |
134 let panel = getActivePanel(page); | 139 if (panels.size == 0) |
135 if (panel) | 140 return; |
141 let request = {url, type, docDomain, thirdParty, sitekey, specificOnly}; | |
142 if (page) | |
136 { | 143 { |
137 let request = {url, type, docDomain, thirdParty, sitekey, specificOnly}; | 144 let panel = getActivePanel(page); |
138 addRecord(panel, request, filter); | 145 if (panel) |
146 addRecord(panel, request, filter); | |
147 return; | |
139 } | 148 } |
149 for (let [tabId, panel] of panels) | |
Sebastian Noack
2017/06/01 17:32:21
The logic above, handling the case of page being n
Jon Sonesen
2017/06/02 05:02:57
Acknowledged.
| |
150 if ((!page || page.id == tabId) && isActivePanel(panel)) | |
151 addRecord(panel, request, filter); | |
140 }; | 152 }; |
141 | 153 |
142 /** | 154 /** |
143 * Logs active element hiding filters to the devtools panel. | 155 * Logs active element hiding filters to the devtools panel. |
144 * | 156 * |
145 * @param {Page} page The page the elements were hidden on | 157 * @param {Page} page The page the elements were hidden on |
146 * @param {string[]} selectors The selectors of applied ElemHideFilters | 158 * @param {string[]} selectors The selectors of applied ElemHideFilters |
147 * @param {string[]} filters The text of applied ElemHideEmulationFilters | 159 * @param {string[]} filters The text of applied ElemHideEmulationFilters |
148 * @param {string} docDomain The IDN-decoded hostname of the document | 160 * @param {string} docDomain The IDN-decoded hostname of the document |
149 */ | 161 */ |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
370 panels.set(inspectedTabId, {port: newPort, records: []}); | 382 panels.set(inspectedTabId, {port: newPort, records: []}); |
371 }); | 383 }); |
372 | 384 |
373 port.on("devtools.traceElemHide", (message, sender) => | 385 port.on("devtools.traceElemHide", (message, sender) => |
374 { | 386 { |
375 logHiddenElements( | 387 logHiddenElements( |
376 sender.page, message.selectors, message.filters, | 388 sender.page, message.selectors, message.filters, |
377 extractHostFromFrame(sender.frame) | 389 extractHostFromFrame(sender.frame) |
378 ); | 390 ); |
379 }); | 391 }); |
OLD | NEW |