Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Merge: Add |legacy_destination_url| back to SessionMessage for EME
Browse files Browse the repository at this point in the history
Recent changes to CDM_7 removed |destination_url| as it is no longer
used in the EME spec. However legacy applications using the prefixed
EME API depend on it, so adding it back in so that it is available
to those applications.

BUG=448242
TEST=existing EME tests pass + Play movies play

Review URL: https://codereview.chromium.org/813683005

Cr-Commit-Position: refs/heads/master@{#311371}
(cherry picked from commit c842f11)

[email protected], [email protected], [email protected]

Review URL: https://codereview.chromium.org/836263004

Cr-Commit-Position: refs/branch-heads/2272@{#34}
Cr-Branched-From: 827a380-refs/heads/master@{#310958}
  • Loading branch information
jrummell-chromium committed Jan 16, 2015
1 parent baaaf5f commit e9359a9
Show file tree
Hide file tree
Showing 36 changed files with 215 additions and 110 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ deps = {
Var('chromium_git') + '/chromium/deps/opus.git' + '@' + 'cae696156f1e60006e39821e79a1811ae1933c69',

'src/media/cdm/ppapi/api':
Var('chromium_git') + '/chromium/cdm.git' + '@' + '4aca5940e0a4f25c8ab3a91ffed3a59b0f7f6800', # from svn revision 293568
Var('chromium_git') + '/chromium/cdm.git' + '@' + '7b7c6cc620e13c8057b4b6bff19e5955feb2c8fa', # from svn revision 293617

'src/third_party/mesa/src':
Var('chromium_git') + '/chromium/deps/mesa.git' + '@' + '071d25db04c23821a12a8b260ab9d96a097402f0',
Expand Down
6 changes: 4 additions & 2 deletions content/renderer/media/crypto/ppapi_decryptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,11 @@ void PpapiDecryptor::OnDecoderInitialized(StreamType stream_type,

void PpapiDecryptor::OnSessionMessage(const std::string& web_session_id,
MessageType message_type,
const std::vector<uint8>& message) {
const std::vector<uint8>& message,
const GURL& legacy_destination_url) {
DCHECK(render_loop_proxy_->BelongsToCurrentThread());
session_message_cb_.Run(web_session_id, message_type, message);
session_message_cb_.Run(web_session_id, message_type, message,
legacy_destination_url);
}

void PpapiDecryptor::OnSessionKeysChange(const std::string& web_session_id,
Expand Down
3 changes: 2 additions & 1 deletion content/renderer/media/crypto/ppapi_decryptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ class PpapiDecryptor : public media::MediaKeys,
// Callbacks for |plugin_cdm_delegate_| to fire session events.
void OnSessionMessage(const std::string& web_session_id,
MediaKeys::MessageType message_type,
const std::vector<uint8>& message);
const std::vector<uint8>& message,
const GURL& legacy_destination_url);
void OnSessionKeysChange(const std::string& web_session_id,
bool has_additional_usable_key,
media::CdmKeysInfo keys_info);
Expand Down
10 changes: 5 additions & 5 deletions content/renderer/media/crypto/proxy_media_keys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ void ProxyMediaKeys::OnSessionCreated(uint32 session_id,

void ProxyMediaKeys::OnSessionMessage(uint32 session_id,
const std::vector<uint8>& message,
const GURL& destination_url) {
const GURL& legacy_destination_url) {
// TODO(jrummell): Once |message_type| is passed, use it rather than
// guessing from the URL.
media::MediaKeys::MessageType message_type =
destination_url.is_empty() ? media::MediaKeys::LICENSE_REQUEST
: media::MediaKeys::LICENSE_RENEWAL;
session_message_cb_.Run(LookupWebSessionId(session_id), message_type,
message);
legacy_destination_url.is_empty() ? media::MediaKeys::LICENSE_REQUEST
: media::MediaKeys::LICENSE_RENEWAL;
session_message_cb_.Run(LookupWebSessionId(session_id), message_type, message,
legacy_destination_url);
}

void ProxyMediaKeys::OnSessionReady(uint32 session_id) {
Expand Down
2 changes: 1 addition & 1 deletion content/renderer/media/crypto/proxy_media_keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ProxyMediaKeys : public media::MediaKeys, public media::CdmContext {
void OnSessionCreated(uint32 session_id, const std::string& web_session_id);
void OnSessionMessage(uint32 session_id,
const std::vector<uint8>& message,
const GURL& destination_url);
const GURL& legacy_destination_url);
void OnSessionReady(uint32 session_id);
void OnSessionClosed(uint32 session_id);
void OnSessionError(uint32 session_id,
Expand Down
19 changes: 17 additions & 2 deletions content/renderer/pepper/content_decryptor_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,8 @@ void ContentDecryptorDelegate::OnPromiseRejected(

void ContentDecryptorDelegate::OnSessionMessage(PP_Var web_session_id,
PP_CdmMessageType message_type,
PP_Var message) {
PP_Var message,
PP_Var legacy_destination_url) {
if (session_message_cb_.is_null())
return;

Expand All @@ -781,9 +782,23 @@ void ContentDecryptorDelegate::OnSessionMessage(PP_Var web_session_id,
message_vector.assign(data, data + message_array_buffer->ByteLength());
}

StringVar* destination_url_string =
StringVar::FromPPVar(legacy_destination_url);
if (!destination_url_string) {
NOTREACHED();
return;
}

GURL verified_gurl = GURL(destination_url_string->value());
if (!verified_gurl.is_valid()) {
DLOG(WARNING) << "SessionMessage legacy_destination_url is invalid : "
<< verified_gurl.possibly_invalid_spec();
verified_gurl = GURL::EmptyGURL(); // Replace invalid destination_url.
}

session_message_cb_.Run(web_session_id_string->value(),
PpCdmMessageTypeToMediaMessageType(message_type),
message_vector);
message_vector, verified_gurl);
}

void ContentDecryptorDelegate::OnSessionKeysChange(
Expand Down
3 changes: 2 additions & 1 deletion content/renderer/pepper/content_decryptor_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ class ContentDecryptorDelegate {
PP_Var error_description);
void OnSessionMessage(PP_Var web_session_id,
PP_CdmMessageType message_type,
PP_Var message);
PP_Var message,
PP_Var legacy_destination_url);
void OnSessionKeysChange(PP_Var web_session_id,
PP_Bool has_additional_usable_key,
uint32_t key_count,
Expand Down
7 changes: 4 additions & 3 deletions content/renderer/pepper/pepper_plugin_instance_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2429,9 +2429,10 @@ void PepperPluginInstanceImpl::PromiseRejected(
void PepperPluginInstanceImpl::SessionMessage(PP_Instance instance,
PP_Var web_session_id_var,
PP_CdmMessageType message_type,
PP_Var message_var) {
content_decryptor_delegate_->OnSessionMessage(web_session_id_var,
message_type, message_var);
PP_Var message_var,
PP_Var legacy_destination_url) {
content_decryptor_delegate_->OnSessionMessage(
web_session_id_var, message_type, message_var, legacy_destination_url);
}

void PepperPluginInstanceImpl::SessionKeysChange(
Expand Down
3 changes: 2 additions & 1 deletion content/renderer/pepper/pepper_plugin_instance_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,8 @@ class CONTENT_EXPORT PepperPluginInstanceImpl
void SessionMessage(PP_Instance instance,
PP_Var web_session_id_var,
PP_CdmMessageType message_type,
PP_Var message_var) override;
PP_Var message_var,
PP_Var legacy_destination_url) override;
void SessionKeysChange(
PP_Instance instance,
PP_Var web_session_id_var,
Expand Down
3 changes: 2 additions & 1 deletion media/base/media_keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ class MEDIA_EXPORT MediaKeys{
// https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted-media.html#event-summary
typedef base::Callback<void(const std::string& web_session_id,
MediaKeys::MessageType message_type,
const std::vector<uint8>& message)>
const std::vector<uint8>& message,
const GURL& legacy_destination_url)>
SessionMessageCB;

typedef base::Callback<void(const std::string& web_session_id)> SessionClosedCB;
Expand Down
8 changes: 5 additions & 3 deletions media/blink/cdm_session_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,11 @@ const std::string& CdmSessionAdapter::GetKeySystemUMAPrefix() const {
return key_system_uma_prefix_;
}

void CdmSessionAdapter::OnSessionMessage(const std::string& web_session_id,
MediaKeys::MessageType message_type,
const std::vector<uint8>& message) {
void CdmSessionAdapter::OnSessionMessage(
const std::string& web_session_id,
MediaKeys::MessageType message_type,
const std::vector<uint8>& message,
const GURL& /* legacy_destination_url */) {
WebContentDecryptionModuleSessionImpl* session = GetSession(web_session_id);
DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session "
<< web_session_id;
Expand Down
3 changes: 2 additions & 1 deletion media/blink/cdm_session_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> {
// Callbacks for firing session events.
void OnSessionMessage(const std::string& web_session_id,
MediaKeys::MessageType message_type,
const std::vector<uint8>& message);
const std::vector<uint8>& message,
const GURL& legacy_destination_url);
void OnSessionKeysChange(const std::string& web_session_id,
bool has_additional_usable_key,
CdmKeysInfo keys_info);
Expand Down
4 changes: 3 additions & 1 deletion media/cdm/aes_decryptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ void AesDecryptor::CreateSessionAndGenerateRequest(

promise->resolve(web_session_id);

session_message_cb_.Run(web_session_id, LICENSE_REQUEST, message);
// No URL needed for license requests.
session_message_cb_.Run(web_session_id, LICENSE_REQUEST, message,
GURL::EmptyGURL());
}

void AesDecryptor::LoadSession(SessionType session_type,
Expand Down
20 changes: 13 additions & 7 deletions media/cdm/aes_decryptor_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ class AesDecryptorTest : public testing::Test {
// Creates a new session using |key_id|. Returns the session ID.
std::string CreateSession(const std::vector<uint8>& key_id) {
DCHECK(!key_id.empty());
EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary()));
EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary(),
GURL::EmptyGURL()));
decryptor_.CreateSessionAndGenerateRequest(
MediaKeys::TEMPORARY_SESSION, std::string(), &key_id[0], key_id.size(),
CreateSessionPromise(RESOLVED));
Expand Down Expand Up @@ -403,10 +404,11 @@ class AesDecryptorTest : public testing::Test {
}
}

MOCK_METHOD3(OnSessionMessage,
MOCK_METHOD4(OnSessionMessage,
void(const std::string& web_session_id,
MediaKeys::MessageType message_type,
const std::vector<uint8>& message));
const std::vector<uint8>& message,
const GURL& legacy_destination_url));
MOCK_METHOD1(OnSessionClosed, void(const std::string& web_session_id));

AesDecryptor decryptor_;
Expand All @@ -425,24 +427,28 @@ class AesDecryptorTest : public testing::Test {
};

TEST_F(AesDecryptorTest, CreateSessionWithNullInitData) {
EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsEmpty()));
EXPECT_CALL(*this,
OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL()));
decryptor_.CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION,
std::string(), NULL, 0,
CreateSessionPromise(RESOLVED));
}

TEST_F(AesDecryptorTest, MultipleCreateSession) {
EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsEmpty()));
EXPECT_CALL(*this,
OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL()));
decryptor_.CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION,
std::string(), NULL, 0,
CreateSessionPromise(RESOLVED));

EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsEmpty()));
EXPECT_CALL(*this,
OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL()));
decryptor_.CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION,
std::string(), NULL, 0,
CreateSessionPromise(RESOLVED));

EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsEmpty()));
EXPECT_CALL(*this,
OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL()));
decryptor_.CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION,
std::string(), NULL, 0,
CreateSessionPromise(RESOLVED));
Expand Down
59 changes: 40 additions & 19 deletions media/cdm/ppapi/cdm_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -715,11 +715,21 @@ void CdmAdapter::OnSessionMessage(const char* session_id,
uint32_t session_id_size,
cdm::MessageType message_type,
const char* message,
uint32_t message_size) {
uint32_t message_size,
const char* legacy_destination_url,
uint32_t legacy_destination_url_size) {
// Only license renewals should specify |legacy_destination_url|.
// |legacy_destination_url| is not passed to unprefixed EME applications,
// so it can be removed when the prefixed API is removed.
PP_DCHECK(legacy_destination_url_size == 0 ||
message_type == cdm::MessageType::kLicenseRenewal);

PostOnMain(callback_factory_.NewCallback(
&CdmAdapter::SendSessionMessageInternal,
std::string(session_id, session_id_size), message_type,
std::vector<uint8_t>(message, message + message_size)));
SessionMessage(
std::string(session_id, session_id_size), message_type, message,
message_size,
std::string(legacy_destination_url, legacy_destination_url_size))));
}

// cdm::Host_6 only.
Expand All @@ -729,16 +739,17 @@ void CdmAdapter::OnSessionMessage(const char* session_id,
uint32_t message_size,
const char* destination_url,
uint32_t destination_url_size) {
// |destination_url| is no longer passed to EME applications, so it is
// dropped. All messages will appear as license renewals if |destination_url|
// is provided, license request if not.
// |destination_url| is no longer passed to unprefixed EME applications,
// so it will be dropped. All messages will appear as license renewals
// if |destination_url| is provided, license request if not.
cdm::MessageType message_type = (destination_url_size > 0)
? cdm::MessageType::kLicenseRenewal
: cdm::MessageType::kLicenseRequest;
PostOnMain(callback_factory_.NewCallback(
&CdmAdapter::SendSessionMessageInternal,
std::string(session_id, session_id_size), message_type,
std::vector<uint8_t>(message, message + message_size)));
SessionMessage(std::string(session_id, session_id_size), message_type,
message, message_size,
std::string(destination_url, destination_url_size))));
}

