Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: lib/notification.js

Issue 5538776168267776: Implemented anti-adblock message notification (Closed)
Left Patch Set: Created Feb. 12, 2014, 6:22 p.m.
Right Patch Set: Created Feb. 13, 2014, 12:50 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « defaults/prefs.js ('k') | lib/ui.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 13 matching lines...) Expand all
24 let {TimeLine} = require("timeline"); 24 let {TimeLine} = require("timeline");
25 let {Prefs} = require("prefs"); 25 let {Prefs} = require("prefs");
26 let {Downloader, Downloadable, MILLIS_IN_MINUTE, MILLIS_IN_HOUR, MILLIS_IN_DAY} = require("downloader"); 26 let {Downloader, Downloadable, MILLIS_IN_MINUTE, MILLIS_IN_HOUR, MILLIS_IN_DAY} = require("downloader");
27 let {Utils} = require("utils"); 27 let {Utils} = require("utils");
28 let {Matcher} = require("matcher"); 28 let {Matcher} = require("matcher");
29 let {Filter} = require("filterClasses"); 29 let {Filter} = require("filterClasses");
30 30
31 let INITIAL_DELAY = 12 * MILLIS_IN_MINUTE; 31 let INITIAL_DELAY = 12 * MILLIS_IN_MINUTE;
32 let CHECK_INTERVAL = 1 * MILLIS_IN_HOUR; 32 let CHECK_INTERVAL = 1 * MILLIS_IN_HOUR;
33 let EXPIRATION_INTERVAL = 1 * MILLIS_IN_DAY; 33 let EXPIRATION_INTERVAL = 1 * MILLIS_IN_DAY;
34 let TYPES = { 34 let TYPE = {
Felix Dahlke 2014/02/13 10:22:04 Maybe we should call this TYPE_SEVERITY since it's
Thomas Greiner 2014/02/13 12:57:54 I don't think we need to make it overly specific g
35 information: 0, 35 information: 0,
36 question: 1, 36 question: 1,
37 critical: 2 37 critical: 2
38 }; 38 };
39 39
40 let listeners = {}; 40 let listeners = {};
41 41
42 function getNumericalSeverity(notification) 42 function getNumericalSeverity(notification)
43 { 43 {
44 let type = ("type" in notification) ? notification.type : notification.severit y; 44 return (notification.type in TYPE ? TYPE[notification.type] : TYPE.information );
45 return (type in TYPES ? TYPES[type] : TYPES.information);
46 } 45 }
47 46
48 function saveNotificationData() 47 function saveNotificationData()
49 { 48 {
50 // HACK: JSON values aren't saved unless they are assigned a different object. 49 // HACK: JSON values aren't saved unless they are assigned a different object.
51 Prefs.notificationdata = JSON.parse(JSON.stringify(Prefs.notificationdata)); 50 Prefs.notificationdata = JSON.parse(JSON.stringify(Prefs.notificationdata));
52 } 51 }
53 52
54 function localize(translations, locale) 53 function localize(translations, locale)
55 { 54 {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 Prefs.notificationdata.lastCheck = downloadable.lastCheck; 120 Prefs.notificationdata.lastCheck = downloadable.lastCheck;
122 Prefs.notificationdata.softExpiration = downloadable.softExpiration; 121 Prefs.notificationdata.softExpiration = downloadable.softExpiration;
123 Prefs.notificationdata.hardExpiration = downloadable.hardExpiration; 122 Prefs.notificationdata.hardExpiration = downloadable.hardExpiration;
124 saveNotificationData(); 123 saveNotificationData();
125 }, 124 },
126 125
127 _onDownloadSuccess: function(downloadable, responseText, errorCallback, redire ctCallback) 126 _onDownloadSuccess: function(downloadable, responseText, errorCallback, redire ctCallback)
128 { 127 {
129 try 128 try
130 { 129 {
131 Prefs.notificationdata.data = JSON.parse(responseText); 130 let data = JSON.parse(responseText);
131 for each (let notification in data.notifications)
132 {
133 if ("severity" in notification)
134 {
135 if (!("type" in notification))
136 notification.type = notification.severity;
137 delete notification.severity;
138 }
139 }
140 Prefs.notificationdata.data = data;
132 } 141 }
133 catch (e) 142 catch (e)
134 { 143 {
135 Cu.reportError(e); 144 Cu.reportError(e);
136 errorCallback("synchronize_invalid_data"); 145 errorCallback("synchronize_invalid_data");
137 return; 146 return;
138 } 147 }
139 148
140 Prefs.notificationdata.lastError = 0; 149 Prefs.notificationdata.lastError = 0;
141 Prefs.notificationdata.downloadStatus = "synchronize_ok"; 150 Prefs.notificationdata.downloadStatus = "synchronize_ok";
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 } 186 }
178 187
179 let notifications = localData.concat(remoteData); 188 let notifications = localData.concat(remoteData);
180 if (notifications.length === 0) 189 if (notifications.length === 0)
181 return null; 190 return null;
182 191
183 let {addonName, addonVersion, application, applicationVersion, platform, pla tformVersion} = require("info"); 192 let {addonName, addonVersion, application, applicationVersion, platform, pla tformVersion} = require("info");
184 let notificationToShow = null; 193 let notificationToShow = null;
185 for each (let notification in notifications) 194 for each (let notification in notifications)
186 { 195 {
187 if ((typeof notification.type === "undefined" || notification.type !== "cr itical") 196 if ((typeof notification.type === "undefined" || notification.type !== "cr itical")
Felix Dahlke 2014/02/13 10:22:04 I'm sorry, my suggestion for being downwards compa
Thomas Greiner 2014/02/13 12:57:54 Done.
188 && Prefs.notificationdata.shown.indexOf(notification.id) !== -1) 197 && Prefs.notificationdata.shown.indexOf(notification.id) !== -1)
189 continue; 198 continue;
190 199
191 if (typeof url === "string" || notification.urlFilters instanceof Array) 200 if (typeof url === "string" || notification.urlFilters instanceof Array)
192 { 201 {
193 if (typeof url === "string" && notification.urlFilters instanceof Array) 202 if (typeof url === "string" && notification.urlFilters instanceof Array)
194 { 203 {
195 let matcher = new Matcher(); 204 let matcher = new Matcher();
196 for each (let urlFilter in notification.urlFilters) 205 for each (let urlFilter in notification.urlFilters)
197 matcher.add(Filter.fromText(urlFilter)); 206 matcher.add(Filter.fromText(urlFilter));
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 */ 329 */
321 triggerQuestionListeners: function(id, approved) 330 triggerQuestionListeners: function(id, approved)
322 { 331 {
323 if (!(id in listeners)) 332 if (!(id in listeners))
324 return; 333 return;
325 for each (let listener in listeners[id]) 334 for each (let listener in listeners[id])
326 listener(approved); 335 listener(approved);
327 } 336 }
328 }; 337 };
329 Notification.init(); 338 Notification.init();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld