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

Unified Diff: lib/filterListener.js

Issue 29824589: Issue 6538, 6781 - Allow snippets only from circumvention lists (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Improve unit tests Created July 10, 2018, 7:15 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 | test/filterListener.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/filterListener.js
===================================================================
--- a/lib/filterListener.js
+++ b/lib/filterListener.js
@@ -29,16 +29,17 @@
const {FilterNotifier} = require("./filterNotifier");
const {ElemHide} = require("./elemHide");
const {ElemHideEmulation} = require("./elemHideEmulation");
const {Snippets} = require("./snippets");
const {defaultMatcher} = require("./matcher");
const {ActiveFilter, RegExpFilter,
ElemHideBase, ElemHideEmulationFilter,
SnippetFilter} = require("./filterClasses");
+const {SpecialSubscription} = require("./subscriptionClasses");
const {Prefs} = require("prefs");
/**
* Increases on filter changes, filters will be saved if it exceeds 1.
* @type {number}
*/
let isDirty = 0;
@@ -135,37 +136,48 @@
* @param {Filter} filter filter that has been added
*/
function addFilter(filter)
{
if (!(filter instanceof ActiveFilter) || filter.disabled)
return;
let hasEnabled = false;
+ let allowSnippets = false;
for (let i = 0; i < filter.subscriptions.length; i++)
kzar 2018/07/10 14:38:35 Nit: `for (let subscription of filter.subscription
Manish Jethani 2018/07/10 18:33:22 I did this initially and then reverted it. There's
kzar 2018/07/10 18:56:00 Sure it's an unrelated change, but you're changing
Manish Jethani 2018/07/11 15:07:03 There are some performance implications of for..of
kzar 2018/07/11 17:22:07 Fine.
{
- if (!filter.subscriptions[i].disabled)
+ let subscription = filter.subscriptions[i];
+
+ if (!subscription.disabled)
{
hasEnabled = true;
- break;
+
+ // Allow snippets to be executed only by the circumvention lists or the
+ // user's own filters.
+ if (subscription.type == "circumvention" ||
+ subscription instanceof SpecialSubscription)
+ {
+ allowSnippets = true;
+ break;
+ }
}
}
if (!hasEnabled)
return;
if (filter instanceof RegExpFilter)
defaultMatcher.add(filter);
else if (filter instanceof ElemHideBase)
{
if (filter instanceof ElemHideEmulationFilter)
ElemHideEmulation.add(filter);
else
ElemHide.add(filter);
}
- else if (filter instanceof SnippetFilter)
+ else if (allowSnippets && filter instanceof SnippetFilter)
Snippets.add(filter);
}
/**
* Notifies Matcher instances or ElemHide object about removal of a filter
* if necessary.
* @param {Filter} filter filter that has been removed
*/
« no previous file with comments | « no previous file | test/filterListener.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld