| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/blink/cdm_session_adapter.h" | 5 #include "media/blink/cdm_session_adapter.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 security_origin, | 43 security_origin, |
| 44 base::Bind(&CdmSessionAdapter::OnSessionMessage, weak_this), | 44 base::Bind(&CdmSessionAdapter::OnSessionMessage, weak_this), |
| 45 base::Bind(&CdmSessionAdapter::OnSessionClosed, weak_this), | 45 base::Bind(&CdmSessionAdapter::OnSessionClosed, weak_this), |
| 46 base::Bind(&CdmSessionAdapter::OnLegacySessionError, weak_this), | 46 base::Bind(&CdmSessionAdapter::OnLegacySessionError, weak_this), |
| 47 base::Bind(&CdmSessionAdapter::OnSessionKeysChange, weak_this), | 47 base::Bind(&CdmSessionAdapter::OnSessionKeysChange, weak_this), |
| 48 base::Bind(&CdmSessionAdapter::OnSessionExpirationUpdate, weak_this), | 48 base::Bind(&CdmSessionAdapter::OnSessionExpirationUpdate, weak_this), |
| 49 base::Bind(&CdmSessionAdapter::OnCdmCreated, this, key_system, result)); | 49 base::Bind(&CdmSessionAdapter::OnCdmCreated, this, key_system, result)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void CdmSessionAdapter::SetServerCertificate( | 52 void CdmSessionAdapter::SetServerCertificate( |
| 53 const uint8* server_certificate, | 53 const std::vector<uint8_t>& certificate, |
| 54 int server_certificate_length, | |
| 55 scoped_ptr<SimpleCdmPromise> promise) { | 54 scoped_ptr<SimpleCdmPromise> promise) { |
| 56 cdm_->SetServerCertificate(server_certificate, server_certificate_length, | 55 cdm_->SetServerCertificate(certificate, promise.Pass()); |
| 57 promise.Pass()); | |
| 58 } | 56 } |
| 59 | 57 |
| 60 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::CreateSession() { | 58 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::CreateSession() { |
| 61 return new WebContentDecryptionModuleSessionImpl(this); | 59 return new WebContentDecryptionModuleSessionImpl(this); |
| 62 } | 60 } |
| 63 | 61 |
| 64 bool CdmSessionAdapter::RegisterSession( | 62 bool CdmSessionAdapter::RegisterSession( |
| 65 const std::string& session_id, | 63 const std::string& session_id, |
| 66 base::WeakPtr<WebContentDecryptionModuleSessionImpl> session) { | 64 base::WeakPtr<WebContentDecryptionModuleSessionImpl> session) { |
| 67 // If this session ID is already registered, don't register it again. | 65 // If this session ID is already registered, don't register it again. |
| 68 if (ContainsKey(sessions_, session_id)) | 66 if (ContainsKey(sessions_, session_id)) |
| 69 return false; | 67 return false; |
| 70 | 68 |
| 71 sessions_[session_id] = session; | 69 sessions_[session_id] = session; |
| 72 return true; | 70 return true; |
| 73 } | 71 } |
| 74 | 72 |
| 75 void CdmSessionAdapter::UnregisterSession(const std::string& session_id) { | 73 void CdmSessionAdapter::UnregisterSession(const std::string& session_id) { |
| 76 DCHECK(ContainsKey(sessions_, session_id)); | 74 DCHECK(ContainsKey(sessions_, session_id)); |
| 77 sessions_.erase(session_id); | 75 sessions_.erase(session_id); |
| 78 } | 76 } |
| 79 | 77 |
| 80 void CdmSessionAdapter::InitializeNewSession( | 78 void CdmSessionAdapter::InitializeNewSession( |
| 81 EmeInitDataType init_data_type, | 79 EmeInitDataType init_data_type, |
| 82 const uint8* init_data, | 80 const std::vector<uint8_t>& init_data, |
| 83 int init_data_length, | |
| 84 MediaKeys::SessionType session_type, | 81 MediaKeys::SessionType session_type, |
| 85 scoped_ptr<NewSessionCdmPromise> promise) { | 82 scoped_ptr<NewSessionCdmPromise> promise) { |
| 86 cdm_->CreateSessionAndGenerateRequest(session_type, init_data_type, init_data, | 83 cdm_->CreateSessionAndGenerateRequest(session_type, init_data_type, init_data, |
| 87 init_data_length, promise.Pass()); | 84 promise.Pass()); |
| 88 } | 85 } |
| 89 | 86 |
| 90 void CdmSessionAdapter::LoadSession(MediaKeys::SessionType session_type, | 87 void CdmSessionAdapter::LoadSession(MediaKeys::SessionType session_type, |
| 91 const std::string& session_id, | 88 const std::string& session_id, |
| 92 scoped_ptr<NewSessionCdmPromise> promise) { | 89 scoped_ptr<NewSessionCdmPromise> promise) { |
| 93 cdm_->LoadSession(session_type, session_id, promise.Pass()); | 90 cdm_->LoadSession(session_type, session_id, promise.Pass()); |
| 94 } | 91 } |
| 95 | 92 |
| 96 void CdmSessionAdapter::UpdateSession(const std::string& session_id, | 93 void CdmSessionAdapter::UpdateSession(const std::string& session_id, |
| 97 const uint8* response, | 94 const std::vector<uint8_t>& response, |
| 98 int response_length, | |
| 99 scoped_ptr<SimpleCdmPromise> promise) { | 95 scoped_ptr<SimpleCdmPromise> promise) { |
| 100 cdm_->UpdateSession(session_id, response, response_length, promise.Pass()); | 96 cdm_->UpdateSession(session_id, response, promise.Pass()); |
| 101 } | 97 } |
| 102 | 98 |
| 103 void CdmSessionAdapter::CloseSession(const std::string& session_id, | 99 void CdmSessionAdapter::CloseSession(const std::string& session_id, |
| 104 scoped_ptr<SimpleCdmPromise> promise) { | 100 scoped_ptr<SimpleCdmPromise> promise) { |
| 105 cdm_->CloseSession(session_id, promise.Pass()); | 101 cdm_->CloseSession(session_id, promise.Pass()); |
| 106 } | 102 } |
| 107 | 103 |
| 108 void CdmSessionAdapter::RemoveSession(const std::string& session_id, | 104 void CdmSessionAdapter::RemoveSession(const std::string& session_id, |
| 109 scoped_ptr<SimpleCdmPromise> promise) { | 105 scoped_ptr<SimpleCdmPromise> promise) { |
| 110 cdm_->RemoveSession(session_id, promise.Pass()); | 106 cdm_->RemoveSession(session_id, promise.Pass()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 139 kMediaEME + GetKeySystemNameForUMA(key_system) + kDot; | 135 kMediaEME + GetKeySystemNameForUMA(key_system) + kDot; |
| 140 cdm_ = cdm.Pass(); | 136 cdm_ = cdm.Pass(); |
| 141 | 137 |
| 142 result.completeWithContentDecryptionModule( | 138 result.completeWithContentDecryptionModule( |
| 143 new WebContentDecryptionModuleImpl(this)); | 139 new WebContentDecryptionModuleImpl(this)); |
| 144 } | 140 } |
| 145 | 141 |
| 146 void CdmSessionAdapter::OnSessionMessage( | 142 void CdmSessionAdapter::OnSessionMessage( |
| 147 const std::string& session_id, | 143 const std::string& session_id, |
| 148 MediaKeys::MessageType message_type, | 144 MediaKeys::MessageType message_type, |
| 149 const std::vector<uint8>& message, | 145 const std::vector<uint8_t>& message, |
| 150 const GURL& /* legacy_destination_url */) { | 146 const GURL& /* legacy_destination_url */) { |
| 151 WebContentDecryptionModuleSessionImpl* session = GetSession(session_id); | 147 WebContentDecryptionModuleSessionImpl* session = GetSession(session_id); |
| 152 DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session " | 148 DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session " |
| 153 << session_id; | 149 << session_id; |
| 154 if (session) | 150 if (session) |
| 155 session->OnSessionMessage(message_type, message); | 151 session->OnSessionMessage(message_type, message); |
| 156 } | 152 } |
| 157 | 153 |
| 158 void CdmSessionAdapter::OnSessionKeysChange(const std::string& session_id, | 154 void CdmSessionAdapter::OnSessionKeysChange(const std::string& session_id, |
| 159 bool has_additional_usable_key, | 155 bool has_additional_usable_key, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 180 WebContentDecryptionModuleSessionImpl* session = GetSession(session_id); | 176 WebContentDecryptionModuleSessionImpl* session = GetSession(session_id); |
| 181 DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session " | 177 DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session " |
| 182 << session_id; | 178 << session_id; |
| 183 if (session) | 179 if (session) |
| 184 session->OnSessionClosed(); | 180 session->OnSessionClosed(); |
| 185 } | 181 } |
| 186 | 182 |
| 187 void CdmSessionAdapter::OnLegacySessionError( | 183 void CdmSessionAdapter::OnLegacySessionError( |
| 188 const std::string& session_id, | 184 const std::string& session_id, |
| 189 MediaKeys::Exception exception_code, | 185 MediaKeys::Exception exception_code, |
| 190 uint32 system_code, | 186 uint32_t system_code, |
| 191 const std::string& error_message) { | 187 const std::string& error_message) { |
| 192 // Error events not used by unprefixed EME. | 188 // Error events not used by unprefixed EME. |
| 193 // TODO(jrummell): Remove when prefixed EME removed. | 189 // TODO(jrummell): Remove when prefixed EME removed. |
| 194 } | 190 } |
| 195 | 191 |
| 196 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::GetSession( | 192 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::GetSession( |
| 197 const std::string& session_id) { | 193 const std::string& session_id) { |
| 198 // Since session objects may get garbage collected, it is possible that there | 194 // Since session objects may get garbage collected, it is possible that there |
| 199 // are events coming back from the CDM and the session has been unregistered. | 195 // are events coming back from the CDM and the session has been unregistered. |
| 200 // We can not tell if the CDM is firing events at sessions that never existed. | 196 // We can not tell if the CDM is firing events at sessions that never existed. |
| 201 SessionMap::iterator session = sessions_.find(session_id); | 197 SessionMap::iterator session = sessions_.find(session_id); |
| 202 return (session != sessions_.end()) ? session->second.get() : NULL; | 198 return (session != sessions_.end()) ? session->second.get() : NULL; |
| 203 } | 199 } |
| 204 | 200 |
| 205 } // namespace media | 201 } // namespace media |
| OLD | NEW |