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

Side by Side Diff: lib/ui.js

Issue 11165026: Show notifications on startup (Closed)
Patch Set: Addressed issues Created July 19, 2013, 5:06 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/notification.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 11 matching lines...) Expand all
22 let {Prefs} = require("prefs"); 22 let {Prefs} = require("prefs");
23 let {Policy} = require("contentPolicy"); 23 let {Policy} = require("contentPolicy");
24 let {FilterListener} = require("filterListener"); 24 let {FilterListener} = require("filterListener");
25 let {FilterStorage} = require("filterStorage"); 25 let {FilterStorage} = require("filterStorage");
26 let {FilterNotifier} = require("filterNotifier"); 26 let {FilterNotifier} = require("filterNotifier");
27 let {RequestNotifier} = require("requestNotifier"); 27 let {RequestNotifier} = require("requestNotifier");
28 let {Filter} = require("filterClasses"); 28 let {Filter} = require("filterClasses");
29 let {Subscription, SpecialSubscription, DownloadableSubscription} = require("sub scriptionClasses"); 29 let {Subscription, SpecialSubscription, DownloadableSubscription} = require("sub scriptionClasses");
30 let {Synchronizer} = require("synchronizer"); 30 let {Synchronizer} = require("synchronizer");
31 let {KeySelector} = require("keySelector"); 31 let {KeySelector} = require("keySelector");
32 let {Notification} = require("notification");
32 33
33 /** 34 /**
34 * Filter corresponding with "disable on site" menu item (set in fillIconMent()) . 35 * Filter corresponding with "disable on site" menu item (set in fillIconMent()) .
35 * @type Filter 36 * @type Filter
36 */ 37 */
37 let siteWhitelist = null; 38 let siteWhitelist = null;
38 /** 39 /**
39 * Filter corresponding with "disable on site" menu item (set in fillIconMenu()) . 40 * Filter corresponding with "disable on site" menu item (set in fillIconMenu()) .
40 * @type Filter 41 * @type Filter
41 */ 42 */
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 258
258 this.timer.cancel(); 259 this.timer.cancel();
259 this.timer = null; 260 this.timer = null;
260 261
261 if (!onShutdown.done) 262 if (!onShutdown.done)
262 this.callback(); 263 this.callback();
263 }, 264 },
264 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakRefer ence]) 265 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakRefer ence])
265 } 266 }
266 267
268 /**
269 * Timer used to delay notification handling.
270 * @type nsITimer
271 */
272 let notificationTimer = null;
273
267 let UI = exports.UI = 274 let UI = exports.UI =
268 { 275 {
269 /** 276 /**
270 * Gets called on startup, initializes UI integration. 277 * Gets called on startup, initializes UI integration.
271 */ 278 */
272 init: function() 279 init: function()
273 { 280 {
274 // We should call initDone once both overlay and filters are loaded 281 // We should call initDone once both overlay and filters are loaded
275 let overlayLoaded = false; 282 let overlayLoaded = false;
276 let filtersLoaded = false; 283 let filtersLoaded = false;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 { 420 {
414 for (let window in this.applicationWindows) 421 for (let window in this.applicationWindows)
415 this.updateStatusbarIcon(window); 422 this.updateStatusbarIcon(window);
416 } 423 }
417 }.bind(this)); 424 }.bind(this));
418 FilterNotifier.addListener(function(action) 425 FilterNotifier.addListener(function(action)
419 { 426 {
420 if (/^(filter|subscription)\.(added|removed|disabled|updated)$/.test(actio n) || action == "load") 427 if (/^(filter|subscription)\.(added|removed|disabled|updated)$/.test(actio n) || action == "load")
421 this.updateState(); 428 this.updateState();
422 }.bind(this)); 429 }.bind(this));
430
431 notificationTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
432 notificationTimer.initWithCallback(this._showNextNotification.bind(this),
433 3 * 60 * 1000, Ci.nsITimer.TYPE_ONE_SHOT) ;
434 onShutdown.add(function() notificationTimer.cancel());
Wladimir Palant 2013/07/20 07:18:07 We need to verify that this doesn't cause an error
Felix Dahlke 2013/07/20 23:00:51 I haven't see us do that in other places, so it se
Wladimir Palant 2013/07/21 11:30:17 I other places we are using repeating timers, not
423 }, 435 },
424 436
425 /** 437 /**
426 * Will be set to true after the check whether first-run actions should run 438 * Will be set to true after the check whether first-run actions should run
427 * has been performed. 439 * has been performed.
428 * @type Boolean 440 * @type Boolean
429 */ 441 */
430 firstRunDone: false, 442 firstRunDone: false,
431 443
432 /** 444 /**
(...skipping 1474 matching lines...) Expand 10 before | Expand all | Expand 10 after
1907 hideContributeButton: function(/**Window*/ window) 1919 hideContributeButton: function(/**Window*/ window)
1908 { 1920 {
1909 Prefs.hideContributeButton = true; 1921 Prefs.hideContributeButton = true;
1910 1922
1911 for each (let id in ["abp-status-contributebutton", "abp-toolbar-contributeb utton", "abp-menuitem-contributebutton"]) 1923 for each (let id in ["abp-status-contributebutton", "abp-toolbar-contributeb utton", "abp-menuitem-contributebutton"])
1912 { 1924 {
1913 let button = window.document.getElementById(id); 1925 let button = window.document.getElementById(id);
1914 if (button) 1926 if (button)
1915 button.hidden = true; 1927 button.hidden = true;
1916 } 1928 }
1929 },
1930
1931 _showNextNotification: function(notification)
1932 {
1933 let window = null;
1934 for (window in this.applicationWindows)
1935 break;
1936
1937 if (!window)
1938 return;
1939
1940 let button = window.document.getElementById("abp-toolbarbutton")
1941 || window.document.getElementById("abp-status");
1942 if (!button)
1943 return;
1944
1945 let notification = Notification.getNextToShow();
1946 if (!notification)
1947 return;
1948
1949 this._showNotification(window, button, notification);
1950 },
1951
1952 _showNotification: function(window, button, notification)
1953 {
1954 function insertMessage(element, text, links)
1955 {
1956 let match = /^(.*?)<(a|strong)>(.*?)<\/\2>(.*)$/.exec(text);
1957 if (!match)
1958 {
1959 element.appendChild(window.document.createTextNode(text));
1960 return;
1961 }
1962
1963 let [_, before, tagName, value, after] = match;
1964
1965 insertMessage(element, before, links);
1966
1967 let newElement = window.document.createElementNS("http://www.w3.org/1999/x html", tagName);
1968 if (tagName === "a" && links && links.length)
1969 newElement.setAttribute("href", links.shift());
1970 insertMessage(newElement, value, links);
1971 element.appendChild(newElement);
1972
1973 insertMessage(element, after, links);
1974 }
1975
1976 let texts = Notification.getLocalizedTexts(notification);
1977 let titleElement = window.document.getElementById("abp-notification-title");
1978 titleElement.setAttribute("value", texts.title);
1979 let messageElement = window.document.getElementById("abp-notification-messag e");
1980 let docLinks = [];
1981 for each (let link in notification.links)
1982 docLinks.push(Utils.getDocLink(link));
1983 insertMessage(messageElement, texts.message, docLinks);
1984
1985 let links = window.document.querySelectorAll("#abp-notification-message a");
1986 for each (let link in links)
1987 {
1988 let url = link.href;
1989 let ui = this;
1990 link.onclick = function(event)
1991 {
1992 event.preventDefault();
1993 event.stopPropagation();
1994 if (!/^https?:\/\//.test(url))
1995 {
1996 Cu.reportError("Illegal link scheme in URL: " + url);
1997 return;
1998 }
Wladimir Palant 2013/07/20 07:18:07 The URL no longer comes from server so we can just
1999 ui.loadInBrowser(url, window);
2000 };
2001 }
2002
2003 let panel = window.document.getElementById("abp-notification");
2004 panel.openPopup(button, "bottomcenter topcenter", 0, 0, false, false, null);
1917 } 2005 }
1918 }; 2006 };
1919 UI.onPopupShowing = UI.onPopupShowing.bind(UI); 2007 UI.onPopupShowing = UI.onPopupShowing.bind(UI);
1920 UI.onKeyPress = UI.onKeyPress.bind(UI); 2008 UI.onKeyPress = UI.onKeyPress.bind(UI);
1921 UI.onIconClick = UI.onIconClick.bind(UI); 2009 UI.onIconClick = UI.onIconClick.bind(UI);
1922 UI.onToolbarCustomization = UI.onToolbarCustomization.bind(UI); 2010 UI.onToolbarCustomization = UI.onToolbarCustomization.bind(UI);
1923 UI.init(); 2011 UI.init();
1924 2012
1925 /** 2013 /**
1926 * List of event handers to be registered for each window. For each event 2014 * List of event handers to be registered for each window. For each event
(...skipping 16 matching lines...) Expand all
1943 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)], 2031 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)],
1944 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)] 2032 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)]
1945 ]; 2033 ];
1946 2034
1947 onShutdown.add(function() 2035 onShutdown.add(function()
1948 { 2036 {
1949 for (let window in UI.applicationWindows) 2037 for (let window in UI.applicationWindows)
1950 if (UI.isBottombarOpen(window)) 2038 if (UI.isBottombarOpen(window))
1951 UI.toggleBottombar(window); 2039 UI.toggleBottombar(window);
1952 }); 2040 });
OLDNEW
« no previous file with comments | « lib/notification.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld