Line data Source code
1 : /* This Source Code Form is subject to the terms of the Mozilla Public
2 : * License, v. 2.0. If a copy of the MPL was not distributed with this
3 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 :
5 : #ifndef mozilla_dom_MediaKeySystemAccessManager_h
6 : #define mozilla_dom_MediaKeySystemAccessManager_h
7 :
8 : #include "mozilla/dom/MediaKeySystemAccess.h"
9 : #include "nsIObserver.h"
10 : #include "nsCycleCollectionParticipant.h"
11 : #include "nsISupportsImpl.h"
12 : #include "nsITimer.h"
13 :
14 : namespace mozilla {
15 : namespace dom {
16 :
17 : class DetailedPromise;
18 : class TestGMPVideoDecoder;
19 :
20 : class MediaKeySystemAccessManager final : public nsIObserver
21 : {
22 : public:
23 :
24 : explicit MediaKeySystemAccessManager(nsPIDOMWindowInner* aWindow);
25 :
26 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
27 0 : NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(MediaKeySystemAccessManager, nsIObserver)
28 : NS_DECL_NSIOBSERVER
29 :
30 : void Request(DetailedPromise* aPromise,
31 : const nsAString& aKeySystem,
32 : const Sequence<MediaKeySystemConfiguration>& aConfig);
33 :
34 : void Shutdown();
35 :
36 : struct PendingRequest {
37 : PendingRequest(DetailedPromise* aPromise,
38 : const nsAString& aKeySystem,
39 : const Sequence<MediaKeySystemConfiguration>& aConfig,
40 : nsITimer* aTimer);
41 : PendingRequest(const PendingRequest& aOther);
42 : ~PendingRequest();
43 : void CancelTimer();
44 : void RejectPromise(const nsCString& aReason);
45 :
46 : RefPtr<DetailedPromise> mPromise;
47 : const nsString mKeySystem;
48 : const Sequence<MediaKeySystemConfiguration> mConfigs;
49 : nsCOMPtr<nsITimer> mTimer;
50 : };
51 :
52 : private:
53 :
54 : enum RequestType {
55 : Initial,
56 : Subsequent
57 : };
58 :
59 : void Request(DetailedPromise* aPromise,
60 : const nsAString& aKeySystem,
61 : const Sequence<MediaKeySystemConfiguration>& aConfig,
62 : RequestType aType);
63 :
64 : ~MediaKeySystemAccessManager();
65 :
66 : bool EnsureObserversAdded();
67 :
68 : bool AwaitInstall(DetailedPromise* aPromise,
69 : const nsAString& aKeySystem,
70 : const Sequence<MediaKeySystemConfiguration>& aConfig);
71 :
72 : void RetryRequest(PendingRequest& aRequest);
73 :
74 : nsTArray<PendingRequest> mRequests;
75 :
76 : nsCOMPtr<nsPIDOMWindowInner> mWindow;
77 : bool mAddedObservers;
78 : };
79 :
80 : } // namespace dom
81 : } // namespace mozilla
82 :
83 : #endif
|