summaryrefslogtreecommitdiffstats
path: root/dom/media/gmp/ChromiumCDMProxy.h
blob: 7f60153ae7f3fe36938fbb023710ca5d4dfb454f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef ChromiumCDMProxy_h_
#define ChromiumCDMProxy_h_

#include "mozilla/AbstractThread.h"
#include "mozilla/CDMProxy.h"
#include "ChromiumCDMParent.h"

namespace mozilla {

class ErrorResult;
class MediaRawData;
class DecryptJob;
class ChromiumCDMCallbackProxy;
class ChromiumCDMProxy : public CDMProxy {
 public:
  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ChromiumCDMProxy, override)

  ChromiumCDMProxy(dom::MediaKeys* aKeys, const nsAString& aKeySystem,
                   GMPCrashHelper* aCrashHelper,
                   bool aAllowDistinctiveIdentifier,
                   bool aAllowPersistentState);

  void Init(PromiseId aPromiseId, const nsAString& aOrigin,
            const nsAString& aTopLevelOrigin,
            const nsAString& aGMPName) override;

  void CreateSession(uint32_t aCreateSessionToken,
                     dom::MediaKeySessionType aSessionType,
                     PromiseId aPromiseId, const nsAString& aInitDataType,
                     nsTArray<uint8_t>& aInitData) override;

  void LoadSession(PromiseId aPromiseId, dom::MediaKeySessionType aSessionType,
                   const nsAString& aSessionId) override;

  void SetServerCertificate(PromiseId aPromiseId,
                            nsTArray<uint8_t>& aCert) override;

  void UpdateSession(const nsAString& aSessionId, PromiseId aPromiseId,
                     nsTArray<uint8_t>& aResponse) override;

  void CloseSession(const nsAString& aSessionId, PromiseId aPromiseId) override;

  void RemoveSession(const nsAString& aSessionId,
                     PromiseId aPromiseId) override;

  void QueryOutputProtectionStatus() override;

  void NotifyOutputProtectionStatus(
      OutputProtectionCheckStatus aCheckStatus,
      OutputProtectionCaptureStatus aCaptureStatus) override;

  void Shutdown() override;

  void Terminated() override;

  void OnSetSessionId(uint32_t aCreateSessionToken,
                      const nsAString& aSessionId) override;

  void OnResolveLoadSessionPromise(uint32_t aPromiseId, bool aSuccess) override;

  void OnSessionMessage(const nsAString& aSessionId,
                        dom::MediaKeyMessageType aMessageType,
                        const nsTArray<uint8_t>& aMessage) override;

  void OnExpirationChange(const nsAString& aSessionId,
                          UnixTime aExpiryTime) override;

  void OnSessionClosed(const nsAString& aSessionId) override;

  void OnSessionError(const nsAString& aSessionId, nsresult aException,
                      uint32_t aSystemCode, const nsAString& aMsg) override;

  void OnRejectPromise(uint32_t aPromiseId, ErrorResult&& aException,
                       const nsCString& aMsg) override;

  RefPtr<DecryptPromise> Decrypt(MediaRawData* aSample) override;

  void OnDecrypted(uint32_t aId, DecryptStatus aResult,
                   const nsTArray<uint8_t>& aDecryptedData) override;

  void RejectPromise(PromiseId aId, ErrorResult&& aException,
                     const nsCString& aReason) override;
  // Reject promise with an InvalidStateError and the given message.
  void RejectPromiseWithStateError(PromiseId aId, const nsCString& aReason);
  // For use for moving rejections from off-main thread.
  void RejectPromiseOnMainThread(PromiseId aId,
                                 CopyableErrorResult&& aException,
                                 const nsCString& aReason);

  void ResolvePromise(PromiseId aId) override;

  void OnKeyStatusesChange(const nsAString& aSessionId) override;

  void GetStatusForPolicy(PromiseId aPromiseId,
                          const nsAString& aMinHdcpVersion) override;

#ifdef DEBUG
  bool IsOnOwnerThread() override;
#endif

  ChromiumCDMProxy* AsChromiumCDMProxy() override { return this; }

  // Threadsafe. Note this may return a reference to a shutdown
  // CDM, which will fail on all operations.
  already_AddRefed<gmp::ChromiumCDMParent> GetCDMParent();

  void OnResolvePromiseWithKeyStatus(uint32_t aPromiseId,
                                     dom::MediaKeyStatus aKeyStatus);

 private:
  void OnCDMCreated(uint32_t aPromiseId);
  void ShutdownCDMIfExists();

  ~ChromiumCDMProxy();

  // True if Shutdown() has been called. Should only be read and written on
  // main thread.
  bool mIsShutdown = false;

  RefPtr<GMPCrashHelper> mCrashHelper;

  Mutex mCDMMutex MOZ_UNANNOTATED;
  RefPtr<gmp::ChromiumCDMParent> mCDM;
  nsCOMPtr<nsISerialEventTarget> mGMPThread;
  UniquePtr<ChromiumCDMCallbackProxy> mCallback;
};

}  // namespace mozilla

#endif  // ChromiumCDMProxy_h_