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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/filterListener.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 16 matching lines...) Expand all
27 27
28 const {FilterStorage} = require("./filterStorage"); 28 const {FilterStorage} = require("./filterStorage");
29 const {FilterNotifier} = require("./filterNotifier"); 29 const {FilterNotifier} = require("./filterNotifier");
30 const {ElemHide} = require("./elemHide"); 30 const {ElemHide} = require("./elemHide");
31 const {ElemHideEmulation} = require("./elemHideEmulation"); 31 const {ElemHideEmulation} = require("./elemHideEmulation");
32 const {Snippets} = require("./snippets"); 32 const {Snippets} = require("./snippets");
33 const {defaultMatcher} = require("./matcher"); 33 const {defaultMatcher} = require("./matcher");
34 const {ActiveFilter, RegExpFilter, 34 const {ActiveFilter, RegExpFilter,
35 ElemHideBase, ElemHideEmulationFilter, 35 ElemHideBase, ElemHideEmulationFilter,
36 SnippetFilter} = require("./filterClasses"); 36 SnippetFilter} = require("./filterClasses");
37 const {SpecialSubscription} = require("./subscriptionClasses");
37 const {Prefs} = require("prefs"); 38 const {Prefs} = require("prefs");
38 39
39 /** 40 /**
40 * Increases on filter changes, filters will be saved if it exceeds 1. 41 * Increases on filter changes, filters will be saved if it exceeds 1.
41 * @type {number} 42 * @type {number}
42 */ 43 */
43 let isDirty = 0; 44 let isDirty = 0;
44 45
45 /** 46 /**
46 * This object can be used to change properties of the filter change listeners. 47 * This object can be used to change properties of the filter change listeners.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 * Notifies Matcher instances or ElemHide object about a new filter 134 * Notifies Matcher instances or ElemHide object about a new filter
134 * if necessary. 135 * if necessary.
135 * @param {Filter} filter filter that has been added 136 * @param {Filter} filter filter that has been added
136 */ 137 */
137 function addFilter(filter) 138 function addFilter(filter)
138 { 139 {
139 if (!(filter instanceof ActiveFilter) || filter.disabled) 140 if (!(filter instanceof ActiveFilter) || filter.disabled)
140 return; 141 return;
141 142
142 let hasEnabled = false; 143 let hasEnabled = false;
144 let allowSnippets = false;
143 for (let i = 0; i < filter.subscriptions.length; i++) 145 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.
144 { 146 {
145 if (!filter.subscriptions[i].disabled) 147 let subscription = filter.subscriptions[i];
148
149 if (!subscription.disabled)
146 { 150 {
147 hasEnabled = true; 151 hasEnabled = true;
148 break; 152
153 // Allow snippets to be executed only by the circumvention lists or the
154 // user's own filters.
155 if (subscription.type == "circumvention" ||
156 subscription instanceof SpecialSubscription)
157 {
158 allowSnippets = true;
159 break;
160 }
149 } 161 }
150 } 162 }
151 if (!hasEnabled) 163 if (!hasEnabled)
152 return; 164 return;
153 165
154 if (filter instanceof RegExpFilter) 166 if (filter instanceof RegExpFilter)
155 defaultMatcher.add(filter); 167 defaultMatcher.add(filter);
156 else if (filter instanceof ElemHideBase) 168 else if (filter instanceof ElemHideBase)
157 { 169 {
158 if (filter instanceof ElemHideEmulationFilter) 170 if (filter instanceof ElemHideEmulationFilter)
159 ElemHideEmulation.add(filter); 171 ElemHideEmulation.add(filter);
160 else 172 else
161 ElemHide.add(filter); 173 ElemHide.add(filter);
162 } 174 }
163 else if (filter instanceof SnippetFilter) 175 else if (allowSnippets && filter instanceof SnippetFilter)
164 Snippets.add(filter); 176 Snippets.add(filter);
165 } 177 }
166 178
167 /** 179 /**
168 * Notifies Matcher instances or ElemHide object about removal of a filter 180 * Notifies Matcher instances or ElemHide object about removal of a filter
169 * if necessary. 181 * if necessary.
170 * @param {Filter} filter filter that has been removed 182 * @param {Filter} filter filter that has been removed
171 */ 183 */
172 function removeFilter(filter) 184 function removeFilter(filter)
173 { 185 {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 { 336 {
325 if (!subscription.disabled) 337 if (!subscription.disabled)
326 addFilters(subscription.filters); 338 addFilters(subscription.filters);
327 } 339 }
328 } 340 }
329 341
330 function onSave() 342 function onSave()
331 { 343 {
332 isDirty = 0; 344 isDirty = 0;
333 } 345 }
OLDNEW
« 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