Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: content/renderer/media/webmediaplayer_impl.cc

Issue 170783010: Encrypted Media: Handle blink::WebString in WebMediaPlayer*. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase only Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/renderer/media/webmediaplayer_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/media/webmediaplayer_impl.h" 5 #include "content/renderer/media/webmediaplayer_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 // performance will be better when it is added than not. 667 // performance will be better when it is added than not.
668 web_graphics_context->flush(); 668 web_graphics_context->flush();
669 return true; 669 return true;
670 } 670 }
671 671
672 // Helper functions to report media EME related stats to UMA. They follow the 672 // Helper functions to report media EME related stats to UMA. They follow the
673 // convention of more commonly used macros UMA_HISTOGRAM_ENUMERATION and 673 // convention of more commonly used macros UMA_HISTOGRAM_ENUMERATION and
674 // UMA_HISTOGRAM_COUNTS. The reason that we cannot use those macros directly is 674 // UMA_HISTOGRAM_COUNTS. The reason that we cannot use those macros directly is
675 // that UMA_* macros require the names to be constant throughout the process' 675 // that UMA_* macros require the names to be constant throughout the process'
676 // lifetime. 676 // lifetime.
677 static void EmeUMAHistogramEnumeration(const blink::WebString& key_system, 677 static void EmeUMAHistogramEnumeration(const std::string& key_system,
678 const std::string& method, 678 const std::string& method,
679 int sample, 679 int sample,
680 int boundary_value) { 680 int boundary_value) {
681 base::LinearHistogram::FactoryGet( 681 base::LinearHistogram::FactoryGet(
682 kMediaEme + KeySystemNameForUMA(key_system) + "." + method, 682 kMediaEme + KeySystemNameForUMA(key_system) + "." + method,
683 1, boundary_value, boundary_value + 1, 683 1, boundary_value, boundary_value + 1,
684 base::Histogram::kUmaTargetedHistogramFlag)->Add(sample); 684 base::Histogram::kUmaTargetedHistogramFlag)->Add(sample);
685 } 685 }
686 686
687 static void EmeUMAHistogramCounts(const blink::WebString& key_system, 687 static void EmeUMAHistogramCounts(const std::string& key_system,
688 const std::string& method, 688 const std::string& method,
689 int sample) { 689 int sample) {
690 // Use the same parameters as UMA_HISTOGRAM_COUNTS. 690 // Use the same parameters as UMA_HISTOGRAM_COUNTS.
691 base::Histogram::FactoryGet( 691 base::Histogram::FactoryGet(
692 kMediaEme + KeySystemNameForUMA(key_system) + "." + method, 692 kMediaEme + KeySystemNameForUMA(key_system) + "." + method,
693 1, 1000000, 50, base::Histogram::kUmaTargetedHistogramFlag)->Add(sample); 693 1, 1000000, 50, base::Histogram::kUmaTargetedHistogramFlag)->Add(sample);
694 } 694 }
695 695
696 // Helper enum for reporting generateKeyRequest/addKey histograms. 696 // Helper enum for reporting generateKeyRequest/addKey histograms.
697 enum MediaKeyException { 697 enum MediaKeyException {
(...skipping 15 matching lines...) Expand all
713 return kSuccess; 713 return kSuccess;
714 default: 714 default:
715 return kUnknownResultId; 715 return kUnknownResultId;
716 } 716 }
717 } 717 }
718 718
719 // Helper for converting |key_system| name and exception |e| to a pair of enum 719 // Helper for converting |key_system| name and exception |e| to a pair of enum
720 // values from above, for reporting to UMA. 720 // values from above, for reporting to UMA.
721 static void ReportMediaKeyExceptionToUMA( 721 static void ReportMediaKeyExceptionToUMA(
722 const std::string& method, 722 const std::string& method,
723 const WebString& key_system, 723 const std::string& key_system,
724 WebMediaPlayer::MediaKeyException e) { 724 WebMediaPlayer::MediaKeyException e) {
725 MediaKeyException result_id = MediaKeyExceptionForUMA(e); 725 MediaKeyException result_id = MediaKeyExceptionForUMA(e);
726 DCHECK_NE(result_id, kUnknownResultId) << e; 726 DCHECK_NE(result_id, kUnknownResultId) << e;
727 EmeUMAHistogramEnumeration( 727 EmeUMAHistogramEnumeration(
728 key_system, method, result_id, kMaxMediaKeyException); 728 key_system, method, result_id, kMaxMediaKeyException);
729 } 729 }
730 730
731 // Convert a WebString to ASCII, falling back on an empty string in the case
732 // of a non-ASCII string.
733 static std::string ToASCIIOrEmpty(const blink::WebString& string) {
734 return IsStringASCII(string) ? UTF16ToASCII(string) : std::string();
735 }
736
731 WebMediaPlayer::MediaKeyException 737 WebMediaPlayer::MediaKeyException
732 WebMediaPlayerImpl::generateKeyRequest(const WebString& key_system, 738 WebMediaPlayerImpl::generateKeyRequest(const WebString& key_system,
733 const unsigned char* init_data, 739 const unsigned char* init_data,
734 unsigned init_data_length) { 740 unsigned init_data_length) {
741 DVLOG(1) << "generateKeyRequest: " << base::string16(key_system) << ": "
742 << std::string(reinterpret_cast<const char*>(init_data),
743 static_cast<size_t>(init_data_length));
744
745 std::string ascii_key_system = ToASCIIOrEmpty(key_system);
746
735 WebMediaPlayer::MediaKeyException e = 747 WebMediaPlayer::MediaKeyException e =
736 GenerateKeyRequestInternal(key_system, init_data, init_data_length); 748 GenerateKeyRequestInternal(ascii_key_system, init_data, init_data_length);
737 ReportMediaKeyExceptionToUMA("generateKeyRequest", key_system, e); 749 ReportMediaKeyExceptionToUMA("generateKeyRequest", ascii_key_system, e);
738 return e; 750 return e;
739 } 751 }
740 752
741 WebMediaPlayer::MediaKeyException 753 WebMediaPlayer::MediaKeyException
742 WebMediaPlayerImpl::GenerateKeyRequestInternal( 754 WebMediaPlayerImpl::GenerateKeyRequestInternal(
743 const WebString& key_system, 755 const std::string& key_system,
744 const unsigned char* init_data, 756 const unsigned char* init_data,
745 unsigned init_data_length) { 757 unsigned init_data_length) {
746 DCHECK(main_loop_->BelongsToCurrentThread()); 758 DCHECK(main_loop_->BelongsToCurrentThread());
747 759
748 DVLOG(1) << "generateKeyRequest: " << key_system.utf8().data() << ": "
749 << std::string(reinterpret_cast<const char*>(init_data),
750 static_cast<size_t>(init_data_length));
751
752 if (!IsConcreteSupportedKeySystem(key_system)) 760 if (!IsConcreteSupportedKeySystem(key_system))
753 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; 761 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
754 762
755 // We do not support run-time switching between key systems for now. 763 // We do not support run-time switching between key systems for now.
756 if (current_key_system_.isEmpty()) { 764 if (current_key_system_.empty()) {
757 if (!proxy_decryptor_) { 765 if (!proxy_decryptor_) {
758 proxy_decryptor_.reset(new ProxyDecryptor( 766 proxy_decryptor_.reset(new ProxyDecryptor(
759 #if defined(ENABLE_PEPPER_CDMS) 767 #if defined(ENABLE_PEPPER_CDMS)
760 client_, 768 client_,
761 frame_, 769 frame_,
762 #endif 770 #endif
763 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyAdded), 771 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyAdded),
764 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyError), 772 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyError),
765 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyMessage))); 773 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyMessage)));
766 } 774 }
767 775
768 if (!proxy_decryptor_->InitializeCDM(key_system.utf8(), 776 if (!proxy_decryptor_->InitializeCDM(key_system,
769 frame_->document().url())) 777 frame_->document().url()))
770 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; 778 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
771 779
772 if (proxy_decryptor_ && !decryptor_ready_cb_.is_null()) { 780 if (proxy_decryptor_ && !decryptor_ready_cb_.is_null()) {
773 base::ResetAndReturn(&decryptor_ready_cb_) 781 base::ResetAndReturn(&decryptor_ready_cb_)
774 .Run(proxy_decryptor_->GetDecryptor()); 782 .Run(proxy_decryptor_->GetDecryptor());
775 } 783 }
776 784
777 current_key_system_ = key_system; 785 current_key_system_ = key_system;
778 } else if (key_system != current_key_system_) { 786 } else if (key_system != current_key_system_) {
779 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; 787 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState;
780 } 788 }
781 789
782 // TODO(xhwang): We assume all streams are from the same container (thus have 790 // TODO(xhwang): We assume all streams are from the same container (thus have
783 // the same "type") for now. In the future, the "type" should be passed down 791 // the same "type") for now. In the future, the "type" should be passed down
784 // from the application. 792 // from the application.
785 if (!proxy_decryptor_->GenerateKeyRequest( 793 if (!proxy_decryptor_->GenerateKeyRequest(
786 init_data_type_, init_data, init_data_length)) { 794 init_data_type_, init_data, init_data_length)) {
787 current_key_system_.reset(); 795 current_key_system_.clear();
788 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; 796 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
789 } 797 }
790 798
791 return WebMediaPlayer::MediaKeyExceptionNoError; 799 return WebMediaPlayer::MediaKeyExceptionNoError;
792 } 800 }
793 801
794 WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::addKey( 802 WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::addKey(
795 const WebString& key_system, 803 const WebString& key_system,
796 const unsigned char* key, 804 const unsigned char* key,
797 unsigned key_length, 805 unsigned key_length,
798 const unsigned char* init_data, 806 const unsigned char* init_data,
799 unsigned init_data_length, 807 unsigned init_data_length,
800 const WebString& session_id) { 808 const WebString& session_id) {
801 WebMediaPlayer::MediaKeyException e = AddKeyInternal( 809 DVLOG(1) << "addKey: " << base::string16(key_system) << ": "
802 key_system, key, key_length, init_data, init_data_length, session_id); 810 << std::string(reinterpret_cast<const char*>(key),
803 ReportMediaKeyExceptionToUMA("addKey", key_system, e); 811 static_cast<size_t>(key_length)) << ", "
812 << std::string(reinterpret_cast<const char*>(init_data),
813 static_cast<size_t>(init_data_length))
814 << " [" << base::string16(session_id) << "]";
815
816 std::string ascii_key_system = ToASCIIOrEmpty(key_system);
817 std::string ascii_session_id = ToASCIIOrEmpty(session_id);
818
819 WebMediaPlayer::MediaKeyException e = AddKeyInternal(ascii_key_system,
820 key,
821 key_length,
822 init_data,
823 init_data_length,
824 ascii_session_id);
825 ReportMediaKeyExceptionToUMA("addKey", ascii_key_system, e);
804 return e; 826 return e;
805 } 827 }
806 828
807 WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::AddKeyInternal( 829 WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::AddKeyInternal(
808 const WebString& key_system, 830 const std::string& key_system,
809 const unsigned char* key, 831 const unsigned char* key,
810 unsigned key_length, 832 unsigned key_length,
811 const unsigned char* init_data, 833 const unsigned char* init_data,
812 unsigned init_data_length, 834 unsigned init_data_length,
813 const WebString& session_id) { 835 const std::string& session_id) {
814 DCHECK(key); 836 DCHECK(key);
815 DCHECK_GT(key_length, 0u); 837 DCHECK_GT(key_length, 0u);
816 DVLOG(1) << "addKey: " << key_system.utf8().data() << ": "
817 << std::string(reinterpret_cast<const char*>(key),
818 static_cast<size_t>(key_length)) << ", "
819 << std::string(reinterpret_cast<const char*>(init_data),
820 static_cast<size_t>(init_data_length))
821 << " [" << session_id.utf8().data() << "]";
822
823 838
824 if (!IsConcreteSupportedKeySystem(key_system)) 839 if (!IsConcreteSupportedKeySystem(key_system))
825 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; 840 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
826 841
827 if (current_key_system_.isEmpty() || key_system != current_key_system_) 842 if (current_key_system_.empty() || key_system != current_key_system_)
828 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; 843 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState;
829 844
830 proxy_decryptor_->AddKey( 845 proxy_decryptor_->AddKey(
831 key, key_length, init_data, init_data_length, session_id.utf8()); 846 key, key_length, init_data, init_data_length, session_id);
832 return WebMediaPlayer::MediaKeyExceptionNoError; 847 return WebMediaPlayer::MediaKeyExceptionNoError;
833 } 848 }
834 849
835 WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::cancelKeyRequest( 850 WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::cancelKeyRequest(
836 const WebString& key_system, 851 const WebString& key_system,
837 const WebString& session_id) { 852 const WebString& session_id) {
853 DVLOG(1) << "cancelKeyRequest: " << base::string16(key_system) << ": "
854 << " [" << base::string16(session_id) << "]";
855
856 std::string ascii_key_system = ToASCIIOrEmpty(key_system);
857 std::string ascii_session_id = ToASCIIOrEmpty(session_id);
858
838 WebMediaPlayer::MediaKeyException e = 859 WebMediaPlayer::MediaKeyException e =
839 CancelKeyRequestInternal(key_system, session_id); 860 CancelKeyRequestInternal(ascii_key_system, ascii_session_id);
840 ReportMediaKeyExceptionToUMA("cancelKeyRequest", key_system, e); 861 ReportMediaKeyExceptionToUMA("cancelKeyRequest", ascii_key_system, e);
841 return e; 862 return e;
842 } 863 }
843 864
844 WebMediaPlayer::MediaKeyException 865 WebMediaPlayer::MediaKeyException
845 WebMediaPlayerImpl::CancelKeyRequestInternal( 866 WebMediaPlayerImpl::CancelKeyRequestInternal(
846 const WebString& key_system, 867 const std::string& key_system,
847 const WebString& session_id) { 868 const std::string& session_id) {
848 if (!IsConcreteSupportedKeySystem(key_system)) 869 if (!IsConcreteSupportedKeySystem(key_system))
849 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; 870 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
850 871
851 if (current_key_system_.isEmpty() || key_system != current_key_system_) 872 if (current_key_system_.empty() || key_system != current_key_system_)
852 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; 873 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState;
853 874
854 proxy_decryptor_->CancelKeyRequest(session_id.utf8()); 875 proxy_decryptor_->CancelKeyRequest(session_id);
855 return WebMediaPlayer::MediaKeyExceptionNoError; 876 return WebMediaPlayer::MediaKeyExceptionNoError;
856 } 877 }
857 878
858 void WebMediaPlayerImpl::setContentDecryptionModule( 879 void WebMediaPlayerImpl::setContentDecryptionModule(
859 blink::WebContentDecryptionModule* cdm) { 880 blink::WebContentDecryptionModule* cdm) {
860 DCHECK(main_loop_->BelongsToCurrentThread()); 881 DCHECK(main_loop_->BelongsToCurrentThread());
861 882
862 // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324 883 // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324
863 if (!cdm) 884 if (!cdm)
864 return; 885 return;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 994
974 void WebMediaPlayerImpl::OnDemuxerOpened() { 995 void WebMediaPlayerImpl::OnDemuxerOpened() {
975 DCHECK(main_loop_->BelongsToCurrentThread()); 996 DCHECK(main_loop_->BelongsToCurrentThread());
976 client_->mediaSourceOpened(new WebMediaSourceImpl( 997 client_->mediaSourceOpened(new WebMediaSourceImpl(
977 chunk_demuxer_, base::Bind(&LogMediaSourceError, media_log_))); 998 chunk_demuxer_, base::Bind(&LogMediaSourceError, media_log_)));
978 } 999 }
979 1000
980 void WebMediaPlayerImpl::OnKeyAdded(const std::string& session_id) { 1001 void WebMediaPlayerImpl::OnKeyAdded(const std::string& session_id) {
981 DCHECK(main_loop_->BelongsToCurrentThread()); 1002 DCHECK(main_loop_->BelongsToCurrentThread());
982 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); 1003 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1);
983 client_->keyAdded(current_key_system_, WebString::fromUTF8(session_id)); 1004 client_->keyAdded(WebString::fromUTF8(current_key_system_),
1005 WebString::fromUTF8(session_id));
984 } 1006 }
985 1007
986 void WebMediaPlayerImpl::OnNeedKey(const std::string& type, 1008 void WebMediaPlayerImpl::OnNeedKey(const std::string& type,
987 const std::vector<uint8>& init_data) { 1009 const std::vector<uint8>& init_data) {
988 DCHECK(main_loop_->BelongsToCurrentThread()); 1010 DCHECK(main_loop_->BelongsToCurrentThread());
989 1011
990 // Do not fire NeedKey event if encrypted media is not enabled. 1012 // Do not fire NeedKey event if encrypted media is not enabled.
991 if (!blink::WebRuntimeFeatures::isPrefixedEncryptedMediaEnabled() && 1013 if (!blink::WebRuntimeFeatures::isPrefixedEncryptedMediaEnabled() &&
992 !blink::WebRuntimeFeatures::isEncryptedMediaEnabled()) { 1014 !blink::WebRuntimeFeatures::isEncryptedMediaEnabled()) {
993 return; 1015 return;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 1052
1031 void WebMediaPlayerImpl::OnKeyError(const std::string& session_id, 1053 void WebMediaPlayerImpl::OnKeyError(const std::string& session_id,
1032 media::MediaKeys::KeyError error_code, 1054 media::MediaKeys::KeyError error_code,
1033 int system_code) { 1055 int system_code) {
1034 DCHECK(main_loop_->BelongsToCurrentThread()); 1056 DCHECK(main_loop_->BelongsToCurrentThread());
1035 1057
1036 EmeUMAHistogramEnumeration(current_key_system_, "KeyError", 1058 EmeUMAHistogramEnumeration(current_key_system_, "KeyError",
1037 error_code, media::MediaKeys::kMaxKeyError); 1059 error_code, media::MediaKeys::kMaxKeyError);
1038 1060
1039 client_->keyError( 1061 client_->keyError(
1040 current_key_system_, 1062 WebString::fromUTF8(current_key_system_),
1041 WebString::fromUTF8(session_id), 1063 WebString::fromUTF8(session_id),
1042 static_cast<blink::WebMediaPlayerClient::MediaKeyErrorCode>(error_code), 1064 static_cast<blink::WebMediaPlayerClient::MediaKeyErrorCode>(error_code),
1043 system_code); 1065 system_code);
1044 } 1066 }
1045 1067
1046 void WebMediaPlayerImpl::OnKeyMessage(const std::string& session_id, 1068 void WebMediaPlayerImpl::OnKeyMessage(const std::string& session_id,
1047 const std::vector<uint8>& message, 1069 const std::vector<uint8>& message,
1048 const std::string& default_url) { 1070 const std::string& default_url) {
1049 DCHECK(main_loop_->BelongsToCurrentThread()); 1071 DCHECK(main_loop_->BelongsToCurrentThread());
1050 1072
1051 const GURL default_url_gurl(default_url); 1073 const GURL default_url_gurl(default_url);
1052 DLOG_IF(WARNING, !default_url.empty() && !default_url_gurl.is_valid()) 1074 DLOG_IF(WARNING, !default_url.empty() && !default_url_gurl.is_valid())
1053 << "Invalid URL in default_url: " << default_url; 1075 << "Invalid URL in default_url: " << default_url;
1054 1076
1055 client_->keyMessage(current_key_system_, 1077 client_->keyMessage(WebString::fromUTF8(current_key_system_),
1056 WebString::fromUTF8(session_id), 1078 WebString::fromUTF8(session_id),
1057 message.empty() ? NULL : &message[0], 1079 message.empty() ? NULL : &message[0],
1058 message.size(), 1080 message.size(),
1059 default_url_gurl); 1081 default_url_gurl);
1060 } 1082 }
1061 1083
1062 void WebMediaPlayerImpl::SetOpaque(bool opaque) { 1084 void WebMediaPlayerImpl::SetOpaque(bool opaque) {
1063 DCHECK(main_loop_->BelongsToCurrentThread()); 1085 DCHECK(main_loop_->BelongsToCurrentThread());
1064 1086
1065 client_->setOpaque(opaque); 1087 client_->setOpaque(opaque);
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 1345
1324 if (web_cdm_) { 1346 if (web_cdm_) {
1325 decryptor_ready_cb.Run(web_cdm_->GetDecryptor()); 1347 decryptor_ready_cb.Run(web_cdm_->GetDecryptor());
1326 return; 1348 return;
1327 } 1349 }
1328 1350
1329 decryptor_ready_cb_ = decryptor_ready_cb; 1351 decryptor_ready_cb_ = decryptor_ready_cb;
1330 } 1352 }
1331 1353
1332 } // namespace content 1354 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webmediaplayer_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698