1 /* -*- Mode: C++; tab-width: 2; 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 nsXULAlerts_h__
7 #define nsXULAlerts_h__
9 #include "nsCycleCollectionParticipant.h"
10 #include "nsHashKeys.h"
11 #include "nsInterfaceHashtable.h"
13 #include "mozIDOMWindow.h"
14 #include "nsIAlertsService.h"
15 #include "nsIObserver.h"
18 void Init(nsIAlertNotification
* aAlert
, nsIObserver
* aListener
) {
20 mListener
= aListener
;
22 nsCOMPtr
<nsIAlertNotification
> mAlert
;
23 nsCOMPtr
<nsIObserver
> mListener
;
26 class nsXULAlerts
: public nsIAlertsService
,
27 public nsIAlertsDoNotDisturb
,
28 public nsIAlertsIconURI
{
29 friend class nsXULAlertObserver
;
32 NS_DECL_NSIALERTSICONURI
33 NS_DECL_NSIALERTSDONOTDISTURB
34 NS_DECL_NSIALERTSSERVICE
37 nsXULAlerts() = default;
39 static already_AddRefed
<nsXULAlerts
> GetInstance();
42 virtual ~nsXULAlerts() = default;
43 void PersistentAlertFinished();
45 nsInterfaceHashtable
<nsStringHashKey
, mozIDOMWindowProxy
> mNamedWindows
;
46 uint32_t mPersistentAlertCount
= 0;
47 nsTArray
<PendingAlert
> mPendingPersistentAlerts
;
48 bool mDoNotDisturb
= false;
51 bool mSuppressForScreenSharing
= false;
55 * This class wraps observers for alerts and watches
56 * for the "alertfinished" event in order to release
57 * the reference on the nsIDOMWindow of the XUL alert.
59 class nsXULAlertObserver
: public nsIObserver
{
61 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
63 NS_DECL_CYCLE_COLLECTION_CLASS(nsXULAlertObserver
)
65 nsXULAlertObserver(nsXULAlerts
* aXULAlerts
, const nsAString
& aAlertName
,
66 nsIObserver
* aObserver
, bool aIsPersistent
)
67 : mXULAlerts(aXULAlerts
),
68 mAlertName(aAlertName
),
70 mIsPersistent(aIsPersistent
) {}
72 void SetAlertWindow(mozIDOMWindowProxy
* aWindow
) { mAlertWindow
= aWindow
; }
75 virtual ~nsXULAlertObserver() = default;
77 RefPtr
<nsXULAlerts
> mXULAlerts
;
79 nsCOMPtr
<mozIDOMWindowProxy
> mAlertWindow
;
80 nsCOMPtr
<nsIObserver
> mObserver
;
84 #endif /* nsXULAlerts_h__ */