diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /widget/windows/ToastNotification.h | |
parent | Initial commit. (diff) | |
download | firefox-e51783d008170d9ab27d25da98ca3a38b0a41b67.tar.xz firefox-e51783d008170d9ab27d25da98ca3a38b0a41b67.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'widget/windows/ToastNotification.h')
-rw-r--r-- | widget/windows/ToastNotification.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/widget/windows/ToastNotification.h b/widget/windows/ToastNotification.h new file mode 100644 index 0000000000..9beb08cc27 --- /dev/null +++ b/widget/windows/ToastNotification.h @@ -0,0 +1,83 @@ +/* -*- 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 ToastNotification_h__ +#define ToastNotification_h__ + +#include "mozilla/Maybe.h" +#include "mozilla/MozPromise.h" +#include "nsIAlertsService.h" +#include "nsIObserver.h" +#include "nsIThread.h" +#include "nsIWindowsAlertsService.h" +#include "nsRefPtrHashtable.h" +#include "mozilla/AlertNotification.h" + +namespace mozilla { +namespace widget { + +using ToastHandledPromise = MozPromise<bool, bool, true>; + +class ToastNotificationHandler; + +class WindowsAlertNotification final : public AlertNotification, + public nsIWindowsAlertNotification { + public: + NS_DECL_NSIWINDOWSALERTNOTIFICATION + NS_FORWARD_NSIALERTNOTIFICATION(AlertNotification::) + NS_DECL_ISUPPORTS_INHERITED + + WindowsAlertNotification() = default; + + protected: + virtual ~WindowsAlertNotification() = default; + bool mHandleActions = false; + nsIWindowsAlertNotification::ImagePlacement mImagePlacement = eInline; +}; + +class ToastNotification final : public nsIWindowsAlertsService, + public nsIAlertsDoNotDisturb, + public nsIObserver { + public: + NS_DECL_NSIALERTSSERVICE + NS_DECL_NSIWINDOWSALERTSSERVICE + NS_DECL_NSIALERTSDONOTDISTURB + NS_DECL_NSIOBSERVER + NS_DECL_ISUPPORTS + + ToastNotification(); + + nsresult Init(); + + bool IsActiveHandler(const nsAString& aAlertName, + ToastNotificationHandler* aHandler); + void RemoveHandler(const nsAString& aAlertName, + ToastNotificationHandler* aHandler); + + nsresult BackgroundDispatch(nsIRunnable* runnable); + + protected: + virtual ~ToastNotification(); + bool EnsureAumidRegistered(); + + static bool AssignIfMsixAumid(Maybe<nsAutoString>& aAumid); + static bool AssignIfNsisAumid(nsAutoString& aInstallHash, + Maybe<nsAutoString>& aAumid); + static bool RegisterRuntimeAumid(nsAutoString& aInstallHash, + Maybe<nsAutoString>& aAumid); + + RefPtr<ToastHandledPromise> VerifyTagPresentOrFallback( + const nsAString& aWindowsTag); + static void SignalComNotificationHandled(const nsAString& aWindowsTag); + + nsRefPtrHashtable<nsStringHashKey, ToastNotificationHandler> mActiveHandlers; + Maybe<nsAutoString> mAumid; + bool mSuppressForScreenSharing = false; +}; + +} // namespace widget +} // namespace mozilla + +#endif |