Bug 1332530 - Flatten GMPLoader and GMPLoaderImpl. r=gerald

MozReview-Commit-ID: GZ8feXmLuCb

--HG--
extra : rebase_source : e869cf9b25bdf3b5a6e6cbdcbd8c521987f826cb
This commit is contained in:
Chris Pearce 2017-01-19 15:44:54 +13:00
Родитель 701e1daf19
Коммит a4fe4d518f
3 изменённых файлов: 43 добавлений и 85 удалений

Просмотреть файл

@ -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<GMPLoader>();
if (!mGMPLoader->CanSandbox()) {
LOGD("%s Can't sandbox GMP, failing", __FUNCTION__);
delete platformAPI;
return IPC_FAIL_NO_REASON(this);
}

Просмотреть файл

@ -28,38 +28,6 @@
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 {
@ -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<SandboxStarter>
MakeSandboxStarter()
{
@ -281,10 +248,15 @@ MakeSandboxStarter()
#endif
}
UniquePtr<GMPLoader>
CreateGMPLoader()
GMPLoader::GMPLoader()
: mSandboxStarter(MakeSandboxStarter())
{
return MakeUnique<GMPLoaderImpl>(MakeSandboxStarter());
}
bool
GMPLoader::CanSandbox() const
{
return !!mSandboxStarter;
}
} // namespace gmp

Просмотреть файл

@ -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<GMPLoader> CreateGMPLoader();
bool CanSandbox() const;
private:
UniquePtr<SandboxStarter> mSandboxStarter;
UniquePtr<GMPAdapter> mAdapter;
};
} // namespace gmp
} // namespace mozilla