1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/metro/base/content/helperui/AlertsHelper.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,45 @@ 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 +var AlertsHelper = { 1.9 + _listener: null, 1.10 + 1.11 + showAlertNotification: function ah_show(aImageURL, aTitle, aText, aTextClickable, aCookie, aListener) { 1.12 + if (aListener) { 1.13 + Services.obs.addObserver(this, "metro_native_toast_clicked", false); 1.14 + Services.obs.addObserver(this, "metro_native_toast_dismissed", false); 1.15 + Services.obs.addObserver(this, "metro_native_toast_shown", false); 1.16 + } 1.17 + this._listener = aListener; 1.18 + 1.19 + if (Services.metro.foreground) { 1.20 + // Firefox is in the foreground, no need for a notification. 1.21 + return; 1.22 + } 1.23 + Services.metro.showNativeToast(aTitle, aText, aImageURL, aCookie); 1.24 + }, 1.25 + 1.26 + closeAlert: function ah_close() { 1.27 + if (this._listener) { 1.28 + Services.obs.removeObserver(this, "metro_native_toast_shown"); 1.29 + Services.obs.removeObserver(this, "metro_native_toast_clicked"); 1.30 + Services.obs.removeObserver(this, "metro_native_toast_dismissed"); 1.31 + this._listener = null; 1.32 + } 1.33 + }, 1.34 + 1.35 + observe: function(aSubject, aTopic, aData) { 1.36 + switch (aTopic) { 1.37 + case "metro_native_toast_clicked": 1.38 + this._listener.observe(null, "alertclickcallback", aData); 1.39 + break; 1.40 + case "metro_native_toast_shown": 1.41 + this._listener.observe(null, "alertshow", aData); 1.42 + break; 1.43 + case "metro_native_toast_dismissed": 1.44 + this._listener.observe(null, "alertfinished", aData); 1.45 + break; 1.46 + } 1.47 + } 1.48 +};