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: Minor changes Created Nov. 21, 2018, 5:23 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 filter = Filter.fromText(subscription.filterTextAt(current));
244 filter.addSubscription(subscription);
245 addFilter(filter);
246 }
247 }
248
249 function onSubscriptionAdded(subscription) 220 function onSubscriptionAdded(subscription)
250 { 221 {
251 FilterListener.setDirty(1); 222 FilterListener.setDirty(1);
252 223
253 if (!subscription.disabled) 224 if (!subscription.disabled)
254 addSubscriptionFilters(subscription); 225 {
226 for (let text of subscription.filterText())
227 addFilter(Filter.fromText(text));
228 }
255 } 229 }
256 230
257 function onSubscriptionRemoved(subscription) 231 function onSubscriptionRemoved(subscription)
258 { 232 {
259 FilterListener.setDirty(1); 233 FilterListener.setDirty(1);
260 234
261 if (!subscription.disabled) 235 if (!subscription.disabled)
262 { 236 {
263 for (let text of subscription.filterText()) 237 for (let text of subscription.filterText())
264 removeFilter(Filter.fromText(text)); 238 removeFilter(Filter.fromText(text));
hub 2018/11/30 01:18:07 here remove filter takes longer since we have to g
Manish Jethani 2018/11/30 07:28:05 Yes, this is a cost of this change, and by itself
hub 2019/01/03 20:22:48 Acknowledged.
265 } 239 }
266 } 240 }
267 241
268 function onSubscriptionDisabled(subscription, newValue) 242 function onSubscriptionDisabled(subscription, newValue)
269 { 243 {
270 FilterListener.setDirty(1); 244 FilterListener.setDirty(1);
271 245
272 if (filterStorage.knownSubscriptions.has(subscription.url)) 246 if (filterStorage.knownSubscriptions.has(subscription.url))
273 { 247 {
274 if (newValue == false) 248 if (newValue == false)
275 { 249 {
276 addSubscriptionFilters(subscription); 250 for (let text of subscription.filterText())
251 addFilter(Filter.fromText(text));
277 } 252 }
278 else 253 else
279 { 254 {
280 for (let text of subscription.filterText()) 255 for (let text of subscription.filterText())
281 removeFilter(Filter.fromText(text)); 256 removeFilter(Filter.fromText(text));
hub 2018/11/30 01:18:07 ...so does disable subscription.
Manish Jethani 2018/11/30 07:28:05 See above.
282 } 257 }
283 } 258 }
284 } 259 }
285 260
286 function onSubscriptionUpdated(subscription, oldFilterText) 261 function onSubscriptionUpdated(subscription, oldFilterText)
287 { 262 {
288 FilterListener.setDirty(1); 263 FilterListener.setDirty(1);
289 264
290 if (!subscription.disabled && 265 if (!subscription.disabled &&
291 filterStorage.knownSubscriptions.has(subscription.url)) 266 filterStorage.knownSubscriptions.has(subscription.url))
292 { 267 {
293 for (let text of oldFilterText) 268 for (let text of oldFilterText)
294 removeFilter(Filter.fromText(text)); 269 removeFilter(Filter.fromText(text));
295 270
296 addSubscriptionFilters(subscription); 271 for (let text of subscription.filterText())
272 addFilter(Filter.fromText(text));
297 } 273 }
298 } 274 }
299 275
300 function onFilterHitCount(filter, newValue) 276 function onFilterHitCount(filter, newValue)
301 { 277 {
302 if (newValue == 0) 278 if (newValue == 0)
303 FilterListener.setDirty(0); 279 FilterListener.setDirty(0);
304 else 280 else
305 FilterListener.setDirty(0.002); 281 FilterListener.setDirty(0.002);
306 } 282 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 323
348 defaultMatcher.clear(); 324 defaultMatcher.clear();
349 ElemHide.clear(); 325 ElemHide.clear();
350 ElemHideEmulation.clear(); 326 ElemHideEmulation.clear();
351 ElemHideExceptions.clear(); 327 ElemHideExceptions.clear();
352 Snippets.clear(); 328 Snippets.clear();
353 329
354 for (let subscription of filterStorage.subscriptions()) 330 for (let subscription of filterStorage.subscriptions())
355 { 331 {
356 if (!subscription.disabled) 332 if (!subscription.disabled)
357 addSubscriptionFilters(subscription); 333 {
334 for (let text of subscription.filterText())
335 addFilter(Filter.fromText(text));
336 }
358 } 337 }
359 } 338 }
360 339
361 function onSave() 340 function onSave()
362 { 341 {
363 isDirty = 0; 342 isDirty = 0;
364 } 343 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld