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

Delta Between Two Patch Sets: lib/subscriptionInit.js

Issue 29827646: Issue 6783 - opt-in to anti circumvention filter list on upgrade (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Left Patch Set: Created July 12, 2018, 2:24 a.m.
Right Patch Set: Change the name of the preference key Created July 17, 2018, 2:29 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 | « lib/prefs.js ('k') | no next file » | 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 { 51 {
52 firstRun = FilterStorage.subscriptions.length == 0; 52 firstRun = FilterStorage.subscriptions.length == 0;
53 53
54 if (firstRun && (!FilterStorage.firstRun || Prefs.currentVersion)) 54 if (firstRun && (!FilterStorage.firstRun || Prefs.currentVersion))
55 reinitialized = true; 55 reinitialized = true;
56 56
57 Prefs.currentVersion = info.addonVersion; 57 Prefs.currentVersion = info.addonVersion;
58 } 58 }
59 59
60 /** 60 /**
61 * Determines whether to add the default ad blocking subscription. 61 * Determines whether to add the default ad blocking subscriptions.
62 * Returns true, if there are no filter subscriptions besides those 62 * Returns true, if there are no filter subscriptions besides those
63 * other subscriptions added automatically, and no custom filters. 63 * other subscriptions added automatically, and no custom filters.
64 * 64 *
65 * On first run, this logic should always result in true since there 65 * On first run, this logic should always result in true since there
66 * is no data and therefore no subscriptions. But it also causes the 66 * is no data and therefore no subscriptions. But it also causes the
67 * default ad blocking subscription to be added again after some 67 * default ad blocking subscriptions to be added again after some
68 * data corruption or misconfiguration. 68 * data corruption or misconfiguration.
69 * 69 *
70 * @return {boolean} 70 * @return {boolean}
71 */ 71 */
72 function shouldAddDefaultSubscription() 72 function shouldAddDefaultSubscriptions()
73 { 73 {
74 for (let subscription of FilterStorage.subscriptions) 74 for (let subscription of FilterStorage.subscriptions)
75 { 75 {
76 if (subscription instanceof DownloadableSubscription && 76 if (subscription instanceof DownloadableSubscription &&
77 subscription.url != Prefs.subscriptions_exceptionsurl && 77 subscription.url != Prefs.subscriptions_exceptionsurl &&
78 subscription.url != Prefs.subscriptions_antiadblockurl) 78 subscription.url != Prefs.subscriptions_antiadblockurl)
79 return false; 79 return false;
80 80
81 if (subscription instanceof SpecialSubscription && 81 if (subscription instanceof SpecialSubscription &&
82 subscription.filters.length > 0) 82 subscription.filters.length > 0)
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 if (supportsNotificationsWithButtons()) 203 if (supportsNotificationsWithButtons())
204 { 204 {
205 let antiAdblockSubscription = Subscription.fromURL( 205 let antiAdblockSubscription = Subscription.fromURL(
206 Prefs.subscriptions_antiadblockurl 206 Prefs.subscriptions_antiadblockurl
207 ); 207 );
208 antiAdblockSubscription.disabled = true; 208 antiAdblockSubscription.disabled = true;
209 subscriptions.push(antiAdblockSubscription); 209 subscriptions.push(antiAdblockSubscription);
210 } 210 }
211 } 211 }
212 212
213 // Add default ad blocking subscription (e.g. EasyList) 213 // Add default ad blocking subscriptions (e.g. EasyList, Anti-Circumvention)
214 // Ensure the Anti Circumvention is added on upgrade. 214 let addDefaultSubscription = shouldAddDefaultSubscriptions();
215 if (shouldAddDefaultSubscription() || !Prefs.subscriptions_checkedanticv) 215 if (addDefaultSubscription || !Prefs.subscriptions_addedanticv)
Manish Jethani 2018/07/12 07:54:27 But this will add an "ads" list as well. Shouldn't
kzar 2018/07/12 10:07:59 Yea, this logic doesn't look right. Perhaps split
hub 2018/07/12 17:14:09 This came to my mind before falling asleep. I'll f
216 { 216 {
217 return fetch("subscriptions.xml") 217 return fetch("subscriptions.xml")
218 .then(response => response.text()) 218 .then(response => response.text())
219 .then(text => 219 .then(text =>
220 { 220 {
221 let doc = new DOMParser().parseFromString(text, "application/xml"); 221 let doc = new DOMParser().parseFromString(text, "application/xml");
222 let nodes = doc.getElementsByTagName("subscription"); 222 let nodes = doc.getElementsByTagName("subscription");
223 223
224 let defaultSubscriptions = chooseFilterSubscriptions(nodes); 224 let defaultSubscriptions = chooseFilterSubscriptions(nodes);
225 if (defaultSubscriptions) 225 if (defaultSubscriptions)
226 { 226 {
227 for (let name in defaultSubscriptions) 227 for (let name in defaultSubscriptions)
228 { 228 {
229 let node = defaultSubscriptions[name]; 229 let node = defaultSubscriptions[name];
230 if (!node) 230 if (!node)
231 continue; 231 continue;
232 232
233 let url = node.getAttribute("url"); 233 let url = node.getAttribute("url");
234 if (url) 234 if (url)
235 { 235 {
236 // Make sure that we don't add Easylist again if we want
237 // to just add the Anti-Circumvention subscription.
238 let type = node.getAttribute("type");
239 if (!addDefaultSubscription && type != "circumvention")
240 continue;
241
236 let subscription = Subscription.fromURL(url); 242 let subscription = Subscription.fromURL(url);
237 subscription.disabled = false; 243 subscription.disabled = false;
238 subscription.title = node.getAttribute("title"); 244 subscription.title = node.getAttribute("title");
239 subscription.homepage = node.getAttribute("homepage"); 245 subscription.homepage = node.getAttribute("homepage");
240 subscription.type = node.getAttribute("type"); 246 subscription.type = type;
241 subscriptions.push(subscription); 247 subscriptions.push(subscription);
242 if (subscription.type == "circumvention") 248 if (subscription.type == "circumvention")
243 Prefs.subscriptions_checkedanticv = true; 249 Prefs.subscriptions_addedanticv = true;
244 } 250 }
245 } 251 }
246 } 252 }
247 253
248 return subscriptions; 254 return subscriptions;
249 }); 255 });
250 } 256 }
251 257
252 return subscriptions; 258 return subscriptions;
253 } 259 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 * 333 *
328 * @param {function} callback 334 * @param {function} callback
329 */ 335 */
330 exports.setSubscriptionsCallback = callback => 336 exports.setSubscriptionsCallback = callback =>
331 { 337 {
332 subscriptionsCallback = callback; 338 subscriptionsCallback = callback;
333 }; 339 };
334 340
335 // Exports for tests only 341 // Exports for tests only
336 exports.chooseFilterSubscriptions = chooseFilterSubscriptions; 342 exports.chooseFilterSubscriptions = chooseFilterSubscriptions;
LEFTRIGHT
« lib/prefs.js ('k') | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld