Backed out changeset b06f19b95b94 (bug 1784438) for causing build bustages CLOSED...
[gecko.git] / toolkit / components / alerts / nsXULAlerts.h
blob62470ea7de32d5bb0d9807d9f875358b2cdb767f
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"
17 struct PendingAlert {
18 void Init(nsIAlertNotification* aAlert, nsIObserver* aListener) {
19 mAlert = aAlert;
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;
31 public:
32 NS_DECL_NSIALERTSICONURI
33 NS_DECL_NSIALERTSDONOTDISTURB
34 NS_DECL_NSIALERTSSERVICE
35 NS_DECL_ISUPPORTS
37 nsXULAlerts() = default;
39 static already_AddRefed<nsXULAlerts> GetInstance();
41 protected:
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;
50 private:
51 bool mSuppressForScreenSharing = false;
54 /**
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 {
60 public:
61 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
62 NS_DECL_NSIOBSERVER
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),
69 mObserver(aObserver),
70 mIsPersistent(aIsPersistent) {}
72 void SetAlertWindow(mozIDOMWindowProxy* aWindow) { mAlertWindow = aWindow; }
74 protected:
75 virtual ~nsXULAlertObserver() = default;
77 RefPtr<nsXULAlerts> mXULAlerts;
78 nsString mAlertName;
79 nsCOMPtr<mozIDOMWindowProxy> mAlertWindow;
80 nsCOMPtr<nsIObserver> mObserver;
81 bool mIsPersistent;
84 #endif /* nsXULAlerts_h__ */