OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/pepper/content_decryptor_delegate.h" | 5 #include "content/renderer/pepper/content_decryptor_delegate.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
11 #include "content/renderer/pepper/ppb_buffer_impl.h" | 11 #include "content/renderer/pepper/ppb_buffer_impl.h" |
12 #include "media/base/audio_buffer.h" | 12 #include "media/base/audio_buffer.h" |
13 #include "media/base/audio_decoder_config.h" | 13 #include "media/base/audio_decoder_config.h" |
14 #include "media/base/bind_to_current_loop.h" | 14 #include "media/base/bind_to_current_loop.h" |
15 #include "media/base/cdm_promise.h" | 15 #include "media/base/cdm_promise.h" |
16 #include "media/base/channel_layout.h" | 16 #include "media/base/channel_layout.h" |
17 #include "media/base/data_buffer.h" | 17 #include "media/base/data_buffer.h" |
18 #include "media/base/decoder_buffer.h" | 18 #include "media/base/decoder_buffer.h" |
19 #include "media/base/decrypt_config.h" | 19 #include "media/base/decrypt_config.h" |
20 #include "media/base/video_decoder_config.h" | 20 #include "media/base/video_decoder_config.h" |
21 #include "media/base/video_frame.h" | 21 #include "media/base/video_frame.h" |
22 #include "media/base/video_util.h" | 22 #include "media/base/video_util.h" |
23 #include "ppapi/shared_impl/array_var.h" | |
23 #include "ppapi/shared_impl/scoped_pp_resource.h" | 24 #include "ppapi/shared_impl/scoped_pp_resource.h" |
24 #include "ppapi/shared_impl/var.h" | 25 #include "ppapi/shared_impl/var.h" |
25 #include "ppapi/shared_impl/var_tracker.h" | 26 #include "ppapi/shared_impl/var_tracker.h" |
26 #include "ppapi/thunk/enter.h" | 27 #include "ppapi/thunk/enter.h" |
27 #include "ppapi/thunk/ppb_buffer_api.h" | 28 #include "ppapi/thunk/ppb_buffer_api.h" |
28 #include "ui/gfx/rect.h" | 29 #include "ui/gfx/rect.h" |
29 | 30 |
30 using media::CdmPromise; | 31 using media::CdmPromise; |
31 using media::Decryptor; | 32 using media::Decryptor; |
33 using media::KeyIdsPromise; | |
32 using media::MediaKeys; | 34 using media::MediaKeys; |
33 using media::NewSessionCdmPromise; | 35 using media::NewSessionCdmPromise; |
34 using media::SimpleCdmPromise; | 36 using media::SimpleCdmPromise; |
35 using ppapi::ArrayBufferVar; | 37 using ppapi::ArrayBufferVar; |
38 using ppapi::ArrayVar; | |
36 using ppapi::PpapiGlobals; | 39 using ppapi::PpapiGlobals; |
37 using ppapi::ScopedPPResource; | 40 using ppapi::ScopedPPResource; |
38 using ppapi::StringVar; | 41 using ppapi::StringVar; |
39 using ppapi::thunk::EnterResourceNoLock; | 42 using ppapi::thunk::EnterResourceNoLock; |
40 using ppapi::thunk::PPB_Buffer_API; | 43 using ppapi::thunk::PPB_Buffer_API; |
41 | 44 |
42 namespace content { | 45 namespace content { |
43 | 46 |
44 namespace { | 47 namespace { |
45 | 48 |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 | 326 |
324 plugin_decryption_interface_->Initialize( | 327 plugin_decryption_interface_->Initialize( |
325 pp_instance_, StringVar::StringToPPVar(key_system_)); | 328 pp_instance_, StringVar::StringToPPVar(key_system_)); |
326 } | 329 } |
327 | 330 |
328 void ContentDecryptorDelegate::InstanceCrashed() { | 331 void ContentDecryptorDelegate::InstanceCrashed() { |
329 fatal_plugin_error_cb_.Run(); | 332 fatal_plugin_error_cb_.Run(); |
330 SatisfyAllPendingCallbacksOnError(); | 333 SatisfyAllPendingCallbacksOnError(); |
331 } | 334 } |
332 | 335 |
336 void ContentDecryptorDelegate::SetServerCertificate( | |
337 const uint8* certificate, | |
338 int certificate_length, | |
339 scoped_ptr<media::SimpleCdmPromise> promise) { | |
340 uint32_t promise_id = SavePromise(promise.PassAs<CdmPromise>()); | |
341 PP_Var certificate_array = | |
342 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( | |
343 certificate_length, certificate); | |
palmer
2014/08/26 19:09:20
Check |certificate_length| for sanity first: minim
jrummell
2014/08/29 22:35:34
Done.
| |
344 plugin_decryption_interface_->SetServerCertificate( | |
345 pp_instance_, promise_id, certificate_array); | |
346 } | |
347 | |
333 void ContentDecryptorDelegate::CreateSession( | 348 void ContentDecryptorDelegate::CreateSession( |
334 const std::string& init_data_type, | 349 const std::string& init_data_type, |
335 const uint8* init_data, | 350 const uint8* init_data, |
336 int init_data_length, | 351 int init_data_length, |
337 MediaKeys::SessionType session_type, | 352 MediaKeys::SessionType session_type, |
338 scoped_ptr<NewSessionCdmPromise> promise) { | 353 scoped_ptr<NewSessionCdmPromise> promise) { |
339 uint32_t promise_id = SavePromise(promise.PassAs<CdmPromise>()); | 354 uint32_t promise_id = SavePromise(promise.PassAs<CdmPromise>()); |
340 PP_Var init_data_array = | 355 PP_Var init_data_array = |
341 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( | 356 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( |
342 init_data_length, init_data); | 357 init_data_length, init_data); |
(...skipping 22 matching lines...) Expand all Loading... | |
365 PP_Var response_array = | 380 PP_Var response_array = |
366 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( | 381 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( |
367 response_length, response); | 382 response_length, response); |
368 plugin_decryption_interface_->UpdateSession( | 383 plugin_decryption_interface_->UpdateSession( |
369 pp_instance_, | 384 pp_instance_, |
370 promise_id, | 385 promise_id, |
371 StringVar::StringToPPVar(web_session_id), | 386 StringVar::StringToPPVar(web_session_id), |
372 response_array); | 387 response_array); |
373 } | 388 } |
374 | 389 |
375 void ContentDecryptorDelegate::ReleaseSession( | 390 void ContentDecryptorDelegate::CloseSession( |
376 const std::string& web_session_id, | 391 const std::string& web_session_id, |
377 scoped_ptr<SimpleCdmPromise> promise) { | 392 scoped_ptr<SimpleCdmPromise> promise) { |
378 uint32_t promise_id = SavePromise(promise.PassAs<CdmPromise>()); | 393 uint32_t promise_id = SavePromise(promise.PassAs<CdmPromise>()); |
379 plugin_decryption_interface_->ReleaseSession( | 394 plugin_decryption_interface_->CloseSession( |
380 pp_instance_, promise_id, StringVar::StringToPPVar(web_session_id)); | 395 pp_instance_, promise_id, StringVar::StringToPPVar(web_session_id)); |
381 } | 396 } |
382 | 397 |
398 void ContentDecryptorDelegate::RemoveSession( | |
399 const std::string& web_session_id, | |
400 scoped_ptr<SimpleCdmPromise> promise) { | |
401 uint32_t promise_id = SavePromise(promise.PassAs<CdmPromise>()); | |
402 plugin_decryption_interface_->RemoveSession( | |
403 pp_instance_, promise_id, StringVar::StringToPPVar(web_session_id)); | |
404 } | |
405 | |
406 void ContentDecryptorDelegate::GetUsableKeyIds( | |
407 const std::string& web_session_id, | |
408 scoped_ptr<media::KeyIdsPromise> promise) { | |
409 uint32_t promise_id = SavePromise(promise.PassAs<CdmPromise>()); | |
410 plugin_decryption_interface_->GetUsableKeyIds( | |
411 pp_instance_, promise_id, StringVar::StringToPPVar(web_session_id)); | |
412 } | |
413 | |
383 // TODO(xhwang): Remove duplication of code in Decrypt(), | 414 // TODO(xhwang): Remove duplication of code in Decrypt(), |
384 // DecryptAndDecodeAudio() and DecryptAndDecodeVideo(). | 415 // DecryptAndDecodeAudio() and DecryptAndDecodeVideo(). |
385 bool ContentDecryptorDelegate::Decrypt( | 416 bool ContentDecryptorDelegate::Decrypt( |
386 Decryptor::StreamType stream_type, | 417 Decryptor::StreamType stream_type, |
387 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | 418 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
388 const Decryptor::DecryptCB& decrypt_cb) { | 419 const Decryptor::DecryptCB& decrypt_cb) { |
389 DVLOG(3) << "Decrypt() - stream_type: " << stream_type; | 420 DVLOG(3) << "Decrypt() - stream_type: " << stream_type; |
390 | 421 |
391 // |{audio|video}_input_resource_| is not being used by the plugin | 422 // |{audio|video}_input_resource_| is not being used by the plugin |
392 // now because there is only one pending audio/video decrypt request at any | 423 // now because there is only one pending audio/video decrypt request at any |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
618 | 649 |
619 // TODO(tomfinegan): Need to get stream type from media stack. | 650 // TODO(tomfinegan): Need to get stream type from media stack. |
620 ScopedPPResource pp_resource(encrypted_resource.get()); | 651 ScopedPPResource pp_resource(encrypted_resource.get()); |
621 plugin_decryption_interface_->DecryptAndDecode( | 652 plugin_decryption_interface_->DecryptAndDecode( |
622 pp_instance_, PP_DECRYPTORSTREAMTYPE_VIDEO, pp_resource, &block_info); | 653 pp_instance_, PP_DECRYPTORSTREAMTYPE_VIDEO, pp_resource, &block_info); |
623 return true; | 654 return true; |
624 } | 655 } |
625 | 656 |
626 void ContentDecryptorDelegate::OnPromiseResolved(uint32 promise_id) { | 657 void ContentDecryptorDelegate::OnPromiseResolved(uint32 promise_id) { |
627 scoped_ptr<CdmPromise> promise = TakePromise(promise_id); | 658 scoped_ptr<CdmPromise> promise = TakePromise(promise_id); |
628 if (promise) { | 659 DCHECK(promise && |
660 promise->GetResolveParameterType() == media::CdmPromise::VOID_TYPE); | |
661 if (promise && | |
662 promise->GetResolveParameterType() == media::CdmPromise::VOID_TYPE) { | |
629 SimpleCdmPromise* simple_promise( | 663 SimpleCdmPromise* simple_promise( |
630 static_cast<SimpleCdmPromise*>(promise.get())); | 664 static_cast<SimpleCdmPromise*>(promise.get())); |
631 simple_promise->resolve(); | 665 simple_promise->resolve(); |
632 } | 666 } |
633 } | 667 } |
634 | 668 |
635 void ContentDecryptorDelegate::OnPromiseResolvedWithSession( | 669 void ContentDecryptorDelegate::OnPromiseResolvedWithSession( |
636 uint32 promise_id, | 670 uint32 promise_id, |
637 PP_Var web_session_id) { | 671 PP_Var web_session_id) { |
638 scoped_ptr<CdmPromise> promise = TakePromise(promise_id); | 672 scoped_ptr<CdmPromise> promise = TakePromise(promise_id); |
639 | 673 |
640 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); | 674 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); |
641 DCHECK(web_session_id_string); | 675 DCHECK(web_session_id_string); |
642 | 676 |
643 if (promise) { | 677 DCHECK(promise && |
678 promise->GetResolveParameterType() == media::CdmPromise::STRING_TYPE); | |
679 if (promise && | |
680 promise->GetResolveParameterType() == media::CdmPromise::STRING_TYPE) { | |
644 NewSessionCdmPromise* session_promise( | 681 NewSessionCdmPromise* session_promise( |
645 static_cast<NewSessionCdmPromise*>(promise.get())); | 682 static_cast<NewSessionCdmPromise*>(promise.get())); |
646 session_promise->resolve(web_session_id_string->value()); | 683 session_promise->resolve(web_session_id_string->value()); |
647 } | 684 } |
648 } | 685 } |
649 | 686 |
687 void ContentDecryptorDelegate::OnPromiseResolvedWithKeyIds( | |
688 uint32 promise_id, | |
689 PP_Var key_ids_array) { | |
690 scoped_ptr<CdmPromise> promise = TakePromise(promise_id); | |
691 | |
692 ArrayVar* key_ids = ArrayVar::FromPPVar(key_ids_array); | |
693 media::KeyIdsVector key_ids_vector; | |
694 DCHECK(key_ids); | |
palmer
2014/08/26 19:09:20
Nit: Might as well move this DCHECK up a line, to
jrummell
2014/08/29 22:35:34
Done.
| |
695 if (key_ids) { | |
696 for (size_t i = 0; i < key_ids->GetLength(); ++i) { | |
697 ArrayBufferVar* array_buffer = ArrayBufferVar::FromPPVar(key_ids->Get(i)); | |
698 DCHECK(array_buffer); | |
699 if (array_buffer) { | |
700 std::vector<uint8> key_id; | |
701 const uint8* data = static_cast<const uint8*>(array_buffer->Map()); | |
702 key_id.assign(data, data + array_buffer->ByteLength()); | |
703 key_ids_vector.push_back(key_id); | |
704 } | |
705 } | |
706 } | |
707 | |
708 DCHECK(promise && | |
709 promise->GetResolveParameterType() == | |
710 media::CdmPromise::KEY_IDS_VECTOR_TYPE); | |
711 if (promise && | |
712 promise->GetResolveParameterType() == | |
713 media::CdmPromise::KEY_IDS_VECTOR_TYPE) { | |
714 KeyIdsPromise* key_ids_promise(static_cast<KeyIdsPromise*>(promise.get())); | |
715 key_ids_promise->resolve(key_ids_vector); | |
716 } | |
717 } | |
718 | |
650 void ContentDecryptorDelegate::OnPromiseRejected( | 719 void ContentDecryptorDelegate::OnPromiseRejected( |
651 uint32 promise_id, | 720 uint32 promise_id, |
652 PP_CdmExceptionCode exception_code, | 721 PP_CdmExceptionCode exception_code, |
653 uint32 system_code, | 722 uint32 system_code, |
654 PP_Var error_description) { | 723 PP_Var error_description) { |
655 StringVar* error_description_string = StringVar::FromPPVar(error_description); | 724 StringVar* error_description_string = StringVar::FromPPVar(error_description); |
656 DCHECK(error_description_string); | 725 DCHECK(error_description_string); |
657 | 726 |
658 scoped_ptr<CdmPromise> promise = TakePromise(promise_id); | 727 scoped_ptr<CdmPromise> promise = TakePromise(promise_id); |
728 DCHECK(promise); | |
659 if (promise) { | 729 if (promise) { |
660 promise->reject(PpExceptionTypeToMediaException(exception_code), | 730 promise->reject(PpExceptionTypeToMediaException(exception_code), |
661 system_code, | 731 system_code, |
662 error_description_string->value()); | 732 error_description_string->value()); |
663 } | 733 } |
664 } | 734 } |
665 | 735 |
666 void ContentDecryptorDelegate::OnSessionMessage(PP_Var web_session_id, | 736 void ContentDecryptorDelegate::OnSessionMessage(PP_Var web_session_id, |
667 PP_Var message, | 737 PP_Var message, |
668 PP_Var destination_url) { | 738 PP_Var destination_url) { |
(...skipping 17 matching lines...) Expand all Loading... | |
686 if (!verified_gurl.is_valid() && !verified_gurl.is_empty()) { | 756 if (!verified_gurl.is_valid() && !verified_gurl.is_empty()) { |
687 DLOG(WARNING) << "SessionMessage default_url is invalid : " | 757 DLOG(WARNING) << "SessionMessage default_url is invalid : " |
688 << verified_gurl.possibly_invalid_spec(); | 758 << verified_gurl.possibly_invalid_spec(); |
689 verified_gurl = GURL::EmptyGURL(); // Replace invalid destination_url. | 759 verified_gurl = GURL::EmptyGURL(); // Replace invalid destination_url. |
690 } | 760 } |
691 | 761 |
692 session_message_cb_.Run( | 762 session_message_cb_.Run( |
693 web_session_id_string->value(), message_vector, verified_gurl); | 763 web_session_id_string->value(), message_vector, verified_gurl); |
694 } | 764 } |
695 | 765 |
766 void ContentDecryptorDelegate::OnSessionKeysChange( | |
767 PP_Var web_session_id, | |
768 PP_Bool has_additional_usable_key) { | |
769 // TODO(jrummell): Pass this event on. | |
770 } | |
771 | |
772 void ContentDecryptorDelegate::OnSessionExpirationChange( | |
773 PP_Var web_session_id, | |
774 PP_Time new_expiry_time) { | |
775 // TODO(jrummell): Pass this event on. | |
776 } | |
777 | |
696 void ContentDecryptorDelegate::OnSessionReady(PP_Var web_session_id) { | 778 void ContentDecryptorDelegate::OnSessionReady(PP_Var web_session_id) { |
697 if (session_ready_cb_.is_null()) | 779 if (session_ready_cb_.is_null()) |
698 return; | 780 return; |
699 | 781 |
700 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); | 782 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); |
701 DCHECK(web_session_id_string); | 783 DCHECK(web_session_id_string); |
702 | 784 |
703 session_ready_cb_.Run(web_session_id_string->value()); | 785 session_ready_cb_.Run(web_session_id_string->value()); |
704 } | 786 } |
705 | 787 |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1174 | 1256 |
1175 scoped_ptr<CdmPromise> ContentDecryptorDelegate::TakePromise( | 1257 scoped_ptr<CdmPromise> ContentDecryptorDelegate::TakePromise( |
1176 uint32_t promise_id) { | 1258 uint32_t promise_id) { |
1177 PromiseMap::iterator it = promises_.find(promise_id); | 1259 PromiseMap::iterator it = promises_.find(promise_id); |
1178 if (it == promises_.end()) | 1260 if (it == promises_.end()) |
1179 return scoped_ptr<CdmPromise>(); | 1261 return scoped_ptr<CdmPromise>(); |
1180 return promises_.take_and_erase(it); | 1262 return promises_.take_and_erase(it); |
1181 } | 1263 } |
1182 | 1264 |
1183 } // namespace content | 1265 } // namespace content |
OLD | NEW |