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

Delta Between Two Patch Sets: lib/ui.js

Issue 11165026: Show notifications on startup (Closed)
Left Patch Set: Created July 19, 2013, 1:41 p.m.
Right Patch Set: Address remaining issue Created July 20, 2013, 10:53 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 | « lib/notification.js ('k') | no next file » | 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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 258
259 this.timer.cancel(); 259 this.timer.cancel();
260 this.timer = null; 260 this.timer = null;
261 261
262 if (!onShutdown.done) 262 if (!onShutdown.done)
263 this.callback(); 263 this.callback();
264 }, 264 },
265 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakRefer ence]) 265 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakRefer ence])
266 } 266 }
267 267
268 /**
269 * Timer used to delay notification handling.
270 * @type nsITimer
271 */
272 let notificationTimer = null;
273
268 let UI = exports.UI = 274 let UI = exports.UI =
269 { 275 {
270 /** 276 /**
271 * Gets called on startup, initializes UI integration. 277 * Gets called on startup, initializes UI integration.
272 */ 278 */
273 init: function() 279 init: function()
274 { 280 {
275 // We should call initDone once both overlay and filters are loaded 281 // We should call initDone once both overlay and filters are loaded
276 let overlayLoaded = false; 282 let overlayLoaded = false;
277 let filtersLoaded = false; 283 let filtersLoaded = false;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 for (let window in this.applicationWindows) 421 for (let window in this.applicationWindows)
416 this.updateStatusbarIcon(window); 422 this.updateStatusbarIcon(window);
417 } 423 }
418 }.bind(this)); 424 }.bind(this));
419 FilterNotifier.addListener(function(action) 425 FilterNotifier.addListener(function(action)
420 { 426 {
421 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")
422 this.updateState(); 428 this.updateState();
423 }.bind(this)); 429 }.bind(this));
424 430
425 let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); 431 notificationTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
Wladimir Palant 2013/07/19 15:17:52 Sure, we do: onShutdown.add(function() timer.ca
Felix Dahlke 2013/07/19 17:07:01 Done.
426 timer.initWithCallback(function() 432 notificationTimer.initWithCallback(this._showNextNotification.bind(this),
427 { 433 3 * 60 * 1000, Ci.nsITimer.TYPE_ONE_SHOT) ;
428 let notificationToShow = Notification.getNextToShow(); 434 onShutdown.add(function() notificationTimer.cancel());
429 if (notificationToShow)
430 this._showNotification(notificationToShow);
431 }.bind(this), 3 * 60 * 1000, Ci.nsITimer.TYPE_ONE_SHOT);
432 }, 435 },
433 436
434 /** 437 /**
435 * 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
436 * has been performed. 439 * has been performed.
437 * @type Boolean 440 * @type Boolean
438 */ 441 */
439 firstRunDone: false, 442 firstRunDone: false,
440 443
441 /** 444 /**
(...skipping 1476 matching lines...) Expand 10 before | Expand all | Expand 10 after
1918 Prefs.hideContributeButton = true; 1921 Prefs.hideContributeButton = true;
1919 1922
1920 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"])
1921 { 1924 {
1922 let button = window.document.getElementById(id); 1925 let button = window.document.getElementById(id);
1923 if (button) 1926 if (button)
1924 button.hidden = true; 1927 button.hidden = true;
1925 } 1928 }
1926 }, 1929 },
1927 1930
1928 _showNotification: function(notification) 1931 _showNextNotification: function(notification)
1929 { 1932 {
1930 let window = null; 1933 let window = null;
1931 for (window in this.applicationWindows) 1934 for (window in this.applicationWindows)
1932 break; 1935 break;
1933 1936
1934 if (!window) 1937 if (!window)
1935 return; 1938 return;
Wladimir Palant 2013/07/19 15:17:52 We already marked the notification as shown at thi
Felix Dahlke 2013/07/19 17:07:01 Done.
1936 1939
1937 let button = window.document.getElementById("abp-toolbarbutton") 1940 let button = window.document.getElementById("abp-toolbarbutton")
1938 || window.document.getElementById("abp-status"); 1941 || window.document.getElementById("abp-status");
1939 if (!button) 1942 if (!button)
1940 return; 1943 return;
1941 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
1942 let texts = Notification.getLocalizedTexts(notification); 1976 let texts = Notification.getLocalizedTexts(notification);
1943 let titleElement = window.document.getElementById("abp-notification-title"); 1977 let titleElement = window.document.getElementById("abp-notification-title");
1944 titleElement.setAttribute("value", texts.title); 1978 titleElement.setAttribute("value", texts.title);
1945 let messageElement = window.document.getElementById("abp-notification-messag e"); 1979 let messageElement = window.document.getElementById("abp-notification-messag e");
1946 let message = texts.message.replace(/<(\/?)a(.*?)>/g, "<$1html:a$2>"); 1980 let docLinks = [];
1947 messageElement.innerHTML = message; 1981 for each (let link in notification.links)
1982 docLinks.push(Utils.getDocLink(link));
1983 insertMessage(messageElement, texts.message, docLinks);
1948 1984
1949 let links = window.document.querySelectorAll("#abp-notification-message a"); 1985 let links = window.document.querySelectorAll("#abp-notification-message a");
1950 for each (let link in links) 1986 for each (let link in links)
1951 { 1987 {
1952 let url = link.href; 1988 let url = link.href;
1953 let ui = this; 1989 let ui = this;
1954 link.onclick = function(event) 1990 link.onclick = function(event)
1955 { 1991 {
1956 event.preventDefault(); 1992 event.preventDefault();
1957 event.stopPropagation(); 1993 event.stopPropagation();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1990 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)], 2026 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)],
1991 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)] 2027 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)]
1992 ]; 2028 ];
1993 2029
1994 onShutdown.add(function() 2030 onShutdown.add(function()
1995 { 2031 {
1996 for (let window in UI.applicationWindows) 2032 for (let window in UI.applicationWindows)
1997 if (UI.isBottombarOpen(window)) 2033 if (UI.isBottombarOpen(window))
1998 UI.toggleBottombar(window); 2034 UI.toggleBottombar(window);
1999 }); 2035 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld