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

Side by Side Diff: lib/filterListener.js

Issue 29783618: Issue 6665 - Split out element hiding exceptions into their own module (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Add lib/elemHideExceptions.js Created Aug. 7, 2018, 2: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 | « lib/elemHideExceptions.js ('k') | test/elemHide.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 11 matching lines...) Expand all
22 * instances and ElemHide. 22 * instances and ElemHide.
23 */ 23 */
24 24
25 const {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); 25 const {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
26 const {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {}); 26 const {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {});
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 {ElemHideExceptions} = require("./elemHideExceptions");
32 const {Snippets} = require("./snippets"); 33 const {Snippets} = require("./snippets");
33 const {defaultMatcher} = require("./matcher"); 34 const {defaultMatcher} = require("./matcher");
34 const {ActiveFilter, RegExpFilter, 35 const {ActiveFilter, RegExpFilter,
35 ElemHideBase, ElemHideEmulationFilter, 36 ElemHideBase, ElemHideFilter, ElemHideEmulationFilter,
36 SnippetFilter} = require("./filterClasses"); 37 SnippetFilter} = require("./filterClasses");
37 const {SpecialSubscription} = require("./subscriptionClasses"); 38 const {SpecialSubscription} = require("./subscriptionClasses");
38 const {Prefs} = require("prefs"); 39 const {Prefs} = require("prefs");
39 40
40 /** 41 /**
41 * Increases on filter changes, filters will be saved if it exceeds 1. 42 * Increases on filter changes, filters will be saved if it exceeds 1.
42 * @type {number} 43 * @type {number}
43 */ 44 */
44 let isDirty = 0; 45 let isDirty = 0;
45 46
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 } 161 }
161 } 162 }
162 } 163 }
163 if (!hasEnabled) 164 if (!hasEnabled)
164 return; 165 return;
165 166
166 if (filter instanceof RegExpFilter) 167 if (filter instanceof RegExpFilter)
167 defaultMatcher.add(filter); 168 defaultMatcher.add(filter);
168 else if (filter instanceof ElemHideBase) 169 else if (filter instanceof ElemHideBase)
169 { 170 {
170 if (filter instanceof ElemHideEmulationFilter) 171 if (filter instanceof ElemHideFilter)
172 ElemHide.add(filter);
173 else if (filter instanceof ElemHideEmulationFilter)
171 ElemHideEmulation.add(filter); 174 ElemHideEmulation.add(filter);
172 else 175 else
173 ElemHide.add(filter); 176 ElemHideExceptions.add(filter);
174 } 177 }
175 else if (allowSnippets && filter instanceof SnippetFilter) 178 else if (allowSnippets && filter instanceof SnippetFilter)
176 Snippets.add(filter); 179 Snippets.add(filter);
177 } 180 }
178 181
179 /** 182 /**
180 * Notifies Matcher instances or ElemHide object about removal of a filter 183 * Notifies Matcher instances or ElemHide object about removal of a filter
181 * if necessary. 184 * if necessary.
182 * @param {Filter} filter filter that has been removed 185 * @param {Filter} filter filter that has been removed
183 */ 186 */
(...skipping 14 matching lines...) Expand all
198 } 201 }
199 } 202 }
200 if (hasEnabled) 203 if (hasEnabled)
201 return; 204 return;
202 } 205 }
203 206
204 if (filter instanceof RegExpFilter) 207 if (filter instanceof RegExpFilter)
205 defaultMatcher.remove(filter); 208 defaultMatcher.remove(filter);
206 else if (filter instanceof ElemHideBase) 209 else if (filter instanceof ElemHideBase)
207 { 210 {
208 if (filter instanceof ElemHideEmulationFilter) 211 if (filter instanceof ElemHideFilter)
212 ElemHide.remove(filter);
213 else if (filter instanceof ElemHideEmulationFilter)
209 ElemHideEmulation.remove(filter); 214 ElemHideEmulation.remove(filter);
210 else 215 else
211 ElemHide.remove(filter); 216 ElemHideExceptions.remove(filter);
212 } 217 }
213 else if (filter instanceof SnippetFilter) 218 else if (filter instanceof SnippetFilter)
214 Snippets.remove(filter); 219 Snippets.remove(filter);
215 } 220 }
216 221
217 const primes = [101, 109, 131, 149, 163, 179, 193, 211, 229, 241]; 222 const primes = [101, 109, 131, 149, 163, 179, 193, 211, 229, 241];
218 223
219 function addFilters(filters) 224 function addFilters(filters)
220 { 225 {
221 // We add filters using pseudo-random ordering. Reason is that ElemHide will 226 // We add filters using pseudo-random ordering. Reason is that ElemHide will
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 FilterListener.setDirty(1); 329 FilterListener.setDirty(1);
325 } 330 }
326 331
327 function onLoad() 332 function onLoad()
328 { 333 {
329 isDirty = 0; 334 isDirty = 0;
330 335
331 defaultMatcher.clear(); 336 defaultMatcher.clear();
332 ElemHide.clear(); 337 ElemHide.clear();
333 ElemHideEmulation.clear(); 338 ElemHideEmulation.clear();
339 ElemHideExceptions.clear();
334 Snippets.clear(); 340 Snippets.clear();
335 for (let subscription of FilterStorage.subscriptions) 341 for (let subscription of FilterStorage.subscriptions)
336 { 342 {
337 if (!subscription.disabled) 343 if (!subscription.disabled)
338 addFilters(subscription.filters); 344 addFilters(subscription.filters);
339 } 345 }
340 } 346 }
341 347
342 function onSave() 348 function onSave()
343 { 349 {
344 isDirty = 0; 350 isDirty = 0;
345 } 351 }
OLDNEW
« no previous file with comments | « lib/elemHideExceptions.js ('k') | test/elemHide.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld