tor-browser

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

ChromiumCDMAdapter.h (2153B)


      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 ChromiumAdapter_h_
      7 #define ChromiumAdapter_h_
      8 
      9 #include <utility>
     10 
     11 #include "GMPLoader.h"
     12 #include "GMPUtils.h"
     13 #include "content_decryption_module_ext.h"
     14 #include "nsString.h"
     15 #include "nsTArray.h"
     16 #include "prlink.h"
     17 
     18 struct GMPPlatformAPI;
     19 
     20 namespace mozilla {
     21 
     22 #if defined(XP_WIN)
     23 typedef nsString HostFileString;
     24 #else
     25 typedef nsCString HostFileString;
     26 #endif
     27 
     28 class HostFile {
     29 public:
     30  explicit HostFile(const nsCString& aPath);
     31  HostFile(HostFile&& aOther);
     32  ~HostFile();
     33 
     34  const HostFileString& Path() const { return mPath; }
     35  cdm::PlatformFile TakePlatformFile();
     36 
     37 private:
     38  const HostFileString mPath;
     39  cdm::PlatformFile mFile = cdm::kInvalidPlatformFile;
     40 };
     41 
     42 struct HostFileData {
     43  HostFileData(HostFile&& aBinary, HostFile&& aSig)
     44      : mBinary(std::move(aBinary)), mSig(std::move(aSig)) {}
     45 
     46  HostFileData(HostFileData&& aOther)
     47      : mBinary(std::move(aOther.mBinary)), mSig(std::move(aOther.mSig)) {}
     48 
     49  ~HostFileData() = default;
     50 
     51  HostFile mBinary;
     52  HostFile mSig;
     53 };
     54 
     55 class ChromiumCDMAdapter : public gmp::GMPAdapter {
     56 public:
     57  explicit ChromiumCDMAdapter(
     58      nsTArray<std::pair<nsCString, nsCString>>&& aHostPathPairs);
     59 
     60  void SetAdaptee(PRLibrary* aLib) override;
     61 
     62  // These are called in place of the corresponding GMP API functions.
     63  GMPErr GMPInit(const GMPPlatformAPI* aPlatformAPI) override;
     64  GMPErr GMPGetAPI(const char* aAPIName, void* aHostAPI, void** aPluginAPI,
     65                   const nsACString& aKeySystem) override;
     66  void GMPShutdown() override;
     67 
     68  static bool Supports(int32_t aModuleVersion, int32_t aInterfaceVersion,
     69                       int32_t aHostVersion);
     70 
     71 private:
     72  void PopulateHostFiles(
     73      nsTArray<std::pair<nsCString, nsCString>>&& aHostFilePaths);
     74 
     75  PRLibrary* mLib = nullptr;
     76  nsTArray<HostFileData> mHostFiles;
     77 };
     78 
     79 }  // namespace mozilla
     80 
     81 #endif  // ChromiumAdapter_h_