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

Unified Diff: lib/filterClasses.js

Issue 29737558: Issue 6538, 6781 - Implement support for snippet filters (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Check for null and blank string instead Created April 3, 2018, 10:46 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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" && typeof value != "undefined")
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()
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld