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/limits.h" |
20 #include "media/base/video_decoder_config.h" | 21 #include "media/base/video_decoder_config.h" |
21 #include "media/base/video_frame.h" | 22 #include "media/base/video_frame.h" |
22 #include "media/base/video_util.h" | 23 #include "media/base/video_util.h" |
| 24 #include "ppapi/shared_impl/array_var.h" |
23 #include "ppapi/shared_impl/scoped_pp_resource.h" | 25 #include "ppapi/shared_impl/scoped_pp_resource.h" |
24 #include "ppapi/shared_impl/var.h" | 26 #include "ppapi/shared_impl/var.h" |
25 #include "ppapi/shared_impl/var_tracker.h" | 27 #include "ppapi/shared_impl/var_tracker.h" |
26 #include "ppapi/thunk/enter.h" | 28 #include "ppapi/thunk/enter.h" |
27 #include "ppapi/thunk/ppb_buffer_api.h" | 29 #include "ppapi/thunk/ppb_buffer_api.h" |
28 #include "ui/gfx/rect.h" | 30 #include "ui/gfx/rect.h" |
29 | 31 |
30 using media::CdmPromise; | 32 using media::CdmPromise; |
31 using media::Decryptor; | 33 using media::Decryptor; |
| 34 using media::KeyIdsPromise; |
32 using media::MediaKeys; | 35 using media::MediaKeys; |
33 using media::NewSessionCdmPromise; | 36 using media::NewSessionCdmPromise; |
34 using media::SimpleCdmPromise; | 37 using media::SimpleCdmPromise; |
35 using ppapi::ArrayBufferVar; | 38 using ppapi::ArrayBufferVar; |
| 39 using ppapi::ArrayVar; |
36 using ppapi::PpapiGlobals; | 40 using ppapi::PpapiGlobals; |
37 using ppapi::ScopedPPResource; | 41 using ppapi::ScopedPPResource; |
38 using ppapi::StringVar; | 42 using ppapi::StringVar; |
39 using ppapi::thunk::EnterResourceNoLock; | 43 using ppapi::thunk::EnterResourceNoLock; |
40 using ppapi::thunk::PPB_Buffer_API; | 44 using ppapi::thunk::PPB_Buffer_API; |
41 | 45 |
42 namespace content { | 46 namespace content { |
43 | 47 |
44 namespace { | 48 namespace { |
45 | 49 |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 | 327 |
324 plugin_decryption_interface_->Initialize( | 328 plugin_decryption_interface_->Initialize( |
325 pp_instance_, StringVar::StringToPPVar(key_system_)); | 329 pp_instance_, StringVar::StringToPPVar(key_system_)); |
326 } | 330 } |
327 | 331 |
328 void ContentDecryptorDelegate::InstanceCrashed() { | 332 void ContentDecryptorDelegate::InstanceCrashed() { |
329 fatal_plugin_error_cb_.Run(); | 333 fatal_plugin_error_cb_.Run(); |
330 SatisfyAllPendingCallbacksOnError(); | 334 SatisfyAllPendingCallbacksOnError(); |
331 } | 335 } |
332 | 336 |
| 337 void ContentDecryptorDelegate::SetServerCertificate( |
| 338 const uint8_t* certificate, |
| 339 uint32_t certificate_length, |
| 340 scoped_ptr<media::SimpleCdmPromise> promise) { |
| 341 if (!certificate || |
| 342 certificate_length < media::limits::kMinCertificateLength || |
| 343 certificate_length > media::limits::kMaxCertificateLength) { |
| 344 promise->reject( |
| 345 media::MediaKeys::INVALID_ACCESS_ERROR, 0, "Incorrect certificate."); |
| 346 return; |
| 347 } |
| 348 |
| 349 uint32_t promise_id = SavePromise(promise.PassAs<CdmPromise>()); |
| 350 PP_Var certificate_array = |
| 351 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( |
| 352 certificate_length, certificate); |
| 353 plugin_decryption_interface_->SetServerCertificate( |
| 354 pp_instance_, promise_id, certificate_array); |
| 355 } |
| 356 |
333 void ContentDecryptorDelegate::CreateSession( | 357 void ContentDecryptorDelegate::CreateSession( |
334 const std::string& init_data_type, | 358 const std::string& init_data_type, |
335 const uint8* init_data, | 359 const uint8* init_data, |
336 int init_data_length, | 360 int init_data_length, |
337 MediaKeys::SessionType session_type, | 361 MediaKeys::SessionType session_type, |
338 scoped_ptr<NewSessionCdmPromise> promise) { | 362 scoped_ptr<NewSessionCdmPromise> promise) { |
339 uint32_t promise_id = SavePromise(promise.PassAs<CdmPromise>()); | 363 uint32_t promise_id = SavePromise(promise.PassAs<CdmPromise>()); |
340 PP_Var init_data_array = | 364 PP_Var init_data_array = |
341 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( | 365 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( |
342 init_data_length, init_data); | 366 init_data_length, init_data); |
(...skipping 22 matching lines...) Expand all Loading... |
365 PP_Var response_array = | 389 PP_Var response_array = |
366 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( | 390 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( |
367 response_length, response); | 391 response_length, response); |
368 plugin_decryption_interface_->UpdateSession( | 392 plugin_decryption_interface_->UpdateSession( |
369 pp_instance_, | 393 pp_instance_, |
370 promise_id, | 394 promise_id, |
371 StringVar::StringToPPVar(web_session_id), | 395 StringVar::StringToPPVar(web_session_id), |
372 response_array); | 396 response_array); |
373 } | 397 } |
374 | 398 |
375 void ContentDecryptorDelegate::ReleaseSession( | 399 void ContentDecryptorDelegate::CloseSession( |
376 const std::string& web_session_id, | 400 const std::string& web_session_id, |
377 scoped_ptr<SimpleCdmPromise> promise) { | 401 scoped_ptr<SimpleCdmPromise> promise) { |
| 402 if (web_session_id.length() > media::limits::kMaxWebSessionIdLength) { |
| 403 promise->reject( |
| 404 media::MediaKeys::INVALID_ACCESS_ERROR, 0, "Incorrect session."); |
| 405 return; |
| 406 } |
| 407 |
378 uint32_t promise_id = SavePromise(promise.PassAs<CdmPromise>()); | 408 uint32_t promise_id = SavePromise(promise.PassAs<CdmPromise>()); |
379 plugin_decryption_interface_->ReleaseSession( | 409 plugin_decryption_interface_->CloseSession( |
380 pp_instance_, promise_id, StringVar::StringToPPVar(web_session_id)); | 410 pp_instance_, promise_id, StringVar::StringToPPVar(web_session_id)); |
381 } | 411 } |
382 | 412 |
| 413 void ContentDecryptorDelegate::RemoveSession( |
| 414 const std::string& web_session_id, |
| 415 scoped_ptr<SimpleCdmPromise> promise) { |
| 416 if (web_session_id.length() > media::limits::kMaxWebSessionIdLength) { |
| 417 promise->reject( |
| 418 media::MediaKeys::INVALID_ACCESS_ERROR, 0, "Incorrect session."); |
| 419 return; |
| 420 } |
| 421 |
| 422 uint32_t promise_id = SavePromise(promise.PassAs<CdmPromise>()); |
| 423 plugin_decryption_interface_->RemoveSession( |
| 424 pp_instance_, promise_id, StringVar::StringToPPVar(web_session_id)); |
| 425 } |
| 426 |
| 427 void ContentDecryptorDelegate::GetUsableKeyIds( |
| 428 const std::string& web_session_id, |
| 429 scoped_ptr<media::KeyIdsPromise> promise) { |
| 430 if (web_session_id.length() > media::limits::kMaxWebSessionIdLength) { |
| 431 promise->reject( |
| 432 media::MediaKeys::INVALID_ACCESS_ERROR, 0, "Incorrect session."); |
| 433 return; |
| 434 } |
| 435 |
| 436 uint32_t promise_id = SavePromise(promise.PassAs<CdmPromise>()); |
| 437 plugin_decryption_interface_->GetUsableKeyIds( |
| 438 pp_instance_, promise_id, StringVar::StringToPPVar(web_session_id)); |
| 439 } |
| 440 |
383 // TODO(xhwang): Remove duplication of code in Decrypt(), | 441 // TODO(xhwang): Remove duplication of code in Decrypt(), |
384 // DecryptAndDecodeAudio() and DecryptAndDecodeVideo(). | 442 // DecryptAndDecodeAudio() and DecryptAndDecodeVideo(). |
385 bool ContentDecryptorDelegate::Decrypt( | 443 bool ContentDecryptorDelegate::Decrypt( |
386 Decryptor::StreamType stream_type, | 444 Decryptor::StreamType stream_type, |
387 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, | 445 const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
388 const Decryptor::DecryptCB& decrypt_cb) { | 446 const Decryptor::DecryptCB& decrypt_cb) { |
389 DVLOG(3) << "Decrypt() - stream_type: " << stream_type; | 447 DVLOG(3) << "Decrypt() - stream_type: " << stream_type; |
390 | 448 |
391 // |{audio|video}_input_resource_| is not being used by the plugin | 449 // |{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 | 450 // now because there is only one pending audio/video decrypt request at any |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 } | 718 } |
661 | 719 |
662 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); | 720 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); |
663 DCHECK(web_session_id_string); | 721 DCHECK(web_session_id_string); |
664 | 722 |
665 NewSessionCdmPromise* session_promise = | 723 NewSessionCdmPromise* session_promise = |
666 static_cast<NewSessionCdmPromise*>(promise.get()); | 724 static_cast<NewSessionCdmPromise*>(promise.get()); |
667 session_promise->resolve(web_session_id_string->value()); | 725 session_promise->resolve(web_session_id_string->value()); |
668 } | 726 } |
669 | 727 |
| 728 void ContentDecryptorDelegate::OnPromiseResolvedWithKeyIds( |
| 729 uint32 promise_id, |
| 730 PP_Var key_ids_array) { |
| 731 scoped_ptr<CdmPromise> promise = TakePromise(promise_id); |
| 732 |
| 733 ArrayVar* key_ids = ArrayVar::FromPPVar(key_ids_array); |
| 734 DCHECK(key_ids && key_ids->GetLength() <= media::limits::kMaxKeyIds); |
| 735 media::KeyIdsVector key_ids_vector; |
| 736 if (key_ids && key_ids->GetLength() <= media::limits::kMaxKeyIds) { |
| 737 for (size_t i = 0; i < key_ids->GetLength(); ++i) { |
| 738 ArrayBufferVar* array_buffer = ArrayBufferVar::FromPPVar(key_ids->Get(i)); |
| 739 |
| 740 if (!array_buffer || |
| 741 array_buffer->ByteLength() < media::limits::kMinKeyIdLength || |
| 742 array_buffer->ByteLength() > media::limits::kMaxKeyIdLength) { |
| 743 NOTREACHED(); |
| 744 continue; |
| 745 } |
| 746 |
| 747 std::vector<uint8> key_id; |
| 748 const uint8* data = static_cast<const uint8*>(array_buffer->Map()); |
| 749 key_id.assign(data, data + array_buffer->ByteLength()); |
| 750 key_ids_vector.push_back(key_id); |
| 751 } |
| 752 } |
| 753 |
| 754 if (!promise || |
| 755 promise->GetResolveParameterType() != |
| 756 media::CdmPromise::KEY_IDS_VECTOR_TYPE) { |
| 757 NOTREACHED(); |
| 758 return; |
| 759 } |
| 760 |
| 761 KeyIdsPromise* key_ids_promise(static_cast<KeyIdsPromise*>(promise.get())); |
| 762 key_ids_promise->resolve(key_ids_vector); |
| 763 } |
| 764 |
670 void ContentDecryptorDelegate::OnPromiseRejected( | 765 void ContentDecryptorDelegate::OnPromiseRejected( |
671 uint32 promise_id, | 766 uint32 promise_id, |
672 PP_CdmExceptionCode exception_code, | 767 PP_CdmExceptionCode exception_code, |
673 uint32 system_code, | 768 uint32 system_code, |
674 PP_Var error_description) { | 769 PP_Var error_description) { |
675 StringVar* error_description_string = StringVar::FromPPVar(error_description); | 770 StringVar* error_description_string = StringVar::FromPPVar(error_description); |
676 DCHECK(error_description_string); | 771 DCHECK(error_description_string); |
677 | 772 |
678 scoped_ptr<CdmPromise> promise = TakePromise(promise_id); | 773 scoped_ptr<CdmPromise> promise = TakePromise(promise_id); |
| 774 DCHECK(promise); |
679 if (promise) { | 775 if (promise) { |
680 promise->reject(PpExceptionTypeToMediaException(exception_code), | 776 promise->reject(PpExceptionTypeToMediaException(exception_code), |
681 system_code, | 777 system_code, |
682 error_description_string->value()); | 778 error_description_string->value()); |
683 } | 779 } |
684 } | 780 } |
685 | 781 |
686 void ContentDecryptorDelegate::OnSessionMessage(PP_Var web_session_id, | 782 void ContentDecryptorDelegate::OnSessionMessage(PP_Var web_session_id, |
687 PP_Var message, | 783 PP_Var message, |
688 PP_Var destination_url) { | 784 PP_Var destination_url) { |
(...skipping 17 matching lines...) Expand all Loading... |
706 if (!verified_gurl.is_valid() && !verified_gurl.is_empty()) { | 802 if (!verified_gurl.is_valid() && !verified_gurl.is_empty()) { |
707 DLOG(WARNING) << "SessionMessage default_url is invalid : " | 803 DLOG(WARNING) << "SessionMessage default_url is invalid : " |
708 << verified_gurl.possibly_invalid_spec(); | 804 << verified_gurl.possibly_invalid_spec(); |
709 verified_gurl = GURL::EmptyGURL(); // Replace invalid destination_url. | 805 verified_gurl = GURL::EmptyGURL(); // Replace invalid destination_url. |
710 } | 806 } |
711 | 807 |
712 session_message_cb_.Run( | 808 session_message_cb_.Run( |
713 web_session_id_string->value(), message_vector, verified_gurl); | 809 web_session_id_string->value(), message_vector, verified_gurl); |
714 } | 810 } |
715 | 811 |
| 812 void ContentDecryptorDelegate::OnSessionKeysChange( |
| 813 PP_Var web_session_id, |
| 814 PP_Bool has_additional_usable_key) { |
| 815 // TODO(jrummell): Pass this event on. |
| 816 } |
| 817 |
| 818 void ContentDecryptorDelegate::OnSessionExpirationChange( |
| 819 PP_Var web_session_id, |
| 820 PP_Time new_expiry_time) { |
| 821 // TODO(jrummell): Pass this event on. |
| 822 } |
| 823 |
716 void ContentDecryptorDelegate::OnSessionReady(PP_Var web_session_id) { | 824 void ContentDecryptorDelegate::OnSessionReady(PP_Var web_session_id) { |
717 if (session_ready_cb_.is_null()) | 825 if (session_ready_cb_.is_null()) |
718 return; | 826 return; |
719 | 827 |
720 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); | 828 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); |
721 DCHECK(web_session_id_string); | 829 DCHECK(web_session_id_string); |
722 | 830 |
723 session_ready_cb_.Run(web_session_id_string->value()); | 831 session_ready_cb_.Run(web_session_id_string->value()); |
724 } | 832 } |
725 | 833 |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1194 | 1302 |
1195 scoped_ptr<CdmPromise> ContentDecryptorDelegate::TakePromise( | 1303 scoped_ptr<CdmPromise> ContentDecryptorDelegate::TakePromise( |
1196 uint32_t promise_id) { | 1304 uint32_t promise_id) { |
1197 PromiseMap::iterator it = promises_.find(promise_id); | 1305 PromiseMap::iterator it = promises_.find(promise_id); |
1198 if (it == promises_.end()) | 1306 if (it == promises_.end()) |
1199 return scoped_ptr<CdmPromise>(); | 1307 return scoped_ptr<CdmPromise>(); |
1200 return promises_.take_and_erase(it); | 1308 return promises_.take_and_erase(it); |
1201 } | 1309 } |
1202 | 1310 |
1203 } // namespace content | 1311 } // namespace content |
OLD | NEW |