Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/renderer/media/crypto/proxy_decryptor.h" | 5 #include "content/renderer/media/crypto/proxy_decryptor.h" |
| 6 | 6 |
| 7 #include <cstring> | 7 #include <cstring> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "content/renderer/media/crypto/content_decryption_module_factory.h" | |
| 14 #include "media/base/cdm_callback_promise.h" | 13 #include "media/base/cdm_callback_promise.h" |
| 14 #include "media/base/cdm_factory.h" | |
| 15 #include "media/cdm/json_web_key.h" | 15 #include "media/cdm/json_web_key.h" |
| 16 #include "media/cdm/key_system_names.h" | 16 #include "media/cdm/key_system_names.h" |
| 17 | 17 |
| 18 #if defined(ENABLE_PEPPER_CDMS) | |
| 19 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h" | |
| 20 #endif // defined(ENABLE_PEPPER_CDMS) | |
| 21 | |
| 22 #if defined(ENABLE_BROWSER_CDMS) | 18 #if defined(ENABLE_BROWSER_CDMS) |
| 23 #include "content/renderer/media/crypto/renderer_cdm_manager.h" | 19 #include "content/renderer/media/crypto/renderer_cdm_manager.h" |
| 24 #endif // defined(ENABLE_BROWSER_CDMS) | 20 #endif // defined(ENABLE_BROWSER_CDMS) |
| 25 | 21 |
| 26 namespace content { | 22 namespace content { |
| 27 | 23 |
| 28 // Special system code to signal a closed persistent session in a SessionError() | 24 // Special system code to signal a closed persistent session in a SessionError() |
| 29 // call. This is needed because there is no SessionClosed() call in the prefixed | 25 // call. This is needed because there is no SessionClosed() call in the prefixed |
| 30 // EME API. | 26 // EME API. |
| 31 const int kSessionClosedSystemCode = 29127; | 27 const int kSessionClosedSystemCode = 29127; |
| 32 | 28 |
| 33 ProxyDecryptor::ProxyDecryptor( | 29 ProxyDecryptor::ProxyDecryptor(scoped_ptr<media::CdmFactory> cdm_factory, |
| 34 #if defined(ENABLE_PEPPER_CDMS) | 30 const KeyAddedCB& key_added_cb, |
| 35 const CreatePepperCdmCB& create_pepper_cdm_cb, | 31 const KeyErrorCB& key_error_cb, |
| 36 #elif defined(ENABLE_BROWSER_CDMS) | 32 const KeyMessageCB& key_message_cb) |
| 37 RendererCdmManager* manager, | 33 : cdm_factory_(cdm_factory.Pass()), |
| 38 #endif // defined(ENABLE_PEPPER_CDMS) | 34 #if defined(ENABLE_BROWSER_CDMS) |
| 39 const KeyAddedCB& key_added_cb, | 35 // TODO(xhwang): Move kInvalidCdmId to src/media. |
| 40 const KeyErrorCB& key_error_cb, | |
| 41 const KeyMessageCB& key_message_cb) | |
| 42 : | |
| 43 #if defined(ENABLE_PEPPER_CDMS) | |
| 44 create_pepper_cdm_cb_(create_pepper_cdm_cb), | |
| 45 #elif defined(ENABLE_BROWSER_CDMS) | |
| 46 manager_(manager), | |
| 47 cdm_id_(RendererCdmManager::kInvalidCdmId), | 36 cdm_id_(RendererCdmManager::kInvalidCdmId), |
| 48 #endif // defined(ENABLE_PEPPER_CDMS) | 37 #endif // defined(ENABLE_PEPPER_CDMS) |
| 49 key_added_cb_(key_added_cb), | 38 key_added_cb_(key_added_cb), |
| 50 key_error_cb_(key_error_cb), | 39 key_error_cb_(key_error_cb), |
| 51 key_message_cb_(key_message_cb), | 40 key_message_cb_(key_message_cb), |
| 52 is_clear_key_(false), | 41 is_clear_key_(false), |
| 53 weak_ptr_factory_(this) { | 42 weak_ptr_factory_(this) { |
| 54 #if defined(ENABLE_PEPPER_CDMS) | 43 DCHECK(cdm_factory_); |
| 55 DCHECK(!create_pepper_cdm_cb_.is_null()); | |
| 56 #endif // defined(ENABLE_PEPPER_CDMS) | |
| 57 DCHECK(!key_added_cb_.is_null()); | 44 DCHECK(!key_added_cb_.is_null()); |
| 58 DCHECK(!key_error_cb_.is_null()); | 45 DCHECK(!key_error_cb_.is_null()); |
| 59 DCHECK(!key_message_cb_.is_null()); | 46 DCHECK(!key_message_cb_.is_null()); |
| 60 } | 47 } |
| 61 | 48 |
| 62 ProxyDecryptor::~ProxyDecryptor() { | 49 ProxyDecryptor::~ProxyDecryptor() { |
| 63 // Destroy the decryptor explicitly before destroying the plugin. | 50 // Destroy the decryptor explicitly before destroying the plugin. |
| 64 media_keys_.reset(); | 51 media_keys_.reset(); |
| 65 } | 52 } |
| 66 | 53 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 web_session_id), | 193 web_session_id), |
| 207 base::Bind(&ProxyDecryptor::OnSessionError, | 194 base::Bind(&ProxyDecryptor::OnSessionError, |
| 208 weak_ptr_factory_.GetWeakPtr(), | 195 weak_ptr_factory_.GetWeakPtr(), |
| 209 web_session_id))); | 196 web_session_id))); |
| 210 media_keys_->RemoveSession(web_session_id, promise.Pass()); | 197 media_keys_->RemoveSession(web_session_id, promise.Pass()); |
| 211 } | 198 } |
| 212 | 199 |
| 213 scoped_ptr<media::MediaKeys> ProxyDecryptor::CreateMediaKeys( | 200 scoped_ptr<media::MediaKeys> ProxyDecryptor::CreateMediaKeys( |
| 214 const std::string& key_system, | 201 const std::string& key_system, |
| 215 const GURL& security_origin) { | 202 const GURL& security_origin) { |
| 216 return ContentDecryptionModuleFactory::Create( | 203 base::WeakPtr<ProxyDecryptor> weak_this = weak_ptr_factory_.GetWeakPtr(); |
| 204 return cdm_factory_->Create( | |
| 217 key_system, | 205 key_system, |
| 218 security_origin, | 206 security_origin, |
| 219 #if defined(ENABLE_PEPPER_CDMS) | 207 #if defined(ENABLE_BROWSER_CDMS) |
|
ddorwin
2014/10/16 17:32:52
We could eliminate 2 of the 3 ifdef's if MediaKeys
xhwang
2014/10/16 20:08:39
Agreed. See comment above. I'll do that in another
| |
| 220 create_pepper_cdm_cb_, | |
| 221 #elif defined(ENABLE_BROWSER_CDMS) | |
| 222 manager_, | |
| 223 &cdm_id_, | 208 &cdm_id_, |
| 224 #endif // defined(ENABLE_PEPPER_CDMS) | 209 #endif |
| 225 base::Bind(&ProxyDecryptor::OnSessionMessage, | 210 base::Bind(&ProxyDecryptor::OnSessionMessage, weak_this), |
| 226 weak_ptr_factory_.GetWeakPtr()), | 211 base::Bind(&ProxyDecryptor::OnSessionReady, weak_this), |
| 227 base::Bind(&ProxyDecryptor::OnSessionReady, | 212 base::Bind(&ProxyDecryptor::OnSessionClosed, weak_this), |
| 228 weak_ptr_factory_.GetWeakPtr()), | 213 base::Bind(&ProxyDecryptor::OnSessionError, weak_this), |
| 229 base::Bind(&ProxyDecryptor::OnSessionClosed, | 214 base::Bind(&ProxyDecryptor::OnSessionKeysChange, weak_this), |
| 230 weak_ptr_factory_.GetWeakPtr()), | 215 base::Bind(&ProxyDecryptor::OnSessionExpirationUpdate, weak_this)); |
| 231 base::Bind(&ProxyDecryptor::OnSessionError, | |
| 232 weak_ptr_factory_.GetWeakPtr()), | |
| 233 base::Bind(&ProxyDecryptor::OnSessionKeysChange, | |
| 234 weak_ptr_factory_.GetWeakPtr()), | |
| 235 base::Bind(&ProxyDecryptor::OnSessionExpirationUpdate, | |
| 236 weak_ptr_factory_.GetWeakPtr())); | |
| 237 } | 216 } |
| 238 | 217 |
| 239 void ProxyDecryptor::OnSessionMessage(const std::string& web_session_id, | 218 void ProxyDecryptor::OnSessionMessage(const std::string& web_session_id, |
| 240 const std::vector<uint8>& message, | 219 const std::vector<uint8>& message, |
| 241 const GURL& destination_url) { | 220 const GURL& destination_url) { |
| 242 // Assumes that OnSessionCreated() has been called before this. | 221 // Assumes that OnSessionCreated() has been called before this. |
| 243 | 222 |
| 244 // For ClearKey, convert the message from JSON into just passing the key | 223 // For ClearKey, convert the message from JSON into just passing the key |
| 245 // as the message. If unable to extract the key, return the message unchanged. | 224 // as the message. If unable to extract the key, return the message unchanged. |
| 246 if (is_clear_key_) { | 225 if (is_clear_key_) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 bool is_persistent = | 303 bool is_persistent = |
| 325 session_type == PersistentSession || session_type == LoadSession; | 304 session_type == PersistentSession || session_type == LoadSession; |
| 326 active_sessions_.insert(std::make_pair(web_session_id, is_persistent)); | 305 active_sessions_.insert(std::make_pair(web_session_id, is_persistent)); |
| 327 | 306 |
| 328 // For LoadSession(), generate the SessionReady event. | 307 // For LoadSession(), generate the SessionReady event. |
| 329 if (session_type == LoadSession) | 308 if (session_type == LoadSession) |
| 330 OnSessionReady(web_session_id); | 309 OnSessionReady(web_session_id); |
| 331 } | 310 } |
| 332 | 311 |
| 333 } // namespace content | 312 } // namespace content |
| OLD | NEW |