Bug 1573976 - Fix GetStatusForPolicy handling of unrecognized values. r=dminor,alwu

GetStatusPolicy should not treat unrecognized values as if they were no hdcp
policy. A trivial example is that if we do not recognize a newer hdcp string,
say "2.3", then we should not query if the CDM supports this policy as if it
were no hdcp.

This patch means that we surface and error to JS if we do no recognize an hdcp
string.

Differential Revision: https://phabricator.services.mozilla.com/D42061

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Bryce Seager van Dyk 2019-08-16 17:47:21 +00:00
Родитель dadf8723f2
Коммит b692482432
5 изменённых файлов: 64 добавлений и 47 удалений

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

@ -500,55 +500,15 @@ mozilla::ipc::IPCResult ChromiumCDMChild::RecvRemoveSession(
return IPC_OK();
}
// See
// https://cs.chromium.org/chromium/src/media/blink/webcontentdecryptionmodule_impl.cc?rcl=9d4e17194fbae2839d269e0b625520eac09efa9b&l=40
static cdm::HdcpVersion ToCDMHdcpVersion(const nsCString& aMinHdcpVersion) {
// String compare with ignoring case.
if (aMinHdcpVersion.IsEmpty()) {
return cdm::HdcpVersion::kHdcpVersionNone;
}
if (aMinHdcpVersion.EqualsIgnoreCase("hdcp-1.0")) {
return cdm::HdcpVersion::kHdcpVersion1_0;
}
if (aMinHdcpVersion.EqualsIgnoreCase("hdcp-1.1")) {
return cdm::HdcpVersion::kHdcpVersion1_1;
}
if (aMinHdcpVersion.EqualsIgnoreCase("hdcp-1.2")) {
return cdm::HdcpVersion::kHdcpVersion1_2;
}
if (aMinHdcpVersion.EqualsIgnoreCase("hdcp-1.3")) {
return cdm::HdcpVersion::kHdcpVersion1_3;
}
if (aMinHdcpVersion.EqualsIgnoreCase("hdcp-1.4")) {
return cdm::HdcpVersion::kHdcpVersion1_4;
}
if (aMinHdcpVersion.EqualsIgnoreCase("hdcp-2.0")) {
return cdm::HdcpVersion::kHdcpVersion2_0;
}
if (aMinHdcpVersion.EqualsIgnoreCase("hdcp-2.1")) {
return cdm::HdcpVersion::kHdcpVersion2_1;
}
if (aMinHdcpVersion.EqualsIgnoreCase("hdcp-2.2")) {
return cdm::HdcpVersion::kHdcpVersion2_2;
}
// Invalid hdcp version string.
return cdm::HdcpVersion::kHdcpVersionNone;
}
mozilla::ipc::IPCResult ChromiumCDMChild::RecvGetStatusForPolicy(
const uint32_t& aPromiseId, const nsCString& aMinHdcpVersion) {
const uint32_t& aPromiseId, const cdm::HdcpVersion& aMinHdcpVersion) {
MOZ_ASSERT(IsOnMessageLoopThread());
GMP_LOG("ChromiumCDMChild::RecvGetStatusForPolicy(pid=%" PRIu32
", MinHdcpVersion=%s)",
aPromiseId, aMinHdcpVersion.get());
", MinHdcpVersion=%" PRIu32 ")",
aPromiseId, static_cast<uint32_t>(aMinHdcpVersion));
if (mCDM) {
cdm::Policy policy;
// We didn't check the return value of ToCDMHdcpVersion.
// Let CDM to handle the cdm::HdcpVersion::kHdcpVersionNone case.
// CDM will callback by OnResolveKeyStatusPromise when it successfully
// executes.
policy.min_hdcp_version = ToCDMHdcpVersion(aMinHdcpVersion);
policy.min_hdcp_version = aMinHdcpVersion;
mCDM->GetStatusForPolicy(aPromiseId, policy);
}
return IPC_OK();

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

