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

Side by Side Diff: lib/notification.js

Issue 29548719: Issue 5728 - Replace Services.vc.compare (Closed)
Patch Set: Addressed comments Created Sept. 23, 2017, 12:07 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 | « no previous file | test/_common.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 "use strict"; 18 "use strict";
19 19
20 /** 20 /**
21 * @fileOverview Handles notifications. 21 * @fileOverview Handles notifications.
22 */ 22 */
23 23
24 const {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
25
26 const {Prefs} = require("prefs"); 24 const {Prefs} = require("prefs");
27 const {Downloader, Downloadable, 25 const {Downloader, Downloadable,
28 MILLIS_IN_MINUTE, MILLIS_IN_HOUR, MILLIS_IN_DAY} = require("downloader"); 26 MILLIS_IN_MINUTE, MILLIS_IN_HOUR, MILLIS_IN_DAY} = require("downloader");
29 const {Utils} = require("utils"); 27 const {Utils} = require("utils");
30 const {Matcher, defaultMatcher} = require("matcher"); 28 const {Matcher, defaultMatcher} = require("matcher");
31 const {Filter, RegExpFilter, WhitelistFilter} = require("filterClasses"); 29 const {Filter, RegExpFilter, WhitelistFilter} = require("filterClasses");
32 30
33 const INITIAL_DELAY = 1 * MILLIS_IN_MINUTE; 31 const INITIAL_DELAY = 1 * MILLIS_IN_MINUTE;
34 const CHECK_INTERVAL = 1 * MILLIS_IN_HOUR; 32 const CHECK_INTERVAL = 1 * MILLIS_IN_HOUR;
35 const EXPIRATION_INTERVAL = 1 * MILLIS_IN_DAY; 33 const EXPIRATION_INTERVAL = 1 * MILLIS_IN_DAY;
(...skipping 26 matching lines...) Expand all
62 return translations[locale]; 60 return translations[locale];
63 61
64 let languagePart = locale.substring(0, locale.indexOf("-")); 62 let languagePart = locale.substring(0, locale.indexOf("-"));
65 if (languagePart && languagePart in translations) 63 if (languagePart && languagePart in translations)
66 return translations[languagePart]; 64 return translations[languagePart];
67 65
68 let defaultLocale = "en-US"; 66 let defaultLocale = "en-US";
69 return translations[defaultLocale]; 67 return translations[defaultLocale];
70 } 68 }
71 69
70 function parseVersionComponent(comp)
71 {
72 if (comp == "*")
73 return Infinity;
74 return parseInt(comp, 10) || 0;
75 }
76
77 function compareVersion(v1, v2)
78 {
79 let regexp = /^(.*?)([a-z].*)?$/i;
80 let [, head1, tail1] = regexp.exec(v1);
81 let [, head2, tail2] = regexp.exec(v2);
82 let components1 = head1.split(".");
83 let components2 = head2.split(".");
84
85 for (let i = 0; i < components1.length ||
86 i < components2.length; i++)
87 {
88 let result = parseVersionComponent(components1[i]) -
89 parseVersionComponent(components2[i]) || 0;
90
91 if (result != 0)
92 return result;
93 }
94
95 // Compare version suffix (e.g. 0.1alpha < 0.1b1 < 01.b2 < 0.1).
96 // However, note that this is a simple string comparision, meaning: b10 < b2
97 if (tail1 == tail2)
98 return 0;
99 if (!tail1 || tail2 && tail1 > tail2)
100 return 1;
101 return -1;
102 }
103
72 /** 104 /**
73 * The object providing actual downloading functionality. 105 * The object providing actual downloading functionality.
74 * @type {Downloader} 106 * @type {Downloader}
75 */ 107 */
76 let downloader = null; 108 let downloader = null;
77 let localData = []; 109 let localData = [];
78 110
79 /** 111 /**
80 * Regularly fetches notifications and decides which to show. 112 * Regularly fetches notifications and decides which to show.
81 * @class 113 * @class
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 let notifications = localData.concat(remoteData); 242 let notifications = localData.concat(remoteData);
211 if (notifications.length === 0) 243 if (notifications.length === 0)
212 return null; 244 return null;
213 245
214 const {addonName, addonVersion, application, 246 const {addonName, addonVersion, application,
215 applicationVersion, platform, platformVersion} = require("info"); 247 applicationVersion, platform, platformVersion} = require("info");
216 248
217 let targetChecks = { 249 let targetChecks = {
218 extension: v => v == addonName, 250 extension: v => v == addonName,
219 extensionMinVersion: 251 extensionMinVersion:
220 v => Services.vc.compare(addonVersion, v) >= 0, 252 v => compareVersion(addonVersion, v) >= 0,
221 extensionMaxVersion: 253 extensionMaxVersion:
222 v => Services.vc.compare(addonVersion, v) <= 0, 254 v => compareVersion(addonVersion, v) <= 0,
223 application: v => v == application, 255 application: v => v == application,
224 applicationMinVersion: 256 applicationMinVersion:
225 v => Services.vc.compare(applicationVersion, v) >= 0, 257 v => compareVersion(applicationVersion, v) >= 0,
226 applicationMaxVersion: 258 applicationMaxVersion:
227 v => Services.vc.compare(applicationVersion, v) <= 0, 259 v => compareVersion(applicationVersion, v) <= 0,
228 platform: v => v == platform, 260 platform: v => v == platform,
229 platformMinVersion: 261 platformMinVersion:
230 v => Services.vc.compare(platformVersion, v) >= 0, 262 v => compareVersion(platformVersion, v) >= 0,
231 platformMaxVersion: 263 platformMaxVersion:
232 v => Services.vc.compare(platformVersion, v) <= 0, 264 v => compareVersion(platformVersion, v) <= 0,
233 blockedTotalMin: v => Prefs.show_statsinpopup && 265 blockedTotalMin: v => Prefs.show_statsinpopup &&
234 Prefs.blocked_total >= v, 266 Prefs.blocked_total >= v,
235 blockedTotalMax: v => Prefs.show_statsinpopup && 267 blockedTotalMax: v => Prefs.show_statsinpopup &&
236 Prefs.blocked_total <= v, 268 Prefs.blocked_total <= v,
237 locales: v => v.includes(Utils.appLocale) 269 locales: v => v.includes(Utils.appLocale)
238 }; 270 };
239 271
240 let notificationToShow = null; 272 let notificationToShow = null;
241 for (let notification of notifications) 273 for (let notification of notifications)
242 { 274 {
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 else if (index != -1 && forceValue !== true) 513 else if (index != -1 && forceValue !== true)
482 categories.splice(index, 1); 514 categories.splice(index, 1);
483 515
484 // HACK: JSON values aren't saved unless they are assigned a 516 // HACK: JSON values aren't saved unless they are assigned a
485 // different object. 517 // different object.
486 Prefs.notifications_ignoredcategories = 518 Prefs.notifications_ignoredcategories =
487 JSON.parse(JSON.stringify(categories)); 519 JSON.parse(JSON.stringify(categories));
488 } 520 }
489 }; 521 };
490 Notification.init(); 522 Notification.init();
OLDNEW
« no previous file with comments | « no previous file | test/_common.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld