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, |
| 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.includes(Utils.appLocale) |
| 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 if (Object.keys(target).every(key => |
295 checkTarget(target, "application", application, | 307 targetChecks.hasOwnProperty(key) && |
296 applicationVersion) && | 308 targetChecks[key](target[key]))) |
297 checkTarget(target, "platform", platform, platformVersion)) | |
298 { | 309 { |
299 match = true; | 310 match = true; |
300 break; | 311 break; |
301 } | 312 } |
302 } | 313 } |
303 if (!match) | 314 if (!match) |
| 315 { |
304 continue; | 316 continue; |
| 317 } |
305 } | 318 } |
306 | 319 |
307 if (!notificationToShow || | 320 if (!notificationToShow || |
308 getNumericalSeverity(notification) > | 321 getNumericalSeverity(notification) > |
309 getNumericalSeverity(notificationToShow)) | 322 getNumericalSeverity(notificationToShow)) |
310 notificationToShow = notification; | 323 notificationToShow = notification; |
311 } | 324 } |
312 | 325 |
313 return notificationToShow; | 326 return notificationToShow; |
314 }, | 327 }, |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 else if (index != -1 && forceValue !== true) | 479 else if (index != -1 && forceValue !== true) |
467 categories.splice(index, 1); | 480 categories.splice(index, 1); |
468 | 481 |
469 // HACK: JSON values aren't saved unless they are assigned a | 482 // HACK: JSON values aren't saved unless they are assigned a |
470 // different object. | 483 // different object. |
471 Prefs.notifications_ignoredcategories = | 484 Prefs.notifications_ignoredcategories = |
472 JSON.parse(JSON.stringify(categories)); | 485 JSON.parse(JSON.stringify(categories)); |
473 } | 486 } |
474 }; | 487 }; |
475 Notification.init(); | 488 Notification.init(); |
OLD | NEW |