Chromium Code Reviews| 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 "webkit/plugins/ppapi/content_decryptor_delegate.h" | 5 #include "webkit/plugins/ppapi/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 "media/base/audio_decoder_config.h" | 10 #include "media/base/audio_decoder_config.h" |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 pending_audio_decrypt_request_id_(0), | 278 pending_audio_decrypt_request_id_(0), |
| 279 pending_video_decrypt_request_id_(0), | 279 pending_video_decrypt_request_id_(0), |
| 280 pending_audio_decoder_init_request_id_(0), | 280 pending_audio_decoder_init_request_id_(0), |
| 281 pending_video_decoder_init_request_id_(0), | 281 pending_video_decoder_init_request_id_(0), |
| 282 pending_audio_decode_request_id_(0), | 282 pending_audio_decode_request_id_(0), |
| 283 pending_video_decode_request_id_(0), | 283 pending_video_decode_request_id_(0), |
| 284 weak_ptr_factory_(this), | 284 weak_ptr_factory_(this), |
| 285 weak_this_(weak_ptr_factory_.GetWeakPtr()) { | 285 weak_this_(weak_ptr_factory_.GetWeakPtr()) { |
| 286 } | 286 } |
| 287 | 287 |
| 288 void ContentDecryptorDelegate::Initialize(const std::string& key_system) { | |
| 289 // TODO(ddorwin): Add an Initialize method to PPP_ContentDecryptor_Private. | |
| 290 DCHECK(!key_system.empty()); | |
| 291 key_system_ = key_system; | |
| 292 } | |
| 293 | |
| 288 void ContentDecryptorDelegate::SetKeyEventCallbacks( | 294 void ContentDecryptorDelegate::SetKeyEventCallbacks( |
| 289 const media::KeyAddedCB& key_added_cb, | 295 const media::KeyAddedCB& key_added_cb, |
| 290 const media::KeyErrorCB& key_error_cb, | 296 const media::KeyErrorCB& key_error_cb, |
| 291 const media::KeyMessageCB& key_message_cb, | 297 const media::KeyMessageCB& key_message_cb, |
| 292 const media::NeedKeyCB& need_key_cb) { | 298 const media::NeedKeyCB& need_key_cb) { |
| 293 key_added_cb_ = key_added_cb; | 299 key_added_cb_ = key_added_cb; |
| 294 key_error_cb_ = key_error_cb; | 300 key_error_cb_ = key_error_cb; |
| 295 key_message_cb_ = key_message_cb; | 301 key_message_cb_ = key_message_cb; |
| 296 need_key_cb_ = need_key_cb; | 302 need_key_cb_ = need_key_cb; |
| 297 } | 303 } |
| 298 | 304 |
| 299 bool ContentDecryptorDelegate::GenerateKeyRequest(const std::string& key_system, | 305 bool ContentDecryptorDelegate::GenerateKeyRequest(const std::string& type, |
| 300 const std::string& type, | |
| 301 const uint8* init_data, | 306 const uint8* init_data, |
| 302 int init_data_length) { | 307 int init_data_length) { |
| 303 if (key_system.empty()) | |
| 304 return false; | |
| 305 | |
| 306 PP_Var init_data_array = | 308 PP_Var init_data_array = |
| 307 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( | 309 PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( |
| 308 init_data_length, init_data); | 310 init_data_length, init_data); |
| 309 | 311 |
| 310 plugin_decryption_interface_->GenerateKeyRequest( | 312 plugin_decryption_interface_->GenerateKeyRequest( |
| 311 pp_instance_, | 313 pp_instance_, |
| 312 StringVar::StringToPPVar(key_system), | 314 StringVar::StringToPPVar(key_system_), // TODO(ddorwin): Remove. |
| 313 StringVar::StringToPPVar(type), | 315 StringVar::StringToPPVar(type), |
| 314 init_data_array); | 316 init_data_array); |
| 315 return true; | 317 return true; |
| 316 } | 318 } |
| 317 | 319 |
| 318 bool ContentDecryptorDelegate::AddKey(const std::string& session_id, | 320 bool ContentDecryptorDelegate::AddKey(const std::string& session_id, |
| 319 const uint8* key, | 321 const uint8* key, |
| 320 int key_length, | 322 int key_length, |
| 321 const uint8* init_data, | 323 const uint8* init_data, |
| 322 int init_data_length) { | 324 int init_data_length) { |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 608 plugin_decryption_interface_->DecryptAndDecode(pp_instance_, | 610 plugin_decryption_interface_->DecryptAndDecode(pp_instance_, |
| 609 PP_DECRYPTORSTREAMTYPE_VIDEO, | 611 PP_DECRYPTORSTREAMTYPE_VIDEO, |
| 610 pp_resource, | 612 pp_resource, |
| 611 &block_info); | 613 &block_info); |
| 612 return true; | 614 return true; |
| 613 } | 615 } |
| 614 | 616 |
| 615 void ContentDecryptorDelegate::NeedKey(PP_Var key_system_var, | 617 void ContentDecryptorDelegate::NeedKey(PP_Var key_system_var, |
| 616 PP_Var session_id_var, | 618 PP_Var session_id_var, |
| 617 PP_Var init_data_var) { | 619 PP_Var init_data_var) { |
| 618 // TODO(tomfinegan): send the data to media stack. | 620 // TODO(ddorwin): Remove from PPB_ContentDecryptor_Private. |
| 621 NOTREACHED(); | |
| 619 } | 622 } |
| 620 | 623 |
| 621 void ContentDecryptorDelegate::KeyAdded(PP_Var key_system_var, | 624 void ContentDecryptorDelegate::KeyAdded(PP_Var key_system_var, |
| 622 PP_Var session_id_var) { | 625 PP_Var session_id_var) { |
| 623 if (key_added_cb_.is_null()) | 626 if (key_added_cb_.is_null()) |
| 624 return; | 627 return; |
| 625 | 628 |
| 626 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); | 629 // Verify the key_system values are the same until the param is removed. |
| 630 DCHECK(StringVar::FromPPVar(key_system_var)->value() == key_system_); | |
| 627 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); | 631 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); |
| 628 if (!key_system_string || !session_id_string) { | 632 if (!session_id_string) { |
| 629 key_error_cb_.Run( | 633 key_error_cb_.Run( |
| 630 std::string(), std::string(), media::MediaKeys::kUnknownError, 0); | 634 std::string(), media::MediaKeys::kUnknownError, 0); |
|
xhwang
2013/06/18 00:43:42
nit: fit in one line?
ddorwin
2013/06/18 16:46:21
Done.
| |
| 631 return; | 635 return; |
| 632 } | 636 } |
| 633 | 637 |
| 634 key_added_cb_.Run(key_system_string->value(), session_id_string->value()); | 638 key_added_cb_.Run(session_id_string->value()); |
| 635 } | 639 } |
| 636 | 640 |
| 637 void ContentDecryptorDelegate::KeyMessage(PP_Var key_system_var, | 641 void ContentDecryptorDelegate::KeyMessage(PP_Var key_system_var, |
| 638 PP_Var session_id_var, | 642 PP_Var session_id_var, |
| 639 PP_Var message_var, | 643 PP_Var message_var, |
| 640 PP_Var default_url_var) { | 644 PP_Var default_url_var) { |
| 641 if (key_message_cb_.is_null()) | 645 if (key_message_cb_.is_null()) |
| 642 return; | 646 return; |
| 643 | 647 |
| 644 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); | 648 DCHECK(StringVar::FromPPVar(key_system_var)->value() == key_system_); |
| 645 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); | 649 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); |
| 646 | 650 |
| 647 ArrayBufferVar* message_array_buffer = | 651 ArrayBufferVar* message_array_buffer = |
| 648 ArrayBufferVar::FromPPVar(message_var); | 652 ArrayBufferVar::FromPPVar(message_var); |
| 649 | 653 |
| 650 std::string message; | 654 std::string message; |
| 651 if (message_array_buffer) { | 655 if (message_array_buffer) { |
| 652 const char* data = static_cast<const char*>(message_array_buffer->Map()); | 656 const char* data = static_cast<const char*>(message_array_buffer->Map()); |
| 653 message.assign(data, message_array_buffer->ByteLength()); | 657 message.assign(data, message_array_buffer->ByteLength()); |
| 654 } | 658 } |
| 655 | 659 |
| 656 StringVar* default_url_string = StringVar::FromPPVar(default_url_var); | 660 StringVar* default_url_string = StringVar::FromPPVar(default_url_var); |
| 657 | 661 |
| 658 if (!key_system_string || !session_id_string || !default_url_string) { | 662 if (!session_id_string || !default_url_string) { |
| 659 key_error_cb_.Run( | 663 key_error_cb_.Run( |
| 660 std::string(), std::string(), media::MediaKeys::kUnknownError, 0); | 664 std::string(), media::MediaKeys::kUnknownError, 0); |
|
xhwang
2013/06/18 00:43:42
ditto
ddorwin
2013/06/18 16:46:21
Done.
| |
| 661 return; | 665 return; |
| 662 } | 666 } |
| 663 | 667 |
| 664 key_message_cb_.Run(key_system_string->value(), | 668 key_message_cb_.Run(session_id_string->value(), |
| 665 session_id_string->value(), | |
| 666 message, | 669 message, |
| 667 default_url_string->value()); | 670 default_url_string->value()); |
| 668 } | 671 } |
| 669 | 672 |
| 670 void ContentDecryptorDelegate::KeyError(PP_Var key_system_var, | 673 void ContentDecryptorDelegate::KeyError(PP_Var key_system_var, |
| 671 PP_Var session_id_var, | 674 PP_Var session_id_var, |
| 672 int32_t media_error, | 675 int32_t media_error, |
| 673 int32_t system_code) { | 676 int32_t system_code) { |
| 674 if (key_error_cb_.is_null()) | 677 if (key_error_cb_.is_null()) |
| 675 return; | 678 return; |
| 676 | 679 |
| 677 StringVar* key_system_string = StringVar::FromPPVar(key_system_var); | 680 DCHECK(StringVar::FromPPVar(key_system_var)->value() == key_system_); |
| 678 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); | 681 StringVar* session_id_string = StringVar::FromPPVar(session_id_var); |
| 679 if (!key_system_string || !session_id_string) { | 682 if (!session_id_string) { |
| 680 key_error_cb_.Run( | 683 key_error_cb_.Run( |
| 681 std::string(), std::string(), media::MediaKeys::kUnknownError, 0); | 684 std::string(), media::MediaKeys::kUnknownError, 0); |
|
xhwang
2013/06/18 00:43:42
ditto
ddorwin
2013/06/18 16:46:21
Done.
| |
| 682 return; | 685 return; |
| 683 } | 686 } |
| 684 | 687 |
| 685 key_error_cb_.Run( | 688 key_error_cb_.Run( |
| 686 key_system_string->value(), | |
| 687 session_id_string->value(), | 689 session_id_string->value(), |
| 688 static_cast<media::MediaKeys::KeyError>(media_error), | 690 static_cast<media::MediaKeys::KeyError>(media_error), |
| 689 system_code); | 691 system_code); |
| 690 } | 692 } |
| 691 | 693 |
| 692 void ContentDecryptorDelegate::DecoderInitializeDone( | 694 void ContentDecryptorDelegate::DecoderInitializeDone( |
| 693 PP_DecryptorStreamType decoder_type, | 695 PP_DecryptorStreamType decoder_type, |
| 694 uint32_t request_id, | 696 uint32_t request_id, |
| 695 PP_Bool success) { | 697 PP_Bool success) { |
| 696 if (decoder_type == PP_DECRYPTORSTREAMTYPE_AUDIO) { | 698 if (decoder_type == PP_DECRYPTORSTREAMTYPE_AUDIO) { |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1024 | 1026 |
| 1025 if (free_buffers_.empty()) | 1027 if (free_buffers_.empty()) |
| 1026 return; | 1028 return; |
| 1027 | 1029 |
| 1028 tracking_info->buffer_id = free_buffers_.front(); | 1030 tracking_info->buffer_id = free_buffers_.front(); |
| 1029 free_buffers_.pop(); | 1031 free_buffers_.pop(); |
| 1030 } | 1032 } |
| 1031 | 1033 |
| 1032 } // namespace ppapi | 1034 } // namespace ppapi |
| 1033 } // namespace webkit | 1035 } // namespace webkit |
| OLD | NEW |