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; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 { | 270 { |
282 continue; | 271 continue; |
283 } | 272 } |
284 } | 273 } |
285 else | 274 else |
286 continue; | 275 continue; |
287 } | 276 } |
288 | 277 |
289 if (notification.targets instanceof Array) | 278 if (notification.targets instanceof Array) |
290 { | 279 { |
291 let match = false; | 280 let checks = new Map([ |
Wladimir Palant
2017/08/22 07:54:58
This shouldn't be set inside the loop, we'll get n
wspee
2017/08/23 10:12:20
Acknowledged.
| |
281 ["extension", v => v == addonName], | |
282 ["extensionMinVersion", | |
283 v => Services.vc.compare(addonVersion, v) >= 0], | |
284 ["extensionMaxVersion", | |
285 v => Services.vc.compare(addonVersion, v) <= 0], | |
286 ["application", v => v == application], | |
287 ["applicationMinVersion", | |
288 v => Services.vc.compare(applicationVersion, v) >= 0], | |
289 ["applicationMaxVersion", | |
290 v => Services.vc.compare(applicationVersion, v) <= 0], | |
291 ["platform", v => v == platform], | |
292 ["platformMinVersion", | |
293 v => Services.vc.compare(platformVersion, v) >= 0], | |
294 ["platformMaxVersion", | |
295 v => Services.vc.compare(platformVersion, v) <= 0], | |
296 ["blockedTotalMax", v => Prefs.blocked_total <= parseInt(v, 10)], | |
297 ["blockedTotalMin", v => Prefs.blocked_total >= parseInt(v, 10)], | |
Wladimir Palant
2017/08/22 07:54:58
Why parseInt() here? I'd say that the backend is s
wspee
2017/08/23 10:12:19
Acknowledged.
Thanks for pointing that out, the b
| |
298 ["locales", v => v.indexOf(Utils.appLocale) != -1] | |
299 ]); | |
300 | |
301 let match = true; | |
Wladimir Palant
2017/08/22 07:54:58
I'd say that this should be initialized with false
wspee
2017/08/23 10:12:20
Acknowledged.
| |
292 for (let target of notification.targets) | 302 for (let target of notification.targets) |
293 { | 303 { |
294 if (checkTarget(target, "extension", addonName, addonVersion) && | 304 match = true; |
295 checkTarget(target, "application", application, | 305 for (let key of Object.keys(target)) |
Wladimir Palant
2017/08/22 07:54:58
How about making this more compact and closer to t
wspee
2017/08/23 10:12:20
Acknowledged.
| |
296 applicationVersion) && | |
297 checkTarget(target, "platform", platform, platformVersion)) | |
298 { | 306 { |
299 match = true; | 307 let value = target[key]; |
308 let check = checks.get(key); | |
309 | |
310 if (!check || !check(value)) | |
wspee
2017/08/21 15:18:21
This implementation no longer ignores unknown targ
Wladimir Palant
2017/08/22 07:54:58
Agreed.
wspee
2017/08/23 10:12:20
See https://issues.adblockplus.org/ticket/5558#tic
| |
311 { | |
312 match = false; | |
313 } | |
314 } | |
315 if (match) | |
316 { | |
300 break; | 317 break; |
301 } | 318 } |
302 } | 319 } |
303 if (!match) | 320 if (!match) |
321 { | |
304 continue; | 322 continue; |
323 } | |
305 } | 324 } |
306 | 325 |
307 if (!notificationToShow || | 326 if (!notificationToShow || |
308 getNumericalSeverity(notification) > | 327 getNumericalSeverity(notification) > |
309 getNumericalSeverity(notificationToShow)) | 328 getNumericalSeverity(notificationToShow)) |
310 notificationToShow = notification; | 329 notificationToShow = notification; |
311 } | 330 } |
312 | 331 |
313 return notificationToShow; | 332 return notificationToShow; |
314 }, | 333 }, |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
466 else if (index != -1 && forceValue !== true) | 485 else if (index != -1 && forceValue !== true) |
467 categories.splice(index, 1); | 486 categories.splice(index, 1); |
468 | 487 |
469 // HACK: JSON values aren't saved unless they are assigned a | 488 // HACK: JSON values aren't saved unless they are assigned a |
470 // different object. | 489 // different object. |
471 Prefs.notifications_ignoredcategories = | 490 Prefs.notifications_ignoredcategories = |
472 JSON.parse(JSON.stringify(categories)); | 491 JSON.parse(JSON.stringify(categories)); |
473 } | 492 } |
474 }; | 493 }; |
475 Notification.init(); | 494 Notification.init(); |
OLD | NEW |