tor-browser

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

GMPContentParent.h (3298B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef GMPContentParent_h_
      7 #define GMPContentParent_h_
      8 
      9 #include "GMPNativeTypes.h"
     10 #include "mozilla/gmp/PGMPContentParent.h"
     11 #include "nsISupportsImpl.h"
     12 
     13 namespace mozilla::gmp {
     14 
     15 class GMPContentParentCloseBlocker;
     16 class GMPParent;
     17 class GMPVideoDecoderParent;
     18 class GMPVideoEncoderParent;
     19 class ChromiumCDMParent;
     20 
     21 /**
     22 * This class allows the parent/content processes to create GMP decoder/encoder
     23 * objects in the GMP process.
     24 */
     25 class GMPContentParent final : public PGMPContentParent {
     26  friend class PGMPContentParent;
     27 
     28 public:
     29  // Mark AddRef and Release as `final`, as they overload pure virtual
     30  // implementations in PGMPContentParent.
     31  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GMPContentParent, final)
     32 
     33  explicit GMPContentParent(GMPParent* aParent = nullptr);
     34 
     35  nsresult GetGMPVideoDecoder(GMPVideoDecoderParent** aGMPVD);
     36  void VideoDecoderDestroyed(GMPVideoDecoderParent* aDecoder);
     37 
     38  nsresult GetGMPVideoEncoder(GMPVideoEncoderParent** aGMPVE);
     39  void VideoEncoderDestroyed(GMPVideoEncoderParent* aEncoder);
     40 
     41  already_AddRefed<ChromiumCDMParent> GetChromiumCDM(
     42      const nsCString& aKeySystem);
     43  void ChromiumCDMDestroyed(ChromiumCDMParent* aCDM);
     44 
     45  nsCOMPtr<nsISerialEventTarget> GMPEventTarget();
     46 
     47  void SetDisplayName(const nsCString& aDisplayName) {
     48    mDisplayName = aDisplayName;
     49  }
     50  const nsCString& GetDisplayName() const { return mDisplayName; }
     51  void SetPluginId(const uint32_t aPluginId) { mPluginId = aPluginId; }
     52  uint32_t GetPluginId() const { return mPluginId; }
     53  void SetPluginType(GMPPluginType aPluginType) { mPluginType = aPluginType; }
     54  GMPPluginType GetPluginType() const { return mPluginType; }
     55 
     56 private:
     57  friend class GMPContentParentCloseBlocker;
     58 
     59  void AddCloseBlocker();
     60  void RemoveCloseBlocker();
     61 
     62  ~GMPContentParent();
     63 
     64  void ActorDestroy(ActorDestroyReason aWhy) override;
     65 
     66  void CloseIfUnused();
     67  // Needed because NewRunnableMethod tried to use the class that the method
     68  // lives on to store the receiver, but PGMPContentParent isn't refcounted.
     69  void Close() { PGMPContentParent::Close(); }
     70 
     71  nsTArray<RefPtr<GMPVideoDecoderParent>> mVideoDecoders;
     72  nsTArray<RefPtr<GMPVideoEncoderParent>> mVideoEncoders;
     73  nsTArray<RefPtr<ChromiumCDMParent>> mChromiumCDMs;
     74  nsCOMPtr<nsISerialEventTarget> mGMPEventTarget;
     75  RefPtr<GMPParent> mParent;
     76  nsCString mDisplayName;
     77  uint32_t mPluginId;
     78  GMPPluginType mPluginType = GMPPluginType::Unknown;
     79  uint32_t mCloseBlockerCount = 0;
     80 };
     81 
     82 class GMPContentParentCloseBlocker final {
     83 public:
     84  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GMPContentParentCloseBlocker)
     85 
     86  explicit GMPContentParentCloseBlocker(GMPContentParent* aParent)
     87      : mParent(aParent), mEventTarget(aParent->GMPEventTarget()) {
     88    MOZ_ASSERT(mEventTarget);
     89    mParent->AddCloseBlocker();
     90  }
     91 
     92  void Destroy();
     93 
     94  RefPtr<GMPContentParent> mParent;
     95 
     96 private:
     97  nsCOMPtr<nsISerialEventTarget> mEventTarget;
     98 
     99  ~GMPContentParentCloseBlocker() { Destroy(); }
    100 };
    101 
    102 }  // namespace mozilla::gmp
    103 
    104 #endif  // GMPParent_h_