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

Side by Side Diff: lib/subscriptionInit.js

Issue 29907589: Issue 7054 - Update the adblockpluscore dependency to 5cb695da5a40, adblockplusui to f86abf2efdfd (Closed)
Patch Set: Address PS12 Comment Created Jan. 8, 2019, 1:02 a.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/requestBlocker.js ('k') | lib/whitelisting.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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /** @module subscriptionInit */ 18 /** @module subscriptionInit */
19 19
20 "use strict"; 20 "use strict";
21 21
22 const {Subscription, 22 const {Subscription,
23 DownloadableSubscription, 23 DownloadableSubscription,
24 SpecialSubscription} = 24 SpecialSubscription} =
25 require("../adblockpluscore/lib/subscriptionClasses"); 25 require("../adblockpluscore/lib/subscriptionClasses");
26 const {FilterStorage} = require("../adblockpluscore/lib/filterStorage"); 26 const {filterStorage} = require("../adblockpluscore/lib/filterStorage");
27 const {filterNotifier} = require("../adblockpluscore/lib/filterNotifier"); 27 const {filterNotifier} = require("../adblockpluscore/lib/filterNotifier");
28 const info = require("info"); 28 const info = require("info");
29 const {Prefs} = require("./prefs"); 29 const {Prefs} = require("./prefs");
30 const {Synchronizer} = require("../adblockpluscore/lib/synchronizer"); 30 const {Synchronizer} = require("../adblockpluscore/lib/synchronizer");
31 const {Utils} = require("./utils"); 31 const {Utils} = require("./utils");
32 const {initNotifications} = require("./notificationHelper"); 32 const {initNotifications} = require("./notificationHelper");
33 const {updatesVersion} = require("../adblockplusui/lib/prefs"); 33 const {updatesVersion} = require("../adblockplusui/lib/prefs");
34 34
35 let firstRun; 35 let firstRun;
36 let subscriptionsCallback = null; 36 let subscriptionsCallback = null;
37 let reinitialized = false; 37 let reinitialized = false;
38 let dataCorrupted = false; 38 let dataCorrupted = false;
39 39
40 /** 40 /**
41 * If there aren't any filters, the default subscriptions are added. 41 * If there aren't any filters, the default subscriptions are added.
42 * However, if patterns.ini already did exist and/or any preference 42 * However, if patterns.ini already did exist and/or any preference
43 * is set to a non-default value, this indicates that this isn't the 43 * is set to a non-default value, this indicates that this isn't the
44 * first run, but something went wrong. 44 * first run, but something went wrong.
45 * 45 *
46 * This function detects the first run, and makes sure that the user 46 * This function detects the first run, and makes sure that the user
47 * gets notified (on the first run page) if the data appears incomplete 47 * gets notified (on the first run page) if the data appears incomplete
48 * and therefore will be reinitialized. 48 * and therefore will be reinitialized.
49 */ 49 */
50 function detectFirstRun() 50 function detectFirstRun()
51 { 51 {
52 firstRun = FilterStorage.subscriptions.length == 0; 52 firstRun = filterStorage.subscriptionCount == 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 subscriptions. 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 subscriptions 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 shouldAddDefaultSubscriptions() 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 subscription.type != "circumvention") 79 subscription.type != "circumvention")
80 return false; 80 return false;
81 81
82 if (subscription instanceof SpecialSubscription && 82 if (subscription instanceof SpecialSubscription &&
83 subscription.filters.length > 0) 83 subscription.filterCount > 0)
84 return false; 84 return false;
85 } 85 }
86 86
87 return true; 87 return true;
88 } 88 }
89 89
90 /** 90 /**
91 * @typedef {object} DefaultSubscriptions 91 * @typedef {object} DefaultSubscriptions
92 * @property {?Element} ads 92 * @property {?Element} ads
93 * @property {?Element} circumvention 93 * @property {?Element} circumvention
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 return subscriptions; 259 return subscriptions;
260 } 260 }
261 261
262 function addSubscriptionsAndNotifyUser(subscriptions) 262 function addSubscriptionsAndNotifyUser(subscriptions)
263 { 263 {
264 if (subscriptionsCallback) 264 if (subscriptionsCallback)
265 subscriptions = subscriptionsCallback(subscriptions); 265 subscriptions = subscriptionsCallback(subscriptions);
266 266
267 for (let subscription of subscriptions) 267 for (let subscription of subscriptions)
268 { 268 {
269 FilterStorage.addSubscription(subscription); 269 filterStorage.addSubscription(subscription);
270 if (subscription instanceof DownloadableSubscription && 270 if (subscription instanceof DownloadableSubscription &&
271 !subscription.lastDownload) 271 !subscription.lastDownload)
272 Synchronizer.execute(subscription); 272 Synchronizer.execute(subscription);
273 } 273 }
274 274
275 // Show first run page or the updates page. The latter is only shown 275 // Show first run page or the updates page. The latter is only shown
276 // on Chromium (since the current updates page announces features that 276 // on Chromium (since the current updates page announces features that
277 // aren't new to Firefox users), and only if this version of the 277 // aren't new to Firefox users), and only if this version of the
278 // updates page hasn't been shown yet. 278 // updates page hasn't been shown yet.
279 if (firstRun || info.platform == "chromium" && 279 if (firstRun || info.platform == "chromium" &&
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 * 334 *
335 * @param {function} callback 335 * @param {function} callback
336 */ 336 */
337 exports.setSubscriptionsCallback = callback => 337 exports.setSubscriptionsCallback = callback =>
338 { 338 {
339 subscriptionsCallback = callback; 339 subscriptionsCallback = callback;
340 }; 340 };
341 341
342 // Exports for tests only 342 // Exports for tests only
343 exports.chooseFilterSubscriptions = chooseFilterSubscriptions; 343 exports.chooseFilterSubscriptions = chooseFilterSubscriptions;
OLDNEW
« no previous file with comments | « lib/requestBlocker.js ('k') | lib/whitelisting.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld