| 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" | 13 #include "content/renderer/media/crypto/content_decryption_module_factory.h" |
| 14 #include "media/base/cdm_promise.h" | 14 #include "media/base/cdm_callback_promise.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) | 18 #if defined(ENABLE_PEPPER_CDMS) |
| 19 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h" | 19 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h" |
| 20 #endif // defined(ENABLE_PEPPER_CDMS) | 20 #endif // defined(ENABLE_PEPPER_CDMS) |
| 21 | 21 |
| 22 #if defined(ENABLE_BROWSER_CDMS) | 22 #if defined(ENABLE_BROWSER_CDMS) |
| 23 #include "content/renderer/media/crypto/renderer_cdm_manager.h" | 23 #include "content/renderer/media/crypto/renderer_cdm_manager.h" |
| 24 #endif // defined(ENABLE_BROWSER_CDMS) | 24 #endif // defined(ENABLE_BROWSER_CDMS) |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 SessionCreationType session_creation_type = TemporarySession; | 105 SessionCreationType session_creation_type = TemporarySession; |
| 106 if (HasHeader(init_data, init_data_length, kPrefixedApiLoadSessionHeader)) { | 106 if (HasHeader(init_data, init_data_length, kPrefixedApiLoadSessionHeader)) { |
| 107 session_creation_type = LoadSession; | 107 session_creation_type = LoadSession; |
| 108 } else if (HasHeader(init_data, | 108 } else if (HasHeader(init_data, |
| 109 init_data_length, | 109 init_data_length, |
| 110 kPrefixedApiPersistentSessionHeader)) { | 110 kPrefixedApiPersistentSessionHeader)) { |
| 111 session_creation_type = PersistentSession; | 111 session_creation_type = PersistentSession; |
| 112 } | 112 } |
| 113 | 113 |
| 114 scoped_ptr<media::NewSessionCdmPromise> promise( | 114 scoped_ptr<media::NewSessionCdmPromise> promise( |
| 115 new media::NewSessionCdmPromise( | 115 new media::CdmCallbackPromise<std::string>( |
| 116 base::Bind(&ProxyDecryptor::SetSessionId, | 116 base::Bind(&ProxyDecryptor::SetSessionId, |
| 117 weak_ptr_factory_.GetWeakPtr(), | 117 weak_ptr_factory_.GetWeakPtr(), |
| 118 session_creation_type), | 118 session_creation_type), |
| 119 base::Bind(&ProxyDecryptor::OnSessionError, | 119 base::Bind(&ProxyDecryptor::OnSessionError, |
| 120 weak_ptr_factory_.GetWeakPtr(), | 120 weak_ptr_factory_.GetWeakPtr(), |
| 121 std::string()))); // No session id until created. | 121 std::string()))); // No session id until created. |
| 122 | 122 |
| 123 if (session_creation_type == LoadSession) { | 123 if (session_creation_type == LoadSession) { |
| 124 media_keys_->LoadSession( | 124 media_keys_->LoadSession( |
| 125 std::string(reinterpret_cast<const char*>( | 125 std::string(reinterpret_cast<const char*>( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 156 session_id = it->first; | 156 session_id = it->first; |
| 157 } else { | 157 } else { |
| 158 OnSessionError(std::string(), | 158 OnSessionError(std::string(), |
| 159 media::MediaKeys::NOT_SUPPORTED_ERROR, | 159 media::MediaKeys::NOT_SUPPORTED_ERROR, |
| 160 0, | 160 0, |
| 161 "SessionId not specified."); | 161 "SessionId not specified."); |
| 162 return; | 162 return; |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 | 165 |
| 166 scoped_ptr<media::SimpleCdmPromise> promise( | 166 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>( |
| 167 new media::SimpleCdmPromise(base::Bind(&ProxyDecryptor::OnSessionReady, | 167 base::Bind(&ProxyDecryptor::OnSessionReady, |
| 168 weak_ptr_factory_.GetWeakPtr(), | 168 weak_ptr_factory_.GetWeakPtr(), |
| 169 web_session_id), | 169 web_session_id), |
| 170 base::Bind(&ProxyDecryptor::OnSessionError, | 170 base::Bind(&ProxyDecryptor::OnSessionError, |
| 171 weak_ptr_factory_.GetWeakPtr(), | 171 weak_ptr_factory_.GetWeakPtr(), |
| 172 web_session_id))); | 172 web_session_id))); |
| 173 | 173 |
| 174 // EME WD spec only supports a single array passed to the CDM. For | 174 // EME WD spec only supports a single array passed to the CDM. For |
| 175 // Clear Key using v0.1b, both arrays are used (|init_data| is key_id). | 175 // Clear Key using v0.1b, both arrays are used (|init_data| is key_id). |
| 176 // Since the EME WD spec supports the key as a JSON Web Key, | 176 // Since the EME WD spec supports the key as a JSON Web Key, |
| 177 // convert the 2 arrays to a JWK and pass it as the single array. | 177 // convert the 2 arrays to a JWK and pass it as the single array. |
| 178 if (is_clear_key_) { | 178 if (is_clear_key_) { |
| 179 // Decryptor doesn't support empty key ID (see http://crbug.com/123265). | 179 // Decryptor doesn't support empty key ID (see http://crbug.com/123265). |
| 180 // So ensure a non-empty value is passed. | 180 // So ensure a non-empty value is passed. |
| 181 if (!init_data) { | 181 if (!init_data) { |
| 182 static const uint8 kDummyInitData[1] = {0}; | 182 static const uint8 kDummyInitData[1] = {0}; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 193 promise.Pass()); | 193 promise.Pass()); |
| 194 return; | 194 return; |
| 195 } | 195 } |
| 196 | 196 |
| 197 media_keys_->UpdateSession(session_id, key, key_length, promise.Pass()); | 197 media_keys_->UpdateSession(session_id, key, key_length, promise.Pass()); |
| 198 } | 198 } |
| 199 | 199 |
| 200 void ProxyDecryptor::CancelKeyRequest(const std::string& web_session_id) { | 200 void ProxyDecryptor::CancelKeyRequest(const std::string& web_session_id) { |
| 201 DVLOG(1) << "CancelKeyRequest()"; | 201 DVLOG(1) << "CancelKeyRequest()"; |
| 202 | 202 |
| 203 scoped_ptr<media::SimpleCdmPromise> promise( | 203 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>( |
| 204 new media::SimpleCdmPromise(base::Bind(&ProxyDecryptor::OnSessionClosed, | 204 base::Bind(&ProxyDecryptor::OnSessionClosed, |
| 205 weak_ptr_factory_.GetWeakPtr(), | 205 weak_ptr_factory_.GetWeakPtr(), |
| 206 web_session_id), | 206 web_session_id), |
| 207 base::Bind(&ProxyDecryptor::OnSessionError, | 207 base::Bind(&ProxyDecryptor::OnSessionError, |
| 208 weak_ptr_factory_.GetWeakPtr(), | 208 weak_ptr_factory_.GetWeakPtr(), |
| 209 web_session_id))); | 209 web_session_id))); |
| 210 media_keys_->RemoveSession(web_session_id, promise.Pass()); | 210 media_keys_->RemoveSession(web_session_id, promise.Pass()); |
| 211 } | 211 } |
| 212 | 212 |
| 213 scoped_ptr<media::MediaKeys> ProxyDecryptor::CreateMediaKeys( | 213 scoped_ptr<media::MediaKeys> ProxyDecryptor::CreateMediaKeys( |
| 214 const std::string& key_system, | 214 const std::string& key_system, |
| 215 const GURL& security_origin) { | 215 const GURL& security_origin) { |
| 216 return ContentDecryptionModuleFactory::Create( | 216 return ContentDecryptionModuleFactory::Create( |
| 217 key_system, | 217 key_system, |
| 218 security_origin, | 218 security_origin, |
| 219 #if defined(ENABLE_PEPPER_CDMS) | 219 #if defined(ENABLE_PEPPER_CDMS) |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 bool is_persistent = | 324 bool is_persistent = |
| 325 session_type == PersistentSession || session_type == LoadSession; | 325 session_type == PersistentSession || session_type == LoadSession; |
| 326 active_sessions_.insert(std::make_pair(web_session_id, is_persistent)); | 326 active_sessions_.insert(std::make_pair(web_session_id, is_persistent)); |
| 327 | 327 |
| 328 // For LoadSession(), generate the SessionReady event. | 328 // For LoadSession(), generate the SessionReady event. |
| 329 if (session_type == LoadSession) | 329 if (session_type == LoadSession) |
| 330 OnSessionReady(web_session_id); | 330 OnSessionReady(web_session_id); |
| 331 } | 331 } |
| 332 | 332 |
| 333 } // namespace content | 333 } // namespace content |
| OLD | NEW |