Backed out changeset 0a133d5fd155 (bug 1864534) for causing screenshot related failur...
[gecko.git] / widget / windows / ToastNotification.h
blob9beb08cc27267b0fa61b4295df16cdb3f8fd7d21
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"
18 namespace mozilla {
19 namespace widget {
21 using ToastHandledPromise = MozPromise<bool, bool, true>;
23 class ToastNotificationHandler;
25 class WindowsAlertNotification final : public AlertNotification,
26 public nsIWindowsAlertNotification {
27 public:
28 NS_DECL_NSIWINDOWSALERTNOTIFICATION
29 NS_FORWARD_NSIALERTNOTIFICATION(AlertNotification::)
30 NS_DECL_ISUPPORTS_INHERITED
32 WindowsAlertNotification() = default;
34 protected:
35 virtual ~WindowsAlertNotification() = default;
36 bool mHandleActions = false;
37 nsIWindowsAlertNotification::ImagePlacement mImagePlacement = eInline;
40 class ToastNotification final : public nsIWindowsAlertsService,
41 public nsIAlertsDoNotDisturb,
42 public nsIObserver {
43 public:
44 NS_DECL_NSIALERTSSERVICE
45 NS_DECL_NSIWINDOWSALERTSSERVICE
46 NS_DECL_NSIALERTSDONOTDISTURB
47 NS_DECL_NSIOBSERVER
48 NS_DECL_ISUPPORTS
50 ToastNotification();
52 nsresult Init();
54 bool IsActiveHandler(const nsAString& aAlertName,
55 ToastNotificationHandler* aHandler);
56 void RemoveHandler(const nsAString& aAlertName,
57 ToastNotificationHandler* aHandler);
59 nsresult BackgroundDispatch(nsIRunnable* runnable);
61 protected:
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;
80 } // namespace widget
81 } // namespace mozilla
83 #endif