Bug 1267918 - Add GMPCrashHelper for MediaKeys. r=gerald

So if a GMP crashes while doing EME, we'll get a crash report using the new
mechanism.

MozReview-Commit-ID: G8BlFI9jmiF

--HG--
extra : rebase_source : 1cda5c93ea9e547636b34ec2149ef9cd2506ca73
This commit is contained in:
Chris Pearce 2016-06-29 11:42:04 +12:00
parent 8b965f3eac
commit 7517d84f1b
4 changed files with 38 additions and 6 deletions

View File

@ -19,6 +19,7 @@
#include "mozilla/CDMCallbackProxy.h"
#include "MediaData.h"
#include "nsPrintfCString.h"
#include "GMPService.h"
namespace mozilla {
@ -43,7 +44,8 @@ CDMProxy::Init(PromiseId aPromiseId,
const nsAString& aOrigin,
const nsAString& aTopLevelOrigin,
const nsAString& aGMPName,
bool aInPrivateBrowsing)
bool aInPrivateBrowsing,
GMPCrashHelper* aCrashHelper)
{
MOZ_ASSERT(NS_IsMainThread());
NS_ENSURE_TRUE_VOID(!mKeys.IsNull());
@ -82,6 +84,7 @@ CDMProxy::Init(PromiseId aPromiseId,
data->mTopLevelOrigin = aTopLevelOrigin;
data->mGMPName = aGMPName;
data->mInPrivateBrowsing = aInPrivateBrowsing;
data->mCrashHelper = aCrashHelper;
nsCOMPtr<nsIRunnable> task(
NewRunnableMethod<nsAutoPtr<InitData>>(this,
&CDMProxy::gmp_Init,
@ -226,9 +229,12 @@ CDMProxy::gmp_InitGetGMPDecryptor(nsresult aResult,
nsTArray<nsCString> tags;
tags.AppendElement(NS_ConvertUTF16toUTF8(mKeySystem));
// Note: must capture helper refptr here, before the Move()
// when we create the GetGMPDecryptorCallback below.
RefPtr<GMPCrashHelper> crashHelper = Move(aData->mCrashHelper);
UniquePtr<GetGMPDecryptorCallback> callback(new gmp_InitDoneCallback(this,
Move(aData)));
nsresult rv = mps->GetGMPDecryptor(nullptr, &tags, GetNodeId(), Move(callback));
nsresult rv = mps->GetGMPDecryptor(crashHelper, &tags, GetNodeId(), Move(callback));
if (NS_FAILED(rv)) {
RejectPromise(promiseID, NS_ERROR_DOM_INVALID_STATE_ERR,
NS_LITERAL_CSTRING("Call to GetGMPDecryptor() failed early"));

View File

@ -58,7 +58,8 @@ public:
const nsAString& aOrigin,
const nsAString& aTopLevelOrigin,
const nsAString& aGMPName,
bool aInPrivateBrowsing);
bool aInPrivateBrowsing,
GMPCrashHelper* aHelper);
// Main thread only.
// Uses the CDM to create a key session.
@ -188,6 +189,7 @@ private:
nsString mOrigin;
nsString mTopLevelOrigin;
nsString mGMPName;
RefPtr<GMPCrashHelper> mCrashHelper;
bool mInPrivateBrowsing;
};

View File

@ -284,6 +284,26 @@ MediaKeys::ResolvePromise(PromiseId aId)
MOZ_ASSERT(!mPromises.Contains(aId));
}
class MediaKeysGMPCrashHelper : public GMPCrashHelper
{
public:
explicit MediaKeysGMPCrashHelper(MediaKeys* aMediaKeys)
: mMediaKeys(aMediaKeys)
{
MOZ_ASSERT(NS_IsMainThread()); // WeakPtr isn't thread safe.
}
already_AddRefed<nsPIDOMWindowInner>
GetPluginCrashedEventTarget() override
{
MOZ_ASSERT(NS_IsMainThread()); // WeakPtr isn't thread safe.
EME_LOG("MediaKeysGMPCrashHelper::GetPluginCrashedEventTarget()");
return (mMediaKeys && mMediaKeys->GetParentObject()) ?
do_AddRef(mMediaKeys->GetParentObject()) : nullptr;
}
private:
WeakPtr<MediaKeys> mMediaKeys;
};
already_AddRefed<DetailedPromise>
MediaKeys::Init(ErrorResult& aRv)
{
@ -367,7 +387,8 @@ MediaKeys::Init(ErrorResult& aRv)
origin,
topLevelOrigin,
KeySystemToGMPName(mKeySystem),
inPrivateBrowsing);
inPrivateBrowsing,
new MediaKeysGMPCrashHelper(this));
return promise.forget();
}

View File

@ -19,6 +19,7 @@
#include "mozilla/dom/MediaKeysBinding.h"
#include "mozIGeckoMediaPluginService.h"
#include "mozilla/DetailedPromise.h"
#include "mozilla/WeakPtr.h"
namespace mozilla {
@ -36,15 +37,17 @@ typedef nsRefPtrHashtable<nsUint32HashKey, MediaKeySession> PendingKeySessionsHa
typedef uint32_t PromiseId;
// This class is used on the main thread only.
// Note: it's addref/release is not (and can't be) thread safe!
// Note: its addref/release is not (and can't be) thread safe!
class MediaKeys final : public nsISupports,
public nsWrapperCache
public nsWrapperCache,
public SupportsWeakPtr<MediaKeys>
{
~MediaKeys();
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MediaKeys)
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(MediaKeys)
MediaKeys(nsPIDOMWindowInner* aParentWindow,
const nsAString& aKeySystem, const nsAString& aCDMVersion);