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

Delta Between Two Patch Sets: lib/filterListener.js

Issue 29737558: Issue 6538, 6781 - Implement support for snippet filters (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Check for null and blank string instead Created April 3, 2018, 10:46 a.m.
Right Patch Set: Improve comment formatting Created July 11, 2018, 1:02 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
LEFTRIGHT
(no file at all)
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 {Snippets} = require("./snippets");
32 const {defaultMatcher} = require("./matcher"); 33 const {defaultMatcher} = require("./matcher");
33 const {ActiveFilter, RegExpFilter, 34 const {ActiveFilter, RegExpFilter,
34 ElemHideBase, ElemHideEmulationFilter} = require("./filterClasses"); 35 ElemHideBase, ElemHideEmulationFilter,
36 SnippetFilter} = require("./filterClasses");
35 const {Prefs} = require("prefs"); 37 const {Prefs} = require("prefs");
36 38
37 /** 39 /**
38 * Increases on filter changes, filters will be saved if it exceeds 1. 40 * Increases on filter changes, filters will be saved if it exceeds 1.
39 * @type {number} 41 * @type {number}
40 */ 42 */
41 let isDirty = 0; 43 let isDirty = 0;
42 44
43 /** 45 /**
44 * This object can be used to change properties of the filter change listeners. 46 * This object can be used to change properties of the filter change listeners.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 153
152 if (filter instanceof RegExpFilter) 154 if (filter instanceof RegExpFilter)
153 defaultMatcher.add(filter); 155 defaultMatcher.add(filter);
154 else if (filter instanceof ElemHideBase) 156 else if (filter instanceof ElemHideBase)
155 { 157 {
156 if (filter instanceof ElemHideEmulationFilter) 158 if (filter instanceof ElemHideEmulationFilter)
157 ElemHideEmulation.add(filter); 159 ElemHideEmulation.add(filter);
158 else 160 else
159 ElemHide.add(filter); 161 ElemHide.add(filter);
160 } 162 }
163 else if (filter instanceof SnippetFilter)
164 Snippets.add(filter);
161 } 165 }
162 166
163 /** 167 /**
164 * Notifies Matcher instances or ElemHide object about removal of a filter 168 * Notifies Matcher instances or ElemHide object about removal of a filter
165 * if necessary. 169 * if necessary.
166 * @param {Filter} filter filter that has been removed 170 * @param {Filter} filter filter that has been removed
167 */ 171 */
168 function removeFilter(filter) 172 function removeFilter(filter)
169 { 173 {
170 if (!(filter instanceof ActiveFilter)) 174 if (!(filter instanceof ActiveFilter))
(...skipping 16 matching lines...) Expand all
187 191
188 if (filter instanceof RegExpFilter) 192 if (filter instanceof RegExpFilter)
189 defaultMatcher.remove(filter); 193 defaultMatcher.remove(filter);
190 else if (filter instanceof ElemHideBase) 194 else if (filter instanceof ElemHideBase)
191 { 195 {
192 if (filter instanceof ElemHideEmulationFilter) 196 if (filter instanceof ElemHideEmulationFilter)
193 ElemHideEmulation.remove(filter); 197 ElemHideEmulation.remove(filter);
194 else 198 else
195 ElemHide.remove(filter); 199 ElemHide.remove(filter);
196 } 200 }
201 else if (filter instanceof SnippetFilter)
202 Snippets.remove(filter);
197 } 203 }
198 204
199 const primes = [101, 109, 131, 149, 163, 179, 193, 211, 229, 241]; 205 const primes = [101, 109, 131, 149, 163, 179, 193, 211, 229, 241];
200 206
201 function addFilters(filters) 207 function addFilters(filters)
202 { 208 {
203 // We add filters using pseudo-random ordering. Reason is that ElemHide will 209 // We add filters using pseudo-random ordering. Reason is that ElemHide will
204 // assign consecutive filter IDs that might be visible to the website. The 210 // assign consecutive filter IDs that might be visible to the website. The
205 // randomization makes sure that no conclusion can be made about the actual 211 // randomization makes sure that no conclusion can be made about the actual
206 // filters applying there. We have ten prime numbers to use as iteration step, 212 // filters applying there. We have ten prime numbers to use as iteration step,
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 FilterListener.setDirty(1); 312 FilterListener.setDirty(1);
307 } 313 }
308 314
309 function onLoad() 315 function onLoad()
310 { 316 {
311 isDirty = 0; 317 isDirty = 0;
312 318
313 defaultMatcher.clear(); 319 defaultMatcher.clear();
314 ElemHide.clear(); 320 ElemHide.clear();
315 ElemHideEmulation.clear(); 321 ElemHideEmulation.clear();
322 Snippets.clear();
316 for (let subscription of FilterStorage.subscriptions) 323 for (let subscription of FilterStorage.subscriptions)
317 { 324 {
318 if (!subscription.disabled) 325 if (!subscription.disabled)
319 addFilters(subscription.filters); 326 addFilters(subscription.filters);
320 } 327 }
321 } 328 }
322 329
323 function onSave() 330 function onSave()
324 { 331 {
325 isDirty = 0; 332 isDirty = 0;
326 } 333 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld