/work/obj-fuzz/dist/include/mozilla/dom/MediaKeys.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
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 file, |
5 | | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef mozilla_dom_mediakeys_h__ |
8 | | #define mozilla_dom_mediakeys_h__ |
9 | | |
10 | | #include "DecoderDoctorLogger.h" |
11 | | #include "nsWrapperCache.h" |
12 | | #include "nsISupports.h" |
13 | | #include "mozilla/Attributes.h" |
14 | | #include "mozilla/RefPtr.h" |
15 | | #include "nsCOMPtr.h" |
16 | | #include "nsCycleCollectionParticipant.h" |
17 | | #include "nsRefPtrHashtable.h" |
18 | | #include "mozilla/dom/Promise.h" |
19 | | #include "mozilla/dom/MediaKeysBinding.h" |
20 | | #include "mozilla/dom/MediaKeyStatusMapBinding.h" // For MediaKeyStatus |
21 | | #include "mozilla/dom/MediaKeySystemAccessBinding.h" |
22 | | #include "mozIGeckoMediaPluginService.h" |
23 | | #include "mozilla/DetailedPromise.h" |
24 | | #include "mozilla/WeakPtr.h" |
25 | | |
26 | | namespace mozilla { |
27 | | |
28 | | class CDMProxy; |
29 | | |
30 | | namespace dom { |
31 | | class MediaKeys; |
32 | | } // namespace dom |
33 | | DDLoggedTypeName(dom::MediaKeys); |
34 | | |
35 | | namespace dom { |
36 | | |
37 | | class ArrayBufferViewOrArrayBuffer; |
38 | | class MediaKeySession; |
39 | | struct MediaKeysPolicy; |
40 | | class HTMLMediaElement; |
41 | | |
42 | | typedef nsRefPtrHashtable<nsStringHashKey, MediaKeySession> KeySessionHashMap; |
43 | | typedef nsRefPtrHashtable<nsUint32HashKey, dom::DetailedPromise> PromiseHashMap; |
44 | | typedef nsRefPtrHashtable<nsUint32HashKey, MediaKeySession> PendingKeySessionsHashMap; |
45 | | typedef nsDataHashtable<nsUint32HashKey, uint32_t> PendingPromiseIdTokenHashMap; |
46 | | typedef uint32_t PromiseId; |
47 | | |
48 | | // This class is used on the main thread only. |
49 | | // Note: its addref/release is not (and can't be) thread safe! |
50 | | class MediaKeys final |
51 | | : public nsISupports |
52 | | , public nsWrapperCache |
53 | | , public SupportsWeakPtr<MediaKeys> |
54 | | , public DecoderDoctorLifeLogger<MediaKeys> |
55 | | { |
56 | | ~MediaKeys(); |
57 | | |
58 | | public: |
59 | | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
60 | | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MediaKeys) |
61 | | MOZ_DECLARE_WEAKREFERENCE_TYPENAME(MediaKeys) |
62 | | |
63 | | MediaKeys(nsPIDOMWindowInner* aParentWindow, |
64 | | const nsAString& aKeySystem, |
65 | | const MediaKeySystemConfiguration& aConfig); |
66 | | |
67 | | already_AddRefed<DetailedPromise> Init(ErrorResult& aRv); |
68 | | |
69 | | nsPIDOMWindowInner* GetParentObject() const; |
70 | | |
71 | | JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; |
72 | | |
73 | | nsresult Bind(HTMLMediaElement* aElement); |
74 | | void Unbind(); |
75 | | |
76 | | // Javascript: readonly attribute DOMString keySystem; |
77 | | void GetKeySystem(nsString& retval) const; |
78 | | |
79 | | // JavaScript: MediaKeys.createSession() |
80 | | already_AddRefed<MediaKeySession> CreateSession(JSContext* aCx, |
81 | | MediaKeySessionType aSessionType, |
82 | | ErrorResult& aRv); |
83 | | |
84 | | // JavaScript: MediaKeys.SetServerCertificate() |
85 | | already_AddRefed<DetailedPromise> |
86 | | SetServerCertificate(const ArrayBufferViewOrArrayBuffer& aServerCertificate, |
87 | | ErrorResult& aRv); |
88 | | |
89 | | already_AddRefed<MediaKeySession> GetSession(const nsAString& aSessionId); |
90 | | |
91 | | // Removes and returns MediaKeySession from the set of sessions awaiting |
92 | | // their sessionId to be assigned. |
93 | | already_AddRefed<MediaKeySession> GetPendingSession(uint32_t aToken); |
94 | | |
95 | | // Called once a Init() operation succeeds. |
96 | | void OnCDMCreated(PromiseId aId, const uint32_t aPluginId); |
97 | | |
98 | | // Called once the CDM generates a sessionId while servicing a |
99 | | // MediaKeySession.generateRequest() or MediaKeySession.load() call, |
100 | | // once the sessionId of a MediaKeySession is known. |
101 | | void OnSessionIdReady(MediaKeySession* aSession); |
102 | | |
103 | | // Called once a LoadSession succeeds. |
104 | | void OnSessionLoaded(PromiseId aId, bool aSuccess); |
105 | | |
106 | | // Called once a session has closed. |
107 | | void OnSessionClosed(MediaKeySession* aSession); |
108 | | |
109 | 0 | CDMProxy* GetCDMProxy() { return mProxy; } |
110 | | |
111 | | // Makes a new promise, or nullptr on failure. |
112 | | already_AddRefed<DetailedPromise> MakePromise(ErrorResult& aRv, |
113 | | const nsACString& aName); |
114 | | // Stores promise in mPromises, returning an ID that can be used to retrieve |
115 | | // it later. The ID is passed to the CDM, so that it can signal specific |
116 | | // promises to be resolved. |
117 | | PromiseId StorePromise(DetailedPromise* aPromise); |
118 | | |
119 | | // Stores a map from promise id to pending session token. Using this |
120 | | // mapping, when a promise is rejected via its ID, we can check if the |
121 | | // promise corresponds to a pending session and retrieve that session |
122 | | // via the mapped-to token, and remove the pending session from the |
123 | | // list of sessions awaiting a session id. |
124 | | void ConnectPendingPromiseIdWithToken(PromiseId aId, uint32_t aToken); |
125 | | |
126 | | // Reject promise with DOMException corresponding to aExceptionCode. |
127 | | void RejectPromise(PromiseId aId, nsresult aExceptionCode, |
128 | | const nsCString& aReason); |
129 | | // Resolves promise with "undefined". |
130 | | void ResolvePromise(PromiseId aId); |
131 | | |
132 | | void Shutdown(); |
133 | | |
134 | | // Called by CDMProxy when CDM crashes or shuts down. It is different from |
135 | | // Shutdown which is called from the script/dom side. |
136 | | void Terminated(); |
137 | | |
138 | | // Returns true if this MediaKeys has been bound to a media element. |
139 | | bool IsBoundToMediaElement() const; |
140 | | |
141 | | void GetSessionsInfo(nsString& sessionsInfo); |
142 | | |
143 | | // JavaScript: MediaKeys.GetStatusForPolicy() |
144 | | already_AddRefed<Promise> GetStatusForPolicy(const MediaKeysPolicy& aPolicy, |
145 | | ErrorResult& aR); |
146 | | // Called by CDMProxy when CDM successfully GetStatusForPolicy. |
147 | | void ResolvePromiseWithKeyStatus(PromiseId aId, dom::MediaKeyStatus aMediaKeyStatus); |
148 | | |
149 | | private: |
150 | | |
151 | | // Instantiate CDMProxy instance. |
152 | | // It could be MediaDrmCDMProxy (Widevine on Fennec) or ChromiumCDMProxy (the rest). |
153 | | already_AddRefed<CDMProxy> CreateCDMProxy(nsIEventTarget* aMainThread); |
154 | | |
155 | | // Removes promise from mPromises, and returns it. |
156 | | already_AddRefed<DetailedPromise> RetrievePromise(PromiseId aId); |
157 | | |
158 | | // Owning ref to proxy. The proxy has a weak reference back to the MediaKeys, |
159 | | // and the MediaKeys destructor clears the proxy's reference to the MediaKeys. |
160 | | RefPtr<CDMProxy> mProxy; |
161 | | |
162 | | RefPtr<HTMLMediaElement> mElement; |
163 | | |
164 | | nsCOMPtr<nsPIDOMWindowInner> mParent; |
165 | | const nsString mKeySystem; |
166 | | KeySessionHashMap mKeySessions; |
167 | | PromiseHashMap mPromises; |
168 | | PendingKeySessionsHashMap mPendingSessions; |
169 | | PromiseId mCreatePromiseId; |
170 | | |
171 | | RefPtr<nsIPrincipal> mPrincipal; |
172 | | RefPtr<nsIPrincipal> mTopLevelPrincipal; |
173 | | |
174 | | const MediaKeySystemConfiguration mConfig; |
175 | | |
176 | | PendingPromiseIdTokenHashMap mPromiseIdToken; |
177 | | }; |
178 | | |
179 | | } // namespace dom |
180 | | } // namespace mozilla |
181 | | |
182 | | #endif // mozilla_dom_mediakeys_h__ |