browser/metro/components/AlertsService.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:6a7b92bdd480
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 const Ci = Components.interfaces;
6 const Cu = Components.utils;
7
8 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
9 Cu.import("resource://gre/modules/Services.jsm");
10
11 // -----------------------------------------------------------------------
12 // Alerts Service
13 // -----------------------------------------------------------------------
14
15 function AlertsService() { }
16
17 AlertsService.prototype = {
18 classID: Components.ID("{fe33c107-82a4-41d6-8c64-5353267e04c9}"),
19 QueryInterface: XPCOMUtils.generateQI([Ci.nsIAlertsService]),
20
21 showAlertNotification: function(aImageUrl, aTitle, aText, aTextClickable,
22 aCookie, aAlertListener, aName, aDir, aLang) {
23 let browser = Services.wm.getMostRecentWindow("navigator:browser");
24 try {
25 browser.AlertsHelper.showAlertNotification(aImageUrl, aTitle, aText, aTextClickable, aCookie, aAlertListener);
26 } catch (ex) {
27 let chromeWin = this._getChromeWindow(browser).wrappedJSObject;
28 let notificationBox = chromeWin.Browser.getNotificationBox();
29 notificationBox.appendNotification(aTitle,
30 aText,
31 aImageUrl,
32 notificationBox.PRIORITY_WARNING_MEDIUM,
33 null);
34 }
35 },
36
37 closeAlert: function(aName) {
38 let browser = Services.wm.getMostRecentWindow("navigator:browser");
39 browser.AlertsHelper.closeAlert();
40 },
41
42 _getChromeWindow: function (aWindow) {
43 let chromeWin = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
44 .getInterface(Ci.nsIWebNavigation)
45 .QueryInterface(Ci.nsIDocShellTreeItem)
46 .rootTreeItem
47 .QueryInterface(Ci.nsIInterfaceRequestor)
48 .getInterface(Ci.nsIDOMWindow)
49 .QueryInterface(Ci.nsIDOMChromeWindow);
50 return chromeWin;
51 }
52 };
53
54 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([AlertsService]);

mercurial