Index: lib/ui.js |
=================================================================== |
--- a/lib/ui.js |
+++ b/lib/ui.js |
@@ -29,6 +29,7 @@ |
let {Subscription, SpecialSubscription, DownloadableSubscription} = require("subscriptionClasses"); |
let {Synchronizer} = require("synchronizer"); |
let {KeySelector} = require("keySelector"); |
+let {Notification} = require("notification"); |
/** |
* Filter corresponding with "disable on site" menu item (set in fillIconMent()). |
@@ -264,6 +265,12 @@ |
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakReference]) |
} |
+/** |
+ * Timer used to delay notification handling. |
+ * @type nsITimer |
+ */ |
+let notificationTimer = null; |
+ |
let UI = exports.UI = |
{ |
/** |
@@ -420,6 +427,11 @@ |
if (/^(filter|subscription)\.(added|removed|disabled|updated)$/.test(action) || action == "load") |
this.updateState(); |
}.bind(this)); |
+ |
+ notificationTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); |
+ notificationTimer.initWithCallback(this._showNextNotification.bind(this), |
+ 3 * 60 * 1000, Ci.nsITimer.TYPE_ONE_SHOT); |
+ 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
|
}, |
/** |
@@ -1914,6 +1926,82 @@ |
if (button) |
button.hidden = true; |
} |
+ }, |
+ |
+ _showNextNotification: function(notification) |
+ { |
+ let window = null; |
+ for (window in this.applicationWindows) |
+ break; |
+ |
+ if (!window) |
+ return; |
+ |
+ let button = window.document.getElementById("abp-toolbarbutton") |
+ || window.document.getElementById("abp-status"); |
+ if (!button) |
+ return; |
+ |
+ let notification = Notification.getNextToShow(); |
+ if (!notification) |
+ return; |
+ |
+ this._showNotification(window, button, notification); |
+ }, |
+ |
+ _showNotification: function(window, button, notification) |
+ { |
+ function insertMessage(element, text, links) |
+ { |
+ let match = /^(.*?)<(a|strong)>(.*?)<\/\2>(.*)$/.exec(text); |
+ if (!match) |
+ { |
+ element.appendChild(window.document.createTextNode(text)); |
+ return; |
+ } |
+ |
+ let [_, before, tagName, value, after] = match; |
+ |
+ insertMessage(element, before, links); |
+ |
+ let newElement = window.document.createElementNS("http://www.w3.org/1999/xhtml", tagName); |
+ if (tagName === "a" && links && links.length) |
+ newElement.setAttribute("href", links.shift()); |
+ insertMessage(newElement, value, links); |
+ element.appendChild(newElement); |
+ |
+ insertMessage(element, after, links); |
+ } |
+ |
+ let texts = Notification.getLocalizedTexts(notification); |
+ let titleElement = window.document.getElementById("abp-notification-title"); |
+ titleElement.setAttribute("value", texts.title); |
+ let messageElement = window.document.getElementById("abp-notification-message"); |
+ let docLinks = []; |
+ for each (let link in notification.links) |
+ docLinks.push(Utils.getDocLink(link)); |
+ insertMessage(messageElement, texts.message, docLinks); |
+ |
+ let links = window.document.querySelectorAll("#abp-notification-message a"); |
+ for each (let link in links) |
+ { |
+ let url = link.href; |
+ let ui = this; |
+ link.onclick = function(event) |
+ { |
+ event.preventDefault(); |
+ event.stopPropagation(); |
+ if (!/^https?:\/\//.test(url)) |
+ { |
+ Cu.reportError("Illegal link scheme in URL: " + url); |
+ return; |
+ } |
Wladimir Palant
2013/07/20 07:18:07
The URL no longer comes from server so we can just
|
+ ui.loadInBrowser(url, window); |
+ }; |
+ } |
+ |
+ let panel = window.document.getElementById("abp-notification"); |
+ panel.openPopup(button, "bottomcenter topcenter", 0, 0, false, false, null); |
} |
}; |
UI.onPopupShowing = UI.onPopupShowing.bind(UI); |