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

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

Issue 2705213007: [Video] MediaSession API event handlers can resume background video. (Closed)
Patch Set: Fixed WMPA Created 3 years, 9 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
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <limits> 9 #include <limits>
10 10
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 #include "third_party/WebKit/public/platform/WebEncryptedMediaTypes.h" 54 #include "third_party/WebKit/public/platform/WebEncryptedMediaTypes.h"
55 #include "third_party/WebKit/public/platform/WebGraphicsContext3DProvider.h" 55 #include "third_party/WebKit/public/platform/WebGraphicsContext3DProvider.h"
56 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" 56 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h"
57 #include "third_party/WebKit/public/platform/WebMediaPlayerEncryptedMediaClient. h" 57 #include "third_party/WebKit/public/platform/WebMediaPlayerEncryptedMediaClient. h"
58 #include "third_party/WebKit/public/platform/WebMediaPlayerSource.h" 58 #include "third_party/WebKit/public/platform/WebMediaPlayerSource.h"
59 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" 59 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
60 #include "third_party/WebKit/public/platform/WebString.h" 60 #include "third_party/WebKit/public/platform/WebString.h"
61 #include "third_party/WebKit/public/platform/WebURL.h" 61 #include "third_party/WebKit/public/platform/WebURL.h"
62 #include "third_party/WebKit/public/web/WebDocument.h" 62 #include "third_party/WebKit/public/web/WebDocument.h"
63 #include "third_party/WebKit/public/web/WebFrame.h" 63 #include "third_party/WebKit/public/web/WebFrame.h"
64 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
64 #include "third_party/WebKit/public/web/WebView.h" 65 #include "third_party/WebKit/public/web/WebView.h"
65 #include "third_party/skia/include/core/SkCanvas.h" 66 #include "third_party/skia/include/core/SkCanvas.h"
66 #include "third_party/skia/include/core/SkImage.h" 67 #include "third_party/skia/include/core/SkImage.h"
67 #include "third_party/skia/include/core/SkPaint.h" 68 #include "third_party/skia/include/core/SkPaint.h"
68 #include "third_party/skia/include/core/SkTypeface.h" 69 #include "third_party/skia/include/core/SkTypeface.h"
69 #include "ui/gfx/image/image.h" 70 #include "ui/gfx/image/image.h"
70 #include "url/gurl.h" 71 #include "url/gurl.h"
71 #include "url/origin.h" 72 #include "url/origin.h"
72 73
73 static const uint32_t kGLTextureExternalOES = 0x8D65; 74 static const uint32_t kGLTextureExternalOES = 0x8D65;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 media_log_(params.media_log()), 171 media_log_(params.media_log()),
171 allow_stored_credentials_(false), 172 allow_stored_credentials_(false),
172 is_local_resource_(false), 173 is_local_resource_(false),
173 interpolator_(&default_tick_clock_), 174 interpolator_(&default_tick_clock_),
174 frame_id_(frame_id), 175 frame_id_(frame_id),
175 enable_texture_copy_(enable_texture_copy), 176 enable_texture_copy_(enable_texture_copy),
176 suppress_deleting_texture_(false), 177 suppress_deleting_texture_(false),
177 playback_completed_(false), 178 playback_completed_(false),
178 volume_(1.0), 179 volume_(1.0),
179 volume_multiplier_(1.0), 180 volume_multiplier_(1.0),
181 video_locked_when_paused_when_hidden_(false),
180 weak_factory_(this) { 182 weak_factory_(this) {
181 DCHECK(player_manager_); 183 DCHECK(player_manager_);
182 184
183 DCHECK(main_thread_checker_.CalledOnValidThread()); 185 DCHECK(main_thread_checker_.CalledOnValidThread());
184 186
185 if (delegate_) { 187 if (delegate_) {
186 delegate_id_ = delegate_->AddObserver(this); 188 delegate_id_ = delegate_->AddObserver(this);
187 delegate_->SetIdle(delegate_id_, true); 189 delegate_->SetIdle(delegate_id_, true);
188 } 190 }
189 191
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 !host.compare("[::1]")) { 288 !host.compare("[::1]")) {
287 return true; 289 return true;
288 } 290 }
289 291
290 return false; 292 return false;
291 } 293 }
292 294
293 void WebMediaPlayerAndroid::play() { 295 void WebMediaPlayerAndroid::play() {
294 DCHECK(main_thread_checker_.CalledOnValidThread()); 296 DCHECK(main_thread_checker_.CalledOnValidThread());
295 297
298 if (blink::WebUserGestureIndicator::isProcessingUserGesture())
299 video_locked_when_paused_when_hidden_ = false;
300
296 if (hasVideo() && player_manager_->render_frame()->IsHidden()) { 301 if (hasVideo() && player_manager_->render_frame()->IsHidden()) {
297 bool can_video_play_in_background = 302 bool can_video_play_in_background =
298 base::CommandLine::ForCurrentProcess()->HasSwitch( 303 base::CommandLine::ForCurrentProcess()->HasSwitch(
299 switches::kDisableMediaSuspend) || 304 switches::kDisableMediaSuspend) ||
300 (IsBackgroundVideoCandidate() && delegate_ && 305 (IsBackgroundVideoCandidate() &&
301 delegate_->IsBackgroundVideoPlaybackUnlocked()); 306 !video_locked_when_paused_when_hidden_);
302 if (!can_video_play_in_background) { 307 if (!can_video_play_in_background) {
303 is_play_pending_ = true; 308 is_play_pending_ = true;
304 return; 309 return;
305 } 310 }
306 } 311 }
307 is_play_pending_ = false; 312 is_play_pending_ = false;
308 313
309 TryCreateStreamTextureProxyIfNeeded(); 314 TryCreateStreamTextureProxyIfNeeded();
310 // There is no need to establish the surface texture peer for fullscreen 315 // There is no need to establish the surface texture peer for fullscreen
311 // video. 316 // video.
312 if ((hasVideo() || IsHLSStream()) && needs_establish_peer_ && 317 if ((hasVideo() || IsHLSStream()) && needs_establish_peer_ &&
313 !is_fullscreen_) { 318 !is_fullscreen_) {
314 EstablishSurfaceTexturePeer(); 319 EstablishSurfaceTexturePeer();
315 } 320 }
316 321
317 // UpdatePlayingState() must be run before calling Start() to ensure that the 322 // UpdatePlayingState() must be run before calling Start() to ensure that the
318 // browser side MediaPlayerAndroid values for hasAudio() and hasVideo() take 323 // browser side MediaPlayerAndroid values for hasAudio() and hasVideo() take
319 // precedent over the guesses that we make based on mime type. 324 // precedent over the guesses that we make based on mime type.
320 const bool is_paused = paused(); 325 const bool is_paused = paused();
321 UpdatePlayingState(true); 326 UpdatePlayingState(true);
322 if (is_paused) 327 if (is_paused)
323 player_manager_->Start(player_id_); 328 player_manager_->Start(player_id_);
324 UpdateNetworkState(WebMediaPlayer::NetworkStateLoading); 329 UpdateNetworkState(WebMediaPlayer::NetworkStateLoading);
325 } 330 }
326 331
327 void WebMediaPlayerAndroid::pause() { 332 void WebMediaPlayerAndroid::pause() {
328 DCHECK(main_thread_checker_.CalledOnValidThread()); 333 DCHECK(main_thread_checker_.CalledOnValidThread());
334
335 if (blink::WebUserGestureIndicator::isProcessingUserGesture()) {
336 video_locked_when_paused_when_hidden_ = true;
337 is_play_pending_ = false;
338 }
339
329 Pause(true); 340 Pause(true);
330 } 341 }
331 342
332 void WebMediaPlayerAndroid::requestRemotePlayback() { 343 void WebMediaPlayerAndroid::requestRemotePlayback() {
333 player_manager_->RequestRemotePlayback(player_id_); 344 player_manager_->RequestRemotePlayback(player_id_);
334 } 345 }
335 346
336 void WebMediaPlayerAndroid::requestRemotePlaybackControl() { 347 void WebMediaPlayerAndroid::requestRemotePlaybackControl() {
337 player_manager_->RequestRemotePlaybackControl(player_id_); 348 player_manager_->RequestRemotePlaybackControl(player_id_);
338 } 349 }
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 delegate_->PlayerGone(delegate_id_); 1234 delegate_->PlayerGone(delegate_id_);
1224 } else { 1235 } else {
1225 delegate_->DidPause(delegate_id_); 1236 delegate_->DidPause(delegate_id_);
1226 } 1237 }
1227 delegate_->SetIdle(delegate_id_, true); 1238 delegate_->SetIdle(delegate_id_, true);
1228 } 1239 }
1229 } 1240 }
1230 } 1241 }
1231 1242
1232 void WebMediaPlayerAndroid::OnFrameHidden() { 1243 void WebMediaPlayerAndroid::OnFrameHidden() {
1244 video_locked_when_paused_when_hidden_ = true;
1245
1233 // Pause audible video preserving its session. 1246 // Pause audible video preserving its session.
1234 if (hasVideo() && IsBackgroundVideoCandidate() && !paused()) { 1247 if (hasVideo() && IsBackgroundVideoCandidate() && !paused()) {
1235 Pause(false); 1248 Pause(false);
1236 is_play_pending_ = true; 1249 is_play_pending_ = true;
1237 return; 1250 return;
1238 } 1251 }
1239 1252
1240 OnIdleTimeout(); 1253 OnIdleTimeout();
1241 } 1254 }
1242 1255
1243 void WebMediaPlayerAndroid::OnFrameClosed() { 1256 void WebMediaPlayerAndroid::OnFrameClosed() {
1244 SuspendAndReleaseResources(); 1257 SuspendAndReleaseResources();
1245 } 1258 }
1246 1259
1247 void WebMediaPlayerAndroid::OnFrameShown() { 1260 void WebMediaPlayerAndroid::OnFrameShown() {
1261 video_locked_when_paused_when_hidden_ = false;
1248 if (is_play_pending_) 1262 if (is_play_pending_)
1249 play(); 1263 play();
1250 } 1264 }
1251 1265
1252 void WebMediaPlayerAndroid::OnIdleTimeout() { 1266 void WebMediaPlayerAndroid::OnIdleTimeout() {
1253 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 1267 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1254 switches::kDisableMediaSuspend)) { 1268 switches::kDisableMediaSuspend)) {
1255 return; 1269 return;
1256 } 1270 }
1257 1271
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1339 switches::kDisableMediaSuspend)) { 1353 switches::kDisableMediaSuspend)) {
1340 return false; 1354 return false;
1341 } 1355 }
1342 1356
1343 return base::FeatureList::IsEnabled(media::kResumeBackgroundVideo) && 1357 return base::FeatureList::IsEnabled(media::kResumeBackgroundVideo) &&
1344 hasAudio() && !isRemote() && delegate_ && delegate_->IsFrameHidden() && 1358 hasAudio() && !isRemote() && delegate_ && delegate_->IsFrameHidden() &&
1345 !delegate_->IsFrameClosed(); 1359 !delegate_->IsFrameClosed();
1346 } 1360 }
1347 1361
1348 } // namespace content 1362 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/android/webmediaplayer_android.h ('k') | content/renderer/media/renderer_webmediaplayer_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698