tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

RemoteCDMChild.h (6098B)


      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
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 #ifndef include_dom_media_ipc_RemoteCDMChild_h
      7 #define include_dom_media_ipc_RemoteCDMChild_h
      8 
      9 #include "mozilla/Atomics.h"
     10 #include "mozilla/CDMProxy.h"
     11 #include "mozilla/MediaActorUtils.h"
     12 #include "mozilla/PRemoteCDMActor.h"
     13 #include "mozilla/PRemoteCDMChild.h"
     14 #include "mozilla/RemoteMediaManagerChild.h"
     15 
     16 namespace mozilla {
     17 
     18 /**
     19 * This class implements the content process actor for managing CDM instances in
     20 * a remote process performing the decoding/decrypting. It is created via
     21 * RemoteMediaManagerChild::CreateCDM. It destroys itself when there is a single
     22 * reference left (the IPDL reference to the actor). The CDMProxy methods are
     23 * threadsafe and dispatch to the RemoteMediaManagerChild IPDL thread.
     24 *
     25 * To provide a remote implementation in another process, one must subclass
     26 * RemoteCDMParent and ensure the correct actor class is created in
     27 * RemoteMediaManagerParent::AllocPRemoteCDMParent.
     28 *
     29 * Remote decoders are supplied the PRemoteCDMActor pointer for encrypted media,
     30 * which they can integrate with depending on the particular CDM API.
     31 */
     32 class RemoteCDMChild final : public PRemoteCDMChild,
     33                             public PRemoteCDMActor,
     34                             public CDMProxy {
     35 public:
     36  MEDIA_INLINE_DECL_THREADSAFE_REFCOUNTING_META(RemoteCDMChild, NS_IMETHOD_,
     37                                                delete(this), Shutdown(),
     38                                                final);
     39 
     40  RemoteCDMChild(nsCOMPtr<nsISerialEventTarget>&& aThread,
     41                 RefPtr<GenericNonExclusivePromise>&& aIPDLPromise,
     42                 RemoteMediaIn aLocation, dom::MediaKeys* aKeys,
     43                 const nsAString& aKeySystem,
     44                 bool aDistinctiveIdentifierRequired,
     45                 bool aPersistentStateRequired);
     46 
     47  nsISerialEventTarget* GetManagerThread() const { return mThread; }
     48 
     49  // PRemoteCDMChild
     50  void ActorDestroy(ActorDestroyReason aWhy) override;
     51  mozilla::ipc::IPCResult RecvProvision(
     52      const RemoteCDMProvisionRequestIPDL& aRequest,
     53      ProvisionResolver&& aResolver);
     54  mozilla::ipc::IPCResult RecvOnSessionKeyStatus(
     55      const RemoteCDMKeyStatusIPDL& aMsg);
     56  mozilla::ipc::IPCResult RecvOnSessionKeyExpiration(
     57      RemoteCDMKeyExpirationIPDL&& aMsg);
     58  mozilla::ipc::IPCResult RecvOnSessionKeyMessage(
     59      RemoteCDMKeyMessageIPDL&& aMsg);
     60 
     61  // CDMProxy
     62  void Init(PromiseId aPromiseId, const nsAString& aOrigin,
     63            const nsAString& aTopLevelOrigin, const nsAString& aName) override;
     64  void CreateSession(uint32_t aCreateSessionToken,
     65                     MediaKeySessionType aSessionType, PromiseId aPromiseId,
     66                     const nsAString& aInitDataType,
     67                     nsTArray<uint8_t>& aInitData) override;
     68  void LoadSession(PromiseId aPromiseId, dom::MediaKeySessionType aSessionType,
     69                   const nsAString& aSessionId) override;
     70  void SetServerCertificate(PromiseId aPromiseId,
     71                            nsTArray<uint8_t>& aCert) override;
     72  void UpdateSession(const nsAString& aSessionId, PromiseId aPromiseId,
     73                     nsTArray<uint8_t>& aResponse) override;
     74  void CloseSession(const nsAString& aSessionId, PromiseId aPromiseId) override;
     75  void RemoveSession(const nsAString& aSessionId,
     76                     PromiseId aPromiseId) override;
     77  void QueryOutputProtectionStatus() override;
     78  void NotifyOutputProtectionStatus(
     79      OutputProtectionCheckStatus aCheckStatus,
     80      OutputProtectionCaptureStatus aCaptureStatus) override;
     81  void Shutdown() override;
     82  void Terminated() override;
     83  void OnSetSessionId(uint32_t aCreateSessionToken,
     84                      const nsAString& aSessionId) override;
     85  void OnResolveLoadSessionPromise(uint32_t aPromiseId, bool aSuccess) override;
     86  void OnSessionMessage(const nsAString& aSessionId,
     87                        dom::MediaKeyMessageType aMessageType,
     88                        const nsTArray<uint8_t>& aMessage) override;
     89  void OnExpirationChange(const nsAString& aSessionId,
     90                          UnixTime aExpiryTime) override;
     91  void OnSessionClosed(const nsAString& aSessionId,
     92                       dom::MediaKeySessionClosedReason aReason) override;
     93  void OnSessionError(const nsAString& aSessionId, nsresult aException,
     94                      uint32_t aSystemCode, const nsAString& aMsg) override;
     95  void OnRejectPromise(uint32_t aPromiseId, ErrorResult&& aException,
     96                       const nsCString& aMsg) override;
     97  RefPtr<DecryptPromise> Decrypt(MediaRawData* aSample) override;
     98  void OnDecrypted(uint32_t aId, DecryptStatus aResult,
     99                   const nsTArray<uint8_t>& aDecryptedData) override;
    100  void RejectPromise(PromiseId aId, ErrorResult&& aException,
    101                     const nsCString& aReason) override;
    102  void ResolvePromise(PromiseId aId) override;
    103  void OnKeyStatusesChange(const nsAString& aSessionId) override;
    104  void GetStatusForPolicy(PromiseId aPromiseId,
    105                          const dom::HDCPVersion& aMinHdcpVersion) override;
    106 #ifdef DEBUG
    107  bool IsOnOwnerThread() override;
    108 #endif
    109  RemoteCDMChild* AsRemoteCDMChild() final { return this; }
    110 
    111  // PRemoteCDMActor
    112  PRemoteCDMChild* AsPRemoteCDMChild() final { return this; }
    113  RemoteMediaIn GetLocation() const final { return mLocation; }
    114 
    115 private:
    116  virtual ~RemoteCDMChild();
    117 
    118  void InitInternal(PromiseId aPromiseId);
    119  void RejectPromise(PromiseId aId, const MediaResult& aResult);
    120  void ResolveOrRejectPromise(PromiseId aId, const MediaResult& aResult);
    121 
    122  void MaybeDestroyActor();
    123 
    124  const nsCOMPtr<nsISerialEventTarget> mThread;
    125  RefPtr<GenericNonExclusivePromise> mIPDLPromise;
    126  const RemoteMediaIn mLocation;
    127  Atomic<bool> mNeedsShutdown{true};
    128 };
    129 
    130 }  // namespace mozilla
    131 
    132 #endif  // include_dom_media_ipc_RemoteCDMChild_h