Left: | ||
Right: |
OLD | NEW |
---|---|
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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 showListeners.splice(index, 1); | 193 showListeners.splice(index, 1); |
194 }, | 194 }, |
195 | 195 |
196 /** | 196 /** |
197 * Determines which notification is to be shown next. | 197 * Determines which notification is to be shown next. |
198 * @param {string} url URL to match notifications to (optional) | 198 * @param {string} url URL to match notifications to (optional) |
199 * @return {Object} notification to be shown, or null if there is none | 199 * @return {Object} notification to be shown, or null if there is none |
200 */ | 200 */ |
201 _getNextToShow(url) | 201 _getNextToShow(url) |
202 { | 202 { |
203 function checkTarget(target, parameter, name, version) | |
204 { | |
205 let minVersionKey = parameter + "MinVersion"; | |
206 let maxVersionKey = parameter + "MaxVersion"; | |
207 return !((parameter in target && target[parameter] != name) || | |
208 (minVersionKey in target && | |
209 Services.vc.compare(version, target[minVersionKey]) < 0) || | |
210 (maxVersionKey in target && | |
211 Services.vc.compare(version, target[maxVersionKey]) > 0)); | |
212 } | |
213 | |
214 let remoteData = []; | 203 let remoteData = []; |
215 if (typeof Prefs.notificationdata.data == "object" && | 204 if (typeof Prefs.notificationdata.data == "object" && |
216 Prefs.notificationdata.data.notifications instanceof Array) | 205 Prefs.notificationdata.data.notifications instanceof Array) |
217 { | 206 { |
218 remoteData = Prefs.notificationdata.data.notifications; | 207 remoteData = Prefs.notificationdata.data.notifications; |
219 } | 208 } |
220 | 209 |
221 let notifications = localData.concat(remoteData); | 210 let notifications = localData.concat(remoteData); |
222 if (notifications.length === 0) | 211 if (notifications.length === 0) |
223 return null; | 212 return null; |
224 | 213 |
225 const {addonName, addonVersion, application, | 214 const {addonName, addonVersion, application, |
226 applicationVersion, platform, platformVersion} = require("info"); | 215 applicationVersion, platform, platformVersion} = require("info"); |
216 | |
217 let targetChecks = { | |
218 extension: v => v == addonName, | |
219 extensionMinVersion: | |
220 v => Services.vc.compare(addonVersion, v) >= 0, | |
Wladimir Palant
2017/08/23 11:00:10
Here and below: we shouldn't have one-space indent
wspee
2017/08/24 16:39:22
Acknowledged.
| |
221 extensionMaxVersion: | |
222 v => Services.vc.compare(addonVersion, v) <= 0, | |
223 application: v => v == application, | |
224 applicationMinVersion: | |
225 v => Services.vc.compare(applicationVersion, v) >= 0, | |
226 applicationMaxVersion: | |
227 v => Services.vc.compare(applicationVersion, v) <= 0, | |
228 platform: v => v == platform, | |
229 platformMinVersion: | |
230 v => Services.vc.compare(platformVersion, v) >= 0, | |
231 platformMaxVersion: | |
232 v => Services.vc.compare(platformVersion, v) <= 0, | |
233 blockedTotalMin: v => Prefs.blocked_total >= v, | |
234 blockedTotalMax: v => Prefs.blocked_total <= v, | |
235 locales: v => v.indexOf(Utils.appLocale) != -1 | |
Wladimir Palant
2017/08/23 11:00:10
Sorry, overlooked a detail in the previous review.
wspee
2017/08/24 16:39:22
Acknowledged.
| |
236 }; | |
237 | |
227 let notificationToShow = null; | 238 let notificationToShow = null; |
228 for (let notification of notifications) | 239 for (let notification of notifications) |
229 { | 240 { |
230 if (typeof notification.type === "undefined" || | 241 if (typeof notification.type === "undefined" || |
231 notification.type !== "critical") | 242 notification.type !== "critical") |
232 { | 243 { |
233 let shown; | 244 let shown; |
234 if (typeof Prefs.notificationdata.shown == "object") | 245 if (typeof Prefs.notificationdata.shown == "object") |
235 shown = Prefs.notificationdata.shown[notification.id]; | 246 shown = Prefs.notificationdata.shown[notification.id]; |
236 | 247 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 continue; | 293 continue; |
283 } | 294 } |
284 } | 295 } |
285 else | 296 else |
286 continue; | 297 continue; |
287 } | 298 } |
288 | 299 |
289 if (notification.targets instanceof Array) | 300 if (notification.targets instanceof Array) |
290 { | 301 { |
291 let match = false; | 302 let match = false; |
303 | |
292 for (let target of notification.targets) | 304 for (let target of notification.targets) |
293 { | 305 { |
294 if (checkTarget(target, "extension", addonName, addonVersion) && | 306 match = false; |
Wladimir Palant
2017/08/23 11:00:11
This assignment is no longer necessary.
wspee
2017/08/24 16:39:22
Acknowledged.
| |
295 checkTarget(target, "application", application, | 307 if (Object.keys(target).every(key => |
296 applicationVersion) && | 308 targetChecks.hasOwnProperty(key) && |
297 checkTarget(target, "platform", platform, platformVersion)) | 309 targetChecks[key](target[key]))) |
298 { | 310 { |
299 match = true; | 311 match = true; |
300 break; | 312 break; |
301 } | 313 } |
302 } | 314 } |
303 if (!match) | 315 if (!match) |
316 { | |
304 continue; | 317 continue; |
318 } | |
305 } | 319 } |
306 | 320 |
307 if (!notificationToShow || | 321 if (!notificationToShow || |
308 getNumericalSeverity(notification) > | 322 getNumericalSeverity(notification) > |
309 getNumericalSeverity(notificationToShow)) | 323 getNumericalSeverity(notificationToShow)) |
310 notificationToShow = notification; | 324 notificationToShow = notification; |
311 } | 325 } |
312 | 326 |
313 return notificationToShow; | 327 return notificationToShow; |
314 }, | 328 }, |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
466 else if (index != -1 && forceValue !== true) | 480 else if (index != -1 && forceValue !== true) |
467 categories.splice(index, 1); | 481 categories.splice(index, 1); |
468 | 482 |
469 // HACK: JSON values aren't saved unless they are assigned a | 483 // HACK: JSON values aren't saved unless they are assigned a |
470 // different object. | 484 // different object. |
471 Prefs.notifications_ignoredcategories = | 485 Prefs.notifications_ignoredcategories = |
472 JSON.parse(JSON.stringify(categories)); | 486 JSON.parse(JSON.stringify(categories)); |
473 } | 487 } |
474 }; | 488 }; |
475 Notification.init(); | 489 Notification.init(); |
OLD | NEW |