electron/shell/browser/notifications/win/windows_toast_notification.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

140 lines
5.3 KiB
C
Raw Normal View History

2017-03-23 19:48:22 +00: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
// and released it as MIT to the world.
#ifndef ELECTRON_SHELL_BROWSER_NOTIFICATIONS_WIN_WINDOWS_TOAST_NOTIFICATION_H_
#define ELECTRON_SHELL_BROWSER_NOTIFICATIONS_WIN_WINDOWS_TOAST_NOTIFICATION_H_
#include <windows.h>
#include <windows.ui.notifications.h>
#include <wrl/implements.h>
#include <string>
#include "shell/browser/notifications/notification.h"
2017-03-23 19:48:22 +00:00
using Microsoft::WRL::ClassicCom;
using Microsoft::WRL::ComPtr;
using Microsoft::WRL::Make;
using Microsoft::WRL::RuntimeClass;
using Microsoft::WRL::RuntimeClassFlags;
namespace electron {
2018-10-24 10:49:10 +00:00
class ScopedHString;
using DesktopToastActivatedEventHandler =
2017-03-23 19:48:22 +00:00
ABI::Windows::Foundation::ITypedEventHandler<
ABI::Windows::UI::Notifications::ToastNotification*,
IInspectable*>;
using DesktopToastDismissedEventHandler =
2017-03-23 19:48:22 +00:00
ABI::Windows::Foundation::ITypedEventHandler<
ABI::Windows::UI::Notifications::ToastNotification*,
ABI::Windows::UI::Notifications::ToastDismissedEventArgs*>;
using DesktopToastFailedEventHandler =
2017-03-23 19:48:22 +00:00
ABI::Windows::Foundation::ITypedEventHandler<
ABI::Windows::UI::Notifications::ToastNotification*,
ABI::Windows::UI::Notifications::ToastFailedEventArgs*>;
2015-12-25 03:05:48 +00:00
class WindowsToastNotification : public Notification {
public:
2015-12-25 03:05:48 +00:00
// Should only be called by NotificationPresenterWin.
static bool Initialize();
2015-12-25 03:05:48 +00:00
WindowsToastNotification(NotificationDelegate* delegate,
NotificationPresenter* presenter);
~WindowsToastNotification() override;
2015-12-25 03:05:48 +00:00
protected:
// Notification:
2017-06-24 11:03:27 +00:00
void Show(const NotificationOptions& options) override;
2015-12-25 03:05:48 +00:00
void Dismiss() override;
void Remove() override;
private:
2015-11-10 12:23:08 +00:00
friend class ToastEventHandler;
HRESULT ShowInternal(const NotificationOptions& options);
HRESULT GetToastXml(
2017-03-23 19:48:22 +00:00
ABI::Windows::UI::Notifications::IToastNotificationManagerStatics*
toastManager,
const std::u16string& title,
const std::u16string& msg,
2017-03-23 19:48:22 +00:00
const std::wstring& icon_path,
const std::u16string& timeout_type,
2017-03-23 19:48:22 +00:00
const bool silent,
ABI::Windows::Data::Xml::Dom::IXmlDocument** toast_xml);
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,
const std::u16string& text);
HRESULT SetXmlText(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc,
const std::u16string& title,
const std::u16string& body);
HRESULT SetXmlImage(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc,
const std::wstring& icon_path);
HRESULT GetTextNodeList(
ScopedHString* tag,
ABI::Windows::Data::Xml::Dom::IXmlDocument* doc,
ABI::Windows::Data::Xml::Dom::IXmlNodeList** node_list,
uint32_t req_length);
HRESULT AppendTextToXml(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc,
ABI::Windows::Data::Xml::Dom::IXmlNode* node,
const std::u16string& text);
HRESULT XmlDocumentFromString(
const wchar_t* xmlString,
ABI::Windows::Data::Xml::Dom::IXmlDocument** doc);
HRESULT SetupCallbacks(
2017-03-23 19:48:22 +00:00
ABI::Windows::UI::Notifications::IToastNotification* toast);
bool RemoveCallbacks(
ABI::Windows::UI::Notifications::IToastNotification* toast);
2015-11-10 12:23:08 +00:00
2017-03-23 19:48:22 +00:00
static ComPtr<
ABI::Windows::UI::Notifications::IToastNotificationManagerStatics>
toast_manager_;
static ComPtr<ABI::Windows::UI::Notifications::IToastNotifier>
toast_notifier_;
2015-12-25 03:05:48 +00:00
EventRegistrationToken activated_token_;
EventRegistrationToken dismissed_token_;
EventRegistrationToken failed_token_;
2015-11-10 12:23:08 +00:00
ComPtr<ToastEventHandler> event_handler_;
2017-03-23 19:48:22 +00:00
ComPtr<ABI::Windows::UI::Notifications::IToastNotification>
toast_notification_;
};
class ToastEventHandler : public RuntimeClass<RuntimeClassFlags<ClassicCom>,
DesktopToastActivatedEventHandler,
DesktopToastDismissedEventHandler,
DesktopToastFailedEventHandler> {
public:
2017-03-23 19:48:22 +00:00
explicit ToastEventHandler(Notification* notification);
~ToastEventHandler() override;
// disable copy
ToastEventHandler(const ToastEventHandler&) = delete;
ToastEventHandler& operator=(const ToastEventHandler&) = delete;
2017-03-23 19:48:22 +00:00
IFACEMETHODIMP Invoke(
ABI::Windows::UI::Notifications::IToastNotification* sender,
chore: bump chromium to 2a7aff41ce73adc0eeee67d364989 (master) (#18505) * chore: bump chromium in DEPS to 07463d3cd628b037c11f36022cb4c788db4628e3 * chore: update patches * fix: Don't leak system network context when nw service is disabled https://chromium-review.googlesource.com/c/chromium/src/+/1632494 NetworkService is now deleted by using SequnceLocalStorageSlot on the IO thread when the service is disabled, which expects all associated NetworkContexts on that sequence to be destroyed. * chore: bump chromium in DEPS to 7c16850e7e40990e141f47101b737ec1092175a1 * fix: Destroy all network contexts before primary network context * Simplify out-of-process service registration https://chromium-review.googlesource.com/c/chromium/src/+/1615882 * [ThreadPool] Rename base::ThreadPool to base::ThreadPoolInstance https://chromium-review.googlesource.com/c/chromium/src/+/1634851 * chore: update patches * fix: -Winconsistent-missing-override warnings * chore: bump chromium in DEPS to 93ebfaccc12715df1d5426797998eed0932f7ae1 * Change CreateBrowserMainParts to return unique_ptrs https://chromium-review.googlesource.com/c/chromium/src/+/1632532 * chore: update patches * chore: bump chromium in DEPS to e656555ffb87bdd05e248d0a3ef9dd9d3433e17b * chore: bump chromium in DEPS to 111e7a8d2e3ae9d70e535009d6afb066ac906063 * chore: bump chromium in DEPS to 9b6b84670d32a7aff41ce73adc0eeee67d364989 * chore: update patches * chore: remove ShouldInterceptResourceAsStream as it is removed upstream Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1639597 * chore: remove ResourceDispatcherHostCreated as it is removed upstream Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1610892 * chore: CreateWithStrongBinding --> CreateWithSelfOwnedReceiver Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1636722 * chore: rename all blink media enums Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1639237 * chore: add accidentally removed patch content back
2019-06-04 03:44:12 +00:00
IInspectable* args) override;
2017-03-23 19:48:22 +00:00
IFACEMETHODIMP Invoke(
ABI::Windows::UI::Notifications::IToastNotification* sender,
chore: bump chromium to 2a7aff41ce73adc0eeee67d364989 (master) (#18505) * chore: bump chromium in DEPS to 07463d3cd628b037c11f36022cb4c788db4628e3 * chore: update patches * fix: Don't leak system network context when nw service is disabled https://chromium-review.googlesource.com/c/chromium/src/+/1632494 NetworkService is now deleted by using SequnceLocalStorageSlot on the IO thread when the service is disabled, which expects all associated NetworkContexts on that sequence to be destroyed. * chore: bump chromium in DEPS to 7c16850e7e40990e141f47101b737ec1092175a1 * fix: Destroy all network contexts before primary network context * Simplify out-of-process service registration https://chromium-review.googlesource.com/c/chromium/src/+/1615882 * [ThreadPool] Rename base::ThreadPool to base::ThreadPoolInstance https://chromium-review.googlesource.com/c/chromium/src/+/1634851 * chore: update patches * fix: -Winconsistent-missing-override warnings * chore: bump chromium in DEPS to 93ebfaccc12715df1d5426797998eed0932f7ae1 * Change CreateBrowserMainParts to return unique_ptrs https://chromium-review.googlesource.com/c/chromium/src/+/1632532 * chore: update patches * chore: bump chromium in DEPS to e656555ffb87bdd05e248d0a3ef9dd9d3433e17b * chore: bump chromium in DEPS to 111e7a8d2e3ae9d70e535009d6afb066ac906063 * chore: bump chromium in DEPS to 9b6b84670d32a7aff41ce73adc0eeee67d364989 * chore: update patches * chore: remove ShouldInterceptResourceAsStream as it is removed upstream Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1639597 * chore: remove ResourceDispatcherHostCreated as it is removed upstream Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1610892 * chore: CreateWithStrongBinding --> CreateWithSelfOwnedReceiver Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1636722 * chore: rename all blink media enums Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1639237 * chore: add accidentally removed patch content back
2019-06-04 03:44:12 +00:00
ABI::Windows::UI::Notifications::IToastDismissedEventArgs* e) override;
2017-03-23 19:48:22 +00:00
IFACEMETHODIMP Invoke(
ABI::Windows::UI::Notifications::IToastNotification* sender,
chore: bump chromium to 2a7aff41ce73adc0eeee67d364989 (master) (#18505) * chore: bump chromium in DEPS to 07463d3cd628b037c11f36022cb4c788db4628e3 * chore: update patches * fix: Don't leak system network context when nw service is disabled https://chromium-review.googlesource.com/c/chromium/src/+/1632494 NetworkService is now deleted by using SequnceLocalStorageSlot on the IO thread when the service is disabled, which expects all associated NetworkContexts on that sequence to be destroyed. * chore: bump chromium in DEPS to 7c16850e7e40990e141f47101b737ec1092175a1 * fix: Destroy all network contexts before primary network context * Simplify out-of-process service registration https://chromium-review.googlesource.com/c/chromium/src/+/1615882 * [ThreadPool] Rename base::ThreadPool to base::ThreadPoolInstance https://chromium-review.googlesource.com/c/chromium/src/+/1634851 * chore: update patches * fix: -Winconsistent-missing-override warnings * chore: bump chromium in DEPS to 93ebfaccc12715df1d5426797998eed0932f7ae1 * Change CreateBrowserMainParts to return unique_ptrs https://chromium-review.googlesource.com/c/chromium/src/+/1632532 * chore: update patches * chore: bump chromium in DEPS to e656555ffb87bdd05e248d0a3ef9dd9d3433e17b * chore: bump chromium in DEPS to 111e7a8d2e3ae9d70e535009d6afb066ac906063 * chore: bump chromium in DEPS to 9b6b84670d32a7aff41ce73adc0eeee67d364989 * chore: update patches * chore: remove ShouldInterceptResourceAsStream as it is removed upstream Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1639597 * chore: remove ResourceDispatcherHostCreated as it is removed upstream Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1610892 * chore: CreateWithStrongBinding --> CreateWithSelfOwnedReceiver Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1636722 * chore: rename all blink media enums Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1639237 * chore: add accidentally removed patch content back
2019-06-04 03:44:12 +00:00
ABI::Windows::UI::Notifications::IToastFailedEventArgs* e) override;
private:
base::WeakPtr<Notification> notification_; // weak ref.
};
} // namespace electron
#endif // ELECTRON_SHELL_BROWSER_NOTIFICATIONS_WIN_WINDOWS_TOAST_NOTIFICATION_H_