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/metrics/sparse_histogram.h" | 10 #include "base/metrics/sparse_histogram.h" |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 case PP_DECRYPTEDSAMPLEFORMAT_PLANAR_F32: | 249 case PP_DECRYPTEDSAMPLEFORMAT_PLANAR_F32: |
250 return media::kSampleFormatPlanarF32; | 250 return media::kSampleFormatPlanarF32; |
251 default: | 251 default: |
252 NOTREACHED(); | 252 NOTREACHED(); |
253 return media::kUnknownSampleFormat; | 253 return media::kUnknownSampleFormat; |
254 } | 254 } |
255 } | 255 } |
256 | 256 |
257 PP_SessionType MediaSessionTypeToPpSessionType( | 257 PP_SessionType MediaSessionTypeToPpSessionType( |
258 MediaKeys::SessionType session_type) { | 258 MediaKeys::SessionType session_type) { |
| 259 // TODO(jrummell): Add support for PP_SESSIONTYPE_RELEASE_LICENSE. |
259 switch (session_type) { | 260 switch (session_type) { |
260 case MediaKeys::TEMPORARY_SESSION: | 261 case MediaKeys::TEMPORARY_SESSION: |
261 return PP_SESSIONTYPE_TEMPORARY; | 262 return PP_SESSIONTYPE_TEMPORARY; |
262 case MediaKeys::PERSISTENT_SESSION: | 263 case MediaKeys::PERSISTENT_SESSION: |
263 return PP_SESSIONTYPE_PERSISTENT; | 264 return PP_SESSIONTYPE_PERSISTENT_LICENSE; |
264 default: | 265 default: |
265 NOTREACHED(); | 266 NOTREACHED(); |
266 return PP_SESSIONTYPE_TEMPORARY; | 267 return PP_SESSIONTYPE_TEMPORARY; |
267 } | 268 } |
268 } | 269 } |
269 | 270 |
270 MediaKeys::Exception PpExceptionTypeToMediaException( | 271 MediaKeys::Exception PpExceptionTypeToMediaException( |
271 PP_CdmExceptionCode exception_code) { | 272 PP_CdmExceptionCode exception_code) { |
272 switch (exception_code) { | 273 switch (exception_code) { |
273 case PP_CDMEXCEPTIONCODE_NOTSUPPORTEDERROR: | 274 case PP_CDMEXCEPTIONCODE_NOTSUPPORTEDERROR: |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 audio_channel_layout_(media::CHANNEL_LAYOUT_NONE), | 314 audio_channel_layout_(media::CHANNEL_LAYOUT_NONE), |
314 next_promise_id_(1), | 315 next_promise_id_(1), |
315 weak_ptr_factory_(this) { | 316 weak_ptr_factory_(this) { |
316 weak_this_ = weak_ptr_factory_.GetWeakPtr(); | 317 weak_this_ = weak_ptr_factory_.GetWeakPtr(); |
317 } | 318 } |
318 | 319 |
319 ContentDecryptorDelegate::~ContentDecryptorDelegate() { | 320 ContentDecryptorDelegate::~ContentDecryptorDelegate() { |
320 SatisfyAllPendingCallbacksOnError(); | 321 SatisfyAllPendingCallbacksOnError(); |
321 } | 322 } |
322 | 323 |
| 324 // TODO(jrummell): Remove |session_ready_cb| and |session_keys_change_cb|. |
323 void ContentDecryptorDelegate::Initialize( | 325 void ContentDecryptorDelegate::Initialize( |
324 const std::string& key_system, | 326 const std::string& key_system, |
325 const media::SessionMessageCB& session_message_cb, | 327 const media::SessionMessageCB& session_message_cb, |
326 const media::SessionClosedCB& session_closed_cb, | 328 const media::SessionClosedCB& session_closed_cb, |
327 const media::SessionErrorCB& session_error_cb, | 329 const media::SessionErrorCB& session_error_cb, |
328 const media::SessionKeysChangeCB& session_keys_change_cb, | 330 const media::SessionKeysChangeCB& session_keys_change_cb, |
329 const media::SessionExpirationUpdateCB& session_expiration_update_cb, | 331 const media::SessionExpirationUpdateCB& session_expiration_update_cb, |
330 const base::Closure& fatal_plugin_error_cb) { | 332 const base::Closure& fatal_plugin_error_cb) { |
331 DCHECK(!key_system.empty()); | 333 DCHECK(!key_system.empty()); |
332 DCHECK(key_system_.empty()); | 334 DCHECK(key_system_.empty()); |
(...skipping 28 matching lines...) Expand all Loading... |
361 } | 363 } |
362 | 364 |
363 uint32_t promise_id = SavePromise(promise.Pass()); | 365 uint32_t promise_id = SavePromise(promise.Pass()); |
364 PP_Var certificate_array = | 366 PP_Var certificate_array = |
365 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( | 367 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( |
366 certificate_length, certificate); | 368 certificate_length, certificate); |
367 plugin_decryption_interface_->SetServerCertificate( | 369 plugin_decryption_interface_->SetServerCertificate( |
368 pp_instance_, promise_id, certificate_array); | 370 pp_instance_, promise_id, certificate_array); |
369 } | 371 } |
370 | 372 |
| 373 // TODO(jrummell): Rename method to CreateSessionAndGenerateRequest() |
| 374 // and reorder parameter list. |
371 void ContentDecryptorDelegate::CreateSession( | 375 void ContentDecryptorDelegate::CreateSession( |
372 const std::string& init_data_type, | 376 const std::string& init_data_type, |
373 const uint8* init_data, | 377 const uint8* init_data, |
374 int init_data_length, | 378 int init_data_length, |
375 MediaKeys::SessionType session_type, | 379 MediaKeys::SessionType session_type, |
376 scoped_ptr<NewSessionCdmPromise> promise) { | 380 scoped_ptr<NewSessionCdmPromise> promise) { |
377 uint32_t promise_id = SavePromise(promise.Pass()); | 381 uint32_t promise_id = SavePromise(promise.Pass()); |
378 PP_Var init_data_array = | 382 PP_Var init_data_array = |
379 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( | 383 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( |
380 init_data_length, init_data); | 384 init_data_length, init_data); |
381 plugin_decryption_interface_->CreateSession( | 385 plugin_decryption_interface_->CreateSessionAndGenerateRequest( |
382 pp_instance_, | 386 pp_instance_, promise_id, MediaSessionTypeToPpSessionType(session_type), |
383 promise_id, | 387 StringVar::StringToPPVar(init_data_type), init_data_array); |
384 StringVar::StringToPPVar(init_data_type), | |
385 init_data_array, | |
386 MediaSessionTypeToPpSessionType(session_type)); | |
387 } | 388 } |
388 | 389 |
| 390 // TODO(jrummell): Pass |session_type| to this method. |
389 void ContentDecryptorDelegate::LoadSession( | 391 void ContentDecryptorDelegate::LoadSession( |
390 const std::string& web_session_id, | 392 const std::string& web_session_id, |
391 scoped_ptr<NewSessionCdmPromise> promise) { | 393 scoped_ptr<NewSessionCdmPromise> promise) { |
392 uint32_t promise_id = SavePromise(promise.Pass()); | 394 uint32_t promise_id = SavePromise(promise.Pass()); |
393 plugin_decryption_interface_->LoadSession( | 395 plugin_decryption_interface_->LoadSession( |
394 pp_instance_, promise_id, StringVar::StringToPPVar(web_session_id)); | 396 pp_instance_, promise_id, PP_SESSIONTYPE_PERSISTENT_LICENSE, |
| 397 StringVar::StringToPPVar(web_session_id)); |
395 } | 398 } |
396 | 399 |
397 void ContentDecryptorDelegate::UpdateSession( | 400 void ContentDecryptorDelegate::UpdateSession( |
398 const std::string& web_session_id, | 401 const std::string& web_session_id, |
399 const uint8* response, | 402 const uint8* response, |
400 int response_length, | 403 int response_length, |
401 scoped_ptr<SimpleCdmPromise> promise) { | 404 scoped_ptr<SimpleCdmPromise> promise) { |
402 uint32_t promise_id = SavePromise(promise.Pass()); | 405 uint32_t promise_id = SavePromise(promise.Pass()); |
403 PP_Var response_array = | 406 PP_Var response_array = |
404 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( | 407 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 } | 708 } |
706 | 709 |
707 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); | 710 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); |
708 DCHECK(web_session_id_string); | 711 DCHECK(web_session_id_string); |
709 | 712 |
710 NewSessionCdmPromise* session_promise = | 713 NewSessionCdmPromise* session_promise = |
711 static_cast<NewSessionCdmPromise*>(promise.get()); | 714 static_cast<NewSessionCdmPromise*>(promise.get()); |
712 session_promise->resolve(web_session_id_string->value()); | 715 session_promise->resolve(web_session_id_string->value()); |
713 } | 716 } |
714 | 717 |
715 void ContentDecryptorDelegate::OnPromiseResolvedWithKeyIds( | |
716 uint32 promise_id, | |
717 PP_Var key_ids_array) { | |
718 // Since there are no calls to GetUsableKeyIds(), this should never be called. | |
719 // FIXME(jrummell): remove once CDM interface updated. | |
720 NOTREACHED(); | |
721 } | |
722 | |
723 void ContentDecryptorDelegate::OnPromiseRejected( | 718 void ContentDecryptorDelegate::OnPromiseRejected( |
724 uint32 promise_id, | 719 uint32 promise_id, |
725 PP_CdmExceptionCode exception_code, | 720 PP_CdmExceptionCode exception_code, |
726 uint32 system_code, | 721 uint32 system_code, |
727 PP_Var error_description) { | 722 PP_Var error_description) { |
728 ReportSystemCodeUMA(key_system_, system_code); | 723 ReportSystemCodeUMA(key_system_, system_code); |
729 | 724 |
730 StringVar* error_description_string = StringVar::FromPPVar(error_description); | 725 StringVar* error_description_string = StringVar::FromPPVar(error_description); |
731 DCHECK(error_description_string); | 726 DCHECK(error_description_string); |
732 | 727 |
733 scoped_ptr<CdmPromise> promise = TakePromise(promise_id); | 728 scoped_ptr<CdmPromise> promise = TakePromise(promise_id); |
734 DCHECK(promise); | 729 DCHECK(promise); |
735 if (promise) { | 730 if (promise) { |
736 promise->reject(PpExceptionTypeToMediaException(exception_code), | 731 promise->reject(PpExceptionTypeToMediaException(exception_code), |
737 system_code, | 732 system_code, |
738 error_description_string->value()); | 733 error_description_string->value()); |
739 } | 734 } |
740 } | 735 } |
741 | 736 |
| 737 // TODO(jrummell): Pass |message_type| to the callback. |
742 void ContentDecryptorDelegate::OnSessionMessage(PP_Var web_session_id, | 738 void ContentDecryptorDelegate::OnSessionMessage(PP_Var web_session_id, |
743 PP_Var message, | 739 PP_CdmMessageType message_type, |
744 PP_Var destination_url) { | 740 PP_Var message) { |
745 if (session_message_cb_.is_null()) | 741 if (session_message_cb_.is_null()) |
746 return; | 742 return; |
747 | 743 |
748 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); | 744 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); |
749 DCHECK(web_session_id_string); | 745 DCHECK(web_session_id_string); |
750 | 746 |
751 ArrayBufferVar* message_array_buffer = ArrayBufferVar::FromPPVar(message); | 747 ArrayBufferVar* message_array_buffer = ArrayBufferVar::FromPPVar(message); |
752 std::vector<uint8> message_vector; | 748 std::vector<uint8> message_vector; |
753 if (message_array_buffer) { | 749 if (message_array_buffer) { |
754 const uint8* data = static_cast<const uint8*>(message_array_buffer->Map()); | 750 const uint8* data = static_cast<const uint8*>(message_array_buffer->Map()); |
755 message_vector.assign(data, data + message_array_buffer->ByteLength()); | 751 message_vector.assign(data, data + message_array_buffer->ByteLength()); |
756 } | 752 } |
757 | 753 |
758 StringVar* destination_url_string = StringVar::FromPPVar(destination_url); | 754 session_message_cb_.Run(web_session_id_string->value(), message_vector, |
759 DCHECK(destination_url_string); | 755 GURL::EmptyGURL()); |
760 | |
761 GURL verified_gurl = GURL(destination_url_string->value()); | |
762 if (!verified_gurl.is_valid() && !verified_gurl.is_empty()) { | |
763 DLOG(WARNING) << "SessionMessage default_url is invalid : " | |
764 << verified_gurl.possibly_invalid_spec(); | |
765 verified_gurl = GURL::EmptyGURL(); // Replace invalid destination_url. | |
766 } | |
767 | |
768 session_message_cb_.Run( | |
769 web_session_id_string->value(), message_vector, verified_gurl); | |
770 } | 756 } |
771 | 757 |
| 758 // TODO(jrummell): Decode |key_information| and pass it to the callback. |
772 void ContentDecryptorDelegate::OnSessionKeysChange( | 759 void ContentDecryptorDelegate::OnSessionKeysChange( |
773 PP_Var web_session_id, | 760 PP_Var web_session_id, |
774 PP_Bool has_additional_usable_key) { | 761 PP_Bool has_additional_usable_key, |
| 762 uint32_t key_count, |
| 763 const struct PP_KeyInformation key_information[]) { |
775 if (session_keys_change_cb_.is_null()) | 764 if (session_keys_change_cb_.is_null()) |
776 return; | 765 return; |
777 | 766 |
778 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); | 767 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); |
779 DCHECK(web_session_id_string); | 768 DCHECK(web_session_id_string); |
780 | 769 |
781 session_keys_change_cb_.Run(web_session_id_string->value(), | 770 session_keys_change_cb_.Run(web_session_id_string->value(), |
782 PP_ToBool(has_additional_usable_key)); | 771 PP_ToBool(has_additional_usable_key)); |
783 } | 772 } |
784 | 773 |
785 void ContentDecryptorDelegate::OnSessionExpirationChange( | 774 void ContentDecryptorDelegate::OnSessionExpirationChange( |
786 PP_Var web_session_id, | 775 PP_Var web_session_id, |
787 PP_Time new_expiry_time) { | 776 PP_Time new_expiry_time) { |
788 if (session_expiration_update_cb_.is_null()) | 777 if (session_expiration_update_cb_.is_null()) |
789 return; | 778 return; |
790 | 779 |
791 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); | 780 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); |
792 DCHECK(web_session_id_string); | 781 DCHECK(web_session_id_string); |
793 | 782 |
794 session_expiration_update_cb_.Run(web_session_id_string->value(), | 783 session_expiration_update_cb_.Run(web_session_id_string->value(), |
795 ppapi::PPTimeToTime(new_expiry_time)); | 784 ppapi::PPTimeToTime(new_expiry_time)); |
796 } | 785 } |
797 | 786 |
798 void ContentDecryptorDelegate::OnSessionReady(PP_Var web_session_id) { | |
799 // Ready events no longer generated. | |
800 // TODO(jrummell): Remove event from Pepper. | |
801 NOTREACHED(); | |
802 } | |
803 | |
804 void ContentDecryptorDelegate::OnSessionClosed(PP_Var web_session_id) { | 787 void ContentDecryptorDelegate::OnSessionClosed(PP_Var web_session_id) { |
805 if (session_closed_cb_.is_null()) | 788 if (session_closed_cb_.is_null()) |
806 return; | 789 return; |
807 | 790 |
808 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); | 791 StringVar* web_session_id_string = StringVar::FromPPVar(web_session_id); |
809 DCHECK(web_session_id_string); | 792 DCHECK(web_session_id_string); |
810 | 793 |
811 session_closed_cb_.Run(web_session_id_string->value()); | 794 session_closed_cb_.Run(web_session_id_string->value()); |
812 } | 795 } |
813 | 796 |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1274 | 1257 |
1275 scoped_ptr<CdmPromise> ContentDecryptorDelegate::TakePromise( | 1258 scoped_ptr<CdmPromise> ContentDecryptorDelegate::TakePromise( |
1276 uint32_t promise_id) { | 1259 uint32_t promise_id) { |
1277 PromiseMap::iterator it = promises_.find(promise_id); | 1260 PromiseMap::iterator it = promises_.find(promise_id); |
1278 if (it == promises_.end()) | 1261 if (it == promises_.end()) |
1279 return scoped_ptr<CdmPromise>(); | 1262 return scoped_ptr<CdmPromise>(); |
1280 return promises_.take_and_erase(it); | 1263 return promises_.take_and_erase(it); |
1281 } | 1264 } |
1282 | 1265 |
1283 } // namespace content | 1266 } // namespace content |
OLD | NEW |