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); | |
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->Type() == media::CdmPromise::SIMPLE_TYPE); |
ddorwin
2014/08/25 22:55:01
promise && ?
If you can't do that, this could cras
jrummell
2014/08/26 00:19:23
Done.
| |
660 if (promise && promise->Type() == media::CdmPromise::SIMPLE_TYPE) { | |
629 SimpleCdmPromise* simple_promise( | 661 SimpleCdmPromise* simple_promise( |
630 static_cast<SimpleCdmPromise*>(promise.get())); | 662 static_cast<SimpleCdmPromise*>(promise.get())); |
631 simple_promise->resolve(); | 663 simple_promise->resolve(); |
632 } | 664 } |
633 } | 665 } |
634 | 666 |
635 void ContentDecryptorDelegate::OnPromiseResolvedWithSession( | 667 void ContentDecryptorDelegate::OnPromiseResolvedWithSession( |
636 uint32 promise_id, | 668 uint32 promise_id, |
637 PP_Var web_session_id) { | 669 PP_Var web_session_id) { |
638 scoped_ptr<CdmPromise> promise = TakePromise(promise_id); | 670 scoped_ptr<CdmPromise> promise = TakePromise(promise_id); |
639 | 671 |
640 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); | 672 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); |
641 DCHECK(web_session_id_string); | 673 DCHECK(web_session_id_string); |
642 | 674 |
643 if (promise) { | 675 DCHECK(promise->Type() == media::CdmPromise::NEW_SESSION_TYPE); |
ddorwin
2014/08/25 22:55:01
ditto
jrummell
2014/08/26 00:19:23
Done.
| |
676 if (promise && promise->Type() == media::CdmPromise::NEW_SESSION_TYPE) { | |
644 NewSessionCdmPromise* session_promise( | 677 NewSessionCdmPromise* session_promise( |
645 static_cast<NewSessionCdmPromise*>(promise.get())); | 678 static_cast<NewSessionCdmPromise*>(promise.get())); |
646 session_promise->resolve(web_session_id_string->value()); | 679 session_promise->resolve(web_session_id_string->value()); |
647 } | 680 } |
648 } | 681 } |
649 | 682 |
683 void ContentDecryptorDelegate::OnPromiseResolvedWithKeyIds( | |
684 uint32 promise_id, | |
685 PP_Var key_ids_array) { | |
686 scoped_ptr<CdmPromise> promise = TakePromise(promise_id); | |
687 | |
688 ArrayVar* key_ids = ArrayVar::FromPPVar(key_ids_array); | |
689 media::KeyIdsVector key_ids_vector; | |
690 DCHECK(key_ids); | |
691 if (key_ids) { | |
692 for (size_t i = 0; i < key_ids->GetLength(); ++i) { | |
693 ArrayBufferVar* array_buffer = ArrayBufferVar::FromPPVar(key_ids->Get(i)); | |
694 DCHECK(array_buffer); | |
695 if (array_buffer) { | |
696 std::vector<uint8> key_id; | |
697 const uint8* data = static_cast<const uint8*>(array_buffer->Map()); | |
698 key_id.assign(data, data + array_buffer->ByteLength()); | |
699 key_ids_vector.push_back(key_id); | |
700 } | |
701 } | |
702 } | |
703 | |
704 DCHECK(promise->Type() == media::CdmPromise::KEY_IDS_TYPE); | |
ddorwin
2014/08/25 22:55:01
ditto
jrummell
2014/08/26 00:19:23
Done.
| |
705 if (promise && promise->Type() == media::CdmPromise::KEY_IDS_TYPE) { | |
706 KeyIdsPromise* key_ids_promise(static_cast<KeyIdsPromise*>(promise.get())); | |
707 key_ids_promise->resolve(key_ids_vector); | |
708 } | |
709 } | |
710 | |
650 void ContentDecryptorDelegate::OnPromiseRejected( | 711 void ContentDecryptorDelegate::OnPromiseRejected( |
651 uint32 promise_id, | 712 uint32 promise_id, |
652 PP_CdmExceptionCode exception_code, | 713 PP_CdmExceptionCode exception_code, |
653 uint32 system_code, | 714 uint32 system_code, |
654 PP_Var error_description) { | 715 PP_Var error_description) { |
655 StringVar* error_description_string = StringVar::FromPPVar(error_description); | 716 StringVar* error_description_string = StringVar::FromPPVar(error_description); |
656 DCHECK(error_description_string); | 717 DCHECK(error_description_string); |
657 | 718 |
658 scoped_ptr<CdmPromise> promise = TakePromise(promise_id); | 719 scoped_ptr<CdmPromise> promise = TakePromise(promise_id); |
720 DCHECK(promise); | |
659 if (promise) { | 721 if (promise) { |
660 promise->reject(PpExceptionTypeToMediaException(exception_code), | 722 promise->reject(PpExceptionTypeToMediaException(exception_code), |
661 system_code, | 723 system_code, |
662 error_description_string->value()); | 724 error_description_string->value()); |
663 } | 725 } |
664 } | 726 } |
665 | 727 |
666 void ContentDecryptorDelegate::OnSessionMessage(PP_Var web_session_id, | 728 void ContentDecryptorDelegate::OnSessionMessage(PP_Var web_session_id, |
667 PP_Var message, | 729 PP_Var message, |
668 PP_Var destination_url) { | 730 PP_Var destination_url) { |
(...skipping 17 matching lines...) Expand all Loading... | |
686 if (!verified_gurl.is_valid() && !verified_gurl.is_empty()) { | 748 if (!verified_gurl.is_valid() && !verified_gurl.is_empty()) { |
687 DLOG(WARNING) << "SessionMessage default_url is invalid : " | 749 DLOG(WARNING) << "SessionMessage default_url is invalid : " |
688 << verified_gurl.possibly_invalid_spec(); | 750 << verified_gurl.possibly_invalid_spec(); |
689 verified_gurl = GURL::EmptyGURL(); // Replace invalid destination_url. | 751 verified_gurl = GURL::EmptyGURL(); // Replace invalid destination_url. |
690 } | 752 } |
691 | 753 |
692 session_message_cb_.Run( | 754 session_message_cb_.Run( |
693 web_session_id_string->value(), message_vector, verified_gurl); | 755 web_session_id_string->value(), message_vector, verified_gurl); |
694 } | 756 } |
695 | 757 |
758 void ContentDecryptorDelegate::OnSessionKeysChange( | |
759 PP_Var web_session_id, | |
760 PP_Bool has_additional_usable_key) { | |
761 // TODO(jrummell): Pass this event on. | |
762 } | |
763 | |
764 void ContentDecryptorDelegate::OnSessionExpirationChange( | |
765 PP_Var web_session_id, | |
766 PP_Time new_expiry_time) { | |
767 // TODO(jrummell): Pass this event on. | |
768 } | |
769 | |
696 void ContentDecryptorDelegate::OnSessionReady(PP_Var web_session_id) { | 770 void ContentDecryptorDelegate::OnSessionReady(PP_Var web_session_id) { |
697 if (session_ready_cb_.is_null()) | 771 if (session_ready_cb_.is_null()) |
698 return; | 772 return; |
699 | 773 |
700 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); | 774 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); |
701 DCHECK(web_session_id_string); | 775 DCHECK(web_session_id_string); |
702 | 776 |
703 session_ready_cb_.Run(web_session_id_string->value()); | 777 session_ready_cb_.Run(web_session_id_string->value()); |
704 } | 778 } |
705 | 779 |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1174 | 1248 |
1175 scoped_ptr<CdmPromise> ContentDecryptorDelegate::TakePromise( | 1249 scoped_ptr<CdmPromise> ContentDecryptorDelegate::TakePromise( |
1176 uint32_t promise_id) { | 1250 uint32_t promise_id) { |
1177 PromiseMap::iterator it = promises_.find(promise_id); | 1251 PromiseMap::iterator it = promises_.find(promise_id); |
1178 if (it == promises_.end()) | 1252 if (it == promises_.end()) |
1179 return scoped_ptr<CdmPromise>(); | 1253 return scoped_ptr<CdmPromise>(); |
1180 return promises_.take_and_erase(it); | 1254 return promises_.take_and_erase(it); |
1181 } | 1255 } |
1182 | 1256 |
1183 } // namespace content | 1257 } // namespace content |
OLD | NEW |