2015-11-08 06:11:15 +00:00
|
|
|
// Copyright (c) 2015 Felix Rieseberg <feriese@microsoft.com> and Jason Poon <jason.poon@microsoft.com>. All rights reserved.
|
2015-11-08 03:41:29 +00:00
|
|
|
// Copyright (c) 2015 Ryan McShane <rmcshane@bandwidth.com> and Brandon Smith <bsmith@bandwidth.com>
|
|
|
|
// Thanks to both of those folks mentioned above who first thought up a bunch of this code
|
|
|
|
// and released it as MIT to the world.
|
|
|
|
|
2015-11-04 18:13:52 +00:00
|
|
|
#ifndef __WINDOWS_TOAST_NOTIFICATION_H__
|
|
|
|
#define __WINDOWS_TOAST_NOTIFICATION_H__
|
|
|
|
|
2015-11-08 03:41:29 +00:00
|
|
|
#include "content/public/browser/desktop_notification_delegate.h"
|
|
|
|
#include "content/public/common/platform_notification_data.h"
|
|
|
|
#include "base/bind.h"
|
|
|
|
|
2015-11-04 18:13:52 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <windows.ui.notifications.h>
|
|
|
|
#include <wrl/implements.h>
|
|
|
|
|
|
|
|
using namespace Microsoft::WRL;
|
|
|
|
using namespace ABI::Windows::UI::Notifications;
|
|
|
|
using namespace ABI::Windows::Foundation;
|
|
|
|
|
2015-11-08 06:11:15 +00:00
|
|
|
namespace WinToasts {
|
2015-11-04 18:13:52 +00:00
|
|
|
|
|
|
|
typedef ITypedEventHandler<ToastNotification*, IInspectable*> DesktopToastActivatedEventHandler;
|
|
|
|
typedef ITypedEventHandler<ToastNotification*, ToastDismissedEventArgs*> DesktopToastDismissedEventHandler;
|
|
|
|
|
|
|
|
class ToastEventHandler;
|
|
|
|
|
|
|
|
class WindowsToastNotification
|
|
|
|
{
|
|
|
|
public:
|
2015-11-08 03:41:29 +00:00
|
|
|
WindowsToastNotification(const char* appName, content::DesktopNotificationDelegate* delegate);
|
2015-11-04 18:13:52 +00:00
|
|
|
~WindowsToastNotification();
|
2015-11-08 06:11:15 +00:00
|
|
|
void ShowNotification(const WCHAR* title, const WCHAR* msg, std::string iconPath, ComPtr<IToastNotification>& toast);
|
|
|
|
void DismissNotification(ComPtr<IToastNotification> toast);
|
2015-11-04 18:13:52 +00:00
|
|
|
void NotificationClicked();
|
|
|
|
void NotificationDismissed();
|
2015-11-08 06:11:15 +00:00
|
|
|
|
|
|
|
private:
|
2015-11-09 19:47:18 +00:00
|
|
|
ComPtr<ToastEventHandler> m_eventHandler;
|
2015-11-08 06:11:15 +00:00
|
|
|
|
|
|
|
content::DesktopNotificationDelegate* n_delegate;
|
|
|
|
ComPtr<IToastNotificationManagerStatics> m_toastManager;
|
|
|
|
ComPtr<IToastNotifier> m_toastNotifier;
|
|
|
|
|
|
|
|
HRESULT GetToastXml(IToastNotificationManagerStatics* toastManager, const WCHAR* title, const WCHAR* msg, std::string iconPath, ABI::Windows::Data::Xml::Dom::IXmlDocument** toastXml);
|
|
|
|
HRESULT SetXmlText(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, const WCHAR* text);
|
|
|
|
HRESULT SetXmlText(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, const WCHAR* title, const WCHAR* body);
|
|
|
|
HRESULT SetXmlImage(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, std::string iconPath);
|
|
|
|
HRESULT GetTextNodeList(HSTRING* tag, ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, ABI::Windows::Data::Xml::Dom::IXmlNodeList** nodeList, UINT32 reqLength);
|
|
|
|
HRESULT AppendTextToXml(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, ABI::Windows::Data::Xml::Dom::IXmlNode* node, const WCHAR* text);
|
|
|
|
HRESULT SetupCallbacks(IToastNotification* toast);
|
|
|
|
HRESULT CreateHString(const WCHAR* source, HSTRING* dest);
|
2015-11-04 18:13:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ToastEventHandler :
|
2015-11-09 19:47:18 +00:00
|
|
|
public RuntimeClass<RuntimeClassFlags<ClassicCom>, DesktopToastActivatedEventHandler, DesktopToastDismissedEventHandler>
|
2015-11-04 18:13:52 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-11-08 03:41:29 +00:00
|
|
|
ToastEventHandler(WindowsToastNotification* notification, content::DesktopNotificationDelegate* delegate);
|
2015-11-04 18:13:52 +00:00
|
|
|
~ToastEventHandler();
|
|
|
|
IFACEMETHODIMP Invoke(IToastNotification* sender, IInspectable* args);
|
|
|
|
IFACEMETHODIMP Invoke(IToastNotification* sender, IToastDismissedEventArgs* e);
|
2015-11-08 06:11:15 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
WindowsToastNotification* m_notification;
|
|
|
|
content::DesktopNotificationDelegate* n_delegate;
|
2015-11-04 18:13:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#endif //__WINDOWS_TOAST_NOTIFICATION_H__
|