From 80428d2eb359a2448c67ae45ece3ea5dbc2f8cef Mon Sep 17 00:00:00 2001 From: jrummell Date: Thu, 25 Sep 2014 17:10:38 -0700 Subject: Update MediaKeys interface for EME To support CDM_6, make the following changes: - add SetServerCertificate - add GetUsableKeyIds - rename ReleaseSession to CloseSession - add RemoveSession - add SessionKeysChange event - add SessionExpirationChange event This gets the new functionality up to the blink boundary. Changes to use these new interfaces in blink in a future CL. For backwards compatibility with existing prefixed EME code, calls to CancelKeyRequest() call RemoveSession() instead of CloseSession(). BUG=358271,417481 TEST=existing EME tests still pass + manual testing Review URL: https://codereview.chromium.org/555223004 Cr-Commit-Position: refs/heads/master@{#296838} --- media/cdm/aes_decryptor.cc | 69 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 20 deletions(-) (limited to 'media/cdm/aes_decryptor.cc') diff --git a/media/cdm/aes_decryptor.cc b/media/cdm/aes_decryptor.cc index b83c9b1..23f41d7 100644 --- a/media/cdm/aes_decryptor.cc +++ b/media/cdm/aes_decryptor.cc @@ -224,17 +224,27 @@ static scoped_refptr DecryptData(const DecoderBuffer& input, } AesDecryptor::AesDecryptor(const SessionMessageCB& session_message_cb, - const SessionClosedCB& session_closed_cb) + const SessionClosedCB& session_closed_cb, + const SessionKeysChangeCB& session_keys_change_cb) : session_message_cb_(session_message_cb), - session_closed_cb_(session_closed_cb) { + session_closed_cb_(session_closed_cb), + session_keys_change_cb_(session_keys_change_cb) { DCHECK(!session_message_cb_.is_null()); DCHECK(!session_closed_cb_.is_null()); + DCHECK(!session_keys_change_cb_.is_null()); } AesDecryptor::~AesDecryptor() { key_map_.clear(); } +void AesDecryptor::SetServerCertificate(const uint8* certificate_data, + int certificate_data_length, + scoped_ptr promise) { + promise->reject( + NOT_SUPPORTED_ERROR, 0, "SetServerCertificate() is not supported."); +} + void AesDecryptor::CreateSession(const std::string& init_data_type, const uint8* init_data, int init_data_length, @@ -318,6 +328,43 @@ void AesDecryptor::UpdateSession(const std::string& web_session_id, } promise->resolve(); + + // Assume that at least 1 new key has been successfully added and thus + // sending true. + session_keys_change_cb_.Run(web_session_id, true); +} + +void AesDecryptor::CloseSession(const std::string& web_session_id, + scoped_ptr promise) { + // Validate that this is a reference to an active session and then forget it. + std::set::iterator it = valid_sessions_.find(web_session_id); + DCHECK(it != valid_sessions_.end()); + + valid_sessions_.erase(it); + + // Close the session. + DeleteKeysForSession(web_session_id); + promise->resolve(); + session_closed_cb_.Run(web_session_id); +} + +void AesDecryptor::RemoveSession(const std::string& web_session_id, + scoped_ptr promise) { + // AesDecryptor doesn't keep any persistent data, so this should be + // NOT_REACHED(). + // TODO(jrummell): Make sure persistent session types are rejected. + // http://crbug.com/384152. + // + // However, v0.1b calls to CancelKeyRequest() will call this, so close the + // session, if it exists. + // TODO(jrummell): Remove the close() call when prefixed EME is removed. + // http://crbug.com/249976. + if (valid_sessions_.find(web_session_id) != valid_sessions_.end()) { + CloseSession(web_session_id, promise.Pass()); + return; + } + + promise->reject(INVALID_ACCESS_ERROR, 0, "Session does not exist."); } void AesDecryptor::GetUsableKeyIds(const std::string& web_session_id, @@ -337,24 +384,6 @@ void AesDecryptor::GetUsableKeyIds(const std::string& web_session_id, promise->resolve(keyids); } -void AesDecryptor::ReleaseSession(const std::string& web_session_id, - scoped_ptr promise) { - // Validate that this is a reference to an active session and then forget it. - std::set::iterator it = valid_sessions_.find(web_session_id); - // TODO(jrummell): Convert back to a DCHECK once prefixed EME is removed. - if (it == valid_sessions_.end()) { - promise->reject(INVALID_ACCESS_ERROR, 0, "Session does not exist."); - return; - } - - valid_sessions_.erase(it); - - // Close the session. - DeleteKeysForSession(web_session_id); - promise->resolve(); - session_closed_cb_.Run(web_session_id); -} - Decryptor* AesDecryptor::GetDecryptor() { return this; } -- cgit v1.1