From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- widget/windows/ToastNotificationHandler.h | 151 ++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 widget/windows/ToastNotificationHandler.h (limited to 'widget/windows/ToastNotificationHandler.h') diff --git a/widget/windows/ToastNotificationHandler.h b/widget/windows/ToastNotificationHandler.h new file mode 100644 index 0000000000..e9f1f8d79c --- /dev/null +++ b/widget/windows/ToastNotificationHandler.h @@ -0,0 +1,151 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef ToastNotificationHandler_h__ +#define ToastNotificationHandler_h__ + +#include +#include +#include +#include "nsCOMPtr.h" +#include "nsIAlertsService.h" +#include "nsICancelable.h" +#include "nsIFile.h" +#include "nsString.h" +#include "mozilla/Result.h" + +namespace mozilla { +namespace widget { + +class ToastNotification; + +class ToastNotificationHandler final + : public nsIAlertNotificationImageListener { + public: + NS_DECL_ISUPPORTS + NS_DECL_NSIALERTNOTIFICATIONIMAGELISTENER + + ToastNotificationHandler(ToastNotification* backend, const nsAString& aumid, + nsIObserver* aAlertListener, const nsAString& aName, + const nsAString& aCookie, const nsAString& aTitle, + const nsAString& aMsg, const nsAString& aHostPort, + bool aClickable, bool aRequireInteraction, + const nsTArray>& aActions, + bool aIsSystemPrincipal, const nsAString& aLaunchUrl, + bool aInPrivateBrowsing, bool aIsSilent) + : mBackend(backend), + mAumid(aumid), + mHasImage(false), + mAlertListener(aAlertListener), + mName(aName), + mCookie(aCookie), + mTitle(aTitle), + mMsg(aMsg), + mHostPort(aHostPort), + mClickable(aClickable), + mRequireInteraction(aRequireInteraction), + mInPrivateBrowsing(aInPrivateBrowsing), + mActions(aActions.Clone()), + mIsSystemPrincipal(aIsSystemPrincipal), + mLaunchUrl(aLaunchUrl), + mIsSilent(aIsSilent), + mSentFinished(!aAlertListener) {} + + nsresult InitAlertAsync(nsIAlertNotification* aAlert); + + void OnWriteImageFinished(nsresult rv); + + void HideAlert(); + bool IsPrivate(); + + void UnregisterHandler(); + + nsresult CreateToastXmlString(const nsAString& aImageURL, nsAString& aString); + + nsresult GetWindowsTag(nsAString& aWindowsTag); + nsresult SetWindowsTag(const nsAString& aWindowsTag); + + // Exposed for consumption by `ToastNotification.cpp`. + static nsresult FindLaunchURLAndPrivilegedNameForWindowsTag( + const nsAString& aWindowsTag, const nsAString& aAumid, bool& aFoundTag, + nsAString& aLaunchUrl, nsAString& aPrivilegedName); + + protected: + virtual ~ToastNotificationHandler(); + + using IXmlDocument = ABI::Windows::Data::Xml::Dom::IXmlDocument; + using IToastNotifier = ABI::Windows::UI::Notifications::IToastNotifier; + using IToastNotification = + ABI::Windows::UI::Notifications::IToastNotification; + using IToastDismissedEventArgs = + ABI::Windows::UI::Notifications::IToastDismissedEventArgs; + using IToastFailedEventArgs = + ABI::Windows::UI::Notifications::IToastFailedEventArgs; + using ToastTemplateType = ABI::Windows::UI::Notifications::ToastTemplateType; + template + using ComPtr = Microsoft::WRL::ComPtr; + + Result GetLaunchArgument(); + + ComPtr mNotification; + ComPtr mNotifier; + + RefPtr mBackend; + + nsString mAumid; + nsString mWindowsTag; + + nsCOMPtr mImageRequest; + nsCOMPtr mImageFile; + nsString mImageUri; + bool mHasImage; + + EventRegistrationToken mActivatedToken; + EventRegistrationToken mDismissedToken; + EventRegistrationToken mFailedToken; + + nsCOMPtr mAlertListener; + nsString mName; + nsString mCookie; + nsString mTitle; + nsString mMsg; + nsString mHostPort; + bool mClickable; + bool mRequireInteraction; + bool mInPrivateBrowsing; + nsTArray> mActions; + bool mIsSystemPrincipal; + nsString mLaunchUrl; + bool mIsSilent; + bool mSentFinished; + + nsresult TryShowAlert(); + bool ShowAlert(); + nsresult AsyncSaveImage(imgIRequest* aRequest); + nsresult OnWriteImageSuccess(); + void SendFinished(); + + nsresult InitWindowsTag(); + bool CreateWindowsNotificationFromXml(ComPtr& aToastXml); + ComPtr CreateToastXmlDocument(); + + HRESULT OnActivate(const ComPtr& notification, + const ComPtr& inspectable); + HRESULT OnDismiss(const ComPtr& notification, + const ComPtr& aArgs); + HRESULT OnFail(const ComPtr& notification, + const ComPtr& aArgs); + + static HRESULT GetLaunchArgumentValueForKey( + const ComPtr toast, const nsAString& key, + nsAString& value); + static ComPtr FindNotificationByTag( + const nsAString& aWindowsTag, const nsAString& aAumid); +}; + +} // namespace widget +} // namespace mozilla + +#endif -- cgit v1.2.3