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