| 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-2016 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 |
| 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, ElemHideFilter} = require("filterClasses"); | 21 WhitelistFilter, |
| 22 ElemHideFilter, |
| 23 ElemHideEmulationFilter} = require("filterClasses"); |
| 24 |
| 22 const {SpecialSubscription} = require("subscriptionClasses"); | 25 const {SpecialSubscription} = require("subscriptionClasses"); |
| 23 const {FilterStorage} = require("filterStorage"); | 26 const {FilterStorage} = require("filterStorage"); |
| 24 const {defaultMatcher} = require("matcher"); | 27 const {defaultMatcher} = require("matcher"); |
| 25 const {FilterNotifier} = require("filterNotifier"); | 28 const {FilterNotifier} = require("filterNotifier"); |
| 26 const {extractHostFromFrame} = require("url"); | 29 const {extractHostFromFrame} = require("url"); |
| 27 const {port} = require("messaging"); | 30 const {port} = require("messaging"); |
| 28 | 31 |
| 29 const nonRequestTypes = ["DOCUMENT", "ELEMHIDE", "GENERICBLOCK", "GENERICHIDE"]; | 32 const nonRequestTypes = ["DOCUMENT", "ELEMHIDE", "GENERICBLOCK", "GENERICHIDE"]; |
| 30 | 33 |
| 31 // Mapping of inspected tabs to their devpanel page | 34 // Mapping of inspected tabs to their devpanel page |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 } | 77 } |
| 75 | 78 |
| 76 function hasRecord(panel, request, filter) | 79 function hasRecord(panel, request, filter) |
| 77 { | 80 { |
| 78 return panel.records.some(record => | 81 return panel.records.some(record => |
| 79 record.request.url == request.url && | 82 record.request.url == request.url && |
| 80 record.request.docDomain == request.docDomain && | 83 record.request.docDomain == request.docDomain && |
| 81 | 84 |
| 82 // Ignore partial (e.g. ELEMHIDE) whitelisting if there is already | 85 // Ignore partial (e.g. ELEMHIDE) whitelisting if there is already |
| 83 // a DOCUMENT exception which disables all means of blocking. | 86 // a DOCUMENT exception which disables all means of blocking. |
| 84 (record.request.type == "DOCUMENT" | 87 (record.request.type == "DOCUMENT" ? |
| 85 ? nonRequestTypes.indexOf(request.type) != -1 | 88 nonRequestTypes.includes(request.type) : |
| 86 : record.request.type == request.type) && | 89 record.request.type == request.type) && |
| 87 | 90 |
| 88 // Matched element hiding filters don't relate to a particular request, | 91 // Matched element hiding filters don't relate to a particular request, |
| 89 // so we also have to match the CSS selector in order to distinguish them. | 92 // so we have to compare the selector in order to avoid duplicates. |
| 90 (record.filter && record.filter.selector) == (filter && filter.selector) | 93 (record.filter && record.filter.selector) == (filter && filter.selector) |
| 91 ); | 94 ); |
| 92 } | 95 } |
| 93 | 96 |
| 94 function addRecord(panel, request, filter) | 97 function addRecord(panel, request, filter) |
| 95 { | 98 { |
| 96 if (!hasRecord(panel, request, filter)) | 99 if (!hasRecord(panel, request, filter)) |
| 97 { | 100 { |
| 98 panel.port.postMessage({ | 101 panel.port.postMessage({ |
| 99 type: "add-record", | 102 type: "add-record", |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 * @param {?BlockingFilter} filter The matched filter or null if there is no | 134 * @param {?BlockingFilter} filter The matched filter or null if there is no |
| 132 * match | 135 * match |
| 133 */ | 136 */ |
| 134 exports.logRequest = function(page, url, type, docDomain, | 137 exports.logRequest = function(page, url, type, docDomain, |
| 135 thirdParty, sitekey, | 138 thirdParty, sitekey, |
| 136 specificOnly, filter) | 139 specificOnly, filter) |
| 137 { | 140 { |
| 138 let panel = getActivePanel(page); | 141 let panel = getActivePanel(page); |
| 139 if (panel) | 142 if (panel) |
| 140 { | 143 { |
| 141 addRecord(panel, {url, type, docDomain, thirdParty, sitekey, specificOnly}, | 144 let request = {url, type, docDomain, thirdParty, sitekey, specificOnly}; |
| 142 filter); | 145 addRecord(panel, request, filter); |
| 143 } | 146 } |
| 144 }; | 147 }; |
| 145 | 148 |
| 146 /** | 149 /** |
| 147 * Logs active element hiding filters to the devtools panel. | 150 * Logs active element hiding filters to the devtools panel. |
| 148 * | 151 * |
| 149 * @param {Page} page The page the elements were hidden on | 152 * @param {Page} page The page the elements were hidden on |
| 150 * @param {string[]} selectors The CSS selectors of active elemhide filters | 153 * @param {string[]} selectors The CSS selectors of active elemhide filters |
| 151 * @param {string} docDomain The IDN-decoded hostname of the document | 154 * @param {string} docDomain The IDN-decoded hostname of the document |
| 152 */ | 155 */ |
| 153 function logHiddenElements(page, selectors, docDomain) | 156 function logHiddenElements(page, selectors, docDomain) |
| 154 { | 157 { |
| 155 let panel = getActivePanel(page); | 158 let panel = getActivePanel(page); |
| 156 if (panel) | 159 if (panel) |
| 157 { | 160 { |
| 158 for (let subscription of FilterStorage.subscriptions) | 161 for (let subscription of FilterStorage.subscriptions) |
| 159 { | 162 { |
| 160 if (subscription.disabled) | 163 if (subscription.disabled) |
| 161 continue; | 164 continue; |
| 162 | 165 |
| 163 for (let filter of subscription.filters) | 166 for (let filter of subscription.filters) |
| 164 { | 167 { |
| 165 if (!(filter instanceof ElemHideFilter)) | 168 if (!(filter instanceof ElemHideFilter) && |
| 169 !(filter instanceof ElemHideEmulationFilter)) |
| 166 continue; | 170 continue; |
| 167 if (selectors.indexOf(filter.selector) == -1) | 171 if (selectors.indexOf(filter.selector) == -1) |
| 168 continue; | 172 continue; |
| 169 if (!filter.isActiveOnDomain(docDomain)) | 173 if (!filter.isActiveOnDomain(docDomain)) |
| 170 continue; | 174 continue; |
| 171 | 175 |
| 172 addRecord(panel, {type: "ELEMHIDE", docDomain}, filter); | 176 addRecord(panel, {type: "ELEMHIDE", docDomain}, filter); |
| 173 } | 177 } |
| 174 } | 178 } |
| 175 } | 179 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 }; | 217 }; |
| 214 | 218 |
| 215 function onBeforeRequest(details) | 219 function onBeforeRequest(details) |
| 216 { | 220 { |
| 217 let panel = panels[details.tabId]; | 221 let panel = panels[details.tabId]; |
| 218 | 222 |
| 219 // Clear the devtools panel and reload the inspected tab without caching | 223 // Clear the devtools panel and reload the inspected tab without caching |
| 220 // when a new request is issued. However, make sure that we don't end up | 224 // when a new request is issued. However, make sure that we don't end up |
| 221 // in an infinite recursion if we already triggered a reload. | 225 // in an infinite recursion if we already triggered a reload. |
| 222 if (panel.reloading) | 226 if (panel.reloading) |
| 227 { |
| 223 panel.reloading = false; | 228 panel.reloading = false; |
| 229 } |
| 224 else | 230 else |
| 225 { | 231 { |
| 226 panel.records = []; | 232 panel.records = []; |
| 227 panel.port.postMessage({type: "reset"}); | 233 panel.port.postMessage({type: "reset"}); |
| 228 | 234 |
| 229 // We can't repeat the request if it isn't a GET request. Chrome would | 235 // We can't repeat the request if it isn't a GET request. Chrome would |
| 230 // prompt the user to confirm reloading the page, and POST requests are | 236 // prompt the user to confirm reloading the page, and POST requests are |
| 231 // known to cause issues on many websites if repeated. | 237 // known to cause issues on many websites if repeated. |
| 232 if (details.method == "GET") | 238 if (details.method == "GET") |
| 233 panel.reload = true; | 239 panel.reload = true; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 panels[inspectedTabId] = {port: newPort, records: []}; | 377 panels[inspectedTabId] = {port: newPort, records: []}; |
| 372 }); | 378 }); |
| 373 | 379 |
| 374 port.on("devtools.traceElemHide", (message, sender) => | 380 port.on("devtools.traceElemHide", (message, sender) => |
| 375 { | 381 { |
| 376 logHiddenElements( | 382 logHiddenElements( |
| 377 sender.page, message.selectors, | 383 sender.page, message.selectors, |
| 378 extractHostFromFrame(sender.frame) | 384 extractHostFromFrame(sender.frame) |
| 379 ); | 385 ); |
| 380 }); | 386 }); |
| LEFT | RIGHT |