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

Unified Diff: lib/filterListener.js

Issue 29934588: Issue 7094 - Encapsulate management of subscription filters (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Nov. 2, 2018, 10:34 p.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 | lib/filterStorage.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
@@ -27,17 +27,17 @@
const {filterStorage} = require("./filterStorage");
const {filterNotifier} = require("./filterNotifier");
const {ElemHide} = require("./elemHide");
const {ElemHideEmulation} = require("./elemHideEmulation");
const {ElemHideExceptions} = require("./elemHideExceptions");
const {Snippets} = require("./snippets");
const {defaultMatcher} = require("./matcher");
-const {ActiveFilter, RegExpFilter,
+const {Filter, ActiveFilter, RegExpFilter,
ElemHideBase, ElemHideFilter, 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}
@@ -214,76 +214,89 @@
ElemHideExceptions.remove(filter);
}
else if (filter instanceof SnippetFilter)
Snippets.remove(filter);
}
const primes = [101, 109, 131, 149, 163, 179, 193, 211, 229, 241];
-function addFilters(filters)
+function addFilters(filters, filterObjects)
{
// We add filters using pseudo-random ordering. Reason is that ElemHide will
// assign consecutive filter IDs that might be visible to the website. The
// randomization makes sure that no conclusion can be made about the actual
// filters applying there. We have ten prime numbers to use as iteration step,
// any of those can be chosen as long as the array length isn't divisible by
// it.
- let len = filters.length;
+ let len = filterObjects ? filterObjects.length : filters.length;
if (!len)
return;
let current = (Math.random() * len) | 0;
let step;
do
{
step = primes[(Math.random() * primes.length) | 0];
} while (len % step == 0);
for (let i = 0; i < len; i++, current = (current + step) % len)
- addFilter(filters[current]);
+ {
+ addFilter(filterObjects ? filterObjects[current] :
+ Filter.fromText(filters[current]));
+ }
}
function onSubscriptionAdded(subscription)
{
FilterListener.setDirty(1);
if (!subscription.disabled)
addFilters(subscription.filters);
}
function onSubscriptionRemoved(subscription)
{
FilterListener.setDirty(1);
if (!subscription.disabled)
- subscription.filters.forEach(removeFilter);
+ {
+ for (let text of subscription.filters)
+ removeFilter(Filter.fromText(text));
+ }
}
function onSubscriptionDisabled(subscription, newValue)
{
FilterListener.setDirty(1);
if (filterStorage.knownSubscriptions.has(subscription.url))
{
if (newValue == false)
+ {
addFilters(subscription.filters);
+ }
else
- subscription.filters.forEach(removeFilter);
+ {
+ for (let text of subscription.filters)
+ removeFilter(Filter.fromText(text));
+ }
}
}
function onSubscriptionUpdated(subscription, oldFilters)
{
FilterListener.setDirty(1);
if (!subscription.disabled &&
filterStorage.knownSubscriptions.has(subscription.url))
{
- oldFilters.forEach(removeFilter);
+ for (let text of oldFilters)
+ removeFilter(Filter.fromText(text));
+
addFilters(subscription.filters);
}
}
function onFilterHitCount(filter, newValue)
{
if (newValue == 0)
FilterListener.setDirty(0);
@@ -334,16 +347,18 @@
defaultMatcher.clear();
ElemHide.clear();
ElemHideEmulation.clear();
ElemHideExceptions.clear();
Snippets.clear();
for (let subscription of filterStorage.subscriptions())
{
if (!subscription.disabled)
- addFilters(subscription.filters);
+ addFilters(subscription.filters, subscription.filterObjects);
+
+ subscription.filterObjects = null;
}
}
function onSave()
{
isDirty = 0;
}
« no previous file with comments | « no previous file | lib/filterStorage.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld