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-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 "use strict"; | |
21 | |
20 let {extractHostFromFrame, stringifyURL, isThirdParty} = require("url"); | 22 let {extractHostFromFrame, stringifyURL, isThirdParty} = require("url"); |
21 let {getKey, checkWhitelisted} = require("whitelisting"); | 23 let {getKey, checkWhitelisted} = require("whitelisting"); |
22 let {defaultMatcher} = require("matcher"); | 24 let {defaultMatcher} = require("matcher"); |
23 let {RegExpFilter} = require("filterClasses"); | 25 let {RegExpFilter} = require("filterClasses"); |
26 let {port} = require("messaging"); | |
24 | 27 |
25 function isValidString(s) { | 28 function isValidString(s) { |
26 return s && s.indexOf("\0") == -1; | 29 return s && s.indexOf("\0") == -1; |
27 } | 30 } |
28 | 31 |
29 function escapeChar(chr) | 32 function escapeChar(chr) |
30 { | 33 { |
31 let code = chr.charCodeAt(0); | 34 let code = chr.charCodeAt(0); |
32 | 35 |
33 // Control characters and leading digits must be escaped based on | 36 // Control characters and leading digits must be escaped based on |
(...skipping 25 matching lines...) Expand all Loading... | |
59 * | 62 * |
60 * @param {string} value | 63 * @param {string} value |
61 * @return {string} | 64 * @return {string} |
62 * @static | 65 * @static |
63 */ | 66 */ |
64 exports.quoteCSS = function(value) | 67 exports.quoteCSS = function(value) |
65 { | 68 { |
66 return '"' + value.replace(/["\\\{\}\x00-\x1F\x7F]/g, escapeChar) + '"'; | 69 return '"' + value.replace(/["\\\{\}\x00-\x1F\x7F]/g, escapeChar) + '"'; |
67 }; | 70 }; |
68 | 71 |
69 /** | 72 function composeFilters(details) |
kzar
2016/03/18 15:22:10
Any reason you deleted this documentation? (I unde
Sebastian Noack
2016/03/18 15:26:21
I found the documentation for this function quite
kzar
2016/03/18 15:52:39
I think it's useful but if you disagree I guess we
| |
70 * Generates filters to block an element. | |
71 * @param {Object} details | |
72 * @param {string} details.tagName The element's tag name | |
73 * @param {string} details.id The element's "id" attribute | |
74 * @param {string} details.src The element's "src" attribute | |
75 * @param {string} details.style The element's "style" attribute | |
76 * @param {string[]} details.classes The classes given by the element's "class" attribute | |
77 * @param {string[]} details.urls The URLs considered when loading the eleme nt | |
78 * @param {string} details.type The request type (will be ignored if there are no URLs) | |
79 * @param {string} details.baseURL The URL of the document containing the ele ment | |
80 * @param {Page} details.page The page containing the element | |
81 * @param {Frame} details.frame The frame containing the element | |
82 * | |
83 * @return {object} An object holding the list of generated filters and | |
84 * the list of CSS selectors for the included element | |
85 * hiding filters: {filters: [...], selectors: [...]} | |
86 */ | |
87 exports.composeFilters = function(details) | |
88 { | 73 { |
89 let filters = []; | 74 let filters = []; |
90 let selectors = []; | 75 let selectors = []; |
91 | 76 |
92 let page = details.page; | 77 let page = details.page; |
93 let frame = details.frame; | 78 let frame = details.frame; |
94 | 79 |
95 if (!checkWhitelisted(page, frame)) | 80 if (!checkWhitelisted(page, frame)) |
96 { | 81 { |
97 let typeMask = RegExpFilter.typeMap[details.type]; | 82 let typeMask = RegExpFilter.typeMap[details.type]; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 if (isValidString(details.style) && selectors.length == 0 && filters.lengt h == 0) | 129 if (isValidString(details.style) && selectors.length == 0 && filters.lengt h == 0) |
145 selectors.push(escapeCSS(details.tagName) + "[style=" + quoteCSS(details .style) + "]"); | 130 selectors.push(escapeCSS(details.tagName) + "[style=" + quoteCSS(details .style) + "]"); |
146 | 131 |
147 // Add an element hiding filter for each generated CSS selector | 132 // Add an element hiding filter for each generated CSS selector |
148 for (let selector of selectors) | 133 for (let selector of selectors) |
149 filters.push(docDomain.replace(/^www\./, "") + "##" + selector); | 134 filters.push(docDomain.replace(/^www\./, "") + "##" + selector); |
150 } | 135 } |
151 } | 136 } |
152 | 137 |
153 return {filters: filters, selectors: selectors}; | 138 return {filters: filters, selectors: selectors}; |
154 }; | 139 } |
140 | |
141 port.on("composer.ready", (message, sender) => | |
142 { | |
143 htmlPages.set(sender.page, null); | |
144 refreshIconAndContextMenu(sender.page); | |
145 }); | |
146 | |
147 port.on("composer.openDialog", (message, sender) => | |
148 { | |
149 return new Promise(resolve => | |
150 { | |
151 ext.windows.create({ | |
152 url: ext.getURL("block.html"), | |
153 left: 50, | |
154 top: 50, | |
155 width: 420, | |
156 height: 200, | |
157 focused: true, | |
158 type: "popup" | |
159 }, | |
160 popupPage => | |
161 { | |
162 let popupPageId = popupPage.id; | |
163 function onRemoved(removedPageId) | |
164 { | |
165 if (popupPageId == removedPageId) | |
166 { | |
167 sender.page.sendMessage({ | |
168 type: "blockelement-popup-closed", | |
169 popupId: popupPageId | |
170 }); | |
171 ext.pages.onRemoved.removeListener(onRemoved); | |
172 } | |
173 } | |
174 ext.pages.onRemoved.addListener(onRemoved); | |
175 resolve(popupPageId); | |
176 }); | |
177 }); | |
178 }); | |
179 | |
180 port.on("composer.getFilters", (message, sender) => | |
181 { | |
182 return composeFilters({ | |
183 tagName: message.tagName, | |
184 id: message.id, | |
185 src: message.src, | |
186 style: message.style, | |
187 classes: message.classes, | |
188 urls: message.urls, | |
189 type: message.mediatype, | |
190 baseURL: message.baseURL, | |
191 page: sender.page, | |
192 frame: sender.frame | |
193 }); | |
194 }); | |
OLD | NEW |