Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 : * vim: sw=4 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 : #include "prlink.h"
12 : #include "gmp-entrypoints.h"
13 : #include "mozilla/UniquePtr.h"
14 :
15 : #if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
16 : #include "mozilla/Sandbox.h"
17 : #endif
18 :
19 : namespace mozilla {
20 : namespace gmp {
21 :
22 : class SandboxStarter {
23 : public:
24 : virtual ~SandboxStarter() {}
25 : virtual bool Start(const char* aLibPath) = 0;
26 : #if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
27 : // On OS X we need to set Mac-specific sandbox info just before we start the
28 : // sandbox, which we don't yet know when the GMPLoader and SandboxStarter
29 : // objects are created.
30 : virtual void SetSandboxInfo(MacSandboxInfo* aSandboxInfo) = 0;
31 : #endif
32 : };
33 :
34 : // Interface that adapts a plugin to the GMP API.
35 0 : class GMPAdapter {
36 : public:
37 0 : virtual ~GMPAdapter() {}
38 : // Sets the adapted to plugin library module.
39 : // Note: the GMPAdapter is responsible for calling PR_UnloadLibrary on aLib
40 : // when it's finished with it.
41 : virtual void SetAdaptee(PRLibrary* aLib) = 0;
42 :
43 : // These are called in place of the corresponding GMP API functions.
44 : virtual GMPErr GMPInit(const GMPPlatformAPI* aPlatformAPI) = 0;
45 : virtual GMPErr GMPGetAPI(const char* aAPIName,
46 : void* aHostAPI,
47 : void** aPluginAPI,
48 : uint32_t aDecryptorId) = 0;
49 : virtual void GMPShutdown() = 0;
50 : };
51 :
52 : // Encapsulates activating the sandbox, and loading the GMP.
53 : // Load() takes an optional GMPAdapter which can be used to adapt non-GMPs
54 : // to adhere to the GMP API.
55 0 : class GMPLoader {
56 : public:
57 : GMPLoader();
58 :
59 : // Activates the sandbox, then loads the GMP library. If aAdapter is
60 : // non-null, the lib path is assumed to be a non-GMP, and the adapter
61 : // is initialized with the lib and the adapter is used to interact with
62 : // the plugin.
63 : bool Load(const char* aUTF8LibPath,
64 : uint32_t aLibPathLen,
65 : const GMPPlatformAPI* aPlatformAPI,
66 : GMPAdapter* aAdapter = nullptr);
67 :
68 : // Retrieves an interface pointer from the GMP.
69 : GMPErr GetAPI(const char* aAPIName,
70 : void* aHostAPI,
71 : void** aPluginAPI,
72 : uint32_t aDecryptorId);
73 :
74 : // Calls the GMPShutdown function exported by the GMP lib, and unloads the
75 : // plugin library.
76 : void Shutdown();
77 :
78 : #if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
79 : // On OS X we need to set Mac-specific sandbox info just before we start the
80 : // sandbox, which we don't yet know when the GMPLoader and SandboxStarter
81 : // objects are created.
82 : void SetSandboxInfo(MacSandboxInfo* aSandboxInfo);
83 : #endif
84 :
85 : bool CanSandbox() const;
86 :
87 : private:
88 : UniquePtr<SandboxStarter> mSandboxStarter;
89 : UniquePtr<GMPAdapter> mAdapter;
90 : };
91 :
92 : } // namespace gmp
93 : } // namespace mozilla
94 :
95 : #endif // GMP_LOADER_H__
|