1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef ToastNotification_h__
7 #define ToastNotification_h__
9 #include "mozilla/Maybe.h"
10 #include "mozilla/MozPromise.h"
11 #include "nsIAlertsService.h"
12 #include "nsIObserver.h"
13 #include "nsIThread.h"
14 #include "nsIWindowsAlertsService.h"
15 #include "nsRefPtrHashtable.h"
16 #include "mozilla/AlertNotification.h"
21 using ToastHandledPromise
= MozPromise
<bool, bool, true>;
23 class ToastNotificationHandler
;
25 class WindowsAlertNotification final
: public AlertNotification
,
26 public nsIWindowsAlertNotification
{
28 NS_DECL_NSIWINDOWSALERTNOTIFICATION
29 NS_FORWARD_NSIALERTNOTIFICATION(AlertNotification::)
30 NS_DECL_ISUPPORTS_INHERITED
32 WindowsAlertNotification() = default;
35 virtual ~WindowsAlertNotification() = default;
36 bool mHandleActions
= false;
37 nsIWindowsAlertNotification::ImagePlacement mImagePlacement
= eInline
;
40 class ToastNotification final
: public nsIWindowsAlertsService
,
41 public nsIAlertsDoNotDisturb
,
44 NS_DECL_NSIALERTSSERVICE
45 NS_DECL_NSIWINDOWSALERTSSERVICE
46 NS_DECL_NSIALERTSDONOTDISTURB
54 bool IsActiveHandler(const nsAString
& aAlertName
,
55 ToastNotificationHandler
* aHandler
);
56 void RemoveHandler(const nsAString
& aAlertName
,
57 ToastNotificationHandler
* aHandler
);
59 nsresult
BackgroundDispatch(nsIRunnable
* runnable
);
62 virtual ~ToastNotification();
63 bool EnsureAumidRegistered();
65 static bool AssignIfMsixAumid(Maybe
<nsAutoString
>& aAumid
);
66 static bool AssignIfNsisAumid(nsAutoString
& aInstallHash
,
67 Maybe
<nsAutoString
>& aAumid
);
68 static bool RegisterRuntimeAumid(nsAutoString
& aInstallHash
,
69 Maybe
<nsAutoString
>& aAumid
);
71 RefPtr
<ToastHandledPromise
> VerifyTagPresentOrFallback(
72 const nsAString
& aWindowsTag
);
73 static void SignalComNotificationHandled(const nsAString
& aWindowsTag
);
75 nsRefPtrHashtable
<nsStringHashKey
, ToastNotificationHandler
> mActiveHandlers
;
76 Maybe
<nsAutoString
> mAumid
;
77 bool mSuppressForScreenSharing
= false;
81 } // namespace mozilla