@ -99,7 +99,8 @@ class ChromiumCDMChild : public PChromiumCDMChild,
ipc::IPCResult RecvRemoveSession(const uint32_t& aPromiseId,
const nsCString& aSessionId) override;
ipc::IPCResult RecvGetStatusForPolicy(
const uint32_t& aPromiseId, const nsCString& aMinHdcpVersion) override;
const uint32_t& aPromiseId,
const cdm::HdcpVersion& aMinHdcpVersion) override;
ipc::IPCResult RecvDecrypt(const uint32_t& aId,
const CDMInputBuffer& aBuffer) override;
ipc::IPCResult RecvInitializeVideoDecoder(

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

@ -216,6 +216,44 @@ void ChromiumCDMParent::RemoveSession(const nsCString& aSessionId,
}
}
// See
// https://cs.chromium.org/chromium/src/media/blink/webcontentdecryptionmodule_impl.cc?rcl=9d4e17194fbae2839d269e0b625520eac09efa9b&l=40
static Result<cdm::HdcpVersion, nsresult> ToCDMHdcpVersion(
const nsCString& aMinHdcpVersion) {
if (aMinHdcpVersion.IsEmpty()) {
return cdm::HdcpVersion::kHdcpVersionNone;
}
if (aMinHdcpVersion.EqualsIgnoreCase("hdcp-1.0")) {
return cdm::HdcpVersion::kHdcpVersion1_0;
}
if (aMinHdcpVersion.EqualsIgnoreCase("hdcp-1.1")) {
return cdm::HdcpVersion::kHdcpVersion1_1;
}
if (aMinHdcpVersion.EqualsIgnoreCase("hdcp-1.2")) {
return cdm::HdcpVersion::kHdcpVersion1_2;
}
if (aMinHdcpVersion.EqualsIgnoreCase("hdcp-1.3")) {
return cdm::HdcpVersion::kHdcpVersion1_3;
}
if (aMinHdcpVersion.EqualsIgnoreCase("hdcp-1.4")) {
return cdm::HdcpVersion::kHdcpVersion1_4;
}
if (aMinHdcpVersion.EqualsIgnoreCase("hdcp-2.0")) {
return cdm::HdcpVersion::kHdcpVersion2_0;
}
if (aMinHdcpVersion.EqualsIgnoreCase("hdcp-2.1")) {
return cdm::HdcpVersion::kHdcpVersion2_1;
}
if (aMinHdcpVersion.EqualsIgnoreCase("hdcp-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) {
GMP_LOG("ChromiumCDMParent::GetStatusForPolicy(this=%p)", this);
@ -224,7 +262,16 @@ void ChromiumCDMParent::GetStatusForPolicy(uint32_t aPromiseId,
NS_LITERAL_CSTRING("CDM is shutdown."));
return;
}
if (!SendGetStatusForPolicy(aPromiseId, aMinHdcpVersion)) {
auto hdcpVersionResult = ToCDMHdcpVersion(aMinHdcpVersion);
if (hdcpVersionResult.isErr()) {
RejectPromise(
aPromiseId, NS_ERROR_INVALID_ARG,
NS_LITERAL_CSTRING(
"getStatusForPolicy failed due to bad hdcp version argument"));
return;
}
if (!SendGetStatusForPolicy(aPromiseId, hdcpVersionResult.unwrap())) {
RejectPromise(
aPromiseId, NS_ERROR_DOM_INVALID_STATE_ERR,
NS_LITERAL_CSTRING("Failed to send getStatusForPolicy to CDM process"));

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

@ -6,6 +6,7 @@
#ifndef GMPMessageUtils_h_
#define GMPMessageUtils_h_
#include "content_decryption_module.h"
#include "gmp-video-codec.h"
#include "gmp-video-frame-encoded.h"
#include "IPCMessageUtils.h"
@ -53,6 +54,12 @@ struct ParamTraits<GMPEncryptionScheme>
GMPEncryptionScheme, GMPEncryptionScheme::kGMPEncryptionNone,
GMPEncryptionScheme::kGMPEncryptionInvalid> {};
template <>
struct ParamTraits<cdm::HdcpVersion>
: public ContiguousEnumSerializerInclusive<
cdm::HdcpVersion, cdm::HdcpVersion::kHdcpVersionNone,
cdm::HdcpVersion::kHdcpVersion2_2> {};
template <>
struct ParamTraits<GMPSimulcastStream> {
typedef GMPSimulcastStream paramType;

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

@ -6,6 +6,8 @@
include protocol PGMPContent;
include GMPTypes;
using cdm::HdcpVersion from "content_decryption_module.h";
namespace mozilla {
namespace gmp {
@ -19,7 +21,7 @@ child:
bool aAllowPersistentState) returns (bool aSuccess);
async GetStatusForPolicy(uint32_t aPromiseId,
nsCString aMinHdcpVersion);
HdcpVersion aMinHdcpVersion);
async SetServerCertificate(uint32_t aPromiseId,
uint8_t[] aServerCert);