Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/android/webmediaplayer_android.h" | 5 #include "content/renderer/media/android/webmediaplayer_android.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/android/build_info.h" | |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 15 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 16 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 18 #include "cc/layers/video_layer.h" | 19 #include "cc/layers/video_layer.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 47 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 48 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| 48 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 49 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
| 49 #include "third_party/WebKit/public/web/WebView.h" | 50 #include "third_party/WebKit/public/web/WebView.h" |
| 50 #include "third_party/skia/include/core/SkBitmap.h" | 51 #include "third_party/skia/include/core/SkBitmap.h" |
| 51 #include "third_party/skia/include/core/SkCanvas.h" | 52 #include "third_party/skia/include/core/SkCanvas.h" |
| 52 #include "third_party/skia/include/core/SkPaint.h" | 53 #include "third_party/skia/include/core/SkPaint.h" |
| 53 #include "third_party/skia/include/core/SkTypeface.h" | 54 #include "third_party/skia/include/core/SkTypeface.h" |
| 54 #include "ui/gfx/image/image.h" | 55 #include "ui/gfx/image/image.h" |
| 55 | 56 |
| 56 static const uint32 kGLTextureExternalOES = 0x8D65; | 57 static const uint32 kGLTextureExternalOES = 0x8D65; |
| 58 static const int kSDKVersionToSupportSecurityOriginCheck = 20; | |
| 57 | 59 |
| 58 using blink::WebMediaPlayer; | 60 using blink::WebMediaPlayer; |
| 59 using blink::WebSize; | 61 using blink::WebSize; |
| 60 using blink::WebString; | 62 using blink::WebString; |
| 61 using blink::WebTimeRanges; | 63 using blink::WebTimeRanges; |
| 62 using blink::WebURL; | 64 using blink::WebURL; |
| 63 using gpu::gles2::GLES2Interface; | 65 using gpu::gles2::GLES2Interface; |
| 64 using media::MediaPlayerAndroid; | 66 using media::MediaPlayerAndroid; |
| 65 using media::VideoFrame; | 67 using media::VideoFrame; |
| 66 | 68 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 has_size_info_(false), | 132 has_size_info_(false), |
| 131 stream_texture_factory_(factory), | 133 stream_texture_factory_(factory), |
| 132 needs_external_surface_(false), | 134 needs_external_surface_(false), |
| 133 video_frame_provider_client_(NULL), | 135 video_frame_provider_client_(NULL), |
| 134 pending_playback_(false), | 136 pending_playback_(false), |
| 135 player_type_(MEDIA_PLAYER_TYPE_URL), | 137 player_type_(MEDIA_PLAYER_TYPE_URL), |
| 136 current_time_(0), | 138 current_time_(0), |
| 137 is_remote_(false), | 139 is_remote_(false), |
| 138 media_log_(media_log), | 140 media_log_(media_log), |
| 139 web_cdm_(NULL), | 141 web_cdm_(NULL), |
| 142 allow_stored_credentials_(false), | |
| 140 weak_factory_(this) { | 143 weak_factory_(this) { |
| 141 DCHECK(player_manager_); | 144 DCHECK(player_manager_); |
| 142 DCHECK(cdm_manager_); | 145 DCHECK(cdm_manager_); |
| 143 | 146 |
| 144 DCHECK(main_thread_checker_.CalledOnValidThread()); | 147 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 145 | 148 |
| 146 player_id_ = player_manager_->RegisterMediaPlayer(this); | 149 player_id_ = player_manager_->RegisterMediaPlayer(this); |
| 147 | 150 |
| 148 #if defined(VIDEO_HOLE) | 151 #if defined(VIDEO_HOLE) |
| 149 force_use_overlay_embedded_video_ = CommandLine::ForCurrentProcess()-> | 152 force_use_overlay_embedded_video_ = CommandLine::ForCurrentProcess()-> |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 media_source_delegate_->InitializeMediaSource( | 226 media_source_delegate_->InitializeMediaSource( |
| 224 base::Bind(&WebMediaPlayerAndroid::OnMediaSourceOpened, | 227 base::Bind(&WebMediaPlayerAndroid::OnMediaSourceOpened, |
| 225 weak_factory_.GetWeakPtr()), | 228 weak_factory_.GetWeakPtr()), |
| 226 base::Bind(&WebMediaPlayerAndroid::OnNeedKey, | 229 base::Bind(&WebMediaPlayerAndroid::OnNeedKey, |
| 227 weak_factory_.GetWeakPtr()), | 230 weak_factory_.GetWeakPtr()), |
| 228 set_decryptor_ready_cb, | 231 set_decryptor_ready_cb, |
| 229 base::Bind(&WebMediaPlayerAndroid::UpdateNetworkState, | 232 base::Bind(&WebMediaPlayerAndroid::UpdateNetworkState, |
| 230 weak_factory_.GetWeakPtr()), | 233 weak_factory_.GetWeakPtr()), |
| 231 base::Bind(&WebMediaPlayerAndroid::OnDurationChanged, | 234 base::Bind(&WebMediaPlayerAndroid::OnDurationChanged, |
| 232 weak_factory_.GetWeakPtr())); | 235 weak_factory_.GetWeakPtr())); |
| 233 InitializePlayer(demuxer_client_id); | 236 InitializePlayer(url_, frame_->document().firstPartyForCookies(), |
| 237 true, demuxer_client_id); | |
| 234 } | 238 } |
| 235 } else { | 239 } else { |
| 236 info_loader_.reset( | 240 info_loader_.reset( |
| 237 new MediaInfoLoader( | 241 new MediaInfoLoader( |
| 238 url, | 242 url, |
| 239 cors_mode, | 243 cors_mode, |
| 240 base::Bind(&WebMediaPlayerAndroid::DidLoadMediaInfo, | 244 base::Bind(&WebMediaPlayerAndroid::DidLoadMediaInfo, |
| 241 weak_factory_.GetWeakPtr()))); | 245 weak_factory_.GetWeakPtr()))); |
| 242 // TODO(qinmin): The url might be redirected when android media player | |
| 243 // requests the stream. As a result, we cannot guarantee there is only | |
| 244 // a single origin. Remove the following line when b/12573548 is fixed. | |
| 245 // Check http://crbug.com/334204. | |
| 246 info_loader_->set_single_origin(false); | |
| 247 info_loader_->Start(frame_); | 246 info_loader_->Start(frame_); |
| 248 } | 247 } |
| 249 | 248 |
| 250 if (player_manager_->ShouldEnterFullscreen(frame_)) | 249 if (player_manager_->ShouldEnterFullscreen(frame_)) |
| 251 player_manager_->EnterFullscreen(player_id_, frame_); | 250 player_manager_->EnterFullscreen(player_id_, frame_); |
| 252 | 251 |
| 253 UpdateNetworkState(WebMediaPlayer::NetworkStateLoading); | 252 UpdateNetworkState(WebMediaPlayer::NetworkStateLoading); |
| 254 UpdateReadyState(WebMediaPlayer::ReadyStateHaveNothing); | 253 UpdateReadyState(WebMediaPlayer::ReadyStateHaveNothing); |
| 255 } | 254 } |
| 256 | 255 |
| 257 void WebMediaPlayerAndroid::DidLoadMediaInfo(MediaInfoLoader::Status status) { | 256 void WebMediaPlayerAndroid::DidLoadMediaInfo( |
| 257 MediaInfoLoader::Status status, | |
| 258 const GURL& redirected_url, | |
| 259 const GURL& fist_party_for_cookies, | |
|
Ken Russell (switch to Gerrit)
2014/07/30 20:44:05
typo: first_party_for_cookies
qinmin
2014/07/30 23:46:05
Done.
| |
| 260 bool allow_stored_credentials) { | |
| 258 DCHECK(!media_source_delegate_); | 261 DCHECK(!media_source_delegate_); |
| 259 if (status == MediaInfoLoader::kFailed) { | 262 if (status == MediaInfoLoader::kFailed) { |
| 260 info_loader_.reset(); | 263 info_loader_.reset(); |
| 261 UpdateNetworkState(WebMediaPlayer::NetworkStateNetworkError); | 264 UpdateNetworkState(WebMediaPlayer::NetworkStateNetworkError); |
| 262 return; | 265 return; |
| 263 } | 266 } |
| 264 | 267 |
| 265 InitializePlayer(0); | 268 InitializePlayer( |
| 269 redirected_url, fist_party_for_cookies, allow_stored_credentials, 0); | |
| 266 | 270 |
| 267 UpdateNetworkState(WebMediaPlayer::NetworkStateIdle); | 271 UpdateNetworkState(WebMediaPlayer::NetworkStateIdle); |
| 268 } | 272 } |
| 269 | 273 |
| 270 void WebMediaPlayerAndroid::play() { | 274 void WebMediaPlayerAndroid::play() { |
| 271 #if defined(VIDEO_HOLE) | 275 #if defined(VIDEO_HOLE) |
| 272 if (hasVideo() && needs_external_surface_ && | 276 if (hasVideo() && needs_external_surface_ && |
| 273 !player_manager_->IsInFullscreen(frame_)) { | 277 !player_manager_->IsInFullscreen(frame_)) { |
| 274 DCHECK(!needs_establish_peer_); | 278 DCHECK(!needs_establish_peer_); |
| 275 player_manager_->RequestExternalSurface(player_id_, last_computed_rect_); | 279 player_manager_->RequestExternalSurface(player_id_, last_computed_rect_); |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 528 | 532 |
| 529 web_graphics_context->deleteTexture(source_texture); | 533 web_graphics_context->deleteTexture(source_texture); |
| 530 web_graphics_context->flush(); | 534 web_graphics_context->flush(); |
| 531 | 535 |
| 532 SyncPointClientImpl client(web_graphics_context); | 536 SyncPointClientImpl client(web_graphics_context); |
| 533 video_frame->UpdateReleaseSyncPoint(&client); | 537 video_frame->UpdateReleaseSyncPoint(&client); |
| 534 return true; | 538 return true; |
| 535 } | 539 } |
| 536 | 540 |
| 537 bool WebMediaPlayerAndroid::hasSingleSecurityOrigin() const { | 541 bool WebMediaPlayerAndroid::hasSingleSecurityOrigin() const { |
| 538 if (info_loader_) | 542 bool ret = HasSingleSecurityOriginInternal(); |
| 539 return info_loader_->HasSingleOrigin(); | 543 // TODO(qinmin): The url might be redirected when android media player |
| 540 // The info loader may have failed. | 544 // requests the stream. As a result, we cannot guarantee there is only |
| 541 if (player_type_ == MEDIA_PLAYER_TYPE_URL) | 545 // a single origin. Only if the credential information is not requested by the |
| 542 return false; | 546 // destination, we will honor the return value from |
|
Ken Russell (switch to Gerrit)
2014/07/30 20:44:05
"Only if the HTTP request was made without credent
qinmin
2014/07/30 23:46:05
Done.
| |
| 543 return true; | 547 // HasSingleSecurityOriginInternal() in pre-L android versions. |
| 548 // Check http://crbug.com/334204. | |
| 549 if (!ret || player_type_ != MEDIA_PLAYER_TYPE_URL) | |
| 550 return ret; | |
| 551 | |
| 552 if (!allow_stored_credentials_) | |
| 553 return true; | |
| 554 | |
| 555 return base::android::BuildInfo::GetInstance()->sdk_int() >= | |
| 556 kSDKVersionToSupportSecurityOriginCheck; | |
| 544 } | 557 } |
| 545 | 558 |
| 546 bool WebMediaPlayerAndroid::didPassCORSAccessCheck() const { | 559 bool WebMediaPlayerAndroid::didPassCORSAccessCheck() const { |
| 547 if (info_loader_) | 560 if (info_loader_) |
| 548 return info_loader_->DidPassCORSAccessCheck(); | 561 return info_loader_->DidPassCORSAccessCheck(); |
| 549 return false; | 562 return false; |
| 550 } | 563 } |
| 551 | 564 |
| 552 double WebMediaPlayerAndroid::mediaTimeForTimeValue(double timeValue) const { | 565 double WebMediaPlayerAndroid::mediaTimeForTimeValue(double timeValue) const { |
| 553 return ConvertSecondsToTimestamp(timeValue).InSecondsF(); | 566 return ConvertSecondsToTimestamp(timeValue).InSecondsF(); |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 863 SetNeedsEstablishPeer(true); | 876 SetNeedsEstablishPeer(true); |
| 864 } | 877 } |
| 865 | 878 |
| 866 void WebMediaPlayerAndroid::OnDestruct() { | 879 void WebMediaPlayerAndroid::OnDestruct() { |
| 867 NOTREACHED() << "WebMediaPlayer should be destroyed before any " | 880 NOTREACHED() << "WebMediaPlayer should be destroyed before any " |
| 868 "RenderFrameObserver::OnDestruct() gets called when " | 881 "RenderFrameObserver::OnDestruct() gets called when " |
| 869 "the RenderFrame goes away."; | 882 "the RenderFrame goes away."; |
| 870 } | 883 } |
| 871 | 884 |
| 872 void WebMediaPlayerAndroid::InitializePlayer( | 885 void WebMediaPlayerAndroid::InitializePlayer( |
| 886 const GURL& url, | |
| 887 const GURL& first_party_for_cookies, | |
| 888 bool allow_stored_credentials, | |
| 873 int demuxer_client_id) { | 889 int demuxer_client_id) { |
| 874 GURL first_party_url = frame_->document().firstPartyForCookies(); | 890 allow_stored_credentials_ = allow_stored_credentials; |
| 875 player_manager_->Initialize( | 891 player_manager_->Initialize( |
| 876 player_type_, player_id_, url_, first_party_url, demuxer_client_id, | 892 player_type_, player_id_, url, first_party_for_cookies, demuxer_client_id, |
| 877 frame_->document().url()); | 893 frame_->document().url(), HasSingleSecurityOriginInternal(), |
| 894 allow_stored_credentials); | |
| 878 } | 895 } |
| 879 | 896 |
| 880 void WebMediaPlayerAndroid::Pause(bool is_media_related_action) { | 897 void WebMediaPlayerAndroid::Pause(bool is_media_related_action) { |
| 881 player_manager_->Pause(player_id_, is_media_related_action); | 898 player_manager_->Pause(player_id_, is_media_related_action); |
| 882 UpdatePlayingState(false); | 899 UpdatePlayingState(false); |
| 883 } | 900 } |
| 884 | 901 |
| 885 void WebMediaPlayerAndroid::DrawRemotePlaybackText( | 902 void WebMediaPlayerAndroid::DrawRemotePlaybackText( |
| 886 const std::string& remote_playback_message) { | 903 const std::string& remote_playback_message) { |
| 887 | 904 |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1234 key_system, method, result_id, kMaxMediaKeyException); | 1251 key_system, method, result_id, kMaxMediaKeyException); |
| 1235 } | 1252 } |
| 1236 | 1253 |
| 1237 bool WebMediaPlayerAndroid::IsKeySystemSupported( | 1254 bool WebMediaPlayerAndroid::IsKeySystemSupported( |
| 1238 const std::string& key_system) { | 1255 const std::string& key_system) { |
| 1239 // On Android, EME only works with MSE. | 1256 // On Android, EME only works with MSE. |
| 1240 return player_type_ == MEDIA_PLAYER_TYPE_MEDIA_SOURCE && | 1257 return player_type_ == MEDIA_PLAYER_TYPE_MEDIA_SOURCE && |
| 1241 IsConcreteSupportedKeySystem(key_system); | 1258 IsConcreteSupportedKeySystem(key_system); |
| 1242 } | 1259 } |
| 1243 | 1260 |
| 1261 bool WebMediaPlayerAndroid::HasSingleSecurityOriginInternal() const { | |
| 1262 if (info_loader_) | |
| 1263 return info_loader_->HasSingleOrigin(); | |
| 1264 // The info loader may have failed. | |
| 1265 if (player_type_ == MEDIA_PLAYER_TYPE_URL) | |
| 1266 return false; | |
| 1267 return true; | |
| 1268 } | |
| 1269 | |
| 1244 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::generateKeyRequest( | 1270 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::generateKeyRequest( |
| 1245 const WebString& key_system, | 1271 const WebString& key_system, |
| 1246 const unsigned char* init_data, | 1272 const unsigned char* init_data, |
| 1247 unsigned init_data_length) { | 1273 unsigned init_data_length) { |
| 1248 DVLOG(1) << "generateKeyRequest: " << base::string16(key_system) << ": " | 1274 DVLOG(1) << "generateKeyRequest: " << base::string16(key_system) << ": " |
| 1249 << std::string(reinterpret_cast<const char*>(init_data), | 1275 << std::string(reinterpret_cast<const char*>(init_data), |
| 1250 static_cast<size_t>(init_data_length)); | 1276 static_cast<size_t>(init_data_length)); |
| 1251 | 1277 |
| 1252 std::string ascii_key_system = | 1278 std::string ascii_key_system = |
| 1253 GetUnprefixedKeySystemName(ToASCIIOrEmpty(key_system)); | 1279 GetUnprefixedKeySystemName(ToASCIIOrEmpty(key_system)); |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1532 player_manager_->EnterFullscreen(player_id_, frame_); | 1558 player_manager_->EnterFullscreen(player_id_, frame_); |
| 1533 SetNeedsEstablishPeer(false); | 1559 SetNeedsEstablishPeer(false); |
| 1534 } | 1560 } |
| 1535 } | 1561 } |
| 1536 | 1562 |
| 1537 bool WebMediaPlayerAndroid::canEnterFullscreen() const { | 1563 bool WebMediaPlayerAndroid::canEnterFullscreen() const { |
| 1538 return player_manager_->CanEnterFullscreen(frame_); | 1564 return player_manager_->CanEnterFullscreen(frame_); |
| 1539 } | 1565 } |
| 1540 | 1566 |
| 1541 } // namespace content | 1567 } // namespace content |
| OLD | NEW |