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::GetUsableKeyIds( |
391 const std::string& web_session_id, | |
392 scoped_ptr<media::KeyIdsPromise> promise) { | |
393 uint32_t promise_id = SavePromise(promise.PassAs<CdmPromise>()); | |
394 plugin_decryption_interface_->GetUsableKeyIds( | |
395 pp_instance_, promise_id, StringVar::StringToPPVar(web_session_id)); | |
396 } | |
397 | |
398 void ContentDecryptorDelegate::CloseSession( | |
376 const std::string& web_session_id, | 399 const std::string& web_session_id, |
377 scoped_ptr<SimpleCdmPromise> promise) { | 400 scoped_ptr<SimpleCdmPromise> promise) { |
378 uint32_t promise_id = SavePromise(promise.PassAs<CdmPromise>()); | 401 uint32_t promise_id = SavePromise(promise.PassAs<CdmPromise>()); |
379 plugin_decryption_interface_->ReleaseSession( | 402 plugin_decryption_interface_->CloseSession( |
380 pp_instance_, promise_id, StringVar::StringToPPVar(web_session_id)); | 403 pp_instance_, promise_id, StringVar::StringToPPVar(web_session_id)); |
381 } | 404 } |
382 | 405 |
406 void ContentDecryptorDelegate::RemoveSession( | |
407 const std::string& web_session_id, | |
408 scoped_ptr<SimpleCdmPromise> promise) { | |
409 uint32_t promise_id = SavePromise(promise.PassAs<CdmPromise>()); | |
410 plugin_decryption_interface_->RemoveSession( | |
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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
640 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); | 671 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); |
641 DCHECK(web_session_id_string); | 672 DCHECK(web_session_id_string); |
642 | 673 |
643 if (promise) { | 674 if (promise) { |
644 NewSessionCdmPromise* session_promise( | 675 NewSessionCdmPromise* session_promise( |
645 static_cast<NewSessionCdmPromise*>(promise.get())); | 676 static_cast<NewSessionCdmPromise*>(promise.get())); |
646 session_promise->resolve(web_session_id_string->value()); | 677 session_promise->resolve(web_session_id_string->value()); |
647 } | 678 } |
648 } | 679 } |
649 | 680 |
681 void ContentDecryptorDelegate::OnPromiseResolvedWithKeyIds(uint32 promise_id, | |
682 PP_Var key_ids) { | |
ddorwin
2014/08/22 20:49:20
..._array?
jrummell
2014/08/25 21:54:36
Done.
| |
683 scoped_ptr<CdmPromise> promise = TakePromise(promise_id); | |
684 | |
685 ArrayVar* key_ids_array = ArrayVar::FromPPVar(key_ids); | |
686 media::KeyIdsVector key_ids_vector; | |
687 if (key_ids_array) { | |
ddorwin
2014/08/22 20:49:20
DCHECK? Or can this be null if the array is empty?
jrummell
2014/08/25 21:54:36
Done.
| |
688 for (size_t i = 0; i < key_ids_array->GetLength(); ++i) { | |
689 ArrayBufferVar* array_buffer = | |
690 ArrayBufferVar::FromPPVar(key_ids_array->Get(i)); | |
691 if (array_buffer) { | |
ddorwin
2014/08/22 20:49:20
DCHECK?
jrummell
2014/08/25 21:54:36
Done.
| |
692 std::vector<uint8> item; | |
ddorwin
2014/08/22 20:49:20
How about key_id?
jrummell
2014/08/25 21:54:36
Done.
| |
693 const uint8* data = static_cast<const uint8*>(array_buffer->Map()); | |
694 item.assign(data, data + array_buffer->ByteLength()); | |
695 key_ids_vector.push_back(item); | |
696 } | |
697 } | |
698 } | |
699 | |
700 if (promise) { | |
ddorwin
2014/08/22 20:49:20
DCHECK?
I wonder why existing code does not have t
jrummell
2014/08/25 21:54:36
The other OnPromise...() do check that promise is
| |
701 KeyIdsPromise* key_ids_promise(static_cast<KeyIdsPromise*>(promise.get())); | |
ddorwin
2014/08/22 20:49:20
This promise ID is coming from a plugin process, w
jrummell
2014/08/25 21:54:36
Added type on CdmPromise so it can be verified.
| |
702 key_ids_promise->resolve(key_ids_vector); | |
703 } | |
704 } | |
705 | |
650 void ContentDecryptorDelegate::OnPromiseRejected( | 706 void ContentDecryptorDelegate::OnPromiseRejected( |
651 uint32 promise_id, | 707 uint32 promise_id, |
652 PP_CdmExceptionCode exception_code, | 708 PP_CdmExceptionCode exception_code, |
653 uint32 system_code, | 709 uint32 system_code, |
654 PP_Var error_description) { | 710 PP_Var error_description) { |
655 StringVar* error_description_string = StringVar::FromPPVar(error_description); | 711 StringVar* error_description_string = StringVar::FromPPVar(error_description); |
656 DCHECK(error_description_string); | 712 DCHECK(error_description_string); |
657 | 713 |
658 scoped_ptr<CdmPromise> promise = TakePromise(promise_id); | 714 scoped_ptr<CdmPromise> promise = TakePromise(promise_id); |
659 if (promise) { | 715 if (promise) { |
(...skipping 26 matching lines...) Expand all Loading... | |
686 if (!verified_gurl.is_valid() && !verified_gurl.is_empty()) { | 742 if (!verified_gurl.is_valid() && !verified_gurl.is_empty()) { |
687 DLOG(WARNING) << "SessionMessage default_url is invalid : " | 743 DLOG(WARNING) << "SessionMessage default_url is invalid : " |
688 << verified_gurl.possibly_invalid_spec(); | 744 << verified_gurl.possibly_invalid_spec(); |
689 verified_gurl = GURL::EmptyGURL(); // Replace invalid destination_url. | 745 verified_gurl = GURL::EmptyGURL(); // Replace invalid destination_url. |
690 } | 746 } |
691 | 747 |
692 session_message_cb_.Run( | 748 session_message_cb_.Run( |
693 web_session_id_string->value(), message_vector, verified_gurl); | 749 web_session_id_string->value(), message_vector, verified_gurl); |
694 } | 750 } |
695 | 751 |
752 void ContentDecryptorDelegate::OnSessionKeysChange( | |
753 PP_Var web_session_id, | |
754 PP_Bool has_additional_usable_key) { | |
755 // TODO(jrummell): Pass this event on. | |
756 } | |
757 | |
758 void ContentDecryptorDelegate::OnSessionExpirationChange( | |
759 PP_Var web_session_id, | |
760 PP_Time new_expiry_time) { | |
761 // TODO(jrummell): Pass this event on. | |
762 } | |
763 | |
696 void ContentDecryptorDelegate::OnSessionReady(PP_Var web_session_id) { | 764 void ContentDecryptorDelegate::OnSessionReady(PP_Var web_session_id) { |
697 if (session_ready_cb_.is_null()) | 765 if (session_ready_cb_.is_null()) |
698 return; | 766 return; |
699 | 767 |
700 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); | 768 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); |
701 DCHECK(web_session_id_string); | 769 DCHECK(web_session_id_string); |
702 | 770 |
703 session_ready_cb_.Run(web_session_id_string->value()); | 771 session_ready_cb_.Run(web_session_id_string->value()); |
704 } | 772 } |
705 | 773 |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1174 | 1242 |
1175 scoped_ptr<CdmPromise> ContentDecryptorDelegate::TakePromise( | 1243 scoped_ptr<CdmPromise> ContentDecryptorDelegate::TakePromise( |
1176 uint32_t promise_id) { | 1244 uint32_t promise_id) { |
1177 PromiseMap::iterator it = promises_.find(promise_id); | 1245 PromiseMap::iterator it = promises_.find(promise_id); |
1178 if (it == promises_.end()) | 1246 if (it == promises_.end()) |
1179 return scoped_ptr<CdmPromise>(); | 1247 return scoped_ptr<CdmPromise>(); |
1180 return promises_.take_and_erase(it); | 1248 return promises_.take_and_erase(it); |
1181 } | 1249 } |
1182 | 1250 |
1183 } // namespace content | 1251 } // namespace content |
OLD | NEW |