This repository has been archived by the owner on Aug 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1397123 - [Part2] Decouple ChromiumCDMProxy from ChromiumCDMParen…
…t. r=cpearce 1. Pass ChromiumCDMCallback interface to ChromiumCDMParent instead of ChromiumCDMProxy directly. 2. Wrap dispatching to main thread function to clean up the redundant code. MozReview-Commit-ID: 5HxS9Fc1yr
- Loading branch information
1 parent
9645db3
commit 2ba9c2d
Showing
8 changed files
with
373 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* -*- 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/. */ | ||
|
||
#ifndef ChromiumCDMCallback_h_ | ||
#define ChromiumCDMCallback_h_ | ||
|
||
#include "mozilla/CDMProxy.h" | ||
#include "mozilla/dom/MediaKeyStatusMapBinding.h" // For MediaKeyStatus | ||
#include "mozilla/dom/MediaKeyMessageEventBinding.h" // For MediaKeyMessageType | ||
#include "mozilla/gmp/GMPTypes.h" // For CDMKeyInformation | ||
|
||
class ChromiumCDMCallback { | ||
public: | ||
|
||
virtual ~ChromiumCDMCallback() {} | ||
|
||
virtual void SetSessionId(uint32_t aPromiseId, | ||
const nsCString& aSessionId) = 0; | ||
|
||
virtual void ResolveLoadSessionPromise(uint32_t aPromiseId, | ||
bool aSuccessful) = 0; | ||
|
||
virtual void ResolvePromise(uint32_t aPromiseId) = 0; | ||
|
||
virtual void RejectPromise(uint32_t aPromiseId, | ||
nsresult aError, | ||
const nsCString& aErrorMessage) = 0; | ||
|
||
virtual void SessionMessage(const nsACString& aSessionId, | ||
uint32_t aMessageType, | ||
nsTArray<uint8_t>&& aMessage) = 0; | ||
|
||
virtual void SessionKeysChange(const nsCString& aSessionId, | ||
nsTArray<mozilla::gmp::CDMKeyInformation>&& aKeysInfo) = 0; | ||
|
||
virtual void ExpirationChange(const nsCString& aSessionId, | ||
double aSecondsSinceEpoch) = 0; | ||
|
||
virtual void SessionClosed(const nsCString& aSessionId) = 0; | ||
|
||
virtual void LegacySessionError(const nsCString& aSessionId, | ||
nsresult aError, | ||
uint32_t aSystemCode, | ||
const nsCString& aMessage) = 0; | ||
virtual void Terminated() = 0; | ||
|
||
virtual void Shutdown() = 0; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
/* -*- 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/. */ | ||
|
||
#include "ChromiumCDMCallbackProxy.h" | ||
|
||
#include "ChromiumCDMProxy.h" | ||
#include "content_decryption_module.h" | ||
|
||
namespace mozilla { | ||
|
||
template<class Func, class... Args> | ||
void ChromiumCDMCallbackProxy::DispatchToMainThread(const char* const aLabel, | ||
Func aFunc, | ||
Args&&... aArgs) | ||
{ | ||
mMainThread->Dispatch( | ||
// Use Decay to ensure all the types are passed by value not by reference. | ||
NewRunnableMethod<typename Decay<Args>::Type...>( | ||
aLabel, | ||
mProxy, | ||
aFunc, | ||
Forward<Args>(aArgs)...), | ||
NS_DISPATCH_NORMAL); | ||
} | ||
|
||
void | ||
ChromiumCDMCallbackProxy::SetSessionId(uint32_t aPromiseId, | ||
const nsCString& aSessionId) | ||
{ | ||
DispatchToMainThread("ChromiumCDMProxy::OnSetSessionId", | ||
&ChromiumCDMProxy::OnSetSessionId, | ||
aPromiseId, | ||
NS_ConvertUTF8toUTF16(aSessionId)); | ||
} | ||
|
||
void | ||
ChromiumCDMCallbackProxy::ResolveLoadSessionPromise(uint32_t aPromiseId, | ||
bool aSuccessful) | ||
{ | ||
DispatchToMainThread("ChromiumCDMProxy::OnResolveLoadSessionPromise", | ||
&ChromiumCDMProxy::OnResolveLoadSessionPromise, | ||
aPromiseId, | ||
aSuccessful); | ||
} | ||
|
||
void | ||
ChromiumCDMCallbackProxy::ResolvePromise(uint32_t aPromiseId) | ||
{ | ||
DispatchToMainThread("ChromiumCDMProxy::ResolvePromise", | ||
&ChromiumCDMProxy::ResolvePromise, | ||
aPromiseId); | ||
} | ||
|
||
void | ||
ChromiumCDMCallbackProxy::RejectPromise(uint32_t aPromiseId, | ||
nsresult aError, | ||
const nsCString& aErrorMessage) | ||
{ | ||
DispatchToMainThread("ChromiumCDMProxy::RejectPromise", | ||
&ChromiumCDMProxy::RejectPromise, | ||
aPromiseId, | ||
aError, | ||
aErrorMessage); | ||
} | ||
|
||
|
||
static dom::MediaKeyMessageType | ||
ToDOMMessageType(uint32_t aMessageType) | ||
{ | ||
switch (static_cast<cdm::MessageType>(aMessageType)) { | ||
case cdm::kLicenseRequest: | ||
return dom::MediaKeyMessageType::License_request; | ||
case cdm::kLicenseRenewal: | ||
return dom::MediaKeyMessageType::License_renewal; | ||
case cdm::kLicenseRelease: | ||
return dom::MediaKeyMessageType::License_release; | ||
} | ||
MOZ_ASSERT_UNREACHABLE("Invalid cdm::MessageType enum value."); | ||
return dom::MediaKeyMessageType::License_request; | ||
} | ||
|
||
void | ||
ChromiumCDMCallbackProxy::SessionMessage(const nsACString& aSessionId, | ||
uint32_t aMessageType, | ||
nsTArray<uint8_t>&& aMessage) | ||
{ | ||
DispatchToMainThread("ChromiumCDMProxy::OnSessionMessage", | ||
&ChromiumCDMProxy::OnSessionMessage, | ||
NS_ConvertUTF8toUTF16(aSessionId), | ||
ToDOMMessageType(aMessageType), | ||
Move(aMessage)); | ||
} | ||
|
||
static dom::MediaKeyStatus | ||
ToDOMMediaKeyStatus(uint32_t aStatus) | ||
{ | ||
switch (static_cast<cdm::KeyStatus>(aStatus)) { | ||
case cdm::kUsable: | ||
return dom::MediaKeyStatus::Usable; | ||
case cdm::kInternalError: | ||
return dom::MediaKeyStatus::Internal_error; | ||
case cdm::kExpired: | ||
return dom::MediaKeyStatus::Expired; | ||
case cdm::kOutputRestricted: | ||
return dom::MediaKeyStatus::Output_restricted; | ||
case cdm::kOutputDownscaled: | ||
return dom::MediaKeyStatus::Output_downscaled; | ||
case cdm::kStatusPending: | ||
return dom::MediaKeyStatus::Status_pending; | ||
case cdm::kReleased: | ||
return dom::MediaKeyStatus::Released; | ||
} | ||
MOZ_ASSERT_UNREACHABLE("Invalid cdm::KeyStatus enum value."); | ||
return dom::MediaKeyStatus::Internal_error; | ||
} | ||
|
||
void | ||
ChromiumCDMCallbackProxy::SessionKeysChange(const nsCString& aSessionId, | ||
nsTArray<mozilla::gmp::CDMKeyInformation> && aKeysInfo) | ||
{ | ||
bool keyStatusesChange = false; | ||
{ | ||
CDMCaps::AutoLock caps(mProxy->Capabilites()); | ||
for (const auto& keyInfo : aKeysInfo) { | ||
keyStatusesChange |= | ||
caps.SetKeyStatus(keyInfo.mKeyId(), | ||
NS_ConvertUTF8toUTF16(aSessionId), | ||
dom::Optional<dom::MediaKeyStatus>( | ||
ToDOMMediaKeyStatus(keyInfo.mStatus()))); | ||
} | ||
} | ||
if (keyStatusesChange) { | ||
DispatchToMainThread("ChromiumCDMProxy::OnKeyStatusesChange", | ||
&ChromiumCDMProxy::OnKeyStatusesChange, | ||
NS_ConvertUTF8toUTF16(aSessionId)); | ||
} | ||
} | ||
|
||
void | ||
ChromiumCDMCallbackProxy::ExpirationChange(const nsCString& aSessionId, | ||
double aSecondsSinceEpoch) | ||
{ | ||
DispatchToMainThread("ChromiumCDMProxy::OnExpirationChange", | ||
&ChromiumCDMProxy::OnExpirationChange, | ||
NS_ConvertUTF8toUTF16(aSessionId), | ||
UnixTime(aSecondsSinceEpoch * 1000)); | ||
|
||
} | ||
|
||
void | ||
ChromiumCDMCallbackProxy::SessionClosed(const nsCString& aSessionId) | ||
{ | ||
DispatchToMainThread("ChromiumCDMProxy::OnSessionClosed", | ||
&ChromiumCDMProxy::OnSessionClosed , | ||
NS_ConvertUTF8toUTF16(aSessionId)); | ||
} | ||
|
||
void | ||
ChromiumCDMCallbackProxy::LegacySessionError(const nsCString& aSessionId, | ||
nsresult aError, | ||
uint32_t aSystemCode, | ||
const nsCString& aMessage) | ||
{ | ||
DispatchToMainThread("ChromiumCDMProxy::OnSessionError", | ||
&ChromiumCDMProxy::OnSessionError , | ||
NS_ConvertUTF8toUTF16(aSessionId), | ||
aError, | ||
aSystemCode, | ||
NS_ConvertUTF8toUTF16(aMessage)); | ||
} | ||
|
||
void | ||
ChromiumCDMCallbackProxy::Terminated() | ||
{ | ||
DispatchToMainThread("ChromiumCDMProxy::Terminated", | ||
&ChromiumCDMProxy::Terminated); | ||
} | ||
|
||
void | ||
ChromiumCDMCallbackProxy::Shutdown() | ||
{ | ||
DispatchToMainThread("ChromiumCDMProxy::Shutdown", | ||
&ChromiumCDMProxy::Shutdown); | ||
} | ||
|
||
} //namespace mozilla |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* -*- 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/. */ | ||
|
||
#ifndef ChromiumCDMCallbackProxy_h_ | ||
#define ChromiumCDMCallbackProxy_h_ | ||
|
||
#include "ChromiumCDMCallback.h" | ||
#include "ChromiumCDMProxy.h" | ||
#include "nsThreadUtils.h" | ||
|
||
namespace mozilla { | ||
|
||
class ChromiumCDMCallbackProxy : public ChromiumCDMCallback { | ||
public: | ||
|
||
ChromiumCDMCallbackProxy(ChromiumCDMProxy* aProxy, | ||
nsIEventTarget* aMainThread) | ||
: mProxy(aProxy), mMainThread(aMainThread) | ||
{ | ||
} | ||
|
||
void SetSessionId(uint32_t aPromiseId, | ||
const nsCString& aSessionId) override; | ||
|
||
void ResolveLoadSessionPromise(uint32_t aPromiseId, | ||
bool aSuccessful) override; | ||
|
||
void ResolvePromise(uint32_t aPromiseId) override; | ||
|
||
void RejectPromise(uint32_t aPromiseId, | ||
nsresult aError, | ||
const nsCString& aErrorMessage) override; | ||
|
||
void SessionMessage(const nsACString& aSessionId, | ||
uint32_t aMessageType, | ||
nsTArray<uint8_t>&& aMessage) override; | ||
|
||
void SessionKeysChange(const nsCString& aSessionId, | ||
nsTArray<mozilla::gmp::CDMKeyInformation>&& aKeysInfo) override; | ||
|
||
void ExpirationChange(const nsCString& aSessionId, | ||
double aSecondsSinceEpoch) override; | ||
|
||
void SessionClosed(const nsCString& aSessionId) override; | ||
|
||
void LegacySessionError(const nsCString& aSessionId, | ||
nsresult aError, | ||
uint32_t aSystemCode, | ||
const nsCString& aMessage) override; | ||
void Terminated() override; | ||
|
||
void Shutdown() override; | ||
|
||
private: | ||
template<class Func, class... Args> | ||
void DispatchToMainThread(const char* const aLabel, | ||
Func aFunc, | ||
Args&&... aArgs); | ||
// Warning: Weak ref. | ||
ChromiumCDMProxy* mProxy; | ||
const nsCOMPtr<nsIEventTarget> mMainThread; | ||
|
||
}; | ||
|
||
} //namespace mozilla | ||
#endif |
Oops, something went wrong.