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

Unified Diff: lib/filterListener.js

Issue 30013628: Issue 7029 - Remove subscriptions property of Filter object (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Feb. 24, 2019, 1:30 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
Index: lib/filterListener.js
===================================================================
--- a/lib/filterListener.js
+++ b/lib/filterListener.js
@@ -129,25 +129,28 @@
});
}
init();
/**
* Notifies Matcher instances or ElemHide object about a new filter
* if necessary.
* @param {Filter} filter filter that has been added
+ * @param {?Array.<Subscription>} [subscriptions] subscriptions to which the
Manish Jethani 2019/02/26 12:29:56 A filter needs only _one_ enabled subscription for
+ * filter belongs
*/
-function addFilter(filter)
+function addFilter(filter, subscriptions = null)
{
if (!(filter instanceof ActiveFilter) || filter.disabled)
return;
let hasEnabled = false;
let allowSnippets = false;
- for (let subscription of filter.subscriptions())
+ for (let subscription of subscriptions ||
+ filterStorage.subscriptions(filter.text))
{
if (!subscription.disabled)
{
hasEnabled = true;
// Allow snippets to be executed only by the circumvention lists or the
// user's own filters.
if (subscription.type == "circumvention" ||
@@ -185,17 +188,17 @@
function removeFilter(filter)
{
if (!(filter instanceof ActiveFilter))
return;
if (!filter.disabled)
{
let hasEnabled = false;
- for (let subscription of filter.subscriptions())
+ for (let subscription of filterStorage.subscriptions(filter.text))
{
if (!subscription.disabled)
{
hasEnabled = true;
break;
}
}
if (hasEnabled)
@@ -219,17 +222,17 @@
function onSubscriptionAdded(subscription)
{
FilterListener.setDirty(1);
if (!subscription.disabled)
{
for (let text of subscription.filterText())
- addFilter(Filter.fromText(text));
+ addFilter(Filter.fromText(text), [subscription]);
}
}
function onSubscriptionRemoved(subscription)
{
FilterListener.setDirty(1);
if (!subscription.disabled)
@@ -243,17 +246,17 @@
{
FilterListener.setDirty(1);
if (filterStorage.knownSubscriptions.has(subscription.url))
{
if (newValue == false)
{
for (let text of subscription.filterText())
- addFilter(Filter.fromText(text));
+ addFilter(Filter.fromText(text), [subscription]);
}
else
{
for (let text of subscription.filterText())
removeFilter(Filter.fromText(text));
}
}
}
@@ -264,17 +267,17 @@
if (!subscription.disabled &&
filterStorage.knownSubscriptions.has(subscription.url))
{
for (let text of oldFilterText)
removeFilter(Filter.fromText(text));
for (let text of subscription.filterText())
- addFilter(Filter.fromText(text));
+ addFilter(Filter.fromText(text), [subscription]);
}
}
function onFilterHitCount(filter, newValue)
{
if (newValue == 0)
FilterListener.setDirty(0);
else
@@ -327,17 +330,17 @@
ElemHideExceptions.clear();
Snippets.clear();
for (let subscription of filterStorage.subscriptions())
{
if (!subscription.disabled)
{
for (let text of subscription.filterText())
- addFilter(Filter.fromText(text));
+ addFilter(Filter.fromText(text), [subscription]);
}
}
}
function onSave()
{
isDirty = 0;
}
« no previous file with comments | « lib/filterClasses.js ('k') | lib/filterStorage.js » ('j') | lib/filterStorage.js » ('J')

Powered by Google App Engine
This is Rietveld