mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 919929 - AlertsService for Metro should send alertshow and alertfinished observer. r=jimm
This commit is contained in:
parent
8175bc3b2a
commit
f6a8ad20c1
@ -4,21 +4,37 @@
|
||||
|
||||
var AlertsHelper = {
|
||||
_listener: null,
|
||||
_cookie: "",
|
||||
|
||||
showAlertNotification: function ah_show(aImageURL, aTitle, aText, aTextClickable, aCookie, aListener) {
|
||||
Services.obs.addObserver(this, "metro_native_toast_clicked", false);
|
||||
if (aListener) {
|
||||
Services.obs.addObserver(this, "metro_native_toast_clicked", false);
|
||||
Services.obs.addObserver(this, "metro_native_toast_dismissed", false);
|
||||
Services.obs.addObserver(this, "metro_native_toast_shown", false);
|
||||
}
|
||||
this._listener = aListener;
|
||||
this._cookie = aCookie;
|
||||
|
||||
Services.metro.showNativeToast(aTitle, aText, aImageURL);
|
||||
Services.metro.showNativeToast(aTitle, aText, aImageURL, aCookie);
|
||||
},
|
||||
|
||||
closeAlert: function ah_close() {
|
||||
if (this._listener) {
|
||||
Services.obs.removeObserver(this, "metro_native_toast_shown");
|
||||
Services.obs.removeObserver(this, "metro_native_toast_clicked");
|
||||
Services.obs.removeObserver(this, "metro_native_toast_dismissed");
|
||||
this._listener = null;
|
||||
}
|
||||
},
|
||||
|
||||
observe: function(aSubject, aTopic, aData) {
|
||||
switch (aTopic) {
|
||||
case "metro_native_toast_clicked":
|
||||
Services.obs.removeObserver(this, "metro_native_toast_clicked");
|
||||
this._listener.observe(null, "alertclickcallback", this._cookie);
|
||||
this._listener.observe(null, "alertclickcallback", aData);
|
||||
break;
|
||||
case "metro_native_toast_shown":
|
||||
this._listener.observe(null, "alertshow", aData);
|
||||
break;
|
||||
case "metro_native_toast_dismissed":
|
||||
this._listener.observe(null, "alertfinished", aData);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,8 @@ AlertsService.prototype = {
|
||||
classID: Components.ID("{fe33c107-82a4-41d6-8c64-5353267e04c9}"),
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIAlertsService]),
|
||||
|
||||
showAlertNotification: function(aImageUrl, aTitle, aText, aTextClickable, aCookie, aAlertListener, aName) {
|
||||
showAlertNotification: function(aImageUrl, aTitle, aText, aTextClickable,
|
||||
aCookie, aAlertListener, aName, aDir, aLang) {
|
||||
let browser = Services.wm.getMostRecentWindow("navigator:browser");
|
||||
try {
|
||||
browser.AlertsHelper.showAlertNotification(aImageUrl, aTitle, aText, aTextClickable, aCookie, aAlertListener);
|
||||
@ -33,6 +34,11 @@ AlertsService.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
closeAlert: function(aName) {
|
||||
let browser = Services.wm.getMostRecentWindow("navigator:browser");
|
||||
browser.AlertsHelper.closeAlert();
|
||||
},
|
||||
|
||||
_getChromeWindow: function (aWindow) {
|
||||
let chromeWin = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIWebNavigation)
|
||||
|
@ -12,7 +12,7 @@
|
||||
* implementation of this interface for non-Windows systems, for testing and
|
||||
* development purposes only.
|
||||
*/
|
||||
[scriptable, uuid(fa6750a2-f0fe-411c-af23-1cd6d2fdeceb)]
|
||||
[scriptable, uuid(25524bde-8b30-4b49-8d67-7070c790aada)]
|
||||
interface nsIWinMetroUtils : nsISupports
|
||||
{
|
||||
/* return constants for the handPreference property */
|
||||
@ -49,7 +49,7 @@ interface nsIWinMetroUtils : nsISupports
|
||||
/**
|
||||
* Displays a native Windows 8 toast.
|
||||
*/
|
||||
void showNativeToast(in AString aTitle, in AString aMessage, in AString anImage);
|
||||
void showNativeToast(in AString aTitle, in AString aMessage, in AString anImage, in AString aCookie);
|
||||
|
||||
/**
|
||||
* Secondary tiles are a Windows 8 specific feature for pinning new tiles
|
||||
|
@ -16,8 +16,16 @@ using namespace mozilla;
|
||||
using namespace ABI::Windows::UI::Notifications;
|
||||
|
||||
typedef __FITypedEventHandler_2_Windows__CUI__CNotifications__CToastNotification_IInspectable_t ToastActivationHandler;
|
||||
typedef __FITypedEventHandler_2_Windows__CUI__CNotifications__CToastNotification_Windows__CUI__CNotifications__CToastDismissedEventArgs ToastDismissHandler;
|
||||
|
||||
void
|
||||
ToastNotificationHandler::DisplayNotification(HSTRING title,
|
||||
HSTRING msg,
|
||||
HSTRING imagePath,
|
||||
const nsAString& aCookie)
|
||||
{
|
||||
mCookie = aCookie;
|
||||
|
||||
void ToastNotificationHandler::DisplayNotification(HSTRING title, HSTRING msg, HSTRING imagePath) {
|
||||
ComPtr<IToastNotificationManagerStatics> toastNotificationManagerStatics;
|
||||
AssertHRESULT(GetActivationFactory(HStringReference(RuntimeClass_Windows_UI_Notifications_ToastNotificationManager).Get(),
|
||||
toastNotificationManagerStatics.GetAddressOf()));
|
||||
@ -57,10 +65,15 @@ void ToastNotificationHandler::DisplayNotification(HSTRING title, HSTRING msg, H
|
||||
EventRegistrationToken activatedToken;
|
||||
AssertHRESULT(notification->add_Activated(Callback<ToastActivationHandler>(this,
|
||||
&ToastNotificationHandler::OnActivate).Get(), &activatedToken));
|
||||
EventRegistrationToken dismissedToken;
|
||||
AssertHRESULT(notification->add_Dismissed(Callback<ToastDismissHandler>(this,
|
||||
&ToastNotificationHandler::OnDismiss).Get(), &dismissedToken));
|
||||
|
||||
ComPtr<IToastNotifier> notifier;
|
||||
toastNotificationManagerStatics->CreateToastNotifier(¬ifier);
|
||||
notifier->Show(notification.Get());
|
||||
|
||||
MetroUtils::FireObserver("metro_native_toast_shown", mCookie.get());
|
||||
}
|
||||
|
||||
void ToastNotificationHandler::SetNodeValueString(HSTRING inputString, ComPtr<IXmlNode> node, ComPtr<IXmlDocument> xml) {
|
||||
@ -73,6 +86,14 @@ void ToastNotificationHandler::SetNodeValueString(HSTRING inputString, ComPtr<IX
|
||||
}
|
||||
|
||||
HRESULT ToastNotificationHandler::OnActivate(IToastNotification *notification, IInspectable *inspectable) {
|
||||
MetroUtils::FireObserver("metro_native_toast_clicked");
|
||||
MetroUtils::FireObserver("metro_native_toast_clicked", mCookie.get());
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT
|
||||
ToastNotificationHandler::OnDismiss(IToastNotification *notification,
|
||||
IToastDismissedEventArgs* aArgs)
|
||||
{
|
||||
MetroUtils::FireObserver("metro_native_toast_dismissed", mCookie.get());
|
||||
return S_OK;
|
||||
}
|
||||
|
@ -8,11 +8,13 @@
|
||||
#include <windows.ui.notifications.h>
|
||||
#include <windows.data.xml.dom.h>
|
||||
#include "mozwrlbase.h"
|
||||
#include "nsString.h"
|
||||
|
||||
using namespace Microsoft::WRL;
|
||||
|
||||
class ToastNotificationHandler {
|
||||
typedef ABI::Windows::UI::Notifications::IToastNotification IToastNotification;
|
||||
typedef ABI::Windows::UI::Notifications::IToastDismissedEventArgs IToastDismissedEventArgs;
|
||||
typedef ABI::Windows::Data::Xml::Dom::IXmlNode IXmlNode;
|
||||
typedef ABI::Windows::Data::Xml::Dom::IXmlDocument IXmlDocument;
|
||||
|
||||
@ -21,6 +23,11 @@ class ToastNotificationHandler {
|
||||
ToastNotificationHandler() {};
|
||||
~ToastNotificationHandler() {};
|
||||
|
||||
void DisplayNotification(HSTRING title, HSTRING msg, HSTRING imagePath);
|
||||
void DisplayNotification(HSTRING title, HSTRING msg, HSTRING imagePath, const nsAString& aCookie);
|
||||
HRESULT OnActivate(IToastNotification *notification, IInspectable *inspectable);
|
||||
HRESULT OnDismiss(IToastNotification *notification,
|
||||
IToastDismissedEventArgs* aArgs);
|
||||
|
||||
private:
|
||||
nsString mCookie;
|
||||
};
|
||||
|
@ -345,7 +345,8 @@ nsWinMetroUtils::LaunchInDesktop(const nsAString &aPath, const nsAString &aArgum
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsWinMetroUtils::ShowNativeToast(const nsAString &aTitle,
|
||||
const nsAString &aMessage, const nsAString &anImage)
|
||||
const nsAString &aMessage, const nsAString &anImage,
|
||||
const nsAString &aCookie)
|
||||
{
|
||||
// Firefox is in the foreground, no need for a notification.
|
||||
if (::GetActiveWindow() == ::GetForegroundWindow()) {
|
||||
@ -358,7 +359,7 @@ nsWinMetroUtils::ShowNativeToast(const nsAString &aTitle,
|
||||
HSTRING title = HStringReference(aTitle.BeginReading()).Get();
|
||||
HSTRING msg = HStringReference(aMessage.BeginReading()).Get();
|
||||
HSTRING imagePath = HStringReference(anImage.BeginReading()).Get();
|
||||
notification_handler->DisplayNotification(title, msg, imagePath);
|
||||
notification_handler->DisplayNotification(title, msg, imagePath, aCookie);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user