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 "media/cdm/ppapi/cdm_adapter.h" | 5 #include "media/cdm/ppapi/cdm_adapter.h" |
| 6 | 6 |
| 7 #include "media/cdm/ppapi/cdm_file_io_impl.h" | 7 #include "media/cdm/ppapi/cdm_file_io_impl.h" |
| 8 #include "media/cdm/ppapi/cdm_helpers.h" | 8 #include "media/cdm/ppapi/cdm_helpers.h" |
| 9 #include "media/cdm/ppapi/cdm_logging.h" | 9 #include "media/cdm/ppapi/cdm_logging.h" |
| 10 #include "media/cdm/ppapi/supported_cdm_versions.h" | 10 #include "media/cdm/ppapi/supported_cdm_versions.h" |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 } | 316 } |
| 317 #endif // defined(CHECK_DOCUMENT_URL) | 317 #endif // defined(CHECK_DOCUMENT_URL) |
| 318 | 318 |
| 319 if (!cdm_ && !CreateCdmInstance(key_system)) | 319 if (!cdm_ && !CreateCdmInstance(key_system)) |
| 320 return; | 320 return; |
| 321 | 321 |
| 322 PP_DCHECK(cdm_); | 322 PP_DCHECK(cdm_); |
| 323 key_system_ = key_system; | 323 key_system_ = key_system; |
| 324 } | 324 } |
| 325 | 325 |
| 326 void CdmAdapter::SetServerCertificate(uint32_t promise_id, | |
| 327 pp::VarArrayBuffer server_certificate) { | |
| 328 const uint8_t* server_certificate_ptr = | |
| 329 static_cast<const uint8_t*>(server_certificate.Map()); | |
| 330 const uint32_t server_certificate_size = server_certificate.ByteLength(); | |
| 331 | |
| 332 PP_DCHECK(server_certificate_ptr); | |
| 333 PP_DCHECK(server_certificate_size > 0); | |
| 334 | |
| 335 // Initialize() doesn't report an error, so SetServerCertificate() can be | |
| 336 // called even if Initialize() failed. | |
|
ddorwin
2014/08/22 20:49:20
Is this true? This function can only be called by
jrummell
2014/08/25 21:54:36
Initialize() is called from PpapiDecryptor constru
| |
| 337 // TODO(jrummell): Remove this code when prefixed EME gets removed. | |
| 338 if (!cdm_) { | |
| 339 RejectPromise(promise_id, | |
| 340 cdm::kInvalidStateError, | |
| 341 0, | |
| 342 "CDM has not been initialized."); | |
| 343 return; | |
| 344 } | |
| 345 | |
| 346 if (!cdm_->SetServerCertificate( | |
| 347 promise_id, server_certificate_ptr, server_certificate_size)) { | |
| 348 // CDM_4 and CDM_5 don't support this method, so reject the promise. | |
| 349 RejectPromise(promise_id, cdm::kNotSupportedError, 0, "Not implemented."); | |
| 350 } | |
| 351 } | |
| 352 | |
| 326 void CdmAdapter::CreateSession(uint32_t promise_id, | 353 void CdmAdapter::CreateSession(uint32_t promise_id, |
| 327 const std::string& init_data_type, | 354 const std::string& init_data_type, |
| 328 pp::VarArrayBuffer init_data, | 355 pp::VarArrayBuffer init_data, |
| 329 PP_SessionType session_type) { | 356 PP_SessionType session_type) { |
| 330 // Initialize() doesn't report an error, so CreateSession() can be called | 357 // Initialize() doesn't report an error, so CreateSession() can be called |
| 331 // even if Initialize() failed. | 358 // even if Initialize() failed. |
| 332 // TODO(jrummell): Remove this code when prefixed EME gets removed. | 359 // TODO(jrummell): Remove this code when prefixed EME gets removed. |
| 333 // TODO(jrummell): Verify that Initialize() failing does not resolve the | 360 // TODO(jrummell): Verify that Initialize() failing does not resolve the |
| 334 // MediaKeys.create() promise. | 361 // MediaKeys.create() promise. |
| 335 if (!cdm_) { | 362 if (!cdm_) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 PP_DCHECK(response_ptr); | 403 PP_DCHECK(response_ptr); |
| 377 PP_DCHECK(response_size > 0); | 404 PP_DCHECK(response_size > 0); |
| 378 | 405 |
| 379 cdm_->UpdateSession(promise_id, | 406 cdm_->UpdateSession(promise_id, |
| 380 web_session_id.data(), | 407 web_session_id.data(), |
| 381 web_session_id.length(), | 408 web_session_id.length(), |
| 382 response_ptr, | 409 response_ptr, |
| 383 response_size); | 410 response_size); |
| 384 } | 411 } |
| 385 | 412 |
| 386 void CdmAdapter::ReleaseSession(uint32_t promise_id, | 413 void CdmAdapter::GetUsableKeyIds(uint32_t promise_id, |
|
ddorwin
2014/08/22 20:49:20
Why did this move?
jrummell
2014/08/25 21:54:36
To line up with the order in the .h file. Moved ba
| |
| 387 const std::string& web_session_id) { | 414 const std::string& web_session_id) { |
| 415 if (!cdm_->GetUsableKeyIds( | |
| 416 promise_id, web_session_id.data(), web_session_id.length())) { | |
| 417 // CDM_4 and CDM_5 don't support this method, so reject the promise. | |
| 418 RejectPromise(promise_id, cdm::kNotSupportedError, 0, "Not implemented."); | |
| 419 } | |
| 420 } | |
| 421 | |
| 422 void CdmAdapter::CloseSession(uint32_t promise_id, | |
| 423 const std::string& web_session_id) { | |
| 388 cdm_->CloseSession( | 424 cdm_->CloseSession( |
| 389 promise_id, web_session_id.data(), web_session_id.length()); | 425 promise_id, web_session_id.data(), web_session_id.length()); |
| 390 } | 426 } |
| 391 | 427 |
| 392 void CdmAdapter::RemoveSession(uint32_t promise_id, | 428 void CdmAdapter::RemoveSession(uint32_t promise_id, |
| 393 const std::string& web_session_id) { | 429 const std::string& web_session_id) { |
| 394 if (!cdm_->RemoveSession( | 430 if (!cdm_->RemoveSession( |
| 395 promise_id, web_session_id.data(), web_session_id.length())) { | 431 promise_id, web_session_id.data(), web_session_id.length())) { |
| 396 // CDM_4 and CDM_5 don't support this method, so reject the promise. | 432 // CDM_4 and CDM_5 don't support this method, so reject the promise. |
| 397 RejectPromise(promise_id, cdm::kNotSupportedError, 0, "Not implemented."); | 433 RejectPromise(promise_id, cdm::kNotSupportedError, 0, "Not implemented."); |
| 398 } | 434 } |
| 399 } | 435 } |
| 400 | 436 |
| 401 void CdmAdapter::GetUsableKeyIds(uint32_t promise_id, | |
| 402 const std::string& web_session_id) { | |
| 403 if (!cdm_->GetUsableKeyIds( | |
| 404 promise_id, web_session_id.data(), web_session_id.length())) { | |
| 405 // CDM_4 and CDM_5 don't support this method, so reject the promise. | |
| 406 RejectPromise(promise_id, cdm::kNotSupportedError, 0, "Not implemented."); | |
| 407 } | |
| 408 } | |
| 409 | |
| 410 // Note: In the following decryption/decoding related functions, errors are NOT | 437 // Note: In the following decryption/decoding related functions, errors are NOT |
| 411 // reported via KeyError, but are reported via corresponding PPB calls. | 438 // reported via KeyError, but are reported via corresponding PPB calls. |
| 412 | 439 |
| 413 void CdmAdapter::Decrypt(pp::Buffer_Dev encrypted_buffer, | 440 void CdmAdapter::Decrypt(pp::Buffer_Dev encrypted_buffer, |
| 414 const PP_EncryptedBlockInfo& encrypted_block_info) { | 441 const PP_EncryptedBlockInfo& encrypted_block_info) { |
| 415 PP_DCHECK(!encrypted_buffer.is_null()); | 442 PP_DCHECK(!encrypted_buffer.is_null()); |
| 416 | 443 |
| 417 // Release a buffer that the caller indicated it is finished with. | 444 // Release a buffer that the caller indicated it is finished with. |
| 418 allocator_.Release(encrypted_block_info.tracking_info.buffer_id); | 445 allocator_.Release(encrypted_block_info.tracking_info.buffer_id); |
| 419 | 446 |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 838 PP_DCHECK(result == PP_OK); | 865 PP_DCHECK(result == PP_OK); |
| 839 pp::ContentDecryptor_Private::PromiseResolvedWithSession(promise_id, | 866 pp::ContentDecryptor_Private::PromiseResolvedWithSession(promise_id, |
| 840 web_session_id); | 867 web_session_id); |
| 841 } | 868 } |
| 842 | 869 |
| 843 void CdmAdapter::SendPromiseResolvedWithUsableKeyIdsInternal( | 870 void CdmAdapter::SendPromiseResolvedWithUsableKeyIdsInternal( |
| 844 int32_t result, | 871 int32_t result, |
| 845 uint32_t promise_id, | 872 uint32_t promise_id, |
| 846 std::vector<std::vector<uint8> > key_ids) { | 873 std::vector<std::vector<uint8> > key_ids) { |
| 847 PP_DCHECK(result == PP_OK); | 874 PP_DCHECK(result == PP_OK); |
| 848 // TODO(jrummell): Implement this event in subsequent CL. | 875 pp::ContentDecryptor_Private::PromiseResolvedWithKeyIds(promise_id, key_ids); |
| 849 // (http://crbug.com/358271). | |
| 850 } | 876 } |
| 851 | 877 |
| 852 void CdmAdapter::SendPromiseRejectedInternal(int32_t result, | 878 void CdmAdapter::SendPromiseRejectedInternal(int32_t result, |
| 853 uint32_t promise_id, | 879 uint32_t promise_id, |
| 854 const SessionError& error) { | 880 const SessionError& error) { |
| 855 PP_DCHECK(result == PP_OK); | 881 PP_DCHECK(result == PP_OK); |
| 856 pp::ContentDecryptor_Private::PromiseRejected( | 882 pp::ContentDecryptor_Private::PromiseRejected( |
| 857 promise_id, | 883 promise_id, |
| 858 CdmExceptionTypeToPpCdmExceptionType(error.error), | 884 CdmExceptionTypeToPpCdmExceptionType(error.error), |
| 859 error.system_code, | 885 error.system_code, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 897 CdmExceptionTypeToPpCdmExceptionType(error.error), | 923 CdmExceptionTypeToPpCdmExceptionType(error.error), |
| 898 error.system_code, | 924 error.system_code, |
| 899 error.error_description); | 925 error.error_description); |
| 900 } | 926 } |
| 901 | 927 |
| 902 void CdmAdapter::SendSessionUsableKeysChangeInternal( | 928 void CdmAdapter::SendSessionUsableKeysChangeInternal( |
| 903 int32_t result, | 929 int32_t result, |
| 904 const std::string& web_session_id, | 930 const std::string& web_session_id, |
| 905 bool has_additional_usable_key) { | 931 bool has_additional_usable_key) { |
| 906 PP_DCHECK(result == PP_OK); | 932 PP_DCHECK(result == PP_OK); |
| 907 // TODO(jrummell): Implement this event in subsequent CL. | 933 pp::ContentDecryptor_Private::SessionKeysChange(web_session_id, |
| 908 // (http://crbug.com/358271). | 934 has_additional_usable_key); |
| 909 } | 935 } |
| 910 | 936 |
| 911 void CdmAdapter::SendExpirationChangeInternal(int32_t result, | 937 void CdmAdapter::SendExpirationChangeInternal(int32_t result, |
| 912 const std::string& web_session_id, | 938 const std::string& web_session_id, |
| 913 cdm::Time new_expiry_time) { | 939 cdm::Time new_expiry_time) { |
| 914 PP_DCHECK(result == PP_OK); | 940 PP_DCHECK(result == PP_OK); |
| 915 // TODO(jrummell): Implement this event in subsequent CL. | 941 pp::ContentDecryptor_Private::SessionExpirationChange(web_session_id, |
| 916 // (http://crbug.com/358271). | 942 new_expiry_time); |
| 917 } | 943 } |
| 918 | 944 |
| 919 void CdmAdapter::DeliverBlock(int32_t result, | 945 void CdmAdapter::DeliverBlock(int32_t result, |
| 920 const cdm::Status& status, | 946 const cdm::Status& status, |
| 921 const LinkedDecryptedBlock& decrypted_block, | 947 const LinkedDecryptedBlock& decrypted_block, |
| 922 const PP_DecryptTrackingInfo& tracking_info) { | 948 const PP_DecryptTrackingInfo& tracking_info) { |
| 923 PP_DCHECK(result == PP_OK); | 949 PP_DCHECK(result == PP_OK); |
| 924 PP_DecryptedBlockInfo decrypted_block_info = {}; | 950 PP_DecryptedBlockInfo decrypted_block_info = {}; |
| 925 decrypted_block_info.tracking_info = tracking_info; | 951 decrypted_block_info.tracking_info = tracking_info; |
| 926 decrypted_block_info.tracking_info.timestamp = decrypted_block->Timestamp(); | 952 decrypted_block_info.tracking_info.timestamp = decrypted_block->Timestamp(); |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1357 } // namespace media | 1383 } // namespace media |
| 1358 | 1384 |
| 1359 namespace pp { | 1385 namespace pp { |
| 1360 | 1386 |
| 1361 // Factory function for your specialization of the Module object. | 1387 // Factory function for your specialization of the Module object. |
| 1362 Module* CreateModule() { | 1388 Module* CreateModule() { |
| 1363 return new media::CdmAdapterModule(); | 1389 return new media::CdmAdapterModule(); |
| 1364 } | 1390 } |
| 1365 | 1391 |
| 1366 } // namespace pp | 1392 } // namespace pp |
| OLD | NEW |