2014-05-18 07:05:46 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2015-05-29 05:07:22 +03:00
|
|
|
#include "GMPService.h"
|
2015-02-09 23:54:12 +03:00
|
|
|
#include "GMPServiceParent.h"
|
2015-02-10 13:49:03 +03:00
|
|
|
#include "GMPServiceChild.h"
|
2015-05-29 05:07:22 +03:00
|
|
|
#include "GMPContentParent.h"
|
2014-10-13 02:53:44 +04:00
|
|
|
#include "prio.h"
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2014-05-18 07:05:46 +04:00
|
|
|
#include "GMPParent.h"
|
|
|
|
#include "GMPVideoDecoderParent.h"
|
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "GeckoChildProcessHost.h"
|
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
|
|
|
#include "mozilla/SyncRunnable.h"
|
|
|
|
#include "nsXPCOMPrivate.h"
|
|
|
|
#include "mozilla/Services.h"
|
2014-07-10 22:48:11 +04:00
|
|
|
#include "nsNativeCharsetUtils.h"
|
2016-12-20 23:53:15 +03:00
|
|
|
#include "nsIXULAppInfo.h"
|
2014-07-10 22:48:11 +04:00
|
|
|
#include "nsIConsoleService.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2014-08-18 01:41:56 +04:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2014-07-28 19:42:55 +04:00
|
|
|
#include "runnable_utils.h"
|
2014-10-13 02:53:43 +04:00
|
|
|
#include "VideoUtils.h"
|
2014-10-01 00:35:21 +04:00
|
|
|
#if defined(XP_LINUX) && defined(MOZ_GMP_SANDBOX)
|
2014-11-25 02:22:13 +03:00
|
|
|
#include "mozilla/SandboxInfo.h"
|
2014-10-01 00:35:21 +04:00
|
|
|
#endif
|
2014-10-13 02:53:44 +04:00
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
|
|
|
#include "nsDirectoryServiceUtils.h"
|
|
|
|
#include "nsDirectoryServiceDefs.h"
|
|
|
|
#include "nsHashKeys.h"
|
|
|
|
#include "nsIFile.h"
|
2015-01-06 03:00:00 +03:00
|
|
|
#include "nsISimpleEnumerator.h"
|
2016-06-30 05:19:08 +03:00
|
|
|
#include "nsThreadUtils.h"
|
2016-11-16 01:35:36 +03:00
|
|
|
#include "GMPCrashHelper.h"
|
2014-05-18 07:05:46 +04:00
|
|
|
|
2015-06-05 12:55:51 +03:00
|
|
|
#include "mozilla/dom/PluginCrashedEvent.h"
|
|
|
|
#include "mozilla/EventDispatcher.h"
|
2016-06-30 05:19:08 +03:00
|
|
|
#include "mozilla/Attributes.h"
|
2017-08-30 06:38:56 +03:00
|
|
|
#include "mozilla/SystemGroup.h"
|
2015-06-05 12:55:51 +03:00
|
|
|
|
2014-05-18 07:05:46 +04:00
|
|
|
namespace mozilla {
|
2014-07-25 05:47:44 +04:00
|
|
|
|
|
|
|
#ifdef LOG
|
|
|
|
#undef LOG
|
|
|
|
#endif
|
|
|
|
|
2015-11-15 16:49:01 +03:00
|
|
|
LogModule*
|
2014-07-25 05:47:44 +04:00
|
|
|
GetGMPLog()
|
|
|
|
{
|
2015-11-15 16:49:01 +03:00
|
|
|
static LazyLogModule sLog("GMP");
|
2014-07-25 05:47:44 +04:00
|
|
|
return sLog;
|
|
|
|
}
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
#define LOGD(msg) MOZ_LOG(GetGMPLog(), mozilla::LogLevel::Debug, msg)
|
2015-05-21 23:22:04 +03:00
|
|
|
#define LOG(level, msg) MOZ_LOG(GetGMPLog(), (level), msg)
|
2014-07-25 05:47:44 +04:00
|
|
|
|
2014-07-28 19:42:55 +04:00
|
|
|
#ifdef __CLASS__
|
|
|
|
#undef __CLASS__
|
|
|
|
#endif
|
|
|
|
#define __CLASS__ "GMPService"
|
|
|
|
|
2014-05-18 07:05:46 +04:00
|
|
|
namespace gmp {
|
|
|
|
|
|
|
|
static StaticRefPtr<GeckoMediaPluginService> sSingletonService;
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class GMPServiceCreateHelper final : public mozilla::Runnable
|
2014-05-18 07:05:46 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GeckoMediaPluginService> mService;
|
2014-05-18 07:05:46 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
static already_AddRefed<GeckoMediaPluginService>
|
|
|
|
GetOrCreate()
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GeckoMediaPluginService> service;
|
2014-05-18 07:05:46 +04:00
|
|
|
|
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
service = GetOrCreateOnMainThread();
|
|
|
|
} else {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GMPServiceCreateHelper> createHelper = new GMPServiceCreateHelper();
|
2014-05-18 07:05:46 +04:00
|
|
|
|
2017-03-09 10:31:11 +03:00
|
|
|
mozilla::SyncRunnable::DispatchToThread(
|
|
|
|
SystemGroup::EventTargetFor(mozilla::TaskCategory::Other),
|
|
|
|
createHelper, true);
|
2014-05-18 07:05:46 +04:00
|
|
|
|
|
|
|
service = createHelper->mService.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
return service.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
GMPServiceCreateHelper()
|
2017-03-09 10:31:11 +03:00
|
|
|
: Runnable("GMPServiceCreateHelper")
|
2014-05-18 07:05:46 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~GMPServiceCreateHelper()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mService);
|
|
|
|
}
|
|
|
|
|
|
|
|
static already_AddRefed<GeckoMediaPluginService>
|
|
|
|
GetOrCreateOnMainThread()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-02-09 23:54:12 +03:00
|
|
|
if (!sSingletonService) {
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GeckoMediaPluginServiceParent> service =
|
2015-02-10 13:49:03 +03:00
|
|
|
new GeckoMediaPluginServiceParent();
|
|
|
|
service->Init();
|
|
|
|
sSingletonService = service;
|
|
|
|
} else {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GeckoMediaPluginServiceChild> service =
|
2015-02-10 13:49:03 +03:00
|
|
|
new GeckoMediaPluginServiceChild();
|
|
|
|
service->Init();
|
|
|
|
sSingletonService = service;
|
|
|
|
}
|
2014-05-18 07:05:46 +04:00
|
|
|
|
|
|
|
ClearOnShutdown(&sSingletonService);
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GeckoMediaPluginService> service = sSingletonService.get();
|
2014-05-18 07:05:46 +04:00
|
|
|
return service.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD
|
2016-08-08 05:18:10 +03:00
|
|
|
Run() override
|
2014-05-18 07:05:46 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
mService = GetOrCreateOnMainThread();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
already_AddRefed<GeckoMediaPluginService>
|
|
|
|
GeckoMediaPluginService::GetGeckoMediaPluginService()
|
|
|
|
{
|
|
|
|
return GMPServiceCreateHelper::GetOrCreate();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(GeckoMediaPluginService, mozIGeckoMediaPluginService, nsIObserver)
|
|
|
|
|
|
|
|
GeckoMediaPluginService::GeckoMediaPluginService()
|
|
|
|
: mMutex("GeckoMediaPluginService::mMutex")
|
2015-02-09 23:54:12 +03:00
|
|
|
, mGMPThreadShutdown(false)
|
2014-05-18 07:05:46 +04:00
|
|
|
, mShuttingDownOnGMPThread(false)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2016-12-20 23:53:15 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIXULAppInfo> appInfo = do_GetService("@mozilla.org/xre/app-info;1");
|
|
|
|
if (appInfo) {
|
|
|
|
nsAutoCString version;
|
|
|
|
nsAutoCString buildID;
|
|
|
|
if (NS_SUCCEEDED(appInfo->GetVersion(version)) &&
|
|
|
|
NS_SUCCEEDED(appInfo->GetAppBuildID(buildID))) {
|
|
|
|
LOGD(("GeckoMediaPluginService created; Gecko version=%s buildID=%s",
|
|
|
|
version.get(), buildID.get()));
|
|
|
|
}
|
|
|
|
}
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
GeckoMediaPluginService::~GeckoMediaPluginService()
|
|
|
|
{
|
2014-10-22 00:45:18 +04:00
|
|
|
}
|
|
|
|
|
2016-05-05 03:32:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GeckoMediaPluginService::RunPluginCrashCallbacks(uint32_t aPluginId,
|
2015-05-04 22:40:29 +03:00
|
|
|
const nsACString& aPluginName)
|
2015-03-26 09:55:30 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-05-04 22:40:29 +03:00
|
|
|
LOGD(("%s::%s(%i)", __CLASS__, __FUNCTION__, aPluginId));
|
2015-06-05 12:55:51 +03:00
|
|
|
|
2016-06-29 02:41:56 +03:00
|
|
|
nsAutoPtr<nsTArray<RefPtr<GMPCrashHelper>>> helpers;
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mMutex);
|
2017-07-05 03:01:45 +03:00
|
|
|
mPluginCrashHelpers.Remove(aPluginId, &helpers);
|
2015-03-26 09:55:30 +03:00
|
|
|
}
|
2016-06-29 02:41:56 +03:00
|
|
|
if (!helpers) {
|
|
|
|
LOGD(("%s::%s(%i) No crash helpers, not handling crash.", __CLASS__, __FUNCTION__, aPluginId));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto& helper : *helpers) {
|
|
|
|
nsCOMPtr<nsPIDOMWindowInner> window = helper->GetPluginCrashedEventTarget();
|
|
|
|
if (NS_WARN_IF(!window)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIDocument> document(window->GetExtantDoc());
|
|
|
|
if (NS_WARN_IF(!document)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom::PluginCrashedEventInit init;
|
|
|
|
init.mPluginID = aPluginId;
|
|
|
|
init.mBubbles = true;
|
|
|
|
init.mCancelable = true;
|
|
|
|
init.mGmpPlugin = true;
|
|
|
|
CopyUTF8toUTF16(aPluginName, init.mPluginName);
|
|
|
|
init.mSubmittedCrashReport = false;
|
|
|
|
RefPtr<dom::PluginCrashedEvent> event =
|
|
|
|
dom::PluginCrashedEvent::Constructor(document,
|
|
|
|
NS_LITERAL_STRING("PluginCrashed"),
|
|
|
|
init);
|
|
|
|
event->SetTrusted(true);
|
|
|
|
event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true;
|
|
|
|
|
|
|
|
EventDispatcher::DispatchDOMEvent(window, nullptr, event, nullptr, nullptr);
|
2015-06-05 12:55:51 +03:00
|
|
|
}
|
2016-05-05 03:32:00 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2015-03-26 09:55:30 +03:00
|
|
|
}
|
|
|
|
|
2014-10-13 02:53:44 +04:00
|
|
|
nsresult
|
2014-05-18 07:05:46 +04:00
|
|
|
GeckoMediaPluginService::Init()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> obsService = mozilla::services::GetObserverService();
|
|
|
|
MOZ_ASSERT(obsService);
|
2016-03-28 20:28:15 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(obsService->AddObserver(this, NS_XPCOM_SHUTDOWN_THREADS_OBSERVER_ID, false));
|
2015-03-18 21:15:00 +03:00
|
|
|
|
|
|
|
// Kick off scanning for plugins
|
|
|
|
nsCOMPtr<nsIThread> thread;
|
|
|
|
return GetThread(getter_AddRefs(thread));
|
|
|
|
}
|
|
|
|
|
2017-02-21 23:26:47 +03:00
|
|
|
RefPtr<GetCDMParentPromise>
|
|
|
|
GeckoMediaPluginService::GetCDM(const NodeId& aNodeId,
|
|
|
|
nsTArray<nsCString> aTags,
|
|
|
|
GMPCrashHelper* aHelper)
|
|
|
|
{
|
2017-06-01 23:41:18 +03:00
|
|
|
MOZ_ASSERT(mGMPThread->EventTarget()->IsOnCurrentThread());
|
2017-02-21 23:26:47 +03:00
|
|
|
|
|
|
|
if (mShuttingDownOnGMPThread || aTags.IsEmpty()) {
|
|
|
|
return GetCDMParentPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef MozPromiseHolder<GetCDMParentPromise> PromiseHolder;
|
|
|
|
PromiseHolder* rawHolder(new PromiseHolder());
|
|
|
|
RefPtr<GetCDMParentPromise> promise = rawHolder->Ensure(__func__);
|
|
|
|
RefPtr<AbstractThread> thread(GetAbstractGMPThread());
|
|
|
|
RefPtr<GMPCrashHelper> helper(aHelper);
|
|
|
|
GetContentParent(
|
|
|
|
aHelper, aNodeId, NS_LITERAL_CSTRING(CHROMIUM_CDM_API), aTags)
|
|
|
|
->Then(thread,
|
|
|
|
__func__,
|
|
|
|
[rawHolder, helper](RefPtr<GMPContentParent::CloseBlocker> wrapper) {
|
|
|
|
RefPtr<GMPContentParent> parent = wrapper->mParent;
|
|
|
|
UniquePtr<PromiseHolder> holder(rawHolder);
|
|
|
|
RefPtr<ChromiumCDMParent> cdm = parent->GetChromiumCDM();
|
|
|
|
if (!parent) {
|
|
|
|
holder->Reject(NS_ERROR_FAILURE, __func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (helper) {
|
|
|
|
cdm->SetCrashHelper(helper);
|
|
|
|
}
|
|
|
|
holder->Resolve(cdm, __func__);
|
|
|
|
},
|
|
|
|
[rawHolder] {
|
|
|
|
UniquePtr<PromiseHolder> holder(rawHolder);
|
|
|
|
holder->Reject(NS_ERROR_FAILURE, __func__);
|
|
|
|
});
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
|
2015-02-09 23:54:12 +03:00
|
|
|
void
|
|
|
|
GeckoMediaPluginService::ShutdownGMPThread()
|
2015-03-18 21:15:00 +03:00
|
|
|
{
|
2015-02-09 23:54:12 +03:00
|
|
|
LOGD(("%s::%s", __CLASS__, __FUNCTION__));
|
|
|
|
nsCOMPtr<nsIThread> gmpThread;
|
|
|
|
{
|
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
mGMPThreadShutdown = true;
|
|
|
|
mGMPThread.swap(gmpThread);
|
2016-05-06 14:36:22 +03:00
|
|
|
mAbstractGMPThread = nullptr;
|
2014-10-13 02:53:44 +04:00
|
|
|
}
|
|
|
|
|
2015-02-09 23:54:12 +03:00
|
|
|
if (gmpThread) {
|
|
|
|
gmpThread->Shutdown();
|
2014-10-13 02:53:44 +04:00
|
|
|
}
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
2015-01-06 03:00:00 +03:00
|
|
|
nsresult
|
2016-05-05 11:45:00 +03:00
|
|
|
GeckoMediaPluginService::GMPDispatch(nsIRunnable* event,
|
|
|
|
uint32_t flags)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRunnable> r(event);
|
|
|
|
return GMPDispatch(r.forget());
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
GeckoMediaPluginService::GMPDispatch(already_AddRefed<nsIRunnable> event,
|
|
|
|
uint32_t flags)
|
2015-01-06 03:00:00 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRunnable> r(event);
|
|
|
|
nsCOMPtr<nsIThread> thread;
|
|
|
|
nsresult rv = GetThread(getter_AddRefs(thread));
|
2017-09-19 11:14:49 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2015-01-06 03:00:00 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return thread->Dispatch(r, flags);
|
|
|
|
}
|
|
|
|
|
2014-07-20 03:14:03 +04:00
|
|
|
// always call with getter_AddRefs, because it does
|
2014-05-18 07:05:46 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GeckoMediaPluginService::GetThread(nsIThread** aThread)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aThread);
|
|
|
|
|
|
|
|
// This can be called from any thread.
|
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
|
|
|
|
if (!mGMPThread) {
|
|
|
|
// Don't allow the thread to be created after shutdown has started.
|
2015-02-09 23:54:12 +03:00
|
|
|
if (mGMPThreadShutdown) {
|
2014-05-18 07:05:46 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = NS_NewNamedThread("GMPThread", getter_AddRefs(mGMPThread));
|
2017-09-19 11:14:49 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2014-05-18 07:05:46 +04:00
|
|
|
return rv;
|
|
|
|
}
|
2014-07-10 22:48:11 +04:00
|
|
|
|
2016-04-12 07:12:22 +03:00
|
|
|
mAbstractGMPThread = AbstractThread::CreateXPCOMThreadWrapper(mGMPThread, false);
|
2016-04-12 07:12:20 +03:00
|
|
|
|
2014-07-10 22:48:11 +04:00
|
|
|
// Tell the thread to initialize plugins
|
2016-05-06 14:36:22 +03:00
|
|
|
InitializePlugins(mAbstractGMPThread.get());
|
2014-05-18 07:05:46 +04:00
|
|
|
}
|
|
|
|
|
2015-04-19 20:22:35 +03:00
|
|
|
nsCOMPtr<nsIThread> copy = mGMPThread;
|
|
|
|
copy.forget(aThread);
|
2014-05-18 07:05:46 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-04-12 07:12:20 +03:00
|
|
|
RefPtr<AbstractThread>
|
|
|
|
GeckoMediaPluginService::GetAbstractGMPThread()
|
|
|
|
{
|
2016-05-06 14:36:22 +03:00
|
|
|
MutexAutoLock lock(mMutex);
|
2016-04-12 07:12:20 +03:00
|
|
|
return mAbstractGMPThread;
|
|
|
|
}
|
|
|
|
|
2014-05-18 07:05:46 +04:00
|
|
|
NS_IMETHODIMP
|
2016-11-14 01:07:02 +03:00
|
|
|
GeckoMediaPluginService::GetDecryptingGMPVideoDecoder(GMPCrashHelper* aHelper,
|
|
|
|
nsTArray<nsCString>* aTags,
|
|
|
|
const nsACString& aNodeId,
|
|
|
|
UniquePtr<GetGMPVideoDecoderCallback>&& aCallback,
|
|
|
|
uint32_t aDecryptorId)
|
2014-05-18 07:05:46 +04:00
|
|
|
{
|
2017-06-01 23:41:18 +03:00
|
|
|
MOZ_ASSERT(mGMPThread->EventTarget()->IsOnCurrentThread());
|
2014-06-30 03:02:39 +04:00
|
|
|
NS_ENSURE_ARG(aTags && aTags->Length() > 0);
|
2015-02-10 13:48:29 +03:00
|
|
|
NS_ENSURE_ARG(aCallback);
|
2014-05-18 07:05:46 +04:00
|
|
|
|
|
|
|
if (mShuttingDownOnGMPThread) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-11-09 05:52:22 +03:00
|
|
|
GetGMPVideoDecoderCallback* rawCallback = aCallback.release();
|
|
|
|
RefPtr<AbstractThread> thread(GetAbstractGMPThread());
|
|
|
|
RefPtr<GMPCrashHelper> helper(aHelper);
|
|
|
|
GetContentParent(aHelper, aNodeId, NS_LITERAL_CSTRING(GMP_API_VIDEO_DECODER), *aTags)
|
|
|
|
->Then(thread, __func__,
|
2016-11-16 00:59:08 +03:00
|
|
|
[rawCallback, helper, aDecryptorId](RefPtr<GMPContentParent::CloseBlocker> wrapper) {
|
|
|
|
RefPtr<GMPContentParent> parent = wrapper->mParent;
|
2016-11-09 05:52:22 +03:00
|
|
|
UniquePtr<GetGMPVideoDecoderCallback> callback(rawCallback);
|
|
|
|
GMPVideoDecoderParent* actor = nullptr;
|
|
|
|
GMPVideoHostImpl* host = nullptr;
|
|
|
|
if (parent && NS_SUCCEEDED(parent->GetGMPVideoDecoder(&actor, aDecryptorId))) {
|
|
|
|
host = &(actor->Host());
|
|
|
|
actor->SetCrashHelper(helper);
|
|
|
|
}
|
|
|
|
callback->Done(actor, host);
|
|
|
|
},
|
|
|
|
[rawCallback] {
|
|
|
|
UniquePtr<GetGMPVideoDecoderCallback> callback(rawCallback);
|
|
|
|
callback->Done(nullptr, nullptr);
|
|
|
|
});
|
2014-05-18 07:05:46 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-06-29 02:41:56 +03:00
|
|
|
GeckoMediaPluginService::GetGMPVideoEncoder(GMPCrashHelper* aHelper,
|
|
|
|
nsTArray<nsCString>* aTags,
|
2014-10-13 02:53:43 +04:00
|
|
|
const nsACString& aNodeId,
|
2015-02-10 13:48:29 +03:00
|
|
|
UniquePtr<GetGMPVideoEncoderCallback>&& aCallback)
|
2014-05-18 07:05:46 +04:00
|
|
|
{
|
2017-06-01 23:41:18 +03:00
|
|
|
MOZ_ASSERT(mGMPThread->EventTarget()->IsOnCurrentThread());
|
2014-06-30 03:02:39 +04:00
|
|
|
NS_ENSURE_ARG(aTags && aTags->Length() > 0);
|
2015-02-10 13:48:29 +03:00
|
|
|
NS_ENSURE_ARG(aCallback);
|
2014-05-18 07:05:46 +04:00
|
|
|
|
|
|
|
if (mShuttingDownOnGMPThread) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-11-09 05:52:22 +03:00
|
|
|
GetGMPVideoEncoderCallback* rawCallback = aCallback.release();
|
|
|
|
RefPtr<AbstractThread> thread(GetAbstractGMPThread());
|
|
|
|
RefPtr<GMPCrashHelper> helper(aHelper);
|
|
|
|
GetContentParent(aHelper, aNodeId, NS_LITERAL_CSTRING(GMP_API_VIDEO_ENCODER), *aTags)
|
|
|
|
->Then(thread, __func__,
|
2016-11-16 00:59:08 +03:00
|
|
|
[rawCallback, helper](RefPtr<GMPContentParent::CloseBlocker> wrapper) {
|
|
|
|
RefPtr<GMPContentParent> parent = wrapper->mParent;
|
2016-11-09 05:52:22 +03:00
|
|
|
UniquePtr<GetGMPVideoEncoderCallback> callback(rawCallback);
|
|
|
|
GMPVideoEncoderParent* actor = nullptr;
|
|
|
|
GMPVideoHostImpl* host = nullptr;
|
|
|
|
if (parent && NS_SUCCEEDED(parent->GetGMPVideoEncoder(&actor))) {
|
|
|
|
host = &(actor->Host());
|
|
|
|
actor->SetCrashHelper(helper);
|
|
|
|
}
|
|
|
|
callback->Done(actor, host);
|
|
|
|
},
|
|
|
|
[rawCallback] {
|
|
|
|
UniquePtr<GetGMPVideoEncoderCallback> callback(rawCallback);
|
|
|
|
callback->Done(nullptr, nullptr);
|
|
|
|
});
|
2014-05-18 07:05:46 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-06-29 02:41:56 +03:00
|
|
|
void
|
|
|
|
GeckoMediaPluginService::ConnectCrashHelper(uint32_t aPluginId, GMPCrashHelper* aHelper)
|
|
|
|
{
|
|
|
|
if (!aHelper) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
nsTArray<RefPtr<GMPCrashHelper>>* helpers;
|
|
|
|
if (!mPluginCrashHelpers.Get(aPluginId, &helpers)) {
|
|
|
|
helpers = new nsTArray<RefPtr<GMPCrashHelper>>();
|
|
|
|
mPluginCrashHelpers.Put(aPluginId, helpers);
|
|
|
|
} else if (helpers->Contains(aHelper)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
helpers->AppendElement(aHelper);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GeckoMediaPluginService::DisconnectCrashHelper(GMPCrashHelper* aHelper)
|
|
|
|
{
|
|
|
|
if (!aHelper) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
for (auto iter = mPluginCrashHelpers.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
nsTArray<RefPtr<GMPCrashHelper>>* helpers = iter.Data();
|
|
|
|
if (!helpers->Contains(aHelper)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
helpers->RemoveElement(aHelper);
|
|
|
|
MOZ_ASSERT(!helpers->Contains(aHelper)); // Ensure there aren't duplicates.
|
|
|
|
if (helpers->IsEmpty()) {
|
|
|
|
iter.Remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-18 07:05:46 +04:00
|
|
|
} // namespace gmp
|
|
|
|
} // namespace mozilla
|