Bug 1332530 - Flatten GMPLoader and GMPLoaderImpl. r=gerald
MozReview-Commit-ID: GZ8feXmLuCb
--- a/dom/media/gmp/GMPChild.cpp
+++ b/dom/media/gmp/GMPChild.cpp
@@ -344,19 +344,19 @@ GMPChild::AnswerStartPlugin(const nsStri
nsCString libPath;
if (!GetUTF8LibPath(libPath)) {
return IPC_FAIL_NO_REASON(this);
}
auto platformAPI = new GMPPlatformAPI();
InitPlatformAPI(*platformAPI, this);
- mGMPLoader = CreateGMPLoader();
- if (!mGMPLoader) {
- NS_WARNING("Failed to get GMPLoader");
+ mGMPLoader = MakeUnique<GMPLoader>();
+ if (!mGMPLoader->CanSandbox()) {
+ LOGD("%s Can't sandbox GMP, failing", __FUNCTION__);
delete platformAPI;
return IPC_FAIL_NO_REASON(this);
}
bool isWidevine = aAdapter.EqualsLiteral("widevine");
#if defined(MOZ_GMP_SANDBOX) && defined(XP_MACOSX)
MacSandboxPluginType pluginType = MacSandboxPluginType_GMPlugin_Default;
if (isWidevine) {
--- a/dom/media/gmp/GMPLoader.cpp
+++ b/dom/media/gmp/GMPLoader.cpp
@@ -23,48 +23,16 @@
#include <string>
#ifdef XP_WIN
#include "windows.h"
#endif
namespace mozilla {
namespace gmp {
-
-class GMPLoaderImpl : public GMPLoader {
-public:
- explicit GMPLoaderImpl(UniquePtr<SandboxStarter> aStarter)
- : mSandboxStarter(Move(aStarter))
- , mAdapter(nullptr)
- {}
- ~GMPLoaderImpl() override = default;
-
- bool Load(const char* aUTF8LibPath,
- uint32_t aUTF8LibPathLen,
- char* aOriginSalt,
- uint32_t aOriginSaltLen,
- const GMPPlatformAPI* aPlatformAPI,
- GMPAdapter* aAdapter) override;
-
- GMPErr GetAPI(const char* aAPIName,
- void* aHostAPI,
- void** aPluginAPI,
- uint32_t aDecryptorId) override;
-
- void Shutdown() override;
-
-#if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
- void SetSandboxInfo(MacSandboxInfo* aSandboxInfo) override;
-#endif
-
-private:
- UniquePtr<SandboxStarter> mSandboxStarter;
- UniquePtr<GMPAdapter> mAdapter;
-};
-
class PassThroughGMPAdapter : public GMPAdapter {
public:
~PassThroughGMPAdapter() override {
// Ensure we're always shutdown, even if caller forgets to call GMPShutdown().
GMPShutdown();
}
void SetAdaptee(PRLibrary* aLib) override
@@ -111,22 +79,22 @@ public:
}
}
private:
PRLibrary* mLib = nullptr;
};
bool
-GMPLoaderImpl::Load(const char* aUTF8LibPath,
- uint32_t aUTF8LibPathLen,
- char* aOriginSalt,
- uint32_t aOriginSaltLen,
- const GMPPlatformAPI* aPlatformAPI,
- GMPAdapter* aAdapter)
+GMPLoader::Load(const char* aUTF8LibPath,
+ uint32_t aUTF8LibPathLen,
+ char* aOriginSalt,
+ uint32_t aOriginSaltLen,
+ const GMPPlatformAPI* aPlatformAPI,
+ GMPAdapter* aAdapter)
{
// Start the sandbox now that we've generated the device bound node id.
// This must happen after the node id is bound to the device id, as
// generating the device id requires privileges.
if (mSandboxStarter && !mSandboxStarter->Start(aUTF8LibPath)) {
return false;
}
@@ -172,35 +140,35 @@ GMPLoaderImpl::Load(const char* aUTF8Lib
if (mAdapter->GMPInit(aPlatformAPI) != GMPNoErr) {
return false;
}
return true;
}
GMPErr
-GMPLoaderImpl::GetAPI(const char* aAPIName,
- void* aHostAPI,
- void** aPluginAPI,
- uint32_t aDecryptorId)
+GMPLoader::GetAPI(const char* aAPIName,
+ void* aHostAPI,
+ void** aPluginAPI,
+ uint32_t aDecryptorId)
{
return mAdapter->GMPGetAPI(aAPIName, aHostAPI, aPluginAPI, aDecryptorId);
}
void
-GMPLoaderImpl::Shutdown()
+GMPLoader::Shutdown()
{
if (mAdapter) {
mAdapter->GMPShutdown();
}
}
#if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
void
-GMPLoaderImpl::SetSandboxInfo(MacSandboxInfo* aSandboxInfo)
+GMPLoader::SetSandboxInfo(MacSandboxInfo* aSandboxInfo)
{
if (mSandboxStarter) {
mSandboxStarter->SetSandboxInfo(aSandboxInfo);
}
}
#endif
#if defined(XP_WIN) && defined(MOZ_SANDBOX)
@@ -261,31 +229,35 @@ public:
{
mozilla::SetMediaPluginSandbox(aLibPath);
return true;
}
};
} // anonymous namespace
#endif // XP_LINUX && MOZ_GMP_SANDBOX
-
static UniquePtr<SandboxStarter>
MakeSandboxStarter()
{
#if defined(XP_WIN) && defined(MOZ_SANDBOX)
return mozilla::MakeUnique<WinSandboxStarter>();
#elif defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
return mozilla::MakeUnique<MacSandboxStarter>();
#elif defined(XP_LINUX) && defined(MOZ_GMP_SANDBOX)
return LinuxSandboxStarter::Make();
#else
return nullptr;
#endif
}
-UniquePtr<GMPLoader>
-CreateGMPLoader()
+GMPLoader::GMPLoader()
+ : mSandboxStarter(MakeSandboxStarter())
{
- return MakeUnique<GMPLoaderImpl>(MakeSandboxStarter());
+}
+
+bool
+GMPLoader::CanSandbox() const
+{
+ return !!mSandboxStarter;
}
} // namespace gmp
} // namespace mozilla
--- a/dom/media/gmp/GMPLoader.h
+++ b/dom/media/gmp/GMPLoader.h
@@ -44,68 +44,54 @@ public:
virtual GMPErr GMPInit(const GMPPlatformAPI* aPlatformAPI) = 0;
virtual GMPErr GMPGetAPI(const char* aAPIName,
void* aHostAPI,
void** aPluginAPI,
uint32_t aDecryptorId) = 0;
virtual void GMPShutdown() = 0;
};
-// Encapsulates generating the device-bound node id, activating the sandbox,
-// loading the GMP, and passing the node id to the GMP (in that order).
-//
-// In Desktop Gecko, the implementation of this lives in plugin-container,
-// and is passed into XUL code from on startup. The GMP IPC child protocol actor
-// uses this interface to load and retrieve interfaces from the GMPs.
-//
-// In Desktop Gecko the implementation lives in the plugin-container so that
-// it can be covered by DRM vendor's voucher.
-//
-// On Android the GMPLoader implementation lives in libxul (because for the time
-// being GMPLoader relies upon NSPR, which we can't use in plugin-container
-// on Android).
-//
-// There is exactly one GMPLoader per GMP child process, and only one GMP
-// per child process (so the GMPLoader only loads one GMP).
-//
+// Encapsulates activating the sandbox, and loading the GMP.
// Load() takes an optional GMPAdapter which can be used to adapt non-GMPs
// to adhere to the GMP API.
class GMPLoader {
public:
- virtual ~GMPLoader() {}
+ GMPLoader();
// Activates the sandbox, then loads the GMP library. If aAdapter is
// non-null, the lib path is assumed to be a non-GMP, and the adapter
// is initialized with the lib and the adapter is used to interact with
// the plugin.
- virtual bool Load(const char* aUTF8LibPath,
- uint32_t aLibPathLen,
- char* aOriginSalt,
- uint32_t aOriginSaltLen,
- const GMPPlatformAPI* aPlatformAPI,
- GMPAdapter* aAdapter = nullptr) = 0;
+ bool Load(const char* aUTF8LibPath,
+ uint32_t aLibPathLen,
+ char* aOriginSalt,
+ uint32_t aOriginSaltLen,
+ const GMPPlatformAPI* aPlatformAPI,
+ GMPAdapter* aAdapter = nullptr);
// Retrieves an interface pointer from the GMP.
- virtual GMPErr GetAPI(const char* aAPIName,
- void* aHostAPI,
- void** aPluginAPI,
- uint32_t aDecryptorId) = 0;
+ GMPErr GetAPI(const char* aAPIName,
+ void* aHostAPI,
+ void** aPluginAPI,
+ uint32_t aDecryptorId);
// Calls the GMPShutdown function exported by the GMP lib, and unloads the
// plugin library.
- virtual void Shutdown() = 0;
+ void Shutdown();
#if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
// On OS X we need to set Mac-specific sandbox info just before we start the
// sandbox, which we don't yet know when the GMPLoader and SandboxStarter
// objects are created.
- virtual void SetSandboxInfo(MacSandboxInfo* aSandboxInfo) = 0;
+ void SetSandboxInfo(MacSandboxInfo* aSandboxInfo);
#endif
-};
+
+ bool CanSandbox() const;
-// On Desktop, this function resides in plugin-container.
-// On Mobile, this function resides in XUL.
-UniquePtr<GMPLoader> CreateGMPLoader();
+private:
+ UniquePtr<SandboxStarter> mSandboxStarter;
+ UniquePtr<GMPAdapter> mAdapter;
+};
} // namespace gmp
} // namespace mozilla
#endif // GMP_LOADER_H__