Bug 1345753 - Pass the event target to the CDMProxy constructor. r?cpearce
MozReview-Commit-ID: 94QzJ5FnGDo
--- a/dom/media/eme/CDMProxy.h
+++ b/dom/media/eme/CDMProxy.h
@@ -76,31 +76,32 @@ protected:
public:
NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
// Main thread only.
CDMProxy(dom::MediaKeys* aKeys,
const nsAString& aKeySystem,
bool aDistinctiveIdentifierRequired,
- bool aPersistentStateRequired)
+ bool aPersistentStateRequired,
+ nsIEventTarget* aMainThread)
: mKeys(aKeys)
, mKeySystem(aKeySystem)
, mDistinctiveIdentifierRequired(aDistinctiveIdentifierRequired)
, mPersistentStateRequired(aPersistentStateRequired)
+ , mMainThread(aMainThread)
{}
// Main thread only.
// Loads the CDM corresponding to mKeySystem.
// Calls MediaKeys::OnCDMCreated() when the CDM is created.
virtual void Init(PromiseId aPromiseId,
const nsAString& aOrigin,
const nsAString& aTopLevelOrigin,
- const nsAString& aName,
- nsIEventTarget* aMainThread) = 0;
+ const nsAString& aName) = 0;
virtual void OnSetDecryptorId(uint32_t aId) {}
// Main thread only.
// Uses the CDM to create a key session.
// Calls MediaKeys::OnSessionActivated() when session is created.
// Assumes ownership of (Move()s) aInitData's contents.
virtual void CreateSession(uint32_t aCreateSessionToken,
@@ -255,27 +256,27 @@ protected:
// Our reference back to the MediaKeys object.
// WARNING: This is a non-owning reference that is cleared by MediaKeys
// destructor. only use on main thread, and always nullcheck before using!
MainThreadOnlyRawPtr<dom::MediaKeys> mKeys;
const nsString mKeySystem;
- // The main thread associated with the root document. Must be set in Init().
- nsCOMPtr<nsIEventTarget> mMainThread;
-
// Onwer specified thread. e.g. Gecko Media Plugin thread.
// All interactions with the out-of-process EME plugin must come from this thread.
RefPtr<nsIThread> mOwnerThread;
nsCString mNodeId;
CDMCaps mCapabilites;
const bool mDistinctiveIdentifierRequired;
const bool mPersistentStateRequired;
+
+ // The main thread associated with the root document.
+ const nsCOMPtr<nsIEventTarget> mMainThread;
};
} // namespace mozilla
#endif // CDMProxy_h_
--- a/dom/media/eme/MediaKeys.cpp
+++ b/dom/media/eme/MediaKeys.cpp
@@ -325,48 +325,48 @@ public:
return (mMediaKeys && mMediaKeys->GetParentObject()) ?
do_AddRef(mMediaKeys->GetParentObject()) : nullptr;
}
private:
WeakPtr<MediaKeys> mMediaKeys;
};
already_AddRefed<CDMProxy>
-MediaKeys::CreateCDMProxy()
+MediaKeys::CreateCDMProxy(nsIEventTarget* aMainThread)
{
RefPtr<CDMProxy> proxy;
#ifdef MOZ_WIDGET_ANDROID
if (IsWidevineKeySystem(mKeySystem)) {
proxy = new MediaDrmCDMProxy(this,
mKeySystem,
mConfig.mDistinctiveIdentifier == MediaKeysRequirement::Required,
- mConfig.mPersistentState == MediaKeysRequirement::Required);
+ mConfig.mPersistentState == MediaKeysRequirement::Required,
+ aMainThread);
} else
#endif
{
proxy = new GMPCDMProxy(this,
mKeySystem,
new MediaKeysGMPCrashHelper(this),
mConfig.mDistinctiveIdentifier == MediaKeysRequirement::Required,
- mConfig.mPersistentState == MediaKeysRequirement::Required);
+ mConfig.mPersistentState == MediaKeysRequirement::Required,
+ aMainThread);
}
return proxy.forget();
}
already_AddRefed<DetailedPromise>
MediaKeys::Init(ErrorResult& aRv)
{
RefPtr<DetailedPromise> promise(MakePromise(aRv,
NS_LITERAL_CSTRING("MediaKeys::Init()")));
if (aRv.Failed()) {
return nullptr;
}
- mProxy = CreateCDMProxy();
-
// Determine principal (at creation time) of the MediaKeys object.
nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(GetParentObject());
if (!sop) {
promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR,
NS_LITERAL_CSTRING("Couldn't get script principal in MediaKeys::Init"));
return promise.forget();
}
mPrincipal = sop->GetPrincipal();
@@ -410,32 +410,33 @@ MediaKeys::Init(ErrorResult& aRv)
return promise.forget();
}
EME_LOG("MediaKeys[%p]::Create() (%s, %s)",
this,
origin.get(),
topLevelOrigin.get());
+ mProxy = CreateCDMProxy(top->GetExtantDoc()->EventTargetFor(TaskCategory::Other));
+
// The CDMProxy's initialization is asynchronous. The MediaKeys is
// refcounted, and its instance is returned to JS by promise once
// it's been initialized. No external refs exist to the MediaKeys while
// we're waiting for the promise to be resolved, so we must hold a
// reference to the new MediaKeys object until it's been created,
// or its creation has failed. Store the id of the promise returned
// here, and hold a self-reference until that promise is resolved or
// rejected.
MOZ_ASSERT(!mCreatePromiseId, "Should only be created once!");
mCreatePromiseId = StorePromise(promise);
AddRef();
mProxy->Init(mCreatePromiseId,
NS_ConvertUTF8toUTF16(origin),
NS_ConvertUTF8toUTF16(topLevelOrigin),
- KeySystemToGMPName(mKeySystem),
- top->GetExtantDoc()->EventTargetFor(TaskCategory::Other));
+ KeySystemToGMPName(mKeySystem));
return promise.forget();
}
void
MediaKeys::OnCDMCreated(PromiseId aId, const uint32_t aPluginId)
{
RefPtr<DetailedPromise> promise(RetrievePromise(aId));
--- a/dom/media/eme/MediaKeys.h
+++ b/dom/media/eme/MediaKeys.h
@@ -129,17 +129,17 @@ public:
bool IsBoundToMediaElement() const;
void GetSessionsInfo(nsString& sessionsInfo);
private:
// Instantiate CDMProxy instance.
// It could be MediaDrmCDMProxy (Widevine on Fennec) or GMPCDMProxy (the rest).
- already_AddRefed<CDMProxy> CreateCDMProxy();
+ already_AddRefed<CDMProxy> CreateCDMProxy(nsIEventTarget* aMainThread);
// Removes promise from mPromises, and returns it.
already_AddRefed<DetailedPromise> RetrievePromise(PromiseId aId);
// Owning ref to proxy. The proxy has a weak reference back to the MediaKeys,
// and the MediaKeys destructor clears the proxy's reference to the MediaKeys.
RefPtr<CDMProxy> mProxy;
--- a/dom/media/eme/mediadrm/MediaDrmCDMProxy.cpp
+++ b/dom/media/eme/mediadrm/MediaDrmCDMProxy.cpp
@@ -20,50 +20,49 @@ ToMediaDrmSessionType(dom::MediaKeySessi
case dom::MediaKeySessionType::Persistent_license: return kKeyOffline;
default: return kKeyStreaming;
};
}
MediaDrmCDMProxy::MediaDrmCDMProxy(dom::MediaKeys* aKeys,
const nsAString& aKeySystem,
bool aDistinctiveIdentifierRequired,
- bool aPersistentStateRequired)
+ bool aPersistentStateRequired,
+ nsIEventTarget* aMainThread)
: CDMProxy(aKeys,
aKeySystem,
aDistinctiveIdentifierRequired,
- aPersistentStateRequired)
+ aPersistentStateRequired,
+ aMainThread)
, mCDM(nullptr)
, mShutdownCalled(false)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_COUNT_CTOR(MediaDrmCDMProxy);
}
MediaDrmCDMProxy::~MediaDrmCDMProxy()
{
MOZ_COUNT_DTOR(MediaDrmCDMProxy);
}
void
MediaDrmCDMProxy::Init(PromiseId aPromiseId,
const nsAString& aOrigin,
const nsAString& aTopLevelOrigin,
- const nsAString& aName,
- nsIEventTarget* aMainThread)
+ const nsAString& aName)
{
MOZ_ASSERT(NS_IsMainThread());
NS_ENSURE_TRUE_VOID(!mKeys.IsNull());
EME_LOG("MediaDrmCDMProxy::Init (%s, %s) %s",
NS_ConvertUTF16toUTF8(aOrigin).get(),
NS_ConvertUTF16toUTF8(aTopLevelOrigin).get(),
NS_ConvertUTF16toUTF8(aName).get());
- mMainThread = aMainThread;
-
// Create a thread to work with cdm.
if (!mOwnerThread) {
nsresult rv = NS_NewNamedThread("MDCDMThread", getter_AddRefs(mOwnerThread));
if (NS_FAILED(rv)) {
RejectPromise(aPromiseId, NS_ERROR_DOM_INVALID_STATE_ERR,
NS_LITERAL_CSTRING("Couldn't create CDM thread MediaDrmCDMProxy::Init"));
return;
}
--- a/dom/media/eme/mediadrm/MediaDrmCDMProxy.h
+++ b/dom/media/eme/mediadrm/MediaDrmCDMProxy.h
@@ -27,23 +27,23 @@ class MediaDrmCDMCallbackProxy;
class MediaDrmCDMProxy : public CDMProxy {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaDrmCDMProxy)
MediaDrmCDMProxy(dom::MediaKeys* aKeys,
const nsAString& aKeySystem,
bool aDistinctiveIdentifierRequired,
- bool aPersistentStateRequired);
+ bool aPersistentStateRequired,
+ nsIEventTarget* aMainThread);
void Init(PromiseId aPromiseId,
const nsAString& aOrigin,
const nsAString& aTopLevelOrigin,
- const nsAString& aGMPName,
- nsIEventTarget* aMainThread) override;
+ const nsAString& aGMPName) override;
void CreateSession(uint32_t aCreateSessionToken,
MediaKeySessionType aSessionType,
PromiseId aPromiseId,
const nsAString& aInitDataType,
nsTArray<uint8_t>& aInitData) override;
void LoadSession(PromiseId aPromiseId,
--- a/dom/media/gmp/GMPCDMProxy.cpp
+++ b/dom/media/gmp/GMPCDMProxy.cpp
@@ -23,21 +23,23 @@
#include "GMPUtils.h"
namespace mozilla {
GMPCDMProxy::GMPCDMProxy(dom::MediaKeys* aKeys,
const nsAString& aKeySystem,
GMPCrashHelper* aCrashHelper,
bool aDistinctiveIdentifierRequired,
- bool aPersistentStateRequired)
+ bool aPersistentStateRequired,
+ nsIEventTarget* aMainThread)
: CDMProxy(aKeys,
aKeySystem,
aDistinctiveIdentifierRequired,
- aPersistentStateRequired)
+ aPersistentStateRequired,
+ aMainThread)
, mCrashHelper(aCrashHelper)
, mCDM(nullptr)
, mShutdownCalled(false)
, mDecryptorId(0)
, mCreatePromiseId(0)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_COUNT_CTOR(GMPCDMProxy);
@@ -47,28 +49,25 @@ GMPCDMProxy::~GMPCDMProxy()
{
MOZ_COUNT_DTOR(GMPCDMProxy);
}
void
GMPCDMProxy::Init(PromiseId aPromiseId,
const nsAString& aOrigin,
const nsAString& aTopLevelOrigin,
- const nsAString& aGMPName,
- nsIEventTarget* aMainThread)
+ const nsAString& aGMPName)
{
MOZ_ASSERT(NS_IsMainThread());
NS_ENSURE_TRUE_VOID(!mKeys.IsNull());
EME_LOG("GMPCDMProxy::Init (%s, %s)",
NS_ConvertUTF16toUTF8(aOrigin).get(),
NS_ConvertUTF16toUTF8(aTopLevelOrigin).get());
- mMainThread = aMainThread;
-
nsCString pluginVersion;
if (!mOwnerThread) {
nsCOMPtr<mozIGeckoMediaPluginService> mps =
do_GetService("@mozilla.org/gecko-media-plugin-service;1");
if (!mps) {
RejectPromise(aPromiseId, NS_ERROR_DOM_INVALID_STATE_ERR,
NS_LITERAL_CSTRING("Couldn't get MediaPluginService in GMPCDMProxy::Init"));
return;
--- a/dom/media/gmp/GMPCDMProxy.h
+++ b/dom/media/gmp/GMPCDMProxy.h
@@ -21,23 +21,23 @@ class GMPCDMProxy : public CDMProxy {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GMPCDMProxy, override)
GMPCDMProxy(dom::MediaKeys* aKeys,
const nsAString& aKeySystem,
GMPCrashHelper* aCrashHelper,
bool aDistinctiveIdentifierRequired,
- bool aPersistentStateRequired);
+ bool aPersistentStateRequired,
+ nsIEventTarget* aMainThread);
void Init(PromiseId aPromiseId,
const nsAString& aOrigin,
const nsAString& aTopLevelOrigin,
- const nsAString& aGMPName,
- nsIEventTarget* aMainThread) override;
+ const nsAString& aGMPName) override;
void OnSetDecryptorId(uint32_t aId) override;
void CreateSession(uint32_t aCreateSessionToken,
dom::MediaKeySessionType aSessionType,
PromiseId aPromiseId,
const nsAString& aInitDataType,
nsTArray<uint8_t>& aInitData) override;