| LEFT | RIGHT |
| (no file at all) | |
| 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 |
| 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 /** @module filterComposer */ | 18 /** @module filterComposer */ |
| 19 | 19 |
| 20 let {extractHostFromFrame, stringifyURL, isThirdParty} = require("url"); | 20 let {extractHostFromFrame, stringifyURL, isThirdParty} = require("url"); |
| 21 let {getKey, isFrameWhitelisted} = require("whitelisting"); | 21 let {getKey, checkWhitelisted} = require("whitelisting"); |
| 22 let {defaultMatcher} = require("matcher"); | 22 let {defaultMatcher} = require("matcher"); |
| 23 let {RegExpFilter} = require("filterClasses"); | 23 let {RegExpFilter} = require("filterClasses"); |
| 24 | 24 |
| 25 function isValidString(s) { | 25 function isValidString(s) { |
| 26 return s && s.indexOf("\0") == -1; | 26 return s && s.indexOf("\0") == -1; |
| 27 } | 27 } |
| 28 | 28 |
| 29 function escapeChar(chr) | 29 function escapeChar(chr) |
| 30 { | 30 { |
| 31 let code = chr.charCodeAt(0); | 31 let code = chr.charCodeAt(0); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 * hiding filters: {filters: [...], selectors: [...]} | 85 * hiding filters: {filters: [...], selectors: [...]} |
| 86 */ | 86 */ |
| 87 exports.composeFilters = function(details) | 87 exports.composeFilters = function(details) |
| 88 { | 88 { |
| 89 let filters = []; | 89 let filters = []; |
| 90 let selectors = []; | 90 let selectors = []; |
| 91 | 91 |
| 92 let page = details.page; | 92 let page = details.page; |
| 93 let frame = details.frame; | 93 let frame = details.frame; |
| 94 | 94 |
| 95 if (!isFrameWhitelisted(page, frame, RegExpFilter.typeMap.DOCUMENT)) | 95 if (!checkWhitelisted(page, frame)) |
| 96 { | 96 { |
| 97 let typeMask = RegExpFilter.typeMap[details.type]; | 97 let typeMask = RegExpFilter.typeMap[details.type]; |
| 98 let docDomain = extractHostFromFrame(frame); | 98 let docDomain = extractHostFromFrame(frame); |
| 99 let specificOnly = checkWhitelisted(page, frame, RegExpFilter.typeMap.GENERI
CBLOCK); | 99 let specificOnly = checkWhitelisted(page, frame, RegExpFilter.typeMap.GENERI
CBLOCK); |
| 100 | 100 |
| 101 // Add a blocking filter for each URL of the element that can be blocked | 101 // Add a blocking filter for each URL of the element that can be blocked |
| 102 for (let url of details.urls) | 102 for (let url of details.urls) |
| 103 { | 103 { |
| 104 let urlObj = new URL(url, details.baseURL); | 104 let urlObj = new URL(url, details.baseURL); |
| 105 url = stringifyURL(urlObj); | 105 url = stringifyURL(urlObj); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 117 if (specificOnly) | 117 if (specificOnly) |
| 118 filterText += "$domain=" + docDomain; | 118 filterText += "$domain=" + docDomain; |
| 119 | 119 |
| 120 if (filters.indexOf(filterText) == -1) | 120 if (filters.indexOf(filterText) == -1) |
| 121 filters.push(filterText); | 121 filters.push(filterText); |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 | 124 |
| 125 // If we couldn't generate any blocking filters, fallback to element hiding | 125 // If we couldn't generate any blocking filters, fallback to element hiding |
| 126 let selectors = []; | 126 let selectors = []; |
| 127 if (filters.length == 0 && !isFrameWhitelisted(page, frame, RegExpFilter.typ
eMap.ELEMHIDE)) | 127 if (filters.length == 0 && !checkWhitelisted(page, frame, RegExpFilter.typeM
ap.ELEMHIDE)) |
| 128 { | 128 { |
| 129 // Generate CSS selectors based on the element's "id" and "class" attribut
e | 129 // Generate CSS selectors based on the element's "id" and "class" attribut
e |
| 130 if (isValidString(details.id)) | 130 if (isValidString(details.id)) |
| 131 selectors.push("#" + escapeCSS(details.id)); | 131 selectors.push("#" + escapeCSS(details.id)); |
| 132 | 132 |
| 133 let classes = details.classes.filter(isValidString); | 133 let classes = details.classes.filter(isValidString); |
| 134 if (classes.length > 0) | 134 if (classes.length > 0) |
| 135 selectors.push(classes.map(c => "." + escapeCSS(c)).join("")); | 135 selectors.push(classes.map(c => "." + escapeCSS(c)).join("")); |
| 136 | 136 |
| 137 // If there is a "src" attribute, specifiying a URL that we can't block, | 137 // If there is a "src" attribute, specifiying a URL that we can't block, |
| 138 // generate a CSS selector matching the "src" attribute | 138 // generate a CSS selector matching the "src" attribute |
| 139 if (isValidString(details.src)) | 139 if (isValidString(details.src)) |
| 140 selectors.push(escapeCSS(details.tagName) + "[src=" + quoteCSS(details.s
rc) + "]"); | 140 selectors.push(escapeCSS(details.tagName) + "[src=" + quoteCSS(details.s
rc) + "]"); |
| 141 | 141 |
| 142 // As last resort, if there is a "style" attribute, and we couldn't genera
te | 142 // As last resort, if there is a "style" attribute, and we couldn't genera
te |
| 143 // any filters so far, generate a CSS selector matching the "style" attrib
ute | 143 // any filters so far, generate a CSS selector matching the "style" attrib
ute |
| 144 if (isValidString(details.style) && selectors.length == 0 && filters.lengt
h == 0) | 144 if (isValidString(details.style) && selectors.length == 0 && filters.lengt
h == 0) |
| 145 selectors.push(escapeCSS(details.tagName) + "[style=" + quoteCSS(details
.style) + "]"); | 145 selectors.push(escapeCSS(details.tagName) + "[style=" + quoteCSS(details
.style) + "]"); |
| 146 | 146 |
| 147 // Add an element hiding filter for each generated CSS selector | 147 // Add an element hiding filter for each generated CSS selector |
| 148 for (let selector of selectors) | 148 for (let selector of selectors) |
| 149 filters.push(docDomain.replace(/^www\./, "") + "##" + selector); | 149 filters.push(docDomain.replace(/^www\./, "") + "##" + selector); |
| 150 } | 150 } |
| 151 } | 151 } |
| 152 | 152 |
| 153 return {filters: filters, selectors: selectors}; | 153 return {filters: filters, selectors: selectors}; |
| 154 }; | 154 }; |
| LEFT | RIGHT |