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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 let {extractHostFromFrame, stringifyURL, isThirdParty} = require("url"); | 18 let {extractHostFromFrame, stringifyURL, isThirdParty} = require("url"); |
19 let {getKey, isFrameWhitelisted} = require("whitelisting"); | 19 let {getKey, isFrameWhitelisted} = require("whitelisting"); |
20 let {defaultMatcher} = require("matcher"); | 20 let {defaultMatcher} = require("matcher"); |
21 let {WhitelistFilter} = require("filterClasses"); | |
22 | 21 |
23 function escapeChar(chr) | 22 function escapeChar(chr) |
24 { | 23 { |
25 let code = chr.charCodeAt(0); | 24 let code = chr.charCodeAt(0); |
26 | 25 |
27 // Control characters and leading digits must be escaped based on | 26 // Control characters and leading digits must be escaped based on |
28 // their char code in CSS. Moreover, curly brackets aren't allowed | 27 // their char code in CSS. Moreover, curly brackets aren't allowed |
29 // in elemhide filters, and therefore must be escaped based on their | 28 // in elemhide filters, and therefore must be escaped based on their |
30 // char code as well. | 29 // char code as well. |
31 if (code <= 0x1F || code == 0x7F || /[\d\{\}]/.test(chr)) | 30 if (code <= 0x1F || code == 0x7F || /[\d\{\}]/.test(chr)) |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 89 |
91 // Add a blocking filter for each URL of the element that can be blocked | 90 // Add a blocking filter for each URL of the element that can be blocked |
92 for (let url of details.urls) | 91 for (let url of details.urls) |
93 { | 92 { |
94 let urlObj = new URL(url, details.baseURL); | 93 let urlObj = new URL(url, details.baseURL); |
95 | 94 |
96 if (urlObj.protocol == "http:" || urlObj.protocol == "https:") | 95 if (urlObj.protocol == "http:" || urlObj.protocol == "https:") |
97 { | 96 { |
98 url = stringifyURL(urlObj); | 97 url = stringifyURL(urlObj); |
99 | 98 |
100 let filter = defaultMatcher.matchesAny( | 99 let filter = defaultMatcher.whitelist.matchesAny( |
101 url, details.type, docDomain, | 100 url, details.type, docDomain, |
102 isThirdParty(urlObj, docDomain), | 101 isThirdParty(urlObj, docDomain), |
103 getKey(page, frame) | 102 getKey(page, frame) |
104 ); | 103 ); |
105 | 104 |
106 if (!(filter instanceof WhitelistFilter)) | 105 if (!filter) |
107 { | 106 { |
108 let filterText = url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||"); | 107 let filterText = url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||"); |
109 | 108 |
110 if (filters.indexOf(filterText) == -1) | 109 if (filters.indexOf(filterText) == -1) |
111 filters.push(filterText); | 110 filters.push(filterText); |
112 } | 111 } |
113 } | 112 } |
114 } | 113 } |
115 | 114 |
116 // If we couldn't generate any blocking filters, fallback to element hiding | 115 // If we couldn't generate any blocking filters, fallback to element hiding |
(...skipping 18 matching lines...) Expand all Loading... |
135 | 134 |
136 // Add an element hiding filter for each generated CSS selector | 135 // Add an element hiding filter for each generated CSS selector |
137 for (let selector of selectors) | 136 for (let selector of selectors) |
138 filters.push(docDomain.replace(/^www\./, "") + "##" + selector); | 137 filters.push(docDomain.replace(/^www\./, "") + "##" + selector); |
139 } | 138 } |
140 } | 139 } |
141 | 140 |
142 return {filters: filters, selectors: selectors}; | 141 return {filters: filters, selectors: selectors}; |
143 } | 142 } |
144 exports.composeFilters = composeFilters; | 143 exports.composeFilters = composeFilters; |
OLD | NEW |