| 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" |
| 11 #include "media/base/cdm_factory.h" | 11 #include "media/base/cdm_factory.h" |
| 12 #include "media/base/cdm_promise.h" | 12 #include "media/base/cdm_promise.h" |
| 13 #include "media/base/key_systems.h" | 13 #include "media/base/key_systems.h" |
| 14 #include "media/base/media_keys.h" | 14 #include "media/base/media_keys.h" |
| 15 #include "media/blink/webcontentdecryptionmodulesession_impl.h" | 15 #include "media/blink/webcontentdecryptionmodulesession_impl.h" |
| 16 #include "media/cdm/aes_decryptor.h" | |
| 17 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 18 | 17 |
| 19 namespace media { | 18 namespace media { |
| 20 | 19 |
| 21 const char kMediaEME[] = "Media.EME."; | 20 const char kMediaEME[] = "Media.EME."; |
| 22 const char kDot[] = "."; | 21 const char kDot[] = "."; |
| 23 | 22 |
| 24 CdmSessionAdapter::CdmSessionAdapter() : weak_ptr_factory_(this) { | 23 CdmSessionAdapter::CdmSessionAdapter() : weak_ptr_factory_(this) { |
| 25 } | 24 } |
| 26 | 25 |
| 27 CdmSessionAdapter::~CdmSessionAdapter() {} | 26 CdmSessionAdapter::~CdmSessionAdapter() {} |
| 28 | 27 |
| 29 bool CdmSessionAdapter::Initialize(CdmFactory* cdm_factory, | 28 bool CdmSessionAdapter::Initialize(CdmFactory* cdm_factory, |
| 30 const std::string& key_system, | 29 const std::string& key_system, |
| 31 const GURL& security_origin) { | 30 const GURL& security_origin) { |
| 32 key_system_uma_prefix_ = | 31 key_system_uma_prefix_ = |
| 33 kMediaEME + GetKeySystemNameForUMA(key_system) + kDot; | 32 kMediaEME + GetKeySystemNameForUMA(key_system) + kDot; |
| 34 | 33 |
| 35 base::WeakPtr<CdmSessionAdapter> weak_this = weak_ptr_factory_.GetWeakPtr(); | 34 base::WeakPtr<CdmSessionAdapter> weak_this = weak_ptr_factory_.GetWeakPtr(); |
| 36 | 35 media_keys_ = cdm_factory->Create( |
| 37 if (CanUseAesDecryptor(key_system)) { | 36 key_system, security_origin, |
| 38 media_keys_.reset(new AesDecryptor( | 37 base::Bind(&CdmSessionAdapter::OnSessionMessage, weak_this), |
| 39 base::Bind(&CdmSessionAdapter::OnSessionMessage, weak_this), | 38 base::Bind(&CdmSessionAdapter::OnSessionClosed, weak_this), |
| 40 base::Bind(&CdmSessionAdapter::OnSessionClosed, weak_this), | 39 base::Bind(&CdmSessionAdapter::OnSessionError, weak_this), |
| 41 base::Bind(&CdmSessionAdapter::OnSessionKeysChange, weak_this))); | 40 base::Bind(&CdmSessionAdapter::OnSessionKeysChange, weak_this), |
| 42 } else if (cdm_factory) { | 41 base::Bind(&CdmSessionAdapter::OnSessionExpirationUpdate, weak_this)); |
| 43 media_keys_ = cdm_factory->Create( | |
| 44 key_system, security_origin, | |
| 45 base::Bind(&CdmSessionAdapter::OnSessionMessage, weak_this), | |
| 46 base::Bind(&CdmSessionAdapter::OnSessionClosed, weak_this), | |
| 47 base::Bind(&CdmSessionAdapter::OnSessionError, weak_this), | |
| 48 base::Bind(&CdmSessionAdapter::OnSessionKeysChange, weak_this), | |
| 49 base::Bind(&CdmSessionAdapter::OnSessionExpirationUpdate, weak_this)); | |
| 50 } | |
| 51 | |
| 52 return media_keys_.get() != nullptr; | 42 return media_keys_.get() != nullptr; |
| 53 } | 43 } |
| 54 | 44 |
| 55 void CdmSessionAdapter::SetServerCertificate( | 45 void CdmSessionAdapter::SetServerCertificate( |
| 56 const uint8* server_certificate, | 46 const uint8* server_certificate, |
| 57 int server_certificate_length, | 47 int server_certificate_length, |
| 58 scoped_ptr<SimpleCdmPromise> promise) { | 48 scoped_ptr<SimpleCdmPromise> promise) { |
| 59 media_keys_->SetServerCertificate( | 49 media_keys_->SetServerCertificate( |
| 60 server_certificate, server_certificate_length, promise.Pass()); | 50 server_certificate, server_certificate_length, promise.Pass()); |
| 61 } | 51 } |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::GetSession( | 167 WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::GetSession( |
| 178 const std::string& web_session_id) { | 168 const std::string& web_session_id) { |
| 179 // Since session objects may get garbage collected, it is possible that there | 169 // Since session objects may get garbage collected, it is possible that there |
| 180 // are events coming back from the CDM and the session has been unregistered. | 170 // are events coming back from the CDM and the session has been unregistered. |
| 181 // We can not tell if the CDM is firing events at sessions that never existed. | 171 // We can not tell if the CDM is firing events at sessions that never existed. |
| 182 SessionMap::iterator session = sessions_.find(web_session_id); | 172 SessionMap::iterator session = sessions_.find(web_session_id); |
| 183 return (session != sessions_.end()) ? session->second.get() : NULL; | 173 return (session != sessions_.end()) ? session->second.get() : NULL; |
| 184 } | 174 } |
| 185 | 175 |
| 186 } // namespace media | 176 } // namespace media |
| OLD | NEW |