| 
									
										
										
										
											2017-03-23 12:48:22 -07:00
										 |  |  | // Copyright (c) 2015 Felix Rieseberg <feriese@microsoft.com> and Jason Poon
 | 
					
						
							|  |  |  | // <jason.poon@microsoft.com>. All rights reserved.
 | 
					
						
							|  |  |  | // 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
 | 
					
						
							| 
									
										
										
										
											2015-11-07 19:41:29 -08:00
										 |  |  | // and released it as MIT to the world.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-22 08:34:31 +01:00
										 |  |  | #ifndef ELECTRON_SHELL_BROWSER_NOTIFICATIONS_WIN_WINDOWS_TOAST_NOTIFICATION_H_
 | 
					
						
							|  |  |  | #define ELECTRON_SHELL_BROWSER_NOTIFICATIONS_WIN_WINDOWS_TOAST_NOTIFICATION_H_
 | 
					
						
							| 
									
										
										
										
											2015-11-07 19:41:29 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-04 10:13:52 -08:00
										 |  |  | #include <windows.h>
 | 
					
						
							|  |  |  | #include <windows.ui.notifications.h>
 | 
					
						
							|  |  |  | #include <wrl/implements.h>
 | 
					
						
							| 
									
										
										
										
											2017-05-18 15:06:57 -07:00
										 |  |  | #include <string>
 | 
					
						
							| 
									
										
										
										
											2017-06-23 20:39:42 +10:00
										 |  |  | #include <vector>
 | 
					
						
							| 
									
										
										
										
											2015-11-04 10:13:52 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 13:46:59 -07:00
										 |  |  | #include "shell/browser/notifications/notification.h"
 | 
					
						
							| 
									
										
										
										
											2015-11-10 18:27:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-23 12:48:22 -07:00
										 |  |  | using Microsoft::WRL::ClassicCom; | 
					
						
							|  |  |  | using Microsoft::WRL::ComPtr; | 
					
						
							|  |  |  | using Microsoft::WRL::Make; | 
					
						
							|  |  |  | using Microsoft::WRL::RuntimeClass; | 
					
						
							|  |  |  | using Microsoft::WRL::RuntimeClassFlags; | 
					
						
							| 
									
										
										
										
											2015-11-04 10:13:52 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-17 20:01:11 +02:00
										 |  |  | namespace electron { | 
					
						
							| 
									
										
										
										
											2015-11-04 10:13:52 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-24 12:49:10 +02:00
										 |  |  | class ScopedHString; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-10 18:27:18 +08:00
										 |  |  | using DesktopToastActivatedEventHandler = | 
					
						
							| 
									
										
										
										
											2017-03-23 12:48:22 -07:00
										 |  |  |     ABI::Windows::Foundation::ITypedEventHandler< | 
					
						
							|  |  |  |         ABI::Windows::UI::Notifications::ToastNotification*, | 
					
						
							|  |  |  |         IInspectable*>; | 
					
						
							| 
									
										
										
										
											2015-11-10 18:27:18 +08:00
										 |  |  | using DesktopToastDismissedEventHandler = | 
					
						
							| 
									
										
										
										
											2017-03-23 12:48:22 -07:00
										 |  |  |     ABI::Windows::Foundation::ITypedEventHandler< | 
					
						
							|  |  |  |         ABI::Windows::UI::Notifications::ToastNotification*, | 
					
						
							|  |  |  |         ABI::Windows::UI::Notifications::ToastDismissedEventArgs*>; | 
					
						
							| 
									
										
										
										
											2015-11-10 20:39:24 +01:00
										 |  |  | using DesktopToastFailedEventHandler = | 
					
						
							| 
									
										
										
										
											2017-03-23 12:48:22 -07:00
										 |  |  |     ABI::Windows::Foundation::ITypedEventHandler< | 
					
						
							|  |  |  |         ABI::Windows::UI::Notifications::ToastNotification*, | 
					
						
							|  |  |  |         ABI::Windows::UI::Notifications::ToastFailedEventArgs*>; | 
					
						
							| 
									
										
										
										
											2015-11-10 18:27:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-25 11:05:48 +08:00
										 |  |  | class WindowsToastNotification : public Notification { | 
					
						
							| 
									
										
										
										
											2015-11-10 18:27:18 +08:00
										 |  |  |  public: | 
					
						
							| 
									
										
										
										
											2015-12-25 11:05:48 +08:00
										 |  |  |   // Should only be called by NotificationPresenterWin.
 | 
					
						
							| 
									
										
										
										
											2015-11-24 14:40:58 +08:00
										 |  |  |   static bool Initialize(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-25 11:05:48 +08:00
										 |  |  |   WindowsToastNotification(NotificationDelegate* delegate, | 
					
						
							|  |  |  |                            NotificationPresenter* presenter); | 
					
						
							| 
									
										
										
										
											2018-06-21 16:45:45 -07:00
										 |  |  |   ~WindowsToastNotification() override; | 
					
						
							| 
									
										
										
										
											2015-11-10 18:27:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-25 11:05:48 +08:00
										 |  |  |  protected: | 
					
						
							|  |  |  |   // Notification:
 | 
					
						
							| 
									
										
										
										
											2017-06-24 21:03:27 +10:00
										 |  |  |   void Show(const NotificationOptions& options) override; | 
					
						
							| 
									
										
										
										
											2015-12-25 11:05:48 +08:00
										 |  |  |   void Dismiss() override; | 
					
						
							| 
									
										
										
										
											2015-11-10 18:27:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |  private: | 
					
						
							| 
									
										
										
										
											2015-11-10 20:23:08 +08:00
										 |  |  |   friend class ToastEventHandler; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-29 12:20:10 -07:00
										 |  |  |   HRESULT ShowInternal(const NotificationOptions& options); | 
					
						
							|  |  |  |   HRESULT GetToastXml( | 
					
						
							| 
									
										
										
										
											2017-03-23 12:48:22 -07:00
										 |  |  |       ABI::Windows::UI::Notifications::IToastNotificationManagerStatics* | 
					
						
							|  |  |  |           toastManager, | 
					
						
							| 
									
										
										
										
											2021-07-12 13:33:26 +09:00
										 |  |  |       const std::u16string& title, | 
					
						
							|  |  |  |       const std::u16string& msg, | 
					
						
							| 
									
										
										
										
											2017-03-23 12:48:22 -07:00
										 |  |  |       const std::wstring& icon_path, | 
					
						
							| 
									
										
										
										
											2021-07-12 13:33:26 +09:00
										 |  |  |       const std::u16string& timeout_type, | 
					
						
							| 
									
										
										
										
											2017-03-23 12:48:22 -07:00
										 |  |  |       const bool silent, | 
					
						
							| 
									
										
										
										
											2020-10-27 08:18:36 -07:00
										 |  |  |       ABI::Windows::Data::Xml::Dom::IXmlDocument** toast_xml); | 
					
						
							| 
									
										
										
										
											2020-09-29 12:20:10 -07:00
										 |  |  |   HRESULT SetXmlAudioSilent(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc); | 
					
						
							|  |  |  |   HRESULT SetXmlScenarioReminder( | 
					
						
							|  |  |  |       ABI::Windows::Data::Xml::Dom::IXmlDocument* doc); | 
					
						
							|  |  |  |   HRESULT SetXmlText(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, | 
					
						
							| 
									
										
										
										
											2021-07-12 13:33:26 +09:00
										 |  |  |                      const std::u16string& text); | 
					
						
							| 
									
										
										
										
											2020-09-29 12:20:10 -07:00
										 |  |  |   HRESULT SetXmlText(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, | 
					
						
							| 
									
										
										
										
											2021-07-12 13:33:26 +09:00
										 |  |  |                      const std::u16string& title, | 
					
						
							|  |  |  |                      const std::u16string& body); | 
					
						
							| 
									
										
										
										
											2020-09-29 12:20:10 -07:00
										 |  |  |   HRESULT SetXmlImage(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, | 
					
						
							|  |  |  |                       const std::wstring& icon_path); | 
					
						
							| 
									
										
										
										
											2020-10-27 08:18:36 -07:00
										 |  |  |   HRESULT GetTextNodeList( | 
					
						
							|  |  |  |       ScopedHString* tag, | 
					
						
							|  |  |  |       ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, | 
					
						
							|  |  |  |       ABI::Windows::Data::Xml::Dom::IXmlNodeList** node_list, | 
					
						
							|  |  |  |       uint32_t req_length); | 
					
						
							| 
									
										
										
										
											2020-09-29 12:20:10 -07:00
										 |  |  |   HRESULT AppendTextToXml(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, | 
					
						
							|  |  |  |                           ABI::Windows::Data::Xml::Dom::IXmlNode* node, | 
					
						
							| 
									
										
										
										
											2021-07-12 13:33:26 +09:00
										 |  |  |                           const std::u16string& text); | 
					
						
							| 
									
										
										
										
											2020-09-29 12:20:10 -07:00
										 |  |  |   HRESULT XmlDocumentFromString( | 
					
						
							|  |  |  |       const wchar_t* xmlString, | 
					
						
							|  |  |  |       ABI::Windows::Data::Xml::Dom::IXmlDocument** doc); | 
					
						
							|  |  |  |   HRESULT SetupCallbacks( | 
					
						
							| 
									
										
										
										
											2017-03-23 12:48:22 -07:00
										 |  |  |       ABI::Windows::UI::Notifications::IToastNotification* toast); | 
					
						
							|  |  |  |   bool RemoveCallbacks( | 
					
						
							|  |  |  |       ABI::Windows::UI::Notifications::IToastNotification* toast); | 
					
						
							| 
									
										
										
										
											2015-11-10 20:23:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-23 12:48:22 -07:00
										 |  |  |   static ComPtr< | 
					
						
							|  |  |  |       ABI::Windows::UI::Notifications::IToastNotificationManagerStatics> | 
					
						
							|  |  |  |       toast_manager_; | 
					
						
							|  |  |  |   static ComPtr<ABI::Windows::UI::Notifications::IToastNotifier> | 
					
						
							|  |  |  |       toast_notifier_; | 
					
						
							| 
									
										
										
										
											2015-11-24 14:40:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-25 11:05:48 +08:00
										 |  |  |   EventRegistrationToken activated_token_; | 
					
						
							|  |  |  |   EventRegistrationToken dismissed_token_; | 
					
						
							|  |  |  |   EventRegistrationToken failed_token_; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-10 20:23:08 +08:00
										 |  |  |   ComPtr<ToastEventHandler> event_handler_; | 
					
						
							| 
									
										
										
										
											2017-03-23 12:48:22 -07:00
										 |  |  |   ComPtr<ABI::Windows::UI::Notifications::IToastNotification> | 
					
						
							|  |  |  |       toast_notification_; | 
					
						
							| 
									
										
										
										
											2015-11-10 18:27:18 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ToastEventHandler : public RuntimeClass<RuntimeClassFlags<ClassicCom>, | 
					
						
							|  |  |  |                                               DesktopToastActivatedEventHandler, | 
					
						
							| 
									
										
										
										
											2015-11-10 20:39:24 +01:00
										 |  |  |                                               DesktopToastDismissedEventHandler, | 
					
						
							|  |  |  |                                               DesktopToastFailedEventHandler> { | 
					
						
							| 
									
										
										
										
											2015-11-10 18:27:18 +08:00
										 |  |  |  public: | 
					
						
							| 
									
										
										
										
											2017-03-23 12:48:22 -07:00
										 |  |  |   explicit ToastEventHandler(Notification* notification); | 
					
						
							| 
									
										
										
										
											2018-06-21 16:45:45 -07:00
										 |  |  |   ~ToastEventHandler() override; | 
					
						
							| 
									
										
										
										
											2015-11-10 18:27:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-03 12:41:45 +01:00
										 |  |  |   // disable copy
 | 
					
						
							|  |  |  |   ToastEventHandler(const ToastEventHandler&) = delete; | 
					
						
							|  |  |  |   ToastEventHandler& operator=(const ToastEventHandler&) = delete; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-23 12:48:22 -07:00
										 |  |  |   IFACEMETHODIMP Invoke( | 
					
						
							|  |  |  |       ABI::Windows::UI::Notifications::IToastNotification* sender, | 
					
						
							| 
									
										
										
										
											2019-06-03 20:44:12 -07:00
										 |  |  |       IInspectable* args) override; | 
					
						
							| 
									
										
										
										
											2017-03-23 12:48:22 -07:00
										 |  |  |   IFACEMETHODIMP Invoke( | 
					
						
							|  |  |  |       ABI::Windows::UI::Notifications::IToastNotification* sender, | 
					
						
							| 
									
										
										
										
											2019-06-03 20:44:12 -07:00
										 |  |  |       ABI::Windows::UI::Notifications::IToastDismissedEventArgs* e) override; | 
					
						
							| 
									
										
										
										
											2017-03-23 12:48:22 -07:00
										 |  |  |   IFACEMETHODIMP Invoke( | 
					
						
							|  |  |  |       ABI::Windows::UI::Notifications::IToastNotification* sender, | 
					
						
							| 
									
										
										
										
											2019-06-03 20:44:12 -07:00
										 |  |  |       ABI::Windows::UI::Notifications::IToastFailedEventArgs* e) override; | 
					
						
							| 
									
										
										
										
											2015-11-10 18:27:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |  private: | 
					
						
							| 
									
										
										
										
											2016-04-15 16:14:13 +09:00
										 |  |  |   base::WeakPtr<Notification> notification_;  // weak ref.
 | 
					
						
							| 
									
										
										
										
											2015-11-10 18:27:18 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2015-11-04 10:13:52 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-17 20:01:11 +02:00
										 |  |  | }  // namespace electron
 | 
					
						
							| 
									
										
										
										
											2015-11-04 10:13:52 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-22 08:34:31 +01:00
										 |  |  | #endif  // ELECTRON_SHELL_BROWSER_NOTIFICATIONS_WIN_WINDOWS_TOAST_NOTIFICATION_H_
 |