Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: lib/filterComposer.js

Issue 6174977720057856: Issue 1853 - Moved filter generation into background page (Closed)
Left Patch Set: Rebased Created Feb. 13, 2015, 4:11 p.m.
Right Patch Set: Rebased and fixed documentation mistakenly indicating arguments as optional Created Feb. 28, 2015, 5:59 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « include.preload.js ('k') | metadata.common » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
(...skipping 16 matching lines...) Expand all
27 // char code as well. 27 // char code as well.
28 if (code <= 0x1F || code == 0x7F || /[\d\{\}]/.test(chr)) 28 if (code <= 0x1F || code == 0x7F || /[\d\{\}]/.test(chr))
29 return "\\" + code.toString(16) + " "; 29 return "\\" + code.toString(16) + " ";
30 30
31 return "\\" + chr; 31 return "\\" + chr;
32 } 32 }
33 33
34 /** 34 /**
35 * Escapes a token (e.g. tag, id, class or attribute) to be used in CSS selector s. 35 * Escapes a token (e.g. tag, id, class or attribute) to be used in CSS selector s.
36 * 36 *
37 * @param {string} [s] 37 * @param {string} s
38 * @return {string} 38 * @return {string}
39 */ 39 */
40 function escapeCSS(s) 40 function escapeCSS(s)
41 { 41 {
42 return s.replace(/^[\d\-]|[^\w\-\u0080-\uFFFF]/g, escapeChar); 42 return s.replace(/^[\d\-]|[^\w\-\u0080-\uFFFF]/g, escapeChar);
43 } 43 }
44 exports.escapeCSS = escapeCSS; 44 exports.escapeCSS = escapeCSS;
45 45
46 /** 46 /**
47 * Quotes a string to be used as attribute value in CSS selectors. 47 * Quotes a string to be used as attribute value in CSS selectors.
48 * 48 *
49 * @param {string} [value] 49 * @param {string} value
50 * @return {string} 50 * @return {string}
51 */ 51 */
52 function quoteCSS(value) 52 function quoteCSS(value)
53 { 53 {
54 return '"' + value.replace(/["\\\{\}\x00-\x1F\x7F]/g, escapeChar) + '"'; 54 return '"' + value.replace(/["\\\{\}\x00-\x1F\x7F]/g, escapeChar) + '"';
55 } 55 }
56 exports.quoteCSS = quoteCSS; 56 exports.quoteCSS = quoteCSS;
57 57
58 function canBlockURL(url) 58 function canBlockURL(url)
59 { 59 {
60 return url.protocol == "http:" || url.protocol == "https:"; 60 return url.protocol == "http:" || url.protocol == "https:";
61 } 61 }
62 62
63 /** 63 /**
64 * Generates filters to block an element. 64 * Generates filters to block an element.
65 * 65 *
66 * @param {string} [tagName] The element's tag name 66 * @param {string} tagName The element's tag name
67 * @param {string} [src] The element's "src" attribute (can be null) 67 * @param {string} [src] The element's "src" attribute
68 * @param {string} [id] The element's "id" attribute (can be null) 68 * @param {string} [id] The element's "id" attribute
69 * @param {string} [style] The element's "style" attribute (can be null) 69 * @param {string} [style] The element's "style" attribute
70 * @param {string[]} [classes] The classes given by the element's "class" attrib ute 70 * @param {string[]} classes The classes given by the element's "class" attribu te
71 * @param {string[]} [urls] The URLs considered when loading the element 71 * @param {string[]} urls The URLs considered when loading the element
72 * @param {URL} [baseURL] The URL of the document containing the element 72 * @param {URL} baseURL The URL of the document containing the element
73 * 73 *
74 * @return {object} An object holding the list of generated filters and 74 * @return {object} An object holding the list of generated filters and
75 * the list of CSS selectors for the included element 75 * the list of CSS selectors for the included element
76 * hiding filters: {filters: [...], selectors: [...]} 76 * hiding filters: {filters: [...], selectors: [...]}
77 */ 77 */
78 function composeFilters(tagName, id, src, style, classes, urls, baseURL) 78 function composeFilters(tagName, id, src, style, classes, urls, baseURL)
79 { 79 {
80 // Add a blocking filter for each HTTP(S) URL associated with the element 80 // Add a blocking filter for each HTTP(S) URL associated with the element
81 let filters = []; 81 let filters = [];
82 for (let url of urls) 82 for (let url of urls)
(...skipping 30 matching lines...) Expand all
113 { 113 {
114 let domain = getDecodedHostname(baseURL).replace(/^www\./, ""); 114 let domain = getDecodedHostname(baseURL).replace(/^www\./, "");
115 115
116 for (let selector of selectors) 116 for (let selector of selectors)
117 filters.push(domain + "##" + selector); 117 filters.push(domain + "##" + selector);
118 } 118 }
119 119
120 return {filters: filters, selectors: selectors}; 120 return {filters: filters, selectors: selectors};
121 } 121 }
122 exports.composeFilters = composeFilters; 122 exports.composeFilters = composeFilters;
LEFTRIGHT

Powered by Google App Engine
This is Rietveld