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: Created July 6, 2018, 3:18 p.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++)
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 (!allowSnippets &&
156 (subscription.type == "circumvention" ||
157 subscription instanceof SpecialSubscription))
158 {
159 allowSnippets = true;
160 break;
161 }
149 } 162 }
150 } 163 }
151 if (!hasEnabled) 164 if (!hasEnabled)
152 return; 165 return;
153 166
154 if (filter instanceof RegExpFilter) 167 if (filter instanceof RegExpFilter)
155 defaultMatcher.add(filter); 168 defaultMatcher.add(filter);
156 else if (filter instanceof ElemHideBase) 169 else if (filter instanceof ElemHideBase)
157 { 170 {
158 if (filter instanceof ElemHideEmulationFilter) 171 if (filter instanceof ElemHideEmulationFilter)
159 ElemHideEmulation.add(filter); 172 ElemHideEmulation.add(filter);
160 else 173 else
161 ElemHide.add(filter); 174 ElemHide.add(filter);
162 } 175 }
163 else if (filter instanceof SnippetFilter) 176 else if (allowSnippets && filter instanceof SnippetFilter)
164 Snippets.add(filter); 177 Snippets.add(filter);
165 } 178 }
166 179
167 /** 180 /**
168 * Notifies Matcher instances or ElemHide object about removal of a filter 181 * Notifies Matcher instances or ElemHide object about removal of a filter
169 * if necessary. 182 * if necessary.
170 * @param {Filter} filter filter that has been removed 183 * @param {Filter} filter filter that has been removed
171 */ 184 */
172 function removeFilter(filter) 185 function removeFilter(filter)
173 { 186 {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 { 337 {
325 if (!subscription.disabled) 338 if (!subscription.disabled)
326 addFilters(subscription.filters); 339 addFilters(subscription.filters);
327 } 340 }
328 } 341 }
329 342
330 function onSave() 343 function onSave()
331 { 344 {
332 isDirty = 0; 345 isDirty = 0;
333 } 346 }
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