| 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-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 Prefs.notificationdata.softExpiration = downloadable.softExpiration; | 121 Prefs.notificationdata.softExpiration = downloadable.softExpiration; |
| 122 Prefs.notificationdata.hardExpiration = downloadable.hardExpiration; | 122 Prefs.notificationdata.hardExpiration = downloadable.hardExpiration; |
| 123 saveNotificationData(); | 123 saveNotificationData(); |
| 124 }, | 124 }, |
| 125 | 125 |
| 126 _onDownloadSuccess: function(downloadable, responseText, errorCallback, redire
ctCallback) | 126 _onDownloadSuccess: function(downloadable, responseText, errorCallback, redire
ctCallback) |
| 127 { | 127 { |
| 128 try | 128 try |
| 129 { | 129 { |
| 130 let data = JSON.parse(responseText); | 130 let data = JSON.parse(responseText); |
| 131 for each (let notification in data.notifications) | 131 for (let notification of data.notifications) |
| 132 { | 132 { |
| 133 if ("severity" in notification) | 133 if ("severity" in notification) |
| 134 { | 134 { |
| 135 if (!("type" in notification)) | 135 if (!("type" in notification)) |
| 136 notification.type = notification.severity; | 136 notification.type = notification.severity; |
| 137 delete notification.severity; | 137 delete notification.severity; |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 Prefs.notificationdata.data = data; | 140 Prefs.notificationdata.data = data; |
| 141 } | 141 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 Prefs.notificationdata.shown = []; | 184 Prefs.notificationdata.shown = []; |
| 185 saveNotificationData(); | 185 saveNotificationData(); |
| 186 } | 186 } |
| 187 | 187 |
| 188 let notifications = localData.concat(remoteData); | 188 let notifications = localData.concat(remoteData); |
| 189 if (notifications.length === 0) | 189 if (notifications.length === 0) |
| 190 return null; | 190 return null; |
| 191 | 191 |
| 192 let {addonName, addonVersion, application, applicationVersion, platform, pla
tformVersion} = require("info"); | 192 let {addonName, addonVersion, application, applicationVersion, platform, pla
tformVersion} = require("info"); |
| 193 let notificationToShow = null; | 193 let notificationToShow = null; |
| 194 for each (let notification in notifications) | 194 for (let notification of notifications) |
| 195 { | 195 { |
| 196 if ((typeof notification.type === "undefined" || notification.type !== "cr
itical") | 196 if ((typeof notification.type === "undefined" || notification.type !== "cr
itical") |
| 197 && Prefs.notificationdata.shown.indexOf(notification.id) !== -1) | 197 && Prefs.notificationdata.shown.indexOf(notification.id) !== -1) |
| 198 continue; | 198 continue; |
| 199 | 199 |
| 200 if (typeof url === "string" || notification.urlFilters instanceof Array) | 200 if (typeof url === "string" || notification.urlFilters instanceof Array) |
| 201 { | 201 { |
| 202 if (typeof url === "string" && notification.urlFilters instanceof Array) | 202 if (typeof url === "string" && notification.urlFilters instanceof Array) |
| 203 { | 203 { |
| 204 let matcher = new Matcher(); | 204 let matcher = new Matcher(); |
| 205 for each (let urlFilter in notification.urlFilters) | 205 for (let urlFilter of notification.urlFilters) |
| 206 matcher.add(Filter.fromText(urlFilter)); | 206 matcher.add(Filter.fromText(urlFilter)); |
| 207 if (!matcher.matchesAny(url, "DOCUMENT", url)) | 207 if (!matcher.matchesAny(url, "DOCUMENT", url)) |
| 208 continue; | 208 continue; |
| 209 } | 209 } |
| 210 else | 210 else |
| 211 continue; | 211 continue; |
| 212 } | 212 } |
| 213 | 213 |
| 214 if (notification.targets instanceof Array) | 214 if (notification.targets instanceof Array) |
| 215 { | 215 { |
| 216 let match = false; | 216 let match = false; |
| 217 for each (let target in notification.targets) | 217 for (let target of notification.targets) |
| 218 { | 218 { |
| 219 if (checkTarget(target, "extension", addonName, addonVersion) && | 219 if (checkTarget(target, "extension", addonName, addonVersion) && |
| 220 checkTarget(target, "application", application, applicationVersion
) && | 220 checkTarget(target, "application", application, applicationVersion
) && |
| 221 checkTarget(target, "platform", platform, platformVersion)) | 221 checkTarget(target, "platform", platform, platformVersion)) |
| 222 { | 222 { |
| 223 match = true; | 223 match = true; |
| 224 break; | 224 break; |
| 225 } | 225 } |
| 226 } | 226 } |
| 227 if (!match) | 227 if (!match) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 256 * @param {Object} notification notification to translate | 256 * @param {Object} notification notification to translate |
| 257 * @param {String} locale the target locale (optional, defaults to the | 257 * @param {String} locale the target locale (optional, defaults to the |
| 258 * application locale) | 258 * application locale) |
| 259 * @return {Object} the translated texts | 259 * @return {Object} the translated texts |
| 260 */ | 260 */ |
| 261 getLocalizedTexts: function(notification, locale) | 261 getLocalizedTexts: function(notification, locale) |
| 262 { | 262 { |
| 263 locale = locale || Utils.appLocale; | 263 locale = locale || Utils.appLocale; |
| 264 let textKeys = ["title", "message"]; | 264 let textKeys = ["title", "message"]; |
| 265 let localizedTexts = []; | 265 let localizedTexts = []; |
| 266 for each (let key in textKeys) | 266 for (let key of textKeys) |
| 267 { | 267 { |
| 268 if (key in notification) | 268 if (key in notification) |
| 269 { | 269 { |
| 270 if (typeof notification[key] == "string") | 270 if (typeof notification[key] == "string") |
| 271 localizedTexts[key] = notification[key]; | 271 localizedTexts[key] = notification[key]; |
| 272 else | 272 else |
| 273 localizedTexts[key] = localize(notification[key], locale); | 273 localizedTexts[key] = localize(notification[key], locale); |
| 274 } | 274 } |
| 275 } | 275 } |
| 276 return localizedTexts; | 276 return localizedTexts; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 /** | 325 /** |
| 326 * Notifies listeners about interactions with a notification | 326 * Notifies listeners about interactions with a notification |
| 327 * @param {String} id notification ID | 327 * @param {String} id notification ID |
| 328 * @param {Boolean} approved indicator whether notification has been approved
or not | 328 * @param {Boolean} approved indicator whether notification has been approved
or not |
| 329 */ | 329 */ |
| 330 triggerQuestionListeners: function(id, approved) | 330 triggerQuestionListeners: function(id, approved) |
| 331 { | 331 { |
| 332 if (!(id in listeners)) | 332 if (!(id in listeners)) |
| 333 return; | 333 return; |
| 334 let questionListeners = listeners[id]; | 334 let questionListeners = listeners[id]; |
| 335 for each (let listener in questionListeners) | 335 for (let listener of questionListeners) |
| 336 listener(approved); | 336 listener(approved); |
| 337 } | 337 } |
| 338 }; | 338 }; |
| 339 Notification.init(); | 339 Notification.init(); |
| OLD | NEW |