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

Delta Between Two Patch Sets: lib/notification.js

Issue 5256408131960832: Issue 2420 - Move notification show logic to core (Closed)
Left Patch Set: Created June 8, 2015, 11:10 a.m.
Right Patch Set: Remove function properly, address nit Created June 8, 2015, 10 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 | « no previous file | 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 <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /** 18 /**
19 * @fileOverview Handles notifications. 19 * @fileOverview Handles notifications.
20 */ 20 */
21 21
22 Cu.import("resource://gre/modules/Services.jsm"); 22 Cu.import("resource://gre/modules/Services.jsm");
23 23
24 let {Prefs} = require("prefs"); 24 let {Prefs} = require("prefs");
25 let {Downloader, Downloadable, MILLIS_IN_MINUTE, MILLIS_IN_HOUR, MILLIS_IN_DAY} = require("downloader"); 25 let {Downloader, Downloadable, MILLIS_IN_MINUTE, MILLIS_IN_HOUR, MILLIS_IN_DAY} = require("downloader");
26 let {Utils} = require("utils"); 26 let {Utils} = require("utils");
27 let {Matcher} = require("matcher"); 27 let {Matcher} = require("matcher");
28 let {Filter} = require("filterClasses"); 28 let {Filter} = require("filterClasses");
29 29
30 let INITIAL_DELAY = 1 * MILLIS_IN_MINUTE; 30 let INITIAL_DELAY = 12 * MILLIS_IN_MINUTE;
31 let CHECK_INTERVAL = 1 * MILLIS_IN_HOUR; 31 let CHECK_INTERVAL = 1 * MILLIS_IN_HOUR;
32 let EXPIRATION_INTERVAL = 1 * MILLIS_IN_DAY; 32 let EXPIRATION_INTERVAL = 1 * MILLIS_IN_DAY;
33 let STARTUP_SHOW_DELAY = 3 * MILLIS_IN_MINUTE; 33 let STARTUP_SHOW_DELAY = 3 * MILLIS_IN_MINUTE;
34 let TYPE = { 34 let TYPE = {
35 information: 0, 35 information: 0,
36 question: 1, 36 question: 1,
37 critical: 2 37 critical: 2
38 }; 38 };
39 39
40 let showListeners = []; 40 let showListeners = [];
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 * @class 76 * @class
77 */ 77 */
78 let Notification = exports.Notification = 78 let Notification = exports.Notification =
79 { 79 {
80 /** 80 /**
81 * Called on module startup. 81 * Called on module startup.
82 */ 82 */
83 init: function() 83 init: function()
84 { 84 {
85 downloader = new Downloader(this._getDownloadables.bind(this), INITIAL_DELAY , CHECK_INTERVAL); 85 downloader = new Downloader(this._getDownloadables.bind(this), INITIAL_DELAY , CHECK_INTERVAL);
86 onShutdown.add(function()
87 {
88 downloader.cancel();
89 });
Wladimir Palant 2015/06/08 11:33:15 Mind changing this into arrow function as well for
Felix Dahlke 2015/06/08 19:34:34 Done.
90
91 downloader.onExpirationChange = this._onExpirationChange.bind(this); 86 downloader.onExpirationChange = this._onExpirationChange.bind(this);
92 downloader.onDownloadSuccess = this._onDownloadSuccess.bind(this); 87 downloader.onDownloadSuccess = this._onDownloadSuccess.bind(this);
93 downloader.onDownloadError = this._onDownloadError.bind(this); 88 downloader.onDownloadError = this._onDownloadError.bind(this);
89 onShutdown.add(() => downloader.cancel());
94 90
95 notificationTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); 91 notificationTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
96 notificationTimer.initWithCallback(Notification.showNext, 92 notificationTimer.initWithCallback(Notification.showNext.bind(this),
Wladimir Palant 2015/06/08 11:33:15 Notification.showNext.bind(this)? The next person
Felix Dahlke 2015/06/08 19:34:34 Done.
97 STARTUP_SHOW_DELAY, 93 STARTUP_SHOW_DELAY,
98 Ci.nsITimer.TYPE_ONE_SHOT); 94 Ci.nsITimer.TYPE_ONE_SHOT);
99 onShutdown.add(() => notificationTimer.cancel()); 95 onShutdown.add(() => notificationTimer.cancel());
100 }, 96 },
101 97
102 /** 98 /**
103 * Yields a Downloadable instances for the notifications download. 99 * Yields a Downloadable instances for the notifications download.
104 */ 100 */
105 _getDownloadables: function*() 101 _getDownloadables: function*()
106 { 102 {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 if (showListeners.indexOf(listener) == -1) 171 if (showListeners.indexOf(listener) == -1)
176 showListeners.push(listener); 172 showListeners.push(listener);
177 }, 173 },
178 174
179 /** 175 /**
180 * Removes the supplied listener. 176 * Removes the supplied listener.
181 * @param {Function} listener Listener that was added via addShowListener() 177 * @param {Function} listener Listener that was added via addShowListener()
182 */ 178 */
183 removeShowListener: function(listener) 179 removeShowListener: function(listener)
184 { 180 {
185 showListeners.splice(showListeners.indexOf(listener)); 181 let index = showListeners.indexOf(listener);
Wladimir Palant 2015/06/08 11:33:15 For reference: [1,2,3].splice(1) => [1] [1,2,3].s
Felix Dahlke 2015/06/08 19:34:34 Done.
186 }, 182 if (index != -1)
187 183 showListeners.splice(index, 1);
188 /**
189 * Removes all listeners added via addShowListener().
190 */
191 removeAllShowListeners: function()
Wladimir Palant 2015/06/08 11:33:15 Why do we need that function? Seems to be a footgu
Felix Dahlke 2015/06/08 19:34:34 Done.
Wladimir Palant 2015/06/08 20:45:15 Why am I still seeing it? :)
Felix Dahlke 2015/06/08 22:01:53 Good question, done for real now.
192 {
193 showListeners = [];
194 }, 184 },
195 185
196 /** 186 /**
197 * Determines which notification is to be shown next. 187 * Determines which notification is to be shown next.
198 * @param {String} url URL to match notifications to (optional) 188 * @param {String} url URL to match notifications to (optional)
199 * @return {Object} notification to be shown, or null if there is none 189 * @return {Object} notification to be shown, or null if there is none
200 */ 190 */
201 _getNextToShow: function(url) 191 _getNextToShow: function(url)
202 { 192 {
203 function checkTarget(target, parameter, name, version) 193 function checkTarget(target, parameter, name, version)
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 362
373 /** 363 /**
374 * Notifies question listeners about interactions with a notification 364 * Notifies question listeners about interactions with a notification
375 * @param {String} id notification ID 365 * @param {String} id notification ID
376 * @param {Boolean} approved indicator whether notification has been approved or not 366 * @param {Boolean} approved indicator whether notification has been approved or not
377 */ 367 */
378 triggerQuestionListeners: function(id, approved) 368 triggerQuestionListeners: function(id, approved)
379 { 369 {
380 if (!(id in questionListeners)) 370 if (!(id in questionListeners))
381 return; 371 return;
382 for (let listener of questionListeners[id]) 372 let listeners = questionListeners[id];
Wladimir Palant 2015/06/08 11:33:15 Please keep using a temporary variable here - othe
Felix Dahlke 2015/06/08 19:34:34 Done.
Wladimir Palant 2015/06/08 20:45:15 I would have called that variable "listeners" or s
Felix Dahlke 2015/06/08 22:01:53 True, wasn't a brilliant name. Done, since I was u
373 for (let listener of listeners)
383 listener(approved); 374 listener(approved);
384 }, 375 },
385 376
386 /** 377 /**
387 * Toggles whether notifications of a specific category should be ignored 378 * Toggles whether notifications of a specific category should be ignored
388 * @param {String} category notification category identifier 379 * @param {String} category notification category identifier
389 * @param {Boolean} [forceValue] force specified value 380 * @param {Boolean} [forceValue] force specified value
390 */ 381 */
391 toggleIgnoreCategory: function(category, forceValue) 382 toggleIgnoreCategory: function(category, forceValue)
392 { 383 {
393 let categories = Prefs.notifications_ignoredcategories; 384 let categories = Prefs.notifications_ignoredcategories;
394 let index = categories.indexOf(category); 385 let index = categories.indexOf(category);
395 if (index == -1 && forceValue !== false) 386 if (index == -1 && forceValue !== false)
396 { 387 {
397 categories.push(category); 388 categories.push(category);
398 Prefs.notifications_showui = true; 389 Prefs.notifications_showui = true;
399 } 390 }
400 else if (index != -1 && forceValue !== true) 391 else if (index != -1 && forceValue !== true)
401 categories.splice(index, 1); 392 categories.splice(index, 1);
402 393
403 // HACK: JSON values aren't saved unless they are assigned a different objec t. 394 // HACK: JSON values aren't saved unless they are assigned a different objec t.
404 Prefs.notifications_ignoredcategories = JSON.parse(JSON.stringify(categories )); 395 Prefs.notifications_ignoredcategories = JSON.parse(JSON.stringify(categories ));
405 } 396 }
406 }; 397 };
407 Notification.init(); 398 Notification.init();
LEFTRIGHT
« no previous file | lib/ui.js » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld