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 ChromiumCDMProxy_h_
8 : #define ChromiumCDMProxy_h_
9 :
10 : #include "mozilla/CDMProxy.h"
11 : #include "mozilla/AbstractThread.h"
12 : #include "ChromiumCDMParent.h"
13 :
14 : namespace mozilla {
15 :
16 : class MediaRawData;
17 : class DecryptJob;
18 :
19 : class ChromiumCDMProxy : public CDMProxy
20 : {
21 : public:
22 0 : NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ChromiumCDMProxy, override)
23 :
24 : ChromiumCDMProxy(dom::MediaKeys* aKeys,
25 : const nsAString& aKeySystem,
26 : GMPCrashHelper* aCrashHelper,
27 : bool aAllowDistinctiveIdentifier,
28 : bool aAllowPersistentState,
29 : nsIEventTarget* aMainThread);
30 :
31 : void Init(PromiseId aPromiseId,
32 : const nsAString& aOrigin,
33 : const nsAString& aTopLevelOrigin,
34 : const nsAString& aGMPName) override;
35 :
36 : void CreateSession(uint32_t aCreateSessionToken,
37 : dom::MediaKeySessionType aSessionType,
38 : PromiseId aPromiseId,
39 : const nsAString& aInitDataType,
40 : nsTArray<uint8_t>& aInitData) override;
41 :
42 : void LoadSession(PromiseId aPromiseId,
43 : dom::MediaKeySessionType aSessionType,
44 : const nsAString& aSessionId) override;
45 :
46 : void SetServerCertificate(PromiseId aPromiseId,
47 : nsTArray<uint8_t>& aCert) override;
48 :
49 : void UpdateSession(const nsAString& aSessionId,
50 : PromiseId aPromiseId,
51 : nsTArray<uint8_t>& aResponse) override;
52 :
53 : void CloseSession(const nsAString& aSessionId, PromiseId aPromiseId) override;
54 :
55 : void RemoveSession(const nsAString& aSessionId,
56 : PromiseId aPromiseId) override;
57 :
58 : void Shutdown() override;
59 :
60 : void Terminated() override;
61 :
62 : const nsCString& GetNodeId() const override;
63 :
64 : void OnSetSessionId(uint32_t aCreateSessionToken,
65 : const nsAString& aSessionId) override;
66 :
67 : void OnResolveLoadSessionPromise(uint32_t aPromiseId, bool aSuccess) override;
68 :
69 : void OnSessionMessage(const nsAString& aSessionId,
70 : dom::MediaKeyMessageType aMessageType,
71 : nsTArray<uint8_t>& aMessage) override;
72 :
73 : void OnExpirationChange(const nsAString& aSessionId,
74 : GMPTimestamp aExpiryTime) override;
75 :
76 : void OnSessionClosed(const nsAString& aSessionId) override;
77 :
78 : void OnSessionError(const nsAString& aSessionId,
79 : nsresult aException,
80 : uint32_t aSystemCode,
81 : const nsAString& aMsg) override;
82 :
83 : void OnRejectPromise(uint32_t aPromiseId,
84 : nsresult aDOMException,
85 : const nsCString& aMsg) override;
86 :
87 : RefPtr<DecryptPromise> Decrypt(MediaRawData* aSample) override;
88 :
89 : void OnDecrypted(uint32_t aId,
90 : DecryptStatus aResult,
91 : const nsTArray<uint8_t>& aDecryptedData) override;
92 :
93 : void RejectPromise(PromiseId aId,
94 : nsresult aExceptionCode,
95 : const nsCString& aReason) override;
96 :
97 : void ResolvePromise(PromiseId aId) override;
98 :
99 : const nsString& KeySystem() const override;
100 :
101 : CDMCaps& Capabilites() override;
102 :
103 : void OnKeyStatusesChange(const nsAString& aSessionId) override;
104 :
105 : void GetSessionIdsForKeyId(const nsTArray<uint8_t>& aKeyId,
106 : nsTArray<nsCString>& aSessionIds) override;
107 :
108 : #ifdef DEBUG
109 : bool IsOnOwnerThread() override;
110 : #endif
111 :
112 0 : ChromiumCDMProxy* AsChromiumCDMProxy() override { return this; }
113 :
114 : // Threadsafe. Note this may return a reference to a shutdown
115 : // CDM, which will fail on all operations.
116 : already_AddRefed<gmp::ChromiumCDMParent> GetCDMParent();
117 :
118 : private:
119 : void OnCDMCreated(uint32_t aPromiseId);
120 :
121 : ~ChromiumCDMProxy();
122 :
123 : GMPCrashHelper* mCrashHelper;
124 :
125 : Mutex mCDMMutex;
126 : RefPtr<gmp::ChromiumCDMParent> mCDM;
127 : RefPtr<AbstractThread> mGMPThread;
128 : };
129 :
130 : } // namespace mozilla
131 :
132 : #endif // GMPCDMProxy_h_
|