michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const Ci = Components.interfaces; michael@0: const Cu = Components.utils; michael@0: michael@0: Cu.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: // ----------------------------------------------------------------------- michael@0: // Alerts Service michael@0: // ----------------------------------------------------------------------- michael@0: michael@0: function AlertsService() { } michael@0: michael@0: AlertsService.prototype = { michael@0: classID: Components.ID("{fe33c107-82a4-41d6-8c64-5353267e04c9}"), michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsIAlertsService]), michael@0: michael@0: showAlertNotification: function(aImageUrl, aTitle, aText, aTextClickable, michael@0: aCookie, aAlertListener, aName, aDir, aLang) { michael@0: let browser = Services.wm.getMostRecentWindow("navigator:browser"); michael@0: try { michael@0: browser.AlertsHelper.showAlertNotification(aImageUrl, aTitle, aText, aTextClickable, aCookie, aAlertListener); michael@0: } catch (ex) { michael@0: let chromeWin = this._getChromeWindow(browser).wrappedJSObject; michael@0: let notificationBox = chromeWin.Browser.getNotificationBox(); michael@0: notificationBox.appendNotification(aTitle, michael@0: aText, michael@0: aImageUrl, michael@0: notificationBox.PRIORITY_WARNING_MEDIUM, michael@0: null); michael@0: } michael@0: }, michael@0: michael@0: closeAlert: function(aName) { michael@0: let browser = Services.wm.getMostRecentWindow("navigator:browser"); michael@0: browser.AlertsHelper.closeAlert(); michael@0: }, michael@0: michael@0: _getChromeWindow: function (aWindow) { michael@0: let chromeWin = aWindow.QueryInterface(Ci.nsIInterfaceRequestor) michael@0: .getInterface(Ci.nsIWebNavigation) michael@0: .QueryInterface(Ci.nsIDocShellTreeItem) michael@0: .rootTreeItem michael@0: .QueryInterface(Ci.nsIInterfaceRequestor) michael@0: .getInterface(Ci.nsIDOMWindow) michael@0: .QueryInterface(Ci.nsIDOMChromeWindow); michael@0: return chromeWin; michael@0: } michael@0: }; michael@0: michael@0: this.NSGetFactory = XPCOMUtils.generateNSGetFactory([AlertsService]);