OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 saveNotificationData(); | 126 saveNotificationData(); |
127 }, | 127 }, |
128 | 128 |
129 /** | 129 /** |
130 * Determines which notification is to be shown next. | 130 * Determines which notification is to be shown next. |
131 * @param {Array of Object} notifications active notifications | 131 * @param {Array of Object} notifications active notifications |
132 * @return {Object} notification to be shown, or null if there is none | 132 * @return {Object} notification to be shown, or null if there is none |
133 */ | 133 */ |
134 getNextToShow: function() | 134 getNextToShow: function() |
135 { | 135 { |
| 136 function checkTarget(target, parameter, name, version) |
| 137 { |
| 138 let minVersionKey = parameter + "MinVersion"; |
| 139 let maxVersionKey = parameter + "MaxVersion"; |
| 140 return !((parameter in target && target[parameter] != name) || |
| 141 (minVersionKey in target && Services.vc.compare(version, target[m
inVersionKey]) < 0) || |
| 142 (maxVersionKey in target && Services.vc.compare(version, target[m
axVersionKey]) > 0)); |
| 143 |
| 144 } |
| 145 |
136 if (typeof Prefs.notificationdata.data != "object" || !(Prefs.notificationda
ta.data.notifications instanceof Array)) | 146 if (typeof Prefs.notificationdata.data != "object" || !(Prefs.notificationda
ta.data.notifications instanceof Array)) |
137 return null; | 147 return null; |
138 | 148 |
139 if (!(Prefs.notificationdata.shown instanceof Array)) | 149 if (!(Prefs.notificationdata.shown instanceof Array)) |
140 { | 150 { |
141 Prefs.notificationdata.shown = []; | 151 Prefs.notificationdata.shown = []; |
142 saveNotificationData(); | 152 saveNotificationData(); |
143 } | 153 } |
144 | 154 |
145 let {application, addonVersion} = require("info"); | 155 let {addonName, addonVersion, application, applicationVersion, platform, pla
tformVersion} = require("info"); |
146 let notifications = Prefs.notificationdata.data.notifications; | 156 let notifications = Prefs.notificationdata.data.notifications; |
147 let notificationToShow = null; | 157 let notificationToShow = null; |
148 for each (let notification in notifications) | 158 for each (let notification in notifications) |
149 { | 159 { |
150 if ((typeof notification.severity == "undefined" || notification.severity
=== "information") | 160 if ((typeof notification.severity == "undefined" || notification.severity
=== "information") |
151 && Prefs.notificationdata.shown.indexOf(notification.id) !== -1) | 161 && Prefs.notificationdata.shown.indexOf(notification.id) !== -1) |
152 continue; | 162 continue; |
153 | 163 |
154 if (notification.platforms instanceof Array | 164 if (notification.targets instanceof Array) |
155 && notification.platforms.indexOf(application) === -1) | 165 { |
156 continue; | 166 let match = false; |
157 | 167 for each (let target in notification.targets) |
158 if ("minVersion" in notification | 168 { |
159 && Services.vc.compare(addonVersion, notification.minVersion) < 0) | 169 if (checkTarget(target, "extension", addonName, addonVersion) && |
160 continue; | 170 checkTarget(target, "application", application, applicationVersion
) && |
161 | 171 checkTarget(target, "platform", platform, platformVersion)) |
162 if ("maxVersion" in notification | 172 { |
163 && Services.vc.compare(addonVersion, notification.maxVersion) > 0) | 173 match = true; |
164 continue; | 174 break; |
| 175 } |
| 176 } |
| 177 if (!match) |
| 178 continue; |
| 179 } |
165 | 180 |
166 if (!notificationToShow | 181 if (!notificationToShow |
167 || getNumericalSeverity(notification) > getNumericalSeverity(notificat
ionToShow)) | 182 || getNumericalSeverity(notification) > getNumericalSeverity(notificat
ionToShow)) |
168 notificationToShow = notification; | 183 notificationToShow = notification; |
169 } | 184 } |
170 | 185 |
171 if (notificationToShow && "id" in notificationToShow) | 186 if (notificationToShow && "id" in notificationToShow) |
172 { | 187 { |
173 Prefs.notificationdata.shown.push(notificationToShow.id); | 188 Prefs.notificationdata.shown.push(notificationToShow.id); |
174 saveNotificationData(); | 189 saveNotificationData(); |
175 } | 190 } |
176 | 191 |
177 return notificationToShow; | 192 return notificationToShow; |
178 } | 193 } |
179 }; | 194 }; |
180 Notification.init(); | 195 Notification.init(); |
OLD | NEW |