Bug 1306327 - Use UniquePtr for CreateGMPLoader. r=cpearce
--- a/dom/media/gmp/GMPLoader.cpp
+++ b/dom/media/gmp/GMPLoader.cpp
@@ -19,18 +19,18 @@
#include "GMPDeviceBinding.h"
namespace mozilla {
namespace gmp {
class GMPLoaderImpl : public GMPLoader {
public:
- explicit GMPLoaderImpl(SandboxStarter* aStarter)
- : mSandboxStarter(aStarter)
+ 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,
@@ -44,22 +44,22 @@ public:
void Shutdown() override;
#if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
void SetSandboxInfo(MacSandboxInfo* aSandboxInfo) override;
#endif
private:
- SandboxStarter* mSandboxStarter;
+ UniquePtr<SandboxStarter> mSandboxStarter;
UniquePtr<GMPAdapter> mAdapter;
};
-UniquePtr<GMPLoader> CreateGMPLoader(SandboxStarter* aStarter) {
- return MakeUnique<GMPLoaderImpl>(aStarter);
+UniquePtr<GMPLoader> CreateGMPLoader(UniquePtr<SandboxStarter> aStarter) {
+ return MakeUnique<GMPLoaderImpl>(Move(aStarter));
}
class PassThroughGMPAdapter : public GMPAdapter {
public:
~PassThroughGMPAdapter() override {
// Ensure we're always shutdown, even if caller forgets to call GMPShutdown().
GMPShutdown();
}
--- a/dom/media/gmp/GMPLoader.h
+++ b/dom/media/gmp/GMPLoader.h
@@ -100,14 +100,14 @@ public:
// sandbox, which we don't yet know when the GMPLoader and SandboxStarter
// objects are created.
virtual void SetSandboxInfo(MacSandboxInfo* aSandboxInfo) = 0;
#endif
};
// On Desktop, this function resides in plugin-container.
// On Mobile, this function resides in XUL.
-UniquePtr<GMPLoader> CreateGMPLoader(SandboxStarter* aStarter);
+UniquePtr<GMPLoader> CreateGMPLoader(UniquePtr<SandboxStarter> aStarter);
} // namespace gmp
} // namespace mozilla
#endif // GMP_LOADER_H__
--- a/ipc/contentproc/plugin-container.cpp
+++ b/ipc/contentproc/plugin-container.cpp
@@ -53,23 +53,23 @@ public:
void SetSandboxInfo(MacSandboxInfo* aSandboxInfo) override {
mInfo = *aSandboxInfo;
}
private:
MacSandboxInfo mInfo;
};
#endif
-mozilla::gmp::SandboxStarter*
+mozilla::UniquePtr<mozilla::gmp::SandboxStarter>
MakeSandboxStarter()
{
#if defined(XP_WIN) && defined(MOZ_SANDBOX)
- return new WinSandboxStarter();
+ return mozilla::MakeUnique<WinSandboxStarter>();
#elif defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
- return new MacSandboxStarter();
+ return mozilla::MakeUnique<MacSandboxStarter>();
#else
return nullptr;
#endif
}
int
content_process_main(int argc, char* argv[])
{
@@ -102,18 +102,17 @@ content_process_main(int argc, char* arg
if (XRE_GetProcessType() != GeckoProcessType_Plugin) {
mozilla::SanitizeEnvironmentVariables();
SetDllDirectoryW(L"");
}
#endif
#if !defined(XP_LINUX) && defined(MOZ_PLUGIN_CONTAINER)
// On Windows and MacOS, the GMPLoader lives in plugin-container, so that its
// code can be covered by an EME/GMP vendor's voucher.
- nsAutoPtr<mozilla::gmp::SandboxStarter> starter(MakeSandboxStarter());
if (XRE_GetProcessType() == GeckoProcessType_GMPlugin) {
- childData.gmpLoader = mozilla::gmp::CreateGMPLoader(starter);
+ childData.gmpLoader = mozilla::gmp::CreateGMPLoader(MakeSandboxStarter());
}
#endif
nsresult rv = XRE_InitChildProcess(argc, argv, &childData);
NS_ENSURE_SUCCESS(rv, 1);
return 0;
}
--- a/toolkit/xre/nsEmbedFunctions.cpp
+++ b/toolkit/xre/nsEmbedFunctions.cpp
@@ -326,21 +326,24 @@ AddContentSandboxLevelAnnotation()
}
}
#endif /* MOZ_CONTENT_SANDBOX && !MOZ_WIDGET_GONK */
#endif /* MOZ_CRASHREPORTER */
#if defined (XP_LINUX) && defined(MOZ_GMP_SANDBOX)
namespace {
class LinuxSandboxStarter : public mozilla::gmp::SandboxStarter {
+private:
LinuxSandboxStarter() { }
+ friend mozilla::detail::UniqueSelector<LinuxSandboxStarter>::SingleObject mozilla::MakeUnique<LinuxSandboxStarter>();
+
public:
- static SandboxStarter* Make() {
+ static UniquePtr<SandboxStarter> Make() {
if (mozilla::SandboxInfo::Get().CanSandboxMedia()) {
- return new LinuxSandboxStarter();
+ return MakeUnique<LinuxSandboxStarter>();
} else {
// Sandboxing isn't possible, but the parent has already
// checked that this plugin doesn't require it. (Bug 1074561)
return nullptr;
}
return nullptr;
}
virtual bool Start(const char *aLibPath) override {
@@ -374,21 +377,21 @@ XRE_InitChildProcess(int aArgc,
#ifdef XP_LINUX
// On Fennec, the GMPLoader's code resides inside XUL (because for the time
// being GMPLoader relies upon NSPR, which we can't use in plugin-container
// on Android), so we create it here inside XUL and pass it to the GMP code.
//
// On desktop Linux, the sandbox code lives in a shared library, and
// the GMPLoader is in libxul instead of executables to avoid unwanted
// library dependencies.
- mozilla::gmp::SandboxStarter* starter = nullptr;
+ UniquePtr<mozilla::gmp::SandboxStarter> starter;
#ifdef MOZ_GMP_SANDBOX
starter = LinuxSandboxStarter::Make();
#endif
- UniquePtr<GMPLoader> loader = CreateGMPLoader(starter);
+ UniquePtr<GMPLoader> loader = CreateGMPLoader(Move(starter));
GMPProcessChild::SetGMPLoader(loader.get());
#else
// On non-Linux platforms, the GMPLoader code resides in plugin-container,
// and we must forward it through to the GMP code here.
GMPProcessChild::SetGMPLoader(aChildData->gmpLoader.get());
#endif
#if defined(XP_WIN)