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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 session_id = it->first; | 167 session_id = it->first; |
168 } else { | 168 } else { |
169 OnSessionError(std::string(), | 169 OnSessionError(std::string(), |
170 media::MediaKeys::NOT_SUPPORTED_ERROR, | 170 media::MediaKeys::NOT_SUPPORTED_ERROR, |
171 0, | 171 0, |
172 "SessionId not specified."); | 172 "SessionId not specified."); |
173 return; | 173 return; |
174 } | 174 } |
175 } | 175 } |
176 | 176 |
177 scoped_ptr<media::SimpleCdmPromise> promise( | 177 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>( |
178 new media::SimpleCdmPromise(base::Bind(&ProxyDecryptor::OnSessionReady, | 178 base::Bind(&ProxyDecryptor::OnSessionReady, |
179 weak_ptr_factory_.GetWeakPtr(), | 179 weak_ptr_factory_.GetWeakPtr(), |
180 web_session_id), | 180 web_session_id), |
181 base::Bind(&ProxyDecryptor::OnSessionError, | 181 base::Bind(&ProxyDecryptor::OnSessionError, |
182 weak_ptr_factory_.GetWeakPtr(), | 182 weak_ptr_factory_.GetWeakPtr(), |
183 web_session_id))); | 183 web_session_id))); |
184 | 184 |
185 // EME WD spec only supports a single array passed to the CDM. For | 185 // EME WD spec only supports a single array passed to the CDM. For |
186 // Clear Key using v0.1b, both arrays are used (|init_data| is key_id). | 186 // Clear Key using v0.1b, both arrays are used (|init_data| is key_id). |
187 // Since the EME WD spec supports the key as a JSON Web Key, | 187 // Since the EME WD spec supports the key as a JSON Web Key, |
188 // convert the 2 arrays to a JWK and pass it as the single array. | 188 // convert the 2 arrays to a JWK and pass it as the single array. |
189 if (is_clear_key_) { | 189 if (is_clear_key_) { |
190 // Decryptor doesn't support empty key ID (see http://crbug.com/123265). | 190 // Decryptor doesn't support empty key ID (see http://crbug.com/123265). |
191 // So ensure a non-empty value is passed. | 191 // So ensure a non-empty value is passed. |
192 if (!init_data) { | 192 if (!init_data) { |
193 static const uint8 kDummyInitData[1] = {0}; | 193 static const uint8 kDummyInitData[1] = {0}; |
(...skipping 10 matching lines...) Expand all Loading... |
204 promise.Pass()); | 204 promise.Pass()); |
205 return; | 205 return; |
206 } | 206 } |
207 | 207 |
208 media_keys_->UpdateSession(session_id, key, key_length, promise.Pass()); | 208 media_keys_->UpdateSession(session_id, key, key_length, promise.Pass()); |
209 } | 209 } |
210 | 210 |
211 void ProxyDecryptor::CancelKeyRequest(const std::string& web_session_id) { | 211 void ProxyDecryptor::CancelKeyRequest(const std::string& web_session_id) { |
212 DVLOG(1) << "CancelKeyRequest()"; | 212 DVLOG(1) << "CancelKeyRequest()"; |
213 | 213 |
214 scoped_ptr<media::SimpleCdmPromise> promise( | 214 scoped_ptr<media::SimpleCdmPromise> promise(new media::CdmCallbackPromise<>( |
215 new media::SimpleCdmPromise(base::Bind(&ProxyDecryptor::OnSessionClosed, | 215 base::Bind(&ProxyDecryptor::OnSessionClosed, |
216 weak_ptr_factory_.GetWeakPtr(), | 216 weak_ptr_factory_.GetWeakPtr(), |
217 web_session_id), | 217 web_session_id), |
218 base::Bind(&ProxyDecryptor::OnSessionError, | 218 base::Bind(&ProxyDecryptor::OnSessionError, |
219 weak_ptr_factory_.GetWeakPtr(), | 219 weak_ptr_factory_.GetWeakPtr(), |
220 web_session_id))); | 220 web_session_id))); |
221 media_keys_->RemoveSession(web_session_id, promise.Pass()); | 221 media_keys_->RemoveSession(web_session_id, promise.Pass()); |
222 } | 222 } |
223 | 223 |
224 scoped_ptr<media::MediaKeys> ProxyDecryptor::CreateMediaKeys( | 224 scoped_ptr<media::MediaKeys> ProxyDecryptor::CreateMediaKeys( |
225 const std::string& key_system, | 225 const std::string& key_system, |
226 const GURL& security_origin) { | 226 const GURL& security_origin) { |
227 return ContentDecryptionModuleFactory::Create( | 227 return ContentDecryptionModuleFactory::Create( |
228 key_system, | 228 key_system, |
229 security_origin, | 229 security_origin, |
230 #if defined(ENABLE_PEPPER_CDMS) | 230 #if defined(ENABLE_PEPPER_CDMS) |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 bool is_persistent = | 335 bool is_persistent = |
336 session_type == PersistentSession || session_type == LoadSession; | 336 session_type == PersistentSession || session_type == LoadSession; |
337 active_sessions_.insert(std::make_pair(web_session_id, is_persistent)); | 337 active_sessions_.insert(std::make_pair(web_session_id, is_persistent)); |
338 | 338 |
339 // For LoadSession(), generate the SessionReady event. | 339 // For LoadSession(), generate the SessionReady event. |
340 if (session_type == LoadSession) | 340 if (session_type == LoadSession) |
341 OnSessionReady(web_session_id); | 341 OnSessionReady(web_session_id); |
342 } | 342 } |
343 | 343 |
344 } // namespace content | 344 } // namespace content |
OLD | NEW |