1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/metro/components/AlertsService.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,54 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +const Ci = Components.interfaces; 1.9 +const Cu = Components.utils; 1.10 + 1.11 +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); 1.12 +Cu.import("resource://gre/modules/Services.jsm"); 1.13 + 1.14 +// ----------------------------------------------------------------------- 1.15 +// Alerts Service 1.16 +// ----------------------------------------------------------------------- 1.17 + 1.18 +function AlertsService() { } 1.19 + 1.20 +AlertsService.prototype = { 1.21 + classID: Components.ID("{fe33c107-82a4-41d6-8c64-5353267e04c9}"), 1.22 + QueryInterface: XPCOMUtils.generateQI([Ci.nsIAlertsService]), 1.23 + 1.24 + showAlertNotification: function(aImageUrl, aTitle, aText, aTextClickable, 1.25 + aCookie, aAlertListener, aName, aDir, aLang) { 1.26 + let browser = Services.wm.getMostRecentWindow("navigator:browser"); 1.27 + try { 1.28 + browser.AlertsHelper.showAlertNotification(aImageUrl, aTitle, aText, aTextClickable, aCookie, aAlertListener); 1.29 + } catch (ex) { 1.30 + let chromeWin = this._getChromeWindow(browser).wrappedJSObject; 1.31 + let notificationBox = chromeWin.Browser.getNotificationBox(); 1.32 + notificationBox.appendNotification(aTitle, 1.33 + aText, 1.34 + aImageUrl, 1.35 + notificationBox.PRIORITY_WARNING_MEDIUM, 1.36 + null); 1.37 + } 1.38 + }, 1.39 + 1.40 + closeAlert: function(aName) { 1.41 + let browser = Services.wm.getMostRecentWindow("navigator:browser"); 1.42 + browser.AlertsHelper.closeAlert(); 1.43 + }, 1.44 + 1.45 + _getChromeWindow: function (aWindow) { 1.46 + let chromeWin = aWindow.QueryInterface(Ci.nsIInterfaceRequestor) 1.47 + .getInterface(Ci.nsIWebNavigation) 1.48 + .QueryInterface(Ci.nsIDocShellTreeItem) 1.49 + .rootTreeItem 1.50 + .QueryInterface(Ci.nsIInterfaceRequestor) 1.51 + .getInterface(Ci.nsIDOMWindow) 1.52 + .QueryInterface(Ci.nsIDOMChromeWindow); 1.53 + return chromeWin; 1.54 + } 1.55 +}; 1.56 + 1.57 +this.NSGetFactory = XPCOMUtils.generateNSGetFactory([AlertsService]);