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

Delta Between Two Patch Sets: lib/filterListener.js

Issue 29946572: Issue 7094 - Keep subscription filters by text only (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Created Nov. 19, 2018, 2:08 a.m.
Right Patch Set: Rebase Created Feb. 16, 2019, 3:10 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | lib/filterStorage.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 ElemHide.remove(filter); 210 ElemHide.remove(filter);
211 else if (filter instanceof ElemHideEmulationFilter) 211 else if (filter instanceof ElemHideEmulationFilter)
212 ElemHideEmulation.remove(filter); 212 ElemHideEmulation.remove(filter);
213 else 213 else
214 ElemHideExceptions.remove(filter); 214 ElemHideExceptions.remove(filter);
215 } 215 }
216 else if (filter instanceof SnippetFilter) 216 else if (filter instanceof SnippetFilter)
217 Snippets.remove(filter); 217 Snippets.remove(filter);
218 } 218 }
219 219
220 const primes = [101, 109, 131, 149, 163, 179, 193, 211, 229, 241];
221
222 function addSubscriptionFilters(subscription)
223 {
224 // We add filters using pseudo-random ordering. Reason is that ElemHide will
225 // assign consecutive filter IDs that might be visible to the website. The
226 // randomization makes sure that no conclusion can be made about the actual
227 // filters applying there. We have ten prime numbers to use as iteration step,
228 // any of those can be chosen as long as the array length isn't divisible by
229 // it.
230 let len = subscription.filterCount;
231 if (!len)
232 return;
233
234 let current = (Math.random() * len) | 0;
235 let step;
236 do
237 {
238 step = primes[(Math.random() * primes.length) | 0];
239 } while (len % step == 0);
240
241 for (let i = 0; i < len; i++, current = (current + step) % len)
242 {
243 let text = subscription.filterTextAt(current);
244 addFilter(Filter.fromText(text));
245 }
246 }
247
248 function onSubscriptionAdded(subscription) 220 function onSubscriptionAdded(subscription)
249 { 221 {
250 FilterListener.setDirty(1); 222 FilterListener.setDirty(1);
251 223
252 if (!subscription.disabled) 224 if (!subscription.disabled)
253 addSubscriptionFilters(subscription); 225 {
226 for (let text of subscription.filterText())
227 addFilter(Filter.fromText(text));
228 }
254 } 229 }
255 230
256 function onSubscriptionRemoved(subscription) 231 function onSubscriptionRemoved(subscription)
257 { 232 {
258 FilterListener.setDirty(1); 233 FilterListener.setDirty(1);
259 234
260 if (!subscription.disabled) 235 if (!subscription.disabled)
261 { 236 {
262 for (let text of subscription.filterText()) 237 for (let text of subscription.filterText())
263 removeFilter(Filter.fromText(text)); 238 removeFilter(Filter.fromText(text));
264 } 239 }
265 } 240 }
266 241
267 function onSubscriptionDisabled(subscription, newValue) 242 function onSubscriptionDisabled(subscription, newValue)
268 { 243 {
269 FilterListener.setDirty(1); 244 FilterListener.setDirty(1);
270 245
271 if (filterStorage.knownSubscriptions.has(subscription.url)) 246 if (filterStorage.knownSubscriptions.has(subscription.url))
272 { 247 {
273 if (newValue == false) 248 if (newValue == false)
274 { 249 {
275 addSubscriptionFilters(subscription); 250 for (let text of subscription.filterText())
251 addFilter(Filter.fromText(text));
276 } 252 }
277 else 253 else
278 { 254 {
279 for (let text of subscription.filterText()) 255 for (let text of subscription.filterText())
280 removeFilter(Filter.fromText(text)); 256 removeFilter(Filter.fromText(text));
281 } 257 }
282 } 258 }
283 } 259 }
284 260
285 function onSubscriptionUpdated(subscription, oldFilterText) 261 function onSubscriptionUpdated(subscription, oldFilterText)
286 { 262 {
287 FilterListener.setDirty(1); 263 FilterListener.setDirty(1);
288 264
289 if (!subscription.disabled && 265 if (!subscription.disabled &&
290 filterStorage.knownSubscriptions.has(subscription.url)) 266 filterStorage.knownSubscriptions.has(subscription.url))
291 { 267 {
292 for (let text of oldFilterText) 268 for (let text of oldFilterText)
293 removeFilter(Filter.fromText(text)); 269 removeFilter(Filter.fromText(text));
294 270
295 addSubscriptionFilters(subscription); 271 for (let text of subscription.filterText())
272 addFilter(Filter.fromText(text));
296 } 273 }
297 } 274 }
298 275
299 function onFilterHitCount(filter, newValue) 276 function onFilterHitCount(filter, newValue)
300 { 277 {
301 if (newValue == 0) 278 if (newValue == 0)
302 FilterListener.setDirty(0); 279 FilterListener.setDirty(0);
303 else 280 else
304 FilterListener.setDirty(0.002); 281 FilterListener.setDirty(0.002);
305 } 282 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 323
347 defaultMatcher.clear(); 324 defaultMatcher.clear();
348 ElemHide.clear(); 325 ElemHide.clear();
349 ElemHideEmulation.clear(); 326 ElemHideEmulation.clear();
350 ElemHideExceptions.clear(); 327 ElemHideExceptions.clear();
351 Snippets.clear(); 328 Snippets.clear();
352 329
353 for (let subscription of filterStorage.subscriptions()) 330 for (let subscription of filterStorage.subscriptions())
354 { 331 {
355 if (!subscription.disabled) 332 if (!subscription.disabled)
356 addSubscriptionFilters(subscription); 333 {
334 for (let text of subscription.filterText())
335 addFilter(Filter.fromText(text));
336 }
357 } 337 }
358 } 338 }
359 339
360 function onSave() 340 function onSave()
361 { 341 {
362 isDirty = 0; 342 isDirty = 0;
363 } 343 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld