| 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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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"; | 20 import {defaultMatcher} from "matcher"; |
| 21 | 21 import {RegExpFilter} from "filterClasses"; |
| 22 const {defaultMatcher} = require("matcher"); | 22 import {FilterNotifier} from "filterNotifier"; |
| 23 const {RegExpFilter} = require("filterClasses"); | 23 import {Prefs} from "prefs"; |
| 24 const {FilterNotifier} = require("filterNotifier"); | 24 import {extractHostFromFrame, stringifyURL, isThirdParty} from "url"; |
| 25 const {Prefs} = require("prefs"); | 25 import {getKey, checkWhitelisted} from "whitelisting"; |
| 26 const {extractHostFromFrame, stringifyURL, isThirdParty} = require("url"); | 26 import {port} from "messaging"; |
| 27 const {getKey, checkWhitelisted} = require("whitelisting"); | 27 import info from "info"; |
| 28 const {port} = require("messaging"); | |
| 29 const info = require("info"); | |
| 30 | 28 |
| 31 let readyPages = new ext.PageMap(); | 29 let readyPages = new ext.PageMap(); |
| 32 | 30 |
| 33 /** | 31 /** |
| 34 * Checks whether the given page is ready to use the filter composer | 32 * Checks whether the given page is ready to use the filter composer |
| 35 * | 33 * |
| 36 * @param {Page} page | 34 * @param {Page} page |
| 37 * @return {boolean} | 35 * @return {boolean} |
| 38 */ | 36 */ |
| 39 exports.isPageReady = page => | 37 export const isPageReady = page => readyPages.has(page); |
| 40 { | |
| 41 return readyPages.has(page); | |
| 42 }; | |
| 43 | 38 |
| 44 function isValidString(s) | 39 function isValidString(s) |
| 45 { | 40 { |
| 46 return s && s.indexOf("\0") == -1; | 41 return s && s.indexOf("\0") == -1; |
| 47 } | 42 } |
| 48 | 43 |
| 49 function escapeChar(chr) | 44 function escapeChar(chr) |
| 50 { | 45 { |
| 51 let code = chr.charCodeAt(0); | 46 let code = chr.charCodeAt(0); |
| 52 | 47 |
| 53 // Control characters and leading digits must be escaped based on | 48 // Control characters and leading digits must be escaped based on |
| 54 // their char code in CSS. Moreover, curly brackets aren't allowed | 49 // their char code in CSS. Moreover, curly brackets aren't allowed |
| 55 // in elemhide filters, and therefore must be escaped based on their | 50 // in elemhide filters, and therefore must be escaped based on their |
| 56 // char code as well. | 51 // char code as well. |
| 57 if (code <= 0x1F || code == 0x7F || /[\d{}]/.test(chr)) | 52 if (code <= 0x1F || code == 0x7F || /[\d{}]/.test(chr)) |
| 58 return "\\" + code.toString(16) + " "; | 53 return "\\" + code.toString(16) + " "; |
| 59 | 54 |
| 60 return "\\" + chr; | 55 return "\\" + chr; |
| 61 } | 56 } |
| 62 | 57 |
| 63 let escapeCSS = | |
| 64 /** | 58 /** |
| 65 * Escapes a token (e.g. tag, id, class or attribute) to be used in | 59 * Escapes a token (e.g. tag, id, class or attribute) to be used in |
| 66 * CSS selectors. | 60 * CSS selectors. |
| 67 * | 61 * |
| 68 * @param {string} s | 62 * @param {string} s |
| 69 * @return {string} | 63 * @return {string} |
| 70 * @static | 64 * @static |
| 71 */ | 65 */ |
| 72 exports.escapeCSS = s => | 66 export const escapeCSS = s => s.replace(/^[\d-]|[^\w\-\u0080-\uFFFF]/g, |
| 73 { | 67 escapeChar); |
| 74 return s.replace(/^[\d-]|[^\w\-\u0080-\uFFFF]/g, escapeChar); | |
| 75 }; | |
| 76 | 68 |
| 77 let quoteCSS = | |
| 78 /** | 69 /** |
| 79 * Quotes a string to be used as attribute value in CSS selectors. | 70 * Quotes a string to be used as attribute value in CSS selectors. |
| 80 * | 71 * |
| 81 * @param {string} value | 72 * @param {string} value |
| 82 * @return {string} | 73 * @return {string} |
| 83 * @static | 74 * @static |
| 84 */ | 75 */ |
| 85 exports.quoteCSS = value => | 76 export const quoteCSS = value => '"' + value.replace(/["\\{}\x00-\x1F\x7F]/g, |
| 86 { | 77 escapeChar) + '"'; |
| 87 return '"' + value.replace(/["\\{}\x00-\x1F\x7F]/g, escapeChar) + '"'; | |
| 88 }; | |
| 89 | 78 |
| 90 function composeFilters(details) | 79 function composeFilters(details) |
| 91 { | 80 { |
| 92 let {page, frame} = details; | 81 let {page, frame} = details; |
| 93 let filters = []; | 82 let filters = []; |
| 94 let selectors = []; | 83 let selectors = []; |
| 95 | 84 |
| 96 if (!checkWhitelisted(page, frame)) | 85 if (!checkWhitelisted(page, frame)) |
| 97 { | 86 { |
| 98 let typeMask = RegExpFilter.typeMap[details.type]; | 87 let typeMask = RegExpFilter.typeMap[details.type]; |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 // When tabs start loading we send them a message to ensure that the state | 312 // When tabs start loading we send them a message to ensure that the state |
| 324 // of the "block element" tool is reset. This is necessary since Firefox will | 313 // of the "block element" tool is reset. This is necessary since Firefox will |
| 325 // sometimes cache the state of a tab when the user navigates back / forward, | 314 // sometimes cache the state of a tab when the user navigates back / forward, |
| 326 // which includes the state of the "block element" tool. | 315 // which includes the state of the "block element" tool. |
| 327 // Since sending this message will often fail (e.g. for new tabs which have | 316 // Since sending this message will often fail (e.g. for new tabs which have |
| 328 // just been opened) we catch and ignore any exception thrown. | 317 // just been opened) we catch and ignore any exception thrown. |
| 329 browser.tabs.sendMessage( | 318 browser.tabs.sendMessage( |
| 330 page.id, {type: "composer.content.finished"} | 319 page.id, {type: "composer.content.finished"} |
| 331 ).catch(() => {}); | 320 ).catch(() => {}); |
| 332 }); | 321 }); |
| OLD | NEW |