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: Address comments Created June 8, 2015, 7:31 p.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 = 12 * MILLIS_IN_MINUTE; 30 let INITIAL_DELAY = 12 * MILLIS_IN_MINUTE;
Felix Dahlke 2015/06/08 19:34:35 Nevermind this, just based this commit on an earli
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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 * @param {Function} listener Listener that was added via addShowListener() 177 * @param {Function} listener Listener that was added via addShowListener()
178 */ 178 */
179 removeShowListener: function(listener) 179 removeShowListener: function(listener)
180 { 180 {
181 let index = showListeners.indexOf(listener); 181 let index = showListeners.indexOf(listener);
182 if (index != -1) 182 if (index != -1)
183 showListeners.splice(index, 1); 183 showListeners.splice(index, 1);
184 }, 184 },
185 185
186 /** 186 /**
187 * Removes all listeners added via addShowListener().
188 */
189 removeAllShowListeners: function()
190 {
191 showListeners = [];
192 },
193
194 /**
195 * Determines which notification is to be shown next. 187 * Determines which notification is to be shown next.
196 * @param {String} url URL to match notifications to (optional) 188 * @param {String} url URL to match notifications to (optional)
197 * @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
198 */ 190 */
199 _getNextToShow: function(url) 191 _getNextToShow: function(url)
200 { 192 {
201 function checkTarget(target, parameter, name, version) 193 function checkTarget(target, parameter, name, version)
202 { 194 {
203 let minVersionKey = parameter + "MinVersion"; 195 let minVersionKey = parameter + "MinVersion";
204 let maxVersionKey = parameter + "MaxVersion"; 196 let maxVersionKey = parameter + "MaxVersion";
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 362
371 /** 363 /**
372 * Notifies question listeners about interactions with a notification 364 * Notifies question listeners about interactions with a notification
373 * @param {String} id notification ID 365 * @param {String} id notification ID
374 * @param {Boolean} approved indicator whether notification has been approved or not 366 * @param {Boolean} approved indicator whether notification has been approved or not
375 */ 367 */
376 triggerQuestionListeners: function(id, approved) 368 triggerQuestionListeners: function(id, approved)
377 { 369 {
378 if (!(id in questionListeners)) 370 if (!(id in questionListeners))
379 return; 371 return;
380 let questionListenersForId = questionListeners[id]; 372 let listeners = questionListeners[id];
381 for (let listener of questionListenersForId) 373 for (let listener of listeners)
382 listener(approved); 374 listener(approved);
383 }, 375 },
384 376
385 /** 377 /**
386 * Toggles whether notifications of a specific category should be ignored 378 * Toggles whether notifications of a specific category should be ignored
387 * @param {String} category notification category identifier 379 * @param {String} category notification category identifier
388 * @param {Boolean} [forceValue] force specified value 380 * @param {Boolean} [forceValue] force specified value
389 */ 381 */
390 toggleIgnoreCategory: function(category, forceValue) 382 toggleIgnoreCategory: function(category, forceValue)
391 { 383 {
392 let categories = Prefs.notifications_ignoredcategories; 384 let categories = Prefs.notifications_ignoredcategories;
393 let index = categories.indexOf(category); 385 let index = categories.indexOf(category);
394 if (index == -1 && forceValue !== false) 386 if (index == -1 && forceValue !== false)
395 { 387 {
396 categories.push(category); 388 categories.push(category);
397 Prefs.notifications_showui = true; 389 Prefs.notifications_showui = true;
398 } 390 }
399 else if (index != -1 && forceValue !== true) 391 else if (index != -1 && forceValue !== true)
400 categories.splice(index, 1); 392 categories.splice(index, 1);
401 393
402 // 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.
403 Prefs.notifications_ignoredcategories = JSON.parse(JSON.stringify(categories )); 395 Prefs.notifications_ignoredcategories = JSON.parse(JSON.stringify(categories ));
404 } 396 }
405 }; 397 };
406 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