tor-browser

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

GMPLoader.h (2712B)


      1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      2 * vim: sw=2 ts=4 et :
      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 
      7 #ifndef GMP_LOADER_H__
      8 #define GMP_LOADER_H__
      9 
     10 #include <stdint.h>
     11 
     12 #include "gmp-entrypoints.h"
     13 #include "mozilla/UniquePtr.h"
     14 #include "nsString.h"
     15 #include "prlink.h"
     16 
     17 #if defined(XP_MACOSX) && defined(MOZ_SANDBOX)
     18 #  include "mozilla/Sandbox.h"
     19 #endif
     20 
     21 namespace mozilla::gmp {
     22 
     23 class SandboxStarter {
     24 public:
     25  virtual ~SandboxStarter() = default;
     26  virtual bool Start(const char* aLibPath) = 0;
     27 };
     28 
     29 // Interface that adapts a plugin to the GMP API.
     30 class GMPAdapter {
     31 public:
     32  virtual ~GMPAdapter() = default;
     33  // Sets the adapted to plugin library module.
     34  // Note: the GMPAdapter is responsible for calling PR_UnloadLibrary on aLib
     35  // when it's finished with it.
     36  virtual void SetAdaptee(PRLibrary* aLib) = 0;
     37 
     38  // These are called in place of the corresponding GMP API functions.
     39  virtual GMPErr GMPInit(const GMPPlatformAPI* aPlatformAPI) = 0;
     40  // The `aKeySystem` arg is used to specify the key system when loading CDMs,
     41  // and will be ignored by non-CDM GMPs. It is not part of the public GMP API
     42  // Gecko exposes.
     43  virtual GMPErr GMPGetAPI(const char* aAPIName, void* aHostAPI,
     44                           void** aPluginAPI, const nsACString& aKeySystem) = 0;
     45  virtual void GMPShutdown() = 0;
     46 };
     47 
     48 // Encapsulates activating the sandbox, and loading the GMP.
     49 // Load() takes an optional GMPAdapter which can be used to adapt non-GMPs
     50 // to adhere to the GMP API.
     51 class GMPLoader {
     52 public:
     53  GMPLoader();
     54 
     55  // Activates the sandbox, then loads the GMP library. If aAdapter is
     56  // non-null, the lib path is assumed to be a non-GMP, and the adapter
     57  // is initialized with the lib and the adapter is used to interact with
     58  // the plugin.
     59  bool Load(const char* aUTF8LibPath, uint32_t aLibPathLen,
     60            const GMPPlatformAPI* aPlatformAPI, GMPAdapter* aAdapter = nullptr);
     61 
     62  // Retrieves an interface pointer from the GMP. If the GMP is loading a CDM,
     63  // aKeySystem is passed to the CDM to allow for key system specific
     64  // configuration by the CDM.
     65  GMPErr GetAPI(const char* aAPIName, void* aHostAPI, void** aPluginAPI,
     66                const nsACString& aKeySystem);
     67 
     68  // Calls the GMPShutdown function exported by the GMP lib, and unloads the
     69  // plugin library.
     70  void Shutdown();
     71 
     72  bool CanSandbox() const;
     73 
     74 private:
     75  UniquePtr<SandboxStarter> mSandboxStarter;
     76  UniquePtr<GMPAdapter> mAdapter;
     77 };
     78 
     79 }  // namespace mozilla::gmp
     80 
     81 #endif  // GMP_LOADER_H__