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/base/limits.h" |
7 #include "media/cdm/ppapi/cdm_file_io_impl.h" | 8 #include "media/cdm/ppapi/cdm_file_io_impl.h" |
8 #include "media/cdm/ppapi/cdm_helpers.h" | 9 #include "media/cdm/ppapi/cdm_helpers.h" |
9 #include "media/cdm/ppapi/cdm_logging.h" | 10 #include "media/cdm/ppapi/cdm_logging.h" |
10 #include "media/cdm/ppapi/supported_cdm_versions.h" | 11 #include "media/cdm/ppapi/supported_cdm_versions.h" |
11 #include "ppapi/c/ppb_console.h" | 12 #include "ppapi/c/ppb_console.h" |
12 #include "ppapi/cpp/private/uma_private.h" | 13 #include "ppapi/cpp/private/uma_private.h" |
13 | 14 |
14 #if defined(CHECK_DOCUMENT_URL) | 15 #if defined(CHECK_DOCUMENT_URL) |
15 #include "ppapi/cpp/dev/url_util_dev.h" | 16 #include "ppapi/cpp/dev/url_util_dev.h" |
16 #include "ppapi/cpp/instance_handle.h" | 17 #include "ppapi/cpp/instance_handle.h" |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 } | 317 } |
317 #endif // defined(CHECK_DOCUMENT_URL) | 318 #endif // defined(CHECK_DOCUMENT_URL) |
318 | 319 |
319 if (!cdm_ && !CreateCdmInstance(key_system)) | 320 if (!cdm_ && !CreateCdmInstance(key_system)) |
320 return; | 321 return; |
321 | 322 |
322 PP_DCHECK(cdm_); | 323 PP_DCHECK(cdm_); |
323 key_system_ = key_system; | 324 key_system_ = key_system; |
324 } | 325 } |
325 | 326 |
| 327 void CdmAdapter::SetServerCertificate(uint32_t promise_id, |
| 328 pp::VarArrayBuffer server_certificate) { |
| 329 const uint8_t* server_certificate_ptr = |
| 330 static_cast<const uint8_t*>(server_certificate.Map()); |
| 331 const uint32_t server_certificate_size = server_certificate.ByteLength(); |
| 332 |
| 333 if (!server_certificate_ptr || |
| 334 server_certificate_size < media::limits::kMinCertificateLength || |
| 335 server_certificate_size > media::limits::kMinCertificateLength) { |
| 336 RejectPromise( |
| 337 promise_id, cdm::kInvalidAccessError, 0, "Incorrect certificate."); |
| 338 return; |
| 339 } |
| 340 |
| 341 // Initialize() doesn't report an error, so SetServerCertificate() can be |
| 342 // called even if Initialize() failed. |
| 343 // TODO(jrummell): Remove this code when prefixed EME gets removed. |
| 344 if (!cdm_) { |
| 345 RejectPromise(promise_id, |
| 346 cdm::kInvalidStateError, |
| 347 0, |
| 348 "CDM has not been initialized."); |
| 349 return; |
| 350 } |
| 351 |
| 352 if (!cdm_->SetServerCertificate( |
| 353 promise_id, server_certificate_ptr, server_certificate_size)) { |
| 354 // CDM_4 and CDM_5 don't support this method, so reject the promise. |
| 355 RejectPromise(promise_id, cdm::kNotSupportedError, 0, "Not implemented."); |
| 356 } |
| 357 } |
| 358 |
326 void CdmAdapter::CreateSession(uint32_t promise_id, | 359 void CdmAdapter::CreateSession(uint32_t promise_id, |
327 const std::string& init_data_type, | 360 const std::string& init_data_type, |
328 pp::VarArrayBuffer init_data, | 361 pp::VarArrayBuffer init_data, |
329 PP_SessionType session_type) { | 362 PP_SessionType session_type) { |
330 // Initialize() doesn't report an error, so CreateSession() can be called | 363 // Initialize() doesn't report an error, so CreateSession() can be called |
331 // even if Initialize() failed. | 364 // even if Initialize() failed. |
332 // TODO(jrummell): Remove this code when prefixed EME gets removed. | 365 // TODO(jrummell): Remove this code when prefixed EME gets removed. |
333 // TODO(jrummell): Verify that Initialize() failing does not resolve the | 366 // TODO(jrummell): Verify that Initialize() failing does not resolve the |
334 // MediaKeys.create() promise. | 367 // MediaKeys.create() promise. |
335 if (!cdm_) { | 368 if (!cdm_) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 | 418 |
386 void CdmAdapter::CloseSession(uint32_t promise_id, | 419 void CdmAdapter::CloseSession(uint32_t promise_id, |
387 const std::string& web_session_id) { | 420 const std::string& web_session_id) { |
388 if (!cdm_->CloseSession( | 421 if (!cdm_->CloseSession( |
389 promise_id, web_session_id.data(), web_session_id.length())) { | 422 promise_id, web_session_id.data(), web_session_id.length())) { |
390 // CDM_4 doesn't support this method, so reject the promise. | 423 // CDM_4 doesn't support this method, so reject the promise. |
391 RejectPromise(promise_id, cdm::kNotSupportedError, 0, "Not implemented."); | 424 RejectPromise(promise_id, cdm::kNotSupportedError, 0, "Not implemented."); |
392 } | 425 } |
393 } | 426 } |
394 | 427 |
395 void CdmAdapter::ReleaseSession(uint32_t promise_id, | 428 void CdmAdapter::RemoveSession(uint32_t promise_id, |
396 const std::string& web_session_id) { | 429 const std::string& web_session_id) { |
397 cdm_->RemoveSession( | 430 cdm_->RemoveSession( |
398 promise_id, web_session_id.data(), web_session_id.length()); | 431 promise_id, web_session_id.data(), web_session_id.length()); |
399 } | 432 } |
400 | 433 |
401 void CdmAdapter::GetUsableKeyIds(uint32_t promise_id, | 434 void CdmAdapter::GetUsableKeyIds(uint32_t promise_id, |
402 const std::string& web_session_id) { | 435 const std::string& web_session_id) { |
403 if (!cdm_->GetUsableKeyIds( | 436 if (!cdm_->GetUsableKeyIds( |
404 promise_id, web_session_id.data(), web_session_id.length())) { | 437 promise_id, web_session_id.data(), web_session_id.length())) { |
405 // CDM_4 doesn't support this method, so reject the promise. | 438 // CDM_4 doesn't support this method, so reject the promise. |
406 RejectPromise(promise_id, cdm::kNotSupportedError, 0, "Not implemented."); | 439 RejectPromise(promise_id, cdm::kNotSupportedError, 0, "Not implemented."); |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 PP_DCHECK(result == PP_OK); | 842 PP_DCHECK(result == PP_OK); |
810 pp::ContentDecryptor_Private::PromiseResolvedWithSession(promise_id, | 843 pp::ContentDecryptor_Private::PromiseResolvedWithSession(promise_id, |
811 web_session_id); | 844 web_session_id); |
812 } | 845 } |
813 | 846 |
814 void CdmAdapter::SendPromiseResolvedWithUsableKeyIdsInternal( | 847 void CdmAdapter::SendPromiseResolvedWithUsableKeyIdsInternal( |
815 int32_t result, | 848 int32_t result, |
816 uint32_t promise_id, | 849 uint32_t promise_id, |
817 std::vector<std::vector<uint8> > key_ids) { | 850 std::vector<std::vector<uint8> > key_ids) { |
818 PP_DCHECK(result == PP_OK); | 851 PP_DCHECK(result == PP_OK); |
819 // TODO(jrummell): Implement this event in subsequent CL. | 852 pp::ContentDecryptor_Private::PromiseResolvedWithKeyIds(promise_id, key_ids); |
820 // (http://crbug.com/358271). | |
821 } | 853 } |
822 | 854 |
823 void CdmAdapter::SendPromiseRejectedInternal(int32_t result, | 855 void CdmAdapter::SendPromiseRejectedInternal(int32_t result, |
824 uint32_t promise_id, | 856 uint32_t promise_id, |
825 const SessionError& error) { | 857 const SessionError& error) { |
826 PP_DCHECK(result == PP_OK); | 858 PP_DCHECK(result == PP_OK); |
827 pp::ContentDecryptor_Private::PromiseRejected( | 859 pp::ContentDecryptor_Private::PromiseRejected( |
828 promise_id, | 860 promise_id, |
829 CdmExceptionTypeToPpCdmExceptionType(error.error), | 861 CdmExceptionTypeToPpCdmExceptionType(error.error), |
830 error.system_code, | 862 error.system_code, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 CdmExceptionTypeToPpCdmExceptionType(error.error), | 900 CdmExceptionTypeToPpCdmExceptionType(error.error), |
869 error.system_code, | 901 error.system_code, |
870 error.error_description); | 902 error.error_description); |
871 } | 903 } |
872 | 904 |
873 void CdmAdapter::SendSessionUsableKeysChangeInternal( | 905 void CdmAdapter::SendSessionUsableKeysChangeInternal( |
874 int32_t result, | 906 int32_t result, |
875 const std::string& web_session_id, | 907 const std::string& web_session_id, |
876 bool has_additional_usable_key) { | 908 bool has_additional_usable_key) { |
877 PP_DCHECK(result == PP_OK); | 909 PP_DCHECK(result == PP_OK); |
878 // TODO(jrummell): Implement this event in subsequent CL. | 910 pp::ContentDecryptor_Private::SessionKeysChange(web_session_id, |
879 // (http://crbug.com/358271). | 911 has_additional_usable_key); |
880 } | 912 } |
881 | 913 |
882 void CdmAdapter::SendExpirationChangeInternal(int32_t result, | 914 void CdmAdapter::SendExpirationChangeInternal(int32_t result, |
883 const std::string& web_session_id, | 915 const std::string& web_session_id, |
884 cdm::Time new_expiry_time) { | 916 cdm::Time new_expiry_time) { |
885 PP_DCHECK(result == PP_OK); | 917 PP_DCHECK(result == PP_OK); |
886 // TODO(jrummell): Implement this event in subsequent CL. | 918 pp::ContentDecryptor_Private::SessionExpirationChange(web_session_id, |
887 // (http://crbug.com/358271). | 919 new_expiry_time); |
888 } | 920 } |
889 | 921 |
890 void CdmAdapter::DeliverBlock(int32_t result, | 922 void CdmAdapter::DeliverBlock(int32_t result, |
891 const cdm::Status& status, | 923 const cdm::Status& status, |
892 const LinkedDecryptedBlock& decrypted_block, | 924 const LinkedDecryptedBlock& decrypted_block, |
893 const PP_DecryptTrackingInfo& tracking_info) { | 925 const PP_DecryptTrackingInfo& tracking_info) { |
894 PP_DCHECK(result == PP_OK); | 926 PP_DCHECK(result == PP_OK); |
895 PP_DecryptedBlockInfo decrypted_block_info = {}; | 927 PP_DecryptedBlockInfo decrypted_block_info = {}; |
896 decrypted_block_info.tracking_info = tracking_info; | 928 decrypted_block_info.tracking_info = tracking_info; |
897 decrypted_block_info.tracking_info.timestamp = decrypted_block->Timestamp(); | 929 decrypted_block_info.tracking_info.timestamp = decrypted_block->Timestamp(); |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1326 } // namespace media | 1358 } // namespace media |
1327 | 1359 |
1328 namespace pp { | 1360 namespace pp { |
1329 | 1361 |
1330 // Factory function for your specialization of the Module object. | 1362 // Factory function for your specialization of the Module object. |
1331 Module* CreateModule() { | 1363 Module* CreateModule() { |
1332 return new media::CdmAdapterModule(); | 1364 return new media::CdmAdapterModule(); |
1333 } | 1365 } |
1334 | 1366 |
1335 } // namespace pp | 1367 } // namespace pp |
OLD | NEW |