Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef mozilla_dom_PresentationAvailability_h
8 : #define mozilla_dom_PresentationAvailability_h
9 :
10 : #include "mozilla/DOMEventTargetHelper.h"
11 : #include "nsIPresentationListener.h"
12 : #include "nsTArray.h"
13 :
14 : namespace mozilla {
15 : namespace dom {
16 :
17 : class Promise;
18 :
19 : class PresentationAvailability final : public DOMEventTargetHelper
20 : , public nsIPresentationAvailabilityListener
21 : , public SupportsWeakPtr<PresentationAvailability>
22 : {
23 : public:
24 : NS_DECL_ISUPPORTS_INHERITED
25 0 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PresentationAvailability,
26 : DOMEventTargetHelper)
27 : NS_DECL_NSIPRESENTATIONAVAILABILITYLISTENER
28 0 : MOZ_DECLARE_WEAKREFERENCE_TYPENAME(PresentationAvailability)
29 :
30 : static already_AddRefed<PresentationAvailability>
31 : Create(nsPIDOMWindowInner* aWindow,
32 : const nsTArray<nsString>& aUrls,
33 : RefPtr<Promise>& aPromise);
34 :
35 : virtual void DisconnectFromOwner() override;
36 :
37 : virtual JSObject* WrapObject(JSContext* aCx,
38 : JS::Handle<JSObject*> aGivenProto) override;
39 :
40 : bool Equals(const uint64_t aWindowID, const nsTArray<nsString>& aUrls) const;
41 :
42 : bool IsCachedValueReady();
43 :
44 : void EnqueuePromise(RefPtr<Promise>& aPromise);
45 :
46 : // WebIDL (public APIs)
47 : bool Value() const;
48 :
49 0 : IMPL_EVENT_HANDLER(change);
50 :
51 : private:
52 : explicit PresentationAvailability(nsPIDOMWindowInner* aWindow,
53 : const nsTArray<nsString>& aUrls);
54 :
55 : virtual ~PresentationAvailability();
56 :
57 : bool Init(RefPtr<Promise>& aPromise);
58 :
59 : void Shutdown();
60 :
61 : void UpdateAvailabilityAndDispatchEvent(bool aIsAvailable);
62 :
63 : bool mIsAvailable;
64 :
65 : nsTArray<RefPtr<Promise>> mPromises;
66 :
67 : nsTArray<nsString> mUrls;
68 : nsTArray<bool> mAvailabilityOfUrl;
69 : };
70 :
71 : } // namespace dom
72 : } // namespace mozilla
73 :
74 : #endif // mozilla_dom_PresentationAvailability_h
|