From a4fe4d518fcfaefb29a7a7ff3501912b256caad3 Mon Sep 17 00:00:00 2001 From: Chris Pearce Date: Thu, 19 Jan 2017 15:44:54 +1300 Subject: [PATCH] Bug 1332530 - Flatten GMPLoader and GMPLoaderImpl. r=gerald MozReview-Commit-ID: GZ8feXmLuCb --HG-- extra : rebase_source : e869cf9b25bdf3b5a6e6cbdcbd8c521987f826cb --- dom/media/gmp/GMPChild.cpp | 6 ++-- dom/media/gmp/GMPLoader.cpp | 68 +++++++++++-------------------------- dom/media/gmp/GMPLoader.h | 54 +++++++++++------------------ 3 files changed, 43 insertions(+), 85 deletions(-) diff --git a/dom/media/gmp/GMPChild.cpp b/dom/media/gmp/GMPChild.cpp index db0492cd80e2..96a5f1631f0d 100644 --- a/dom/media/gmp/GMPChild.cpp +++ b/dom/media/gmp/GMPChild.cpp @@ -349,9 +349,9 @@ GMPChild::AnswerStartPlugin(const nsString& aAdapter) auto platformAPI = new GMPPlatformAPI(); InitPlatformAPI(*platformAPI, this); - mGMPLoader = CreateGMPLoader(); - if (!mGMPLoader) { - NS_WARNING("Failed to get GMPLoader"); + mGMPLoader = MakeUnique(); + if (!mGMPLoader->CanSandbox()) { + LOGD("%s Can't sandbox GMP, failing", __FUNCTION__); delete platformAPI; return IPC_FAIL_NO_REASON(this); } diff --git a/dom/media/gmp/GMPLoader.cpp b/dom/media/gmp/GMPLoader.cpp index 8295d54d54ec..f39f180c0fdc 100644 --- a/dom/media/gmp/GMPLoader.cpp +++ b/dom/media/gmp/GMPLoader.cpp @@ -28,38 +28,6 @@ namespace mozilla { namespace gmp { - -class GMPLoaderImpl : public GMPLoader { -public: - explicit GMPLoaderImpl(UniquePtr 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 mSandboxStarter; - UniquePtr mAdapter; -}; - class PassThroughGMPAdapter : public GMPAdapter { public: ~PassThroughGMPAdapter() override { @@ -116,12 +84,12 @@ private: }; 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 @@ -177,16 +145,16 @@ GMPLoaderImpl::Load(const char* aUTF8LibPath, } 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(); @@ -195,7 +163,7 @@ GMPLoaderImpl::Shutdown() #if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX) void -GMPLoaderImpl::SetSandboxInfo(MacSandboxInfo* aSandboxInfo) +GMPLoader::SetSandboxInfo(MacSandboxInfo* aSandboxInfo) { if (mSandboxStarter) { mSandboxStarter->SetSandboxInfo(aSandboxInfo); @@ -266,7 +234,6 @@ public: } // anonymous namespace #endif // XP_LINUX && MOZ_GMP_SANDBOX - static UniquePtr MakeSandboxStarter() { @@ -281,10 +248,15 @@ MakeSandboxStarter() #endif } -UniquePtr -CreateGMPLoader() +GMPLoader::GMPLoader() + : mSandboxStarter(MakeSandboxStarter()) { - return MakeUnique(MakeSandboxStarter()); +} + +bool +GMPLoader::CanSandbox() const +{ + return !!mSandboxStarter; } } // namespace gmp diff --git a/dom/media/gmp/GMPLoader.h b/dom/media/gmp/GMPLoader.h index 837b9909c6a5..c7a224bd0ee8 100644 --- a/dom/media/gmp/GMPLoader.h +++ b/dom/media/gmp/GMPLoader.h @@ -49,61 +49,47 @@ public: 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 -}; -// On Desktop, this function resides in plugin-container. -// On Mobile, this function resides in XUL. -UniquePtr CreateGMPLoader(); + bool CanSandbox() const; + +private: + UniquePtr mSandboxStarter; + UniquePtr mAdapter; +}; } // namespace gmp } // namespace mozilla