browser/metro/components/AlertsService.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     5 const Ci = Components.interfaces;
     6 const Cu = Components.utils;
     8 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
     9 Cu.import("resource://gre/modules/Services.jsm");
    11 // -----------------------------------------------------------------------
    12 // Alerts Service
    13 // -----------------------------------------------------------------------
    15 function AlertsService() { }
    17 AlertsService.prototype = {
    18   classID: Components.ID("{fe33c107-82a4-41d6-8c64-5353267e04c9}"),
    19   QueryInterface: XPCOMUtils.generateQI([Ci.nsIAlertsService]),
    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   },
    37   closeAlert: function(aName) {
    38     let browser = Services.wm.getMostRecentWindow("navigator:browser");
    39     browser.AlertsHelper.closeAlert();
    40   },
    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 };
    54 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([AlertsService]);

mercurial