// cdm::Host_7 only.
Expand Down Expand Up @@ -851,21 +862,19 @@ void CdmAdapter::SendPromiseRejectedInternal(int32_t result,
error.error_description);
}

void CdmAdapter::SendSessionMessageInternal(
int32_t result,
const std::string& session_id,
cdm::MessageType message_type,
const std::vector<uint8_t>& message) {
void CdmAdapter::SendSessionMessageInternal(int32_t result,
const SessionMessage& message) {
PP_DCHECK(result == PP_OK);

pp::VarArrayBuffer message_array_buffer(message.size());
if (message.size() > 0) {
memcpy(message_array_buffer.Map(), message.data(), message.size());
pp::VarArrayBuffer message_array_buffer(message.message.size());
if (message.message.size() > 0) {
memcpy(message_array_buffer.Map(), message.message.data(),
message.message.size());
}

pp::ContentDecryptor_Private::SessionMessage(
session_id, CdmMessageTypeToPpMessageType(message_type),
message_array_buffer);
message.session_id, CdmMessageTypeToPpMessageType(message.message_type),
message_array_buffer, message.legacy_destination_url);
}

void CdmAdapter::SendSessionClosedInternal(int32_t result,
Expand Down Expand Up @@ -1300,12 +1309,24 @@ void CdmAdapter::QueryOutputProtectionStatusDone(int32_t result) {

CdmAdapter::SessionError::SessionError(cdm::Error error,
uint32_t system_code,
std::string error_description)
const std::string& error_description)
: error(error),
system_code(system_code),
error_description(error_description) {
}

CdmAdapter::SessionMessage::SessionMessage(
const std::string& session_id,
cdm::MessageType message_type,
const char* message,
uint32_t message_size,
const std::string& legacy_destination_url)
: session_id(session_id),
message_type(message_type),
message(message, message + message_size),
legacy_destination_url(legacy_destination_url) {
}

void* GetCdmHost(int host_interface_version, void* user_data) {
if (!host_interface_version || !user_data)
return NULL;
Expand Down
22 changes: 17 additions & 5 deletions media/cdm/ppapi/cdm_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ class CdmAdapter : public pp::Instance,
uint32_t session_id_size,
cdm::MessageType message_type,
const char* message,
uint32_t message_size) override;
uint32_t message_size,
const char* legacy_destination_url,
uint32_t legacy_destination_url_size) override;
void OnSessionKeysChange(const char* session_id,
uint32_t session_id_size,
bool has_additional_usable_key,
Expand Down Expand Up @@ -164,12 +166,24 @@ class CdmAdapter : public pp::Instance,
struct SessionError {
SessionError(cdm::Error error,
uint32_t system_code,
std::string error_description);
const std::string& error_description);
cdm::Error error;
uint32_t system_code;
std::string error_description;
};

struct SessionMessage {
SessionMessage(const std::string& session_id,
cdm::MessageType message_type,
const char* message,
uint32_t message_size,
const std::string& legacy_destination_url);
std::string session_id;
cdm::MessageType message_type;
std::vector<uint8_t> message;
std::string legacy_destination_url;
};

bool CreateCdmInstance(const std::string& key_system);

// <code>PPB_ContentDecryptor_Private</code> dispatchers. These are passed to
Expand All @@ -183,9 +197,7 @@ class CdmAdapter : public pp::Instance,
uint32_t promise_id,
const SessionError& error);
void SendSessionMessageInternal(int32_t result,
const std::string& session_id,
cdm::MessageType message_type,
const std::vector<uint8_t>& message);
const SessionMessage& message);
void SendSessionClosedInternal(int32_t result, const std::string& session_id);
void SendSessionErrorInternal(int32_t result,
const std::string& session_id,
Expand Down
Loading

0 comments on commit e9359a9

Please sign in to comment.