|
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 var AlertsHelper = { |
|
6 _listener: null, |
|
7 |
|
8 showAlertNotification: function ah_show(aImageURL, aTitle, aText, aTextClickable, aCookie, aListener) { |
|
9 if (aListener) { |
|
10 Services.obs.addObserver(this, "metro_native_toast_clicked", false); |
|
11 Services.obs.addObserver(this, "metro_native_toast_dismissed", false); |
|
12 Services.obs.addObserver(this, "metro_native_toast_shown", false); |
|
13 } |
|
14 this._listener = aListener; |
|
15 |
|
16 if (Services.metro.foreground) { |
|
17 // Firefox is in the foreground, no need for a notification. |
|
18 return; |
|
19 } |
|
20 Services.metro.showNativeToast(aTitle, aText, aImageURL, aCookie); |
|
21 }, |
|
22 |
|
23 closeAlert: function ah_close() { |
|
24 if (this._listener) { |
|
25 Services.obs.removeObserver(this, "metro_native_toast_shown"); |
|
26 Services.obs.removeObserver(this, "metro_native_toast_clicked"); |
|
27 Services.obs.removeObserver(this, "metro_native_toast_dismissed"); |
|
28 this._listener = null; |
|
29 } |
|
30 }, |
|
31 |
|
32 observe: function(aSubject, aTopic, aData) { |
|
33 switch (aTopic) { |
|
34 case "metro_native_toast_clicked": |
|
35 this._listener.observe(null, "alertclickcallback", aData); |
|
36 break; |
|
37 case "metro_native_toast_shown": |
|
38 this._listener.observe(null, "alertshow", aData); |
|
39 break; |
|
40 case "metro_native_toast_dismissed": |
|
41 this._listener.observe(null, "alertfinished", aData); |
|
42 break; |
|
43 } |
|
44 } |
|
45 }; |