Bug 1878713 - part1 : use enum HDCPVersion to replace DOMString. r=media-playback-reviewers,webidl,jolin,smaug

Per spec [1], `minHDCPVersion` should be enum `HDCPVersion`.

[1] https://w3c.github.io/encrypted-media/#idl-def-mediakeyspolicy

Differential Revision: https://phabricator.services.mozilla.com/D200756
This commit is contained in:
alwu 2024-02-10 00:24:32 +00:00
Родитель ab3210c5ce
Коммит d8f7773781
12 изменённых файлов: 70 добавлений и 71 удалений

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

@ -241,7 +241,7 @@ class CDMProxy {
// Calls MediaKeys->ResolvePromiseWithKeyStatus(aPromiseId, aKeyStatus) after
// the CDM has processed the request.
virtual void GetStatusForPolicy(PromiseId aPromiseId,
const nsAString& aMinHdcpVersion) = 0;
const dom::HDCPVersion& aMinHdcpVersion) = 0;
#ifdef DEBUG
virtual bool IsOnOwnerThread() = 0;

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

@ -800,6 +800,7 @@ void MediaKeys::GetSessionsInfo(nsString& sessionsInfo) {
}
}
// https://w3c.github.io/encrypted-media/#dom-mediakeys-getstatusforpolicy
already_AddRefed<Promise> MediaKeys::GetStatusForPolicy(
const MediaKeysPolicy& aPolicy, ErrorResult& aRv) {
RefPtr<DetailedPromise> promise(
@ -808,6 +809,13 @@ already_AddRefed<Promise> MediaKeys::GetStatusForPolicy(
return nullptr;
}
// 1. If policy has no present members, return a promise rejected with a newly
// created TypeError.
if (!aPolicy.mMinHdcpVersion.WasPassed()) {
promise->MaybeRejectWithTypeError("No minHdcpVersion in MediaKeysPolicy");
return promise.forget();
}
// Currently, only widevine CDM supports for this API.
if (!IsWidevineKeySystem(mKeySystem)) {
EME_LOG(
@ -828,8 +836,9 @@ already_AddRefed<Promise> MediaKeys::GetStatusForPolicy(
}
EME_LOG("GetStatusForPolicy minHdcpVersion = %s.",
NS_ConvertUTF16toUTF8(aPolicy.mMinHdcpVersion).get());
mProxy->GetStatusForPolicy(StorePromise(promise), aPolicy.mMinHdcpVersion);
HDCPVersionValues::GetString(aPolicy.mMinHdcpVersion.Value()).data());
mProxy->GetStatusForPolicy(StorePromise(promise),
aPolicy.mMinHdcpVersion.Value());
return promise.forget();
}

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

@ -332,8 +332,8 @@ void MediaDrmCDMProxy::OnKeyStatusesChange(const nsAString& aSessionId) {
}
}
void MediaDrmCDMProxy::GetStatusForPolicy(PromiseId aPromiseId,
const nsAString& aMinHdcpVersion) {
void MediaDrmCDMProxy::GetStatusForPolicy(
PromiseId aPromiseId, const dom::HDCPVersion& aMinHdcpVersion) {
// TODO: Implement GetStatusForPolicy.
constexpr auto err =
"Currently Fennec does not support GetStatusForPolicy"_ns;

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

@ -99,7 +99,7 @@ class MediaDrmCDMProxy final : public CDMProxy {
void OnKeyStatusesChange(const nsAString& aSessionId) override;
void GetStatusForPolicy(PromiseId aPromiseId,
const nsAString& aMinHdcpVersion) override;
const dom::HDCPVersion& aMinHdcpVersion) override;
#ifdef DEBUG
bool IsOnOwnerThread() override;

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

@ -100,7 +100,7 @@ class WMFCDMProxy : public CDMProxy {
void OnKeyStatusesChange(const nsAString& aSessionId) override;
void GetStatusForPolicy(PromiseId aPromiseId,
const nsAString& aMinHdcpVersion) override {}
const dom::HDCPVersion& aMinHdcpVersion) override {}
#ifdef DEBUG
bool IsOnOwnerThread() override {

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

@ -276,67 +276,44 @@ void ChromiumCDMParent::CompleteQueryOutputProtectionStatus(
aProtectionMask);
}
// See
// https://cs.chromium.org/chromium/src/media/blink/webcontentdecryptionmodule_impl.cc?l=33-66&rcl=d49aa59ac8c2925d5bec229f3f1906537b6b4547
static Result<cdm::HdcpVersion, nsresult> ToCDMHdcpVersion(
const nsCString& aMinHdcpVersion) {
if (aMinHdcpVersion.IsEmpty()) {
return cdm::HdcpVersion::kHdcpVersionNone;
static cdm::HdcpVersion ToCDMHdcpVersion(
const dom::HDCPVersion& aMinHdcpVersion) {
switch (aMinHdcpVersion) {
case dom::HDCPVersion::_1_0:
return cdm::HdcpVersion::kHdcpVersion1_0;
case dom::HDCPVersion::_1_1:
return cdm::HdcpVersion::kHdcpVersion1_1;
case dom::HDCPVersion::_1_2:
return cdm::HdcpVersion::kHdcpVersion1_2;
case dom::HDCPVersion::_1_3:
return cdm::HdcpVersion::kHdcpVersion1_3;
case dom::HDCPVersion::_1_4:
return cdm::HdcpVersion::kHdcpVersion1_4;
case dom::HDCPVersion::_2_0:
return cdm::HdcpVersion::kHdcpVersion2_0;
case dom::HDCPVersion::_2_1:
return cdm::HdcpVersion::kHdcpVersion2_1;
case dom::HDCPVersion::_2_2:
return cdm::HdcpVersion::kHdcpVersion2_2;
case dom::HDCPVersion::_2_3:
return cdm::HdcpVersion::kHdcpVersion2_3;
// When adding another version remember to update GMPMessageUtils so that we
// can serialize it correctly and have correct bounds on the enum!
default:
MOZ_ASSERT_UNREACHABLE("Unexpected HDCP version!");
return cdm::HdcpVersion::kHdcpVersionNone;
}
if (aMinHdcpVersion.EqualsIgnoreCase("1.0")) {
return cdm::HdcpVersion::kHdcpVersion1_0;
}
if (aMinHdcpVersion.EqualsIgnoreCase("1.1")) {
return cdm::HdcpVersion::kHdcpVersion1_1;
}
if (aMinHdcpVersion.EqualsIgnoreCase("1.2")) {
return cdm::HdcpVersion::kHdcpVersion1_2;
}
if (aMinHdcpVersion.EqualsIgnoreCase("1.3")) {
return cdm::HdcpVersion::kHdcpVersion1_3;
}
if (aMinHdcpVersion.EqualsIgnoreCase("1.4")) {
return cdm::HdcpVersion::kHdcpVersion1_4;
}
if (aMinHdcpVersion.EqualsIgnoreCase("2.0")) {
return cdm::HdcpVersion::kHdcpVersion2_0;
}
if (aMinHdcpVersion.EqualsIgnoreCase("2.1")) {
return cdm::HdcpVersion::kHdcpVersion2_1;
}
if (aMinHdcpVersion.EqualsIgnoreCase("2.2")) {
return cdm::HdcpVersion::kHdcpVersion2_2;
}
// When adding another version remember to update GMPMessageUtils so that we
// can serialize it correctly and have correct bounds on the enum!
// Invalid hdcp version string.
return Err(NS_ERROR_INVALID_ARG);
}
void ChromiumCDMParent::GetStatusForPolicy(uint32_t aPromiseId,
const nsCString& aMinHdcpVersion) {
void ChromiumCDMParent::GetStatusForPolicy(
uint32_t aPromiseId, const dom::HDCPVersion& aMinHdcpVersion) {
MOZ_ASSERT(mGMPThread->IsOnCurrentThread());
GMP_LOG_DEBUG("ChromiumCDMParent::GetStatusForPolicy(this=%p)", this);
if (mIsShutdown) {
RejectPromiseShutdown(aPromiseId);
return;
}
auto hdcpVersionResult = ToCDMHdcpVersion(aMinHdcpVersion);
if (hdcpVersionResult.isErr()) {
ErrorResult rv;
// XXXbz there's no spec for this yet, and
// <https://github.com/WICG/hdcp-detection/blob/master/explainer.md>
// does not define what exceptions get thrown. Let's assume
// TypeError for invalid args, as usual.
constexpr auto err =
"getStatusForPolicy failed due to bad hdcp version argument"_ns;
rv.ThrowTypeError(err);
RejectPromise(aPromiseId, std::move(rv), err);
return;
}
if (!SendGetStatusForPolicy(aPromiseId, hdcpVersionResult.unwrap())) {
if (!SendGetStatusForPolicy(aPromiseId, ToCDMHdcpVersion(aMinHdcpVersion))) {
RejectPromiseWithStateError(
aPromiseId, "Failed to send getStatusForPolicy to CDM process"_ns);
}

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

@ -80,7 +80,7 @@ class ChromiumCDMParent final : public PChromiumCDMParent,
uint32_t aProtectionMask);
void GetStatusForPolicy(uint32_t aPromiseId,
const nsCString& aMinHdcpVersion);
const dom::HDCPVersion& aMinHdcpVersion);
RefPtr<DecryptPromise> Decrypt(MediaRawData* aSample);

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

@ -8,6 +8,7 @@
#include "ChromiumCDMCallbackProxy.h"
#include "MediaResult.h"
#include "mozilla/dom/MediaKeySession.h"
#include "mozilla/dom/MediaKeysBinding.h"
#include "GMPUtils.h"
#include "nsPrintfCString.h"
#include "GMPService.h"
@ -599,12 +600,13 @@ RefPtr<DecryptPromise> ChromiumCDMProxy::Decrypt(MediaRawData* aSample) {
[cdm, sample]() { return cdm->Decrypt(sample); });
}
void ChromiumCDMProxy::GetStatusForPolicy(PromiseId aPromiseId,
const nsAString& aMinHdcpVersion) {
void ChromiumCDMProxy::GetStatusForPolicy(
PromiseId aPromiseId, const dom::HDCPVersion& aMinHdcpVersion) {
MOZ_ASSERT(NS_IsMainThread());
EME_LOG("ChromiumCDMProxy::GetStatusForPolicy(this=%p, pid=%" PRIu32
") minHdcpVersion=%s",
this, aPromiseId, NS_ConvertUTF16toUTF8(aMinHdcpVersion).get());
this, aPromiseId,
dom::HDCPVersionValues::GetString(aMinHdcpVersion).data());
RefPtr<gmp::ChromiumCDMParent> cdm = GetCDMParent();
if (!cdm) {
@ -613,10 +615,10 @@ void ChromiumCDMProxy::GetStatusForPolicy(PromiseId aPromiseId,
return;
}
mGMPThread->Dispatch(NewRunnableMethod<uint32_t, nsCString>(
mGMPThread->Dispatch(NewRunnableMethod<uint32_t, dom::HDCPVersion>(
"gmp::ChromiumCDMParent::GetStatusForPolicy", cdm,
&gmp::ChromiumCDMParent::GetStatusForPolicy, aPromiseId,
NS_ConvertUTF16toUTF8(aMinHdcpVersion)));
aMinHdcpVersion));
}
void ChromiumCDMProxy::Terminated() {

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

@ -98,7 +98,7 @@ class ChromiumCDMProxy : public CDMProxy {
void OnKeyStatusesChange(const nsAString& aSessionId) override;
void GetStatusForPolicy(PromiseId aPromiseId,
const nsAString& aMinHdcpVersion) override;
const dom::HDCPVersion& aMinHdcpVersion) override;
#ifdef DEBUG
bool IsOnOwnerThread() override;

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

@ -70,7 +70,7 @@ template <>
struct ParamTraits<cdm::HdcpVersion>
: public ContiguousEnumSerializerInclusive<
cdm::HdcpVersion, cdm::HdcpVersion::kHdcpVersionNone,
cdm::HdcpVersion::kHdcpVersion2_2> {};
cdm::HdcpVersion::kHdcpVersion2_3> {};
template <>
struct ParamTraits<GMPSimulcastStream> {

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

@ -18,9 +18,22 @@ enum MediaKeySessionType {
// persistent-usage-record,
};
// https://github.com/WICG/media-capabilities/blob/master/eme-extension-policy-check.md
// https://w3c.github.io/encrypted-media/#idl-def-hdcpversion
enum HDCPVersion {
"1.0",
"1.1",
"1.2",
"1.3",
"1.4",
"2.0",
"2.1",
"2.2",
"2.3",
};
// https://w3c.github.io/encrypted-media/#idl-def-mediakeyspolicy
dictionary MediaKeysPolicy {
DOMString minHdcpVersion = "";
HDCPVersion minHdcpVersion;
};
[Exposed=Window]

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

@ -1,5 +1,3 @@
[idlharness.https.html]
expected:
if (os == "android") and fission: [OK, TIMEOUT]
[MediaKeys interface: operation getStatusForPolicy(optional MediaKeysPolicy)]
expected: FAIL