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

Side by Side Diff: content/renderer/media/android/webmediaplayer_android.cc

Issue 408873004: Fix for cross-origin video check for webgl on android (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix clang warnings Created 6 years, 4 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
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/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 29 matching lines...) Expand all
48 #include "third_party/WebKit/public/web/WebFrame.h" 49 #include "third_party/WebKit/public/web/WebFrame.h"
49 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" 50 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
50 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" 51 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
51 #include "third_party/WebKit/public/web/WebView.h" 52 #include "third_party/WebKit/public/web/WebView.h"
52 #include "third_party/skia/include/core/SkCanvas.h" 53 #include "third_party/skia/include/core/SkCanvas.h"
53 #include "third_party/skia/include/core/SkPaint.h" 54 #include "third_party/skia/include/core/SkPaint.h"
54 #include "third_party/skia/include/core/SkTypeface.h" 55 #include "third_party/skia/include/core/SkTypeface.h"
55 #include "ui/gfx/image/image.h" 56 #include "ui/gfx/image/image.h"
56 57
57 static const uint32 kGLTextureExternalOES = 0x8D65; 58 static const uint32 kGLTextureExternalOES = 0x8D65;
59 static const int kSDKVersionToSupportSecurityOriginCheck = 20;
58 60
59 using blink::WebMediaPlayer; 61 using blink::WebMediaPlayer;
60 using blink::WebSize; 62 using blink::WebSize;
61 using blink::WebString; 63 using blink::WebString;
62 using blink::WebTimeRanges; 64 using blink::WebTimeRanges;
63 using blink::WebURL; 65 using blink::WebURL;
64 using gpu::gles2::GLES2Interface; 66 using gpu::gles2::GLES2Interface;
65 using media::MediaPlayerAndroid; 67 using media::MediaPlayerAndroid;
66 using media::VideoFrame; 68 using media::VideoFrame;
67 69
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 has_size_info_(false), 133 has_size_info_(false),
132 stream_texture_factory_(factory), 134 stream_texture_factory_(factory),
133 needs_external_surface_(false), 135 needs_external_surface_(false),
134 video_frame_provider_client_(NULL), 136 video_frame_provider_client_(NULL),
135 pending_playback_(false), 137 pending_playback_(false),
136 player_type_(MEDIA_PLAYER_TYPE_URL), 138 player_type_(MEDIA_PLAYER_TYPE_URL),
137 current_time_(0), 139 current_time_(0),
138 is_remote_(false), 140 is_remote_(false),
139 media_log_(media_log), 141 media_log_(media_log),
140 web_cdm_(NULL), 142 web_cdm_(NULL),
143 allow_stored_credentials_(false),
141 weak_factory_(this) { 144 weak_factory_(this) {
142 DCHECK(player_manager_); 145 DCHECK(player_manager_);
143 DCHECK(cdm_manager_); 146 DCHECK(cdm_manager_);
144 147
145 DCHECK(main_thread_checker_.CalledOnValidThread()); 148 DCHECK(main_thread_checker_.CalledOnValidThread());
146 149
147 player_id_ = player_manager_->RegisterMediaPlayer(this); 150 player_id_ = player_manager_->RegisterMediaPlayer(this);
148 151
149 #if defined(VIDEO_HOLE) 152 #if defined(VIDEO_HOLE)
150 force_use_overlay_embedded_video_ = CommandLine::ForCurrentProcess()-> 153 force_use_overlay_embedded_video_ = CommandLine::ForCurrentProcess()->
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 media_source_delegate_->InitializeMediaSource( 227 media_source_delegate_->InitializeMediaSource(
225 base::Bind(&WebMediaPlayerAndroid::OnMediaSourceOpened, 228 base::Bind(&WebMediaPlayerAndroid::OnMediaSourceOpened,
226 weak_factory_.GetWeakPtr()), 229 weak_factory_.GetWeakPtr()),
227 base::Bind(&WebMediaPlayerAndroid::OnNeedKey, 230 base::Bind(&WebMediaPlayerAndroid::OnNeedKey,
228 weak_factory_.GetWeakPtr()), 231 weak_factory_.GetWeakPtr()),
229 set_decryptor_ready_cb, 232 set_decryptor_ready_cb,
230 base::Bind(&WebMediaPlayerAndroid::UpdateNetworkState, 233 base::Bind(&WebMediaPlayerAndroid::UpdateNetworkState,
231 weak_factory_.GetWeakPtr()), 234 weak_factory_.GetWeakPtr()),
232 base::Bind(&WebMediaPlayerAndroid::OnDurationChanged, 235 base::Bind(&WebMediaPlayerAndroid::OnDurationChanged,
233 weak_factory_.GetWeakPtr())); 236 weak_factory_.GetWeakPtr()));
234 InitializePlayer(demuxer_client_id); 237 InitializePlayer(url_, frame_->document().firstPartyForCookies(),
238 true, demuxer_client_id);
235 } 239 }
236 } else { 240 } else {
237 info_loader_.reset( 241 info_loader_.reset(
238 new MediaInfoLoader( 242 new MediaInfoLoader(
239 url, 243 url,
240 cors_mode, 244 cors_mode,
241 base::Bind(&WebMediaPlayerAndroid::DidLoadMediaInfo, 245 base::Bind(&WebMediaPlayerAndroid::DidLoadMediaInfo,
242 weak_factory_.GetWeakPtr()))); 246 weak_factory_.GetWeakPtr())));
243 // TODO(qinmin): The url might be redirected when android media player
244 // requests the stream. As a result, we cannot guarantee there is only
245 // a single origin. Remove the following line when b/12573548 is fixed.
246 // Check http://crbug.com/334204.
247 info_loader_->set_single_origin(false);
248 info_loader_->Start(frame_); 247 info_loader_->Start(frame_);
249 } 248 }
250 249
251 UpdateNetworkState(WebMediaPlayer::NetworkStateLoading); 250 UpdateNetworkState(WebMediaPlayer::NetworkStateLoading);
252 UpdateReadyState(WebMediaPlayer::ReadyStateHaveNothing); 251 UpdateReadyState(WebMediaPlayer::ReadyStateHaveNothing);
253 } 252 }
254 253
255 void WebMediaPlayerAndroid::DidLoadMediaInfo(MediaInfoLoader::Status status) { 254 void WebMediaPlayerAndroid::DidLoadMediaInfo(
255 MediaInfoLoader::Status status,
256 const GURL& redirected_url,
257 const GURL& first_party_for_cookies,
258 bool allow_stored_credentials) {
256 DCHECK(!media_source_delegate_); 259 DCHECK(!media_source_delegate_);
257 if (status == MediaInfoLoader::kFailed) { 260 if (status == MediaInfoLoader::kFailed) {
258 info_loader_.reset(); 261 info_loader_.reset();
259 UpdateNetworkState(WebMediaPlayer::NetworkStateNetworkError); 262 UpdateNetworkState(WebMediaPlayer::NetworkStateNetworkError);
260 return; 263 return;
261 } 264 }
262 265
263 InitializePlayer(0); 266 InitializePlayer(
267 redirected_url, first_party_for_cookies, allow_stored_credentials, 0);
264 268
265 UpdateNetworkState(WebMediaPlayer::NetworkStateIdle); 269 UpdateNetworkState(WebMediaPlayer::NetworkStateIdle);
266 } 270 }
267 271
268 void WebMediaPlayerAndroid::play() { 272 void WebMediaPlayerAndroid::play() {
269 #if defined(VIDEO_HOLE) 273 #if defined(VIDEO_HOLE)
270 if (hasVideo() && needs_external_surface_ && 274 if (hasVideo() && needs_external_surface_ &&
271 !player_manager_->IsInFullscreen(frame_)) { 275 !player_manager_->IsInFullscreen(frame_)) {
272 DCHECK(!needs_establish_peer_); 276 DCHECK(!needs_establish_peer_);
273 player_manager_->RequestExternalSurface(player_id_, last_computed_rect_); 277 player_manager_->RequestExternalSurface(player_id_, last_computed_rect_);
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 599
596 web_graphics_context->deleteTexture(src_texture); 600 web_graphics_context->deleteTexture(src_texture);
597 web_graphics_context->flush(); 601 web_graphics_context->flush();
598 602
599 SyncPointClientImpl client(web_graphics_context); 603 SyncPointClientImpl client(web_graphics_context);
600 video_frame->UpdateReleaseSyncPoint(&client); 604 video_frame->UpdateReleaseSyncPoint(&client);
601 return true; 605 return true;
602 } 606 }
603 607
604 bool WebMediaPlayerAndroid::hasSingleSecurityOrigin() const { 608 bool WebMediaPlayerAndroid::hasSingleSecurityOrigin() const {
605 if (info_loader_) 609 if (player_type_ != MEDIA_PLAYER_TYPE_URL)
606 return info_loader_->HasSingleOrigin(); 610 return true;
607 // The info loader may have failed. 611
608 if (player_type_ == MEDIA_PLAYER_TYPE_URL) 612 if (!info_loader_ || !info_loader_->HasSingleOrigin())
609 return false; 613 return false;
610 return true; 614
615 // TODO(qinmin): The url might be redirected when android media player
616 // requests the stream. As a result, we cannot guarantee there is only
617 // a single origin. Only if the HTTP request was made without credentials,
618 // we will honor the return value from HasSingleSecurityOriginInternal()
619 // in pre-L android versions.
620 // Check http://crbug.com/334204.
621 if (!allow_stored_credentials_)
622 return true;
623
624 return base::android::BuildInfo::GetInstance()->sdk_int() >=
625 kSDKVersionToSupportSecurityOriginCheck;
dshwang 2014/08/11 08:01:33 This method allows SSO for systems >=L although th
dshwang 2014/08/15 09:25:55 This CL makes WebGL more restricted on systems <K,
611 } 626 }
612 627
613 bool WebMediaPlayerAndroid::didPassCORSAccessCheck() const { 628 bool WebMediaPlayerAndroid::didPassCORSAccessCheck() const {
614 if (info_loader_) 629 if (info_loader_)
615 return info_loader_->DidPassCORSAccessCheck(); 630 return info_loader_->DidPassCORSAccessCheck();
616 return false; 631 return false;
617 } 632 }
618 633
619 double WebMediaPlayerAndroid::mediaTimeForTimeValue(double timeValue) const { 634 double WebMediaPlayerAndroid::mediaTimeForTimeValue(double timeValue) const {
620 return ConvertSecondsToTimestamp(timeValue).InSecondsF(); 635 return ConvertSecondsToTimestamp(timeValue).InSecondsF();
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 SetNeedsEstablishPeer(true); 945 SetNeedsEstablishPeer(true);
931 } 946 }
932 947
933 void WebMediaPlayerAndroid::OnDestruct() { 948 void WebMediaPlayerAndroid::OnDestruct() {
934 NOTREACHED() << "WebMediaPlayer should be destroyed before any " 949 NOTREACHED() << "WebMediaPlayer should be destroyed before any "
935 "RenderFrameObserver::OnDestruct() gets called when " 950 "RenderFrameObserver::OnDestruct() gets called when "
936 "the RenderFrame goes away."; 951 "the RenderFrame goes away.";
937 } 952 }
938 953
939 void WebMediaPlayerAndroid::InitializePlayer( 954 void WebMediaPlayerAndroid::InitializePlayer(
955 const GURL& url,
956 const GURL& first_party_for_cookies,
957 bool allow_stored_credentials,
940 int demuxer_client_id) { 958 int demuxer_client_id) {
941 GURL first_party_url = frame_->document().firstPartyForCookies(); 959 allow_stored_credentials_ = allow_stored_credentials;
942 player_manager_->Initialize( 960 player_manager_->Initialize(
943 player_type_, player_id_, url_, first_party_url, demuxer_client_id, 961 player_type_, player_id_, url, first_party_for_cookies, demuxer_client_id,
944 frame_->document().url()); 962 frame_->document().url(), allow_stored_credentials);
945 if (player_manager_->ShouldEnterFullscreen(frame_)) 963 if (player_manager_->ShouldEnterFullscreen(frame_))
946 player_manager_->EnterFullscreen(player_id_, frame_); 964 player_manager_->EnterFullscreen(player_id_, frame_);
947 } 965 }
948 966
949 void WebMediaPlayerAndroid::Pause(bool is_media_related_action) { 967 void WebMediaPlayerAndroid::Pause(bool is_media_related_action) {
950 player_manager_->Pause(player_id_, is_media_related_action); 968 player_manager_->Pause(player_id_, is_media_related_action);
951 UpdatePlayingState(false); 969 UpdatePlayingState(false);
952 } 970 }
953 971
954 void WebMediaPlayerAndroid::DrawRemotePlaybackText( 972 void WebMediaPlayerAndroid::DrawRemotePlaybackText(
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
1601 player_manager_->EnterFullscreen(player_id_, frame_); 1619 player_manager_->EnterFullscreen(player_id_, frame_);
1602 SetNeedsEstablishPeer(false); 1620 SetNeedsEstablishPeer(false);
1603 } 1621 }
1604 } 1622 }
1605 1623
1606 bool WebMediaPlayerAndroid::canEnterFullscreen() const { 1624 bool WebMediaPlayerAndroid::canEnterFullscreen() const {
1607 return player_manager_->CanEnterFullscreen(frame_); 1625 return player_manager_->CanEnterFullscreen(frame_);
1608 } 1626 }
1609 1627
1610 } // namespace content 1628 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698