Line data Source code
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 GMPCDMProxy_h_
8 : #define GMPCDMProxy_h_
9 :
10 : #include "mozilla/CDMProxy.h"
11 : #include "GMPCDMCallbackProxy.h"
12 : #include "GMPDecryptorProxy.h"
13 :
14 : namespace mozilla {
15 :
16 : class MediaRawData;
17 : class DecryptJob;
18 :
19 : // Implementation of CDMProxy which is based on GMP architecture.
20 : class GMPCDMProxy : public CDMProxy {
21 : public:
22 :
23 0 : NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GMPCDMProxy, override)
24 :
25 : GMPCDMProxy(dom::MediaKeys* aKeys,
26 : const nsAString& aKeySystem,
27 : GMPCrashHelper* aCrashHelper,
28 : bool aDistinctiveIdentifierRequired,
29 : bool aPersistentStateRequired,
30 : nsIEventTarget* aMainThread);
31 :
32 : void Init(PromiseId aPromiseId,
33 : const nsAString& aOrigin,
34 : const nsAString& aTopLevelOrigin,
35 : const nsAString& aGMPName) override;
36 :
37 : void OnSetDecryptorId(uint32_t aId) override;
38 :
39 : void CreateSession(uint32_t aCreateSessionToken,
40 : dom::MediaKeySessionType aSessionType,
41 : PromiseId aPromiseId,
42 : const nsAString& aInitDataType,
43 : nsTArray<uint8_t>& aInitData) override;
44 :
45 : void LoadSession(PromiseId aPromiseId,
46 : dom::MediaKeySessionType aSessionType,
47 : const nsAString& aSessionId) override;
48 :
49 : void SetServerCertificate(PromiseId aPromiseId,
50 : nsTArray<uint8_t>& aCert) override;
51 :
52 : void UpdateSession(const nsAString& aSessionId,
53 : PromiseId aPromiseId,
54 : nsTArray<uint8_t>& aResponse) override;
55 :
56 : void CloseSession(const nsAString& aSessionId,
57 : PromiseId aPromiseId) override;
58 :
59 : void RemoveSession(const nsAString& aSessionId,
60 : PromiseId aPromiseId) override;
61 :
62 : void Shutdown() override;
63 :
64 : void Terminated() override;
65 :
66 : const nsCString& GetNodeId() const override;
67 :
68 : void OnSetSessionId(uint32_t aCreateSessionToken,
69 : const nsAString& aSessionId) override;
70 :
71 : void OnResolveLoadSessionPromise(uint32_t aPromiseId, bool aSuccess) override;
72 :
73 : void OnSessionMessage(const nsAString& aSessionId,
74 : dom::MediaKeyMessageType aMessageType,
75 : nsTArray<uint8_t>& aMessage) override;
76 :
77 : void OnExpirationChange(const nsAString& aSessionId,
78 : GMPTimestamp aExpiryTime) override;
79 :
80 : void OnSessionClosed(const nsAString& aSessionId) override;
81 :
82 : void OnSessionError(const nsAString& aSessionId,
83 : nsresult aException,
84 : uint32_t aSystemCode,
85 : const nsAString& aMsg) override;
86 :
87 : void OnRejectPromise(uint32_t aPromiseId,
88 : nsresult aDOMException,
89 : const nsCString& aMsg) override;
90 :
91 : RefPtr<DecryptPromise> Decrypt(MediaRawData* aSample) override;
92 :
93 : void OnDecrypted(uint32_t aId,
94 : DecryptStatus aResult,
95 : const nsTArray<uint8_t>& aDecryptedData) override;
96 :
97 : void RejectPromise(PromiseId aId, nsresult aExceptionCode,
98 : const nsCString& aReason) override;
99 :
100 : void ResolvePromise(PromiseId aId) override;
101 :
102 : const nsString& KeySystem() const override;
103 :
104 : CDMCaps& Capabilites() override;
105 :
106 : void OnKeyStatusesChange(const nsAString& aSessionId) override;
107 :
108 : void GetSessionIdsForKeyId(const nsTArray<uint8_t>& aKeyId,
109 : nsTArray<nsCString>& aSessionIds) override;
110 :
111 : #ifdef DEBUG
112 : bool IsOnOwnerThread() override;
113 : #endif
114 :
115 : uint32_t GetDecryptorId() override;
116 :
117 : private:
118 : friend class gmp_InitDoneCallback;
119 : friend class gmp_InitGetGMPDecryptorCallback;
120 :
121 0 : struct InitData {
122 : uint32_t mPromiseId;
123 : nsString mOrigin;
124 : nsString mTopLevelOrigin;
125 : nsString mGMPName;
126 : RefPtr<GMPCrashHelper> mCrashHelper;
127 : };
128 :
129 : // GMP thread only.
130 : void gmp_Init(UniquePtr<InitData>&& aData);
131 : void gmp_InitDone(GMPDecryptorProxy* aCDM, UniquePtr<InitData>&& aData);
132 : void gmp_InitGetGMPDecryptor(nsresult aResult,
133 : const nsACString& aNodeId,
134 : UniquePtr<InitData>&& aData);
135 :
136 : // GMP thread only.
137 : void gmp_Shutdown();
138 :
139 : // Main thread only.
140 : void OnCDMCreated(uint32_t aPromiseId);
141 :
142 0 : struct CreateSessionData {
143 : dom::MediaKeySessionType mSessionType;
144 : uint32_t mCreateSessionToken;
145 : PromiseId mPromiseId;
146 : nsCString mInitDataType;
147 : nsTArray<uint8_t> mInitData;
148 : };
149 : // GMP thread only.
150 : void gmp_CreateSession(UniquePtr<CreateSessionData>&& aData);
151 :
152 0 : struct SessionOpData {
153 : PromiseId mPromiseId;
154 : nsCString mSessionId;
155 : };
156 : // GMP thread only.
157 : void gmp_LoadSession(UniquePtr<SessionOpData>&& aData);
158 :
159 0 : struct SetServerCertificateData {
160 : PromiseId mPromiseId;
161 : nsTArray<uint8_t> mCert;
162 : };
163 : // GMP thread only.
164 : void gmp_SetServerCertificate(UniquePtr<SetServerCertificateData>&& aData);
165 :
166 0 : struct UpdateSessionData {
167 : PromiseId mPromiseId;
168 : nsCString mSessionId;
169 : nsTArray<uint8_t> mResponse;
170 : };
171 : // GMP thread only.
172 : void gmp_UpdateSession(UniquePtr<UpdateSessionData>&& aData);
173 :
174 : // GMP thread only.
175 : void gmp_CloseSession(UniquePtr<SessionOpData>&& aData);
176 :
177 : // GMP thread only.
178 : void gmp_RemoveSession(UniquePtr<SessionOpData>&& aData);
179 :
180 : // GMP thread only.
181 : void gmp_Decrypt(RefPtr<DecryptJob> aJob);
182 :
183 : // GMP thread only.
184 : void gmp_Decrypted(uint32_t aId,
185 : DecryptStatus aResult,
186 : const nsTArray<uint8_t>& aDecryptedData);
187 :
188 0 : class RejectPromiseTask : public Runnable {
189 : public:
190 0 : RejectPromiseTask(GMPCDMProxy* aProxy,
191 : PromiseId aId,
192 : nsresult aCode,
193 : const nsCString& aReason)
194 0 : : Runnable("GMPCDMProxy::RejectPromiseTask")
195 : , mProxy(aProxy)
196 : , mId(aId)
197 : , mCode(aCode)
198 0 : , mReason(aReason)
199 : {
200 0 : }
201 0 : NS_IMETHOD Run() override {
202 0 : mProxy->RejectPromise(mId, mCode, mReason);
203 0 : return NS_OK;
204 : }
205 : private:
206 : RefPtr<GMPCDMProxy> mProxy;
207 : PromiseId mId;
208 : nsresult mCode;
209 : nsCString mReason;
210 : };
211 :
212 : ~GMPCDMProxy();
213 :
214 : GMPCrashHelper* mCrashHelper;
215 :
216 : GMPDecryptorProxy* mCDM;
217 :
218 : UniquePtr<GMPCDMCallbackProxy> mCallback;
219 :
220 : // Decryption jobs sent to CDM, awaiting result.
221 : // GMP thread only.
222 : nsTArray<RefPtr<DecryptJob>> mDecryptionJobs;
223 :
224 : // True if GMPCDMProxy::gmp_Shutdown was called.
225 : // GMP thread only.
226 : bool mShutdownCalled;
227 :
228 : uint32_t mDecryptorId;
229 :
230 : PromiseId mCreatePromiseId;
231 : };
232 :
233 :
234 : } // namespace mozilla
235 :
236 : #endif // GMPCDMProxy_h_
|