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 "media/cdm/proxy_decryptor.h" | 5 #include "media/cdm/proxy_decryptor.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | |
9 #include <cstring> | 8 #include <cstring> |
| 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "media/base/cdm_callback_promise.h" | 17 #include "media/base/cdm_callback_promise.h" |
18 #include "media/base/cdm_config.h" | 18 #include "media/base/cdm_config.h" |
19 #include "media/base/cdm_factory.h" | 19 #include "media/base/cdm_factory.h" |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 session_creation_type), | 178 session_creation_type), |
179 base::Bind(&ProxyDecryptor::OnLegacySessionError, | 179 base::Bind(&ProxyDecryptor::OnLegacySessionError, |
180 weak_ptr_factory_.GetWeakPtr(), | 180 weak_ptr_factory_.GetWeakPtr(), |
181 std::string()))); // No session id until created. | 181 std::string()))); // No session id until created. |
182 | 182 |
183 if (session_creation_type == LoadSession) { | 183 if (session_creation_type == LoadSession) { |
184 media_keys_->LoadSession( | 184 media_keys_->LoadSession( |
185 MediaKeys::PERSISTENT_LICENSE_SESSION, | 185 MediaKeys::PERSISTENT_LICENSE_SESSION, |
186 std::string(reinterpret_cast<const char*>(stripped_init_data.data()), | 186 std::string(reinterpret_cast<const char*>(stripped_init_data.data()), |
187 stripped_init_data.size()), | 187 stripped_init_data.size()), |
188 promise.Pass()); | 188 std::move(promise)); |
189 return; | 189 return; |
190 } | 190 } |
191 | 191 |
192 MediaKeys::SessionType session_type = | 192 MediaKeys::SessionType session_type = |
193 session_creation_type == PersistentSession | 193 session_creation_type == PersistentSession |
194 ? MediaKeys::PERSISTENT_LICENSE_SESSION | 194 ? MediaKeys::PERSISTENT_LICENSE_SESSION |
195 : MediaKeys::TEMPORARY_SESSION; | 195 : MediaKeys::TEMPORARY_SESSION; |
196 | 196 |
197 // No permission required when AesDecryptor is used or when the key system is | 197 // No permission required when AesDecryptor is used or when the key system is |
198 // external clear key. | 198 // external clear key. |
199 DCHECK(!key_system_.empty()); | 199 DCHECK(!key_system_.empty()); |
200 if (CanUseAesDecryptor(key_system_) || IsExternalClearKey(key_system_)) { | 200 if (CanUseAesDecryptor(key_system_) || IsExternalClearKey(key_system_)) { |
201 OnPermissionStatus(session_type, init_data_type, stripped_init_data, | 201 OnPermissionStatus(session_type, init_data_type, stripped_init_data, |
202 promise.Pass(), true /* granted */); | 202 std::move(promise), true /* granted */); |
203 return; | 203 return; |
204 } | 204 } |
205 | 205 |
206 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) | 206 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
207 media_permission_->RequestPermission( | 207 media_permission_->RequestPermission( |
208 MediaPermission::PROTECTED_MEDIA_IDENTIFIER, security_origin_, | 208 MediaPermission::PROTECTED_MEDIA_IDENTIFIER, security_origin_, |
209 base::Bind(&ProxyDecryptor::OnPermissionStatus, | 209 base::Bind(&ProxyDecryptor::OnPermissionStatus, |
210 weak_ptr_factory_.GetWeakPtr(), session_type, init_data_type, | 210 weak_ptr_factory_.GetWeakPtr(), session_type, init_data_type, |
211 stripped_init_data, base::Passed(&promise))); | 211 stripped_init_data, base::Passed(&promise))); |
212 #else | 212 #else |
213 OnPermissionStatus(session_type, init_data_type, stripped_init_data, | 213 OnPermissionStatus(session_type, init_data_type, stripped_init_data, |
214 promise.Pass(), true /* granted */); | 214 std::move(promise), true /* granted */); |
215 #endif | 215 #endif |
216 } | 216 } |
217 | 217 |
218 void ProxyDecryptor::OnPermissionStatus( | 218 void ProxyDecryptor::OnPermissionStatus( |
219 MediaKeys::SessionType session_type, | 219 MediaKeys::SessionType session_type, |
220 EmeInitDataType init_data_type, | 220 EmeInitDataType init_data_type, |
221 const std::vector<uint8_t>& init_data, | 221 const std::vector<uint8_t>& init_data, |
222 scoped_ptr<NewSessionCdmPromise> promise, | 222 scoped_ptr<NewSessionCdmPromise> promise, |
223 bool granted) { | 223 bool granted) { |
224 // ProxyDecryptor is only used by Prefixed EME, where RequestPermission() is | 224 // ProxyDecryptor is only used by Prefixed EME, where RequestPermission() is |
225 // only for triggering the permission UI. Later CheckPermission() will be | 225 // only for triggering the permission UI. Later CheckPermission() will be |
226 // called (e.g. in PlatformVerificationFlow on ChromeOS; in BrowserCdmManager | 226 // called (e.g. in PlatformVerificationFlow on ChromeOS; in BrowserCdmManager |
227 // on Android) and the permission status will be evaluated then. | 227 // on Android) and the permission status will be evaluated then. |
228 DVLOG_IF(1, !granted) << "Permission request rejected."; | 228 DVLOG_IF(1, !granted) << "Permission request rejected."; |
229 | 229 |
230 media_keys_->CreateSessionAndGenerateRequest(session_type, init_data_type, | 230 media_keys_->CreateSessionAndGenerateRequest(session_type, init_data_type, |
231 init_data, promise.Pass()); | 231 init_data, std::move(promise)); |
232 } | 232 } |
233 | 233 |
234 void ProxyDecryptor::AddKey(const uint8_t* key, | 234 void ProxyDecryptor::AddKey(const uint8_t* key, |
235 int key_length, | 235 int key_length, |
236 const uint8_t* init_data, | 236 const uint8_t* init_data, |
237 int init_data_length, | 237 int init_data_length, |
238 const std::string& session_id) { | 238 const std::string& session_id) { |
239 DVLOG(1) << "AddKey()"; | 239 DVLOG(1) << "AddKey()"; |
240 | 240 |
241 if (!media_keys_) { | 241 if (!media_keys_) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 static const uint8_t kDummyInitData[1] = {0}; | 275 static const uint8_t kDummyInitData[1] = {0}; |
276 init_data = kDummyInitData; | 276 init_data = kDummyInitData; |
277 init_data_length = arraysize(kDummyInitData); | 277 init_data_length = arraysize(kDummyInitData); |
278 } | 278 } |
279 | 279 |
280 std::string jwk = | 280 std::string jwk = |
281 GenerateJWKSet(key, key_length, init_data, init_data_length); | 281 GenerateJWKSet(key, key_length, init_data, init_data_length); |
282 DCHECK(!jwk.empty()); | 282 DCHECK(!jwk.empty()); |
283 media_keys_->UpdateSession(new_session_id, | 283 media_keys_->UpdateSession(new_session_id, |
284 std::vector<uint8_t>(jwk.begin(), jwk.end()), | 284 std::vector<uint8_t>(jwk.begin(), jwk.end()), |
285 promise.Pass()); | 285 std::move(promise)); |
286 return; | 286 return; |
287 } | 287 } |
288 | 288 |
289 media_keys_->UpdateSession(new_session_id, | 289 media_keys_->UpdateSession(new_session_id, |
290 std::vector<uint8_t>(key, key + key_length), | 290 std::vector<uint8_t>(key, key + key_length), |
291 promise.Pass()); | 291 std::move(promise)); |
292 } | 292 } |
293 | 293 |
294 void ProxyDecryptor::CancelKeyRequest(const std::string& session_id) { | 294 void ProxyDecryptor::CancelKeyRequest(const std::string& session_id) { |
295 DVLOG(1) << "CancelKeyRequest()"; | 295 DVLOG(1) << "CancelKeyRequest()"; |
296 | 296 |
297 if (!media_keys_) { | 297 if (!media_keys_) { |
298 OnLegacySessionError(std::string(), MediaKeys::INVALID_STATE_ERROR, 0, | 298 OnLegacySessionError(std::string(), MediaKeys::INVALID_STATE_ERROR, 0, |
299 "CDM is not available."); | 299 "CDM is not available."); |
300 return; | 300 return; |
301 } | 301 } |
302 | 302 |
303 scoped_ptr<SimpleCdmPromise> promise(new CdmCallbackPromise<>( | 303 scoped_ptr<SimpleCdmPromise> promise(new CdmCallbackPromise<>( |
304 base::Bind(&ProxyDecryptor::OnSessionClosed, | 304 base::Bind(&ProxyDecryptor::OnSessionClosed, |
305 weak_ptr_factory_.GetWeakPtr(), session_id), | 305 weak_ptr_factory_.GetWeakPtr(), session_id), |
306 base::Bind(&ProxyDecryptor::OnLegacySessionError, | 306 base::Bind(&ProxyDecryptor::OnLegacySessionError, |
307 weak_ptr_factory_.GetWeakPtr(), session_id))); | 307 weak_ptr_factory_.GetWeakPtr(), session_id))); |
308 media_keys_->RemoveSession(session_id, promise.Pass()); | 308 media_keys_->RemoveSession(session_id, std::move(promise)); |
309 } | 309 } |
310 | 310 |
311 void ProxyDecryptor::OnSessionMessage(const std::string& session_id, | 311 void ProxyDecryptor::OnSessionMessage(const std::string& session_id, |
312 MediaKeys::MessageType message_type, | 312 MediaKeys::MessageType message_type, |
313 const std::vector<uint8_t>& message, | 313 const std::vector<uint8_t>& message, |
314 const GURL& legacy_destination_url) { | 314 const GURL& legacy_destination_url) { |
315 // Assumes that OnSessionCreated() has been called before this. | 315 // Assumes that OnSessionCreated() has been called before this. |
316 | 316 |
317 // For ClearKey, convert the message from JSON into just passing the key | 317 // For ClearKey, convert the message from JSON into just passing the key |
318 // as the message. If unable to extract the key, return the message unchanged. | 318 // as the message. If unable to extract the key, return the message unchanged. |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 bool is_persistent = | 406 bool is_persistent = |
407 session_type == PersistentSession || session_type == LoadSession; | 407 session_type == PersistentSession || session_type == LoadSession; |
408 active_sessions_.insert(std::make_pair(session_id, is_persistent)); | 408 active_sessions_.insert(std::make_pair(session_id, is_persistent)); |
409 | 409 |
410 // For LoadSession(), generate the KeyAdded event. | 410 // For LoadSession(), generate the KeyAdded event. |
411 if (session_type == LoadSession) | 411 if (session_type == LoadSession) |
412 GenerateKeyAdded(session_id); | 412 GenerateKeyAdded(session_id); |
413 } | 413 } |
414 | 414 |
415 } // namespace media | 415 } // namespace media |
OLD | NEW |