Bug 1345753 - Pass the event target to the CDMProxy constructor. r=cpearce

MozReview-Commit-ID: 94QzJ5FnGDo

--HG--
extra : rebase_source : b863f95c7906327f00eb8e08dd5b7f37a3b3cc6c
extra : source : 6e6242c50af23128b23d3b955a081481cec0b6e2
This commit is contained in:
JW Wang 2017-03-09 14:58:18 +08:00
Родитель b16e3e3861
Коммит 3be61ebd8d
7 изменённых файлов: 32 добавлений и 32 удалений

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

@ -81,11 +81,13 @@ public:
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.
@ -94,8 +96,7 @@ public:
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) {}
@ -260,9 +261,6 @@ protected:
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;
@ -273,6 +271,9 @@ protected:
const bool mDistinctiveIdentifierRequired;
const bool mPersistentStateRequired;
// The main thread associated with the root document.
const nsCOMPtr<nsIEventTarget> mMainThread;
};

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

@ -330,7 +330,7 @@ private:
};
already_AddRefed<CDMProxy>
MediaKeys::CreateCDMProxy()
MediaKeys::CreateCDMProxy(nsIEventTarget* aMainThread)
{
RefPtr<CDMProxy> proxy;
#ifdef MOZ_WIDGET_ANDROID
@ -338,7 +338,8 @@ MediaKeys::CreateCDMProxy()
proxy = new MediaDrmCDMProxy(this,
mKeySystem,
mConfig.mDistinctiveIdentifier == MediaKeysRequirement::Required,
mConfig.mPersistentState == MediaKeysRequirement::Required);
mConfig.mPersistentState == MediaKeysRequirement::Required,
aMainThread);
} else
#endif
{
@ -346,7 +347,8 @@ MediaKeys::CreateCDMProxy()
mKeySystem,
new MediaKeysGMPCrashHelper(this),
mConfig.mDistinctiveIdentifier == MediaKeysRequirement::Required,
mConfig.mPersistentState == MediaKeysRequirement::Required);
mConfig.mPersistentState == MediaKeysRequirement::Required,
aMainThread);
}
return proxy.forget();
}
@ -360,8 +362,6 @@ MediaKeys::Init(ErrorResult& aRv)
return nullptr;
}
mProxy = CreateCDMProxy();
// Determine principal (at creation time) of the MediaKeys object.
nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(GetParentObject());
if (!sop) {
@ -415,6 +415,8 @@ MediaKeys::Init(ErrorResult& aRv)
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
@ -429,8 +431,7 @@ MediaKeys::Init(ErrorResult& aRv)
mProxy->Init(mCreatePromiseId,
NS_ConvertUTF8toUTF16(origin),
NS_ConvertUTF8toUTF16(topLevelOrigin),
KeySystemToGMPName(mKeySystem),
top->GetExtantDoc()->EventTargetFor(TaskCategory::Other));
KeySystemToGMPName(mKeySystem));
return promise.forget();
}

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

@ -134,7 +134,7 @@ 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);

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

@ -25,11 +25,13 @@ ToMediaDrmSessionType(dom::MediaKeySessionType aSessionType)
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)
{
@ -46,8 +48,7 @@ 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());
@ -57,8 +58,6 @@ MediaDrmCDMProxy::Init(PromiseId aPromiseId,
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));

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

@ -32,13 +32,13 @@ public:
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,

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

@ -28,11 +28,13 @@ 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)
@ -52,8 +54,7 @@ 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());
@ -62,8 +63,6 @@ GMPCDMProxy::Init(PromiseId aPromiseId,
NS_ConvertUTF16toUTF8(aOrigin).get(),
NS_ConvertUTF16toUTF8(aTopLevelOrigin).get());
mMainThread = aMainThread;
nsCString pluginVersion;
if (!mOwnerThread) {
nsCOMPtr<mozIGeckoMediaPluginService> mps =

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

@ -26,13 +26,13 @@ public:
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;