Index: lib/filterClasses.js |
=================================================================== |
--- a/lib/filterClasses.js |
+++ b/lib/filterClasses.js |
@@ -766,16 +766,17 @@ |
let contentType = null; |
let matchCase = null; |
let domains = null; |
let sitekeys = null; |
let thirdParty = null; |
let collapse = null; |
let csp = null; |
+ let snippets = null; |
let options; |
let match = (text.indexOf("$") >= 0 ? Filter.optionsRegExp.exec(text) : null); |
if (match) |
{ |
options = match[1].split(","); |
text = match.input.substr(0, match.index); |
for (let option of options) |
{ |
@@ -790,16 +791,18 @@ |
if (option in RegExpFilter.typeMap) |
{ |
if (contentType == null) |
contentType = 0; |
contentType |= RegExpFilter.typeMap[option]; |
if (option == "CSP" && value) |
csp = value; |
+ else if (option == "SNIPPET" && value) |
+ snippets = value.split("|"); |
} |
else if (option[0] == "~" && option.substr(1) in RegExpFilter.typeMap) |
{ |
if (contentType == null) |
({contentType} = RegExpFilter.prototype); |
contentType &= ~RegExpFilter.typeMap[option.substr(1)]; |
} |
else if (option == "MATCH_CASE") |
@@ -826,17 +829,17 @@ |
try |
{ |
if (blocking) |
{ |
if (csp && Filter.invalidCSPRegExp.test(csp)) |
return new InvalidFilter(origText, "filter_invalid_csp"); |
return new BlockingFilter(origText, text, contentType, matchCase, domains, |
- thirdParty, sitekeys, collapse, csp); |
+ thirdParty, sitekeys, collapse, csp, snippets); |
} |
return new WhitelistFilter(origText, text, contentType, matchCase, domains, |
thirdParty, sitekeys); |
} |
catch (e) |
{ |
return new InvalidFilter(origText, "filter_invalid_regexp"); |
} |
@@ -855,31 +858,33 @@ |
DOCUMENT: 64, |
WEBSOCKET: 128, |
WEBRTC: 256, |
CSP: 512, |
XBL: 1, |
PING: 1024, |
XMLHTTPREQUEST: 2048, |
OBJECT_SUBREQUEST: 4096, |
+ SNIPPET: 8192, |
DTD: 1, |
MEDIA: 16384, |
FONT: 32768, |
BACKGROUND: 4, // Backwards compat, same as IMAGE |
POPUP: 0x10000000, |
GENERICBLOCK: 0x20000000, |
ELEMHIDE: 0x40000000, |
GENERICHIDE: 0x80000000 |
}; |
-// CSP, DOCUMENT, ELEMHIDE, POPUP, GENERICHIDE and GENERICBLOCK options |
+// CSP, SNIPPET, DOCUMENT, ELEMHIDE, POPUP, GENERICHIDE and GENERICBLOCK options |
// shouldn't be there by default |
RegExpFilter.prototype.contentType &= ~(RegExpFilter.typeMap.CSP | |
+ RegExpFilter.typeMap.SNIPPET | |
RegExpFilter.typeMap.DOCUMENT | |
RegExpFilter.typeMap.ELEMHIDE | |
RegExpFilter.typeMap.POPUP | |
RegExpFilter.typeMap.GENERICHIDE | |
RegExpFilter.typeMap.GENERICBLOCK); |
/** |
* Class for blocking filters |
@@ -889,27 +894,30 @@ |
* @param {boolean} matchCase see RegExpFilter() |
* @param {string} domains see RegExpFilter() |
* @param {boolean} thirdParty see RegExpFilter() |
* @param {string} sitekeys see RegExpFilter() |
* @param {boolean} collapse |
* defines whether the filter should collapse blocked content, can be null |
* @param {string} [csp] |
* Content Security Policy to inject when the filter matches |
+ * @param {string} [snippets] |
+ * the code snippets to inject when the filter matches |
* @constructor |
* @augments RegExpFilter |
*/ |
function BlockingFilter(text, regexpSource, contentType, matchCase, domains, |
- thirdParty, sitekeys, collapse, csp) |
+ thirdParty, sitekeys, collapse, csp, snippets) |
{ |
RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, |
thirdParty, sitekeys); |
this.collapse = collapse; |
this.csp = csp; |
+ this.snippets = snippets; |
} |
exports.BlockingFilter = BlockingFilter; |
BlockingFilter.prototype = extend(RegExpFilter, { |
type: "blocking", |
/** |
* Defines whether the filter should collapse blocked content. |
@@ -917,17 +925,23 @@ |
* @type {boolean} |
*/ |
collapse: null, |
/** |
* Content Security Policy to inject for matching requests. |
* @type {string} |
*/ |
- csp: null |
+ csp: null, |
+ |
+ /** |
+ * The code snippets to inject for matching requests. |
+ * @type {string[]} |
+ */ |
+ snippets: null |
}); |
/** |
* Class for whitelist filters |
* @param {string} text see Filter() |
* @param {string} regexpSource see RegExpFilter() |
* @param {number} contentType see RegExpFilter() |
* @param {boolean} matchCase see RegExpFilter() |