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

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp

Issue 2681863005: [Video] MediaSession API event handlers can resume background video. (Closed)
Patch Set: Whitespace polishing Created 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights
3 * reserved. 3 * reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
13 * 13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #include "core/html/HTMLMediaElement.h" 27 #include "core/html/HTMLMediaElement.h"
28 28
29 #include <limits>
29 #include "bindings/core/v8/ExceptionState.h" 30 #include "bindings/core/v8/ExceptionState.h"
30 #include "bindings/core/v8/Microtask.h" 31 #include "bindings/core/v8/Microtask.h"
31 #include "bindings/core/v8/ScriptController.h" 32 #include "bindings/core/v8/ScriptController.h"
32 #include "bindings/core/v8/ScriptEventListener.h" 33 #include "bindings/core/v8/ScriptEventListener.h"
33 #include "bindings/core/v8/ScriptPromiseResolver.h" 34 #include "bindings/core/v8/ScriptPromiseResolver.h"
34 #include "core/HTMLNames.h" 35 #include "core/HTMLNames.h"
35 #include "core/css/MediaList.h" 36 #include "core/css/MediaList.h"
36 #include "core/dom/Attribute.h" 37 #include "core/dom/Attribute.h"
37 #include "core/dom/DOMException.h" 38 #include "core/dom/DOMException.h"
39 #include "core/dom/DocumentUserGestureToken.h"
38 #include "core/dom/ElementTraversal.h" 40 #include "core/dom/ElementTraversal.h"
39 #include "core/dom/ElementVisibilityObserver.h" 41 #include "core/dom/ElementVisibilityObserver.h"
40 #include "core/dom/Fullscreen.h" 42 #include "core/dom/Fullscreen.h"
41 #include "core/dom/TaskRunnerHelper.h" 43 #include "core/dom/TaskRunnerHelper.h"
42 #include "core/dom/shadow/ShadowRoot.h" 44 #include "core/dom/shadow/ShadowRoot.h"
43 #include "core/events/Event.h" 45 #include "core/events/Event.h"
44 #include "core/frame/FrameView.h" 46 #include "core/frame/FrameView.h"
45 #include "core/frame/LocalFrame.h" 47 #include "core/frame/LocalFrame.h"
46 #include "core/frame/Settings.h" 48 #include "core/frame/Settings.h"
47 #include "core/frame/UseCounter.h" 49 #include "core/frame/UseCounter.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 #include "public/platform/WebMediaPlayerSource.h" 92 #include "public/platform/WebMediaPlayerSource.h"
91 #include "public/platform/WebMediaStream.h" 93 #include "public/platform/WebMediaStream.h"
92 #include "public/platform/modules/remoteplayback/WebRemotePlaybackAvailability.h " 94 #include "public/platform/modules/remoteplayback/WebRemotePlaybackAvailability.h "
93 #include "public/platform/modules/remoteplayback/WebRemotePlaybackClient.h" 95 #include "public/platform/modules/remoteplayback/WebRemotePlaybackClient.h"
94 #include "public/platform/modules/remoteplayback/WebRemotePlaybackState.h" 96 #include "public/platform/modules/remoteplayback/WebRemotePlaybackState.h"
95 #include "wtf/AutoReset.h" 97 #include "wtf/AutoReset.h"
96 #include "wtf/CurrentTime.h" 98 #include "wtf/CurrentTime.h"
97 #include "wtf/MathExtras.h" 99 #include "wtf/MathExtras.h"
98 #include "wtf/PtrUtil.h" 100 #include "wtf/PtrUtil.h"
99 #include "wtf/text/CString.h" 101 #include "wtf/text/CString.h"
100 #include <limits>
101 102
102 #ifndef BLINK_MEDIA_LOG 103 #ifndef BLINK_MEDIA_LOG
103 #define BLINK_MEDIA_LOG DVLOG(3) 104 #define BLINK_MEDIA_LOG DVLOG(3)
104 #endif 105 #endif
105 106
106 #ifndef LOG_MEDIA_EVENTS 107 #ifndef LOG_MEDIA_EVENTS
107 // Default to not logging events because so many are generated they can 108 // Default to not logging events because so many are generated they can
108 // overwhelm the rest of the logging. 109 // overwhelm the rest of the logging.
109 #define LOG_MEDIA_EVENTS 0 110 #define LOG_MEDIA_EVENTS 0
110 #endif 111 #endif
(...skipping 2197 matching lines...) Expand 10 before | Expand all | Expand 10 after
2308 2309
2309 setIgnorePreloadNone(); 2310 setIgnorePreloadNone();
2310 updatePlayState(); 2311 updatePlayState();
2311 } 2312 }
2312 2313
2313 void HTMLMediaElement::pause() { 2314 void HTMLMediaElement::pause() {
2314 BLINK_MEDIA_LOG << "pause(" << (void*)this << ")"; 2315 BLINK_MEDIA_LOG << "pause(" << (void*)this << ")";
2315 2316
2316 // Only buffer aggressively on a user-initiated pause. Other types of pauses 2317 // Only buffer aggressively on a user-initiated pause. Other types of pauses
2317 // (which go directly to pauseInternal()) should not cause this behavior. 2318 // (which go directly to pauseInternal()) should not cause this behavior.
2318 if (webMediaPlayer() && UserGestureIndicator::utilizeUserGesture()) 2319 if (webMediaPlayer() && UserGestureIndicator::utilizeUserGesture()) {
2319 webMediaPlayer()->setBufferingStrategy( 2320 webMediaPlayer()->setBufferingStrategy(
2320 WebMediaPlayer::BufferingStrategy::Aggressive); 2321 WebMediaPlayer::BufferingStrategy::Aggressive);
2321 2322
2323 // Don't allow webpages to override user-initiated pause.
2324 if (hasVideo() && computeLockedPendingUserGesture(document()))
2325 m_lockedPendingUserGesture = true;
2326 }
2327
2322 if (m_autoplayVisibilityObserver) { 2328 if (m_autoplayVisibilityObserver) {
2323 m_autoplayVisibilityObserver->stop(); 2329 m_autoplayVisibilityObserver->stop();
2324 m_autoplayVisibilityObserver = nullptr; 2330 m_autoplayVisibilityObserver = nullptr;
2325 } 2331 }
2326 2332
2327 pauseInternal(); 2333 pauseInternal();
2328 } 2334 }
2329 2335
2330 void HTMLMediaElement::pauseInternal() { 2336 void HTMLMediaElement::pauseInternal() {
2331 BLINK_MEDIA_LOG << "pauseInternal(" << (void*)this << ")"; 2337 BLINK_MEDIA_LOG << "pauseInternal(" << (void*)this << ")";
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after
3113 if (requestSeek) 3119 if (requestSeek)
3114 seek(duration); 3120 seek(duration);
3115 } 3121 }
3116 3122
3117 void HTMLMediaElement::playbackStateChanged() { 3123 void HTMLMediaElement::playbackStateChanged() {
3118 BLINK_MEDIA_LOG << "playbackStateChanged(" << (void*)this << ")"; 3124 BLINK_MEDIA_LOG << "playbackStateChanged(" << (void*)this << ")";
3119 3125
3120 if (!webMediaPlayer()) 3126 if (!webMediaPlayer())
3121 return; 3127 return;
3122 3128
3129 // playbackStateChanged() is always a result of a user gesture.
3130 UserGestureIndicator gestureIndicator(
3131 DocumentUserGestureToken::create(&document()));
mlamouri (slow - plz ping) 2017/02/17 12:31:31 You can create the user gesture token from the cal
whywhat 2017/02/17 16:30:24 So the callers don't know a user gesture. Ideally
3123 if (webMediaPlayer()->paused()) 3132 if (webMediaPlayer()->paused())
3124 pauseInternal(); 3133 pause();
3125 else 3134 else
3126 playInternal(); 3135 play();
mlamouri (slow - plz ping) 2017/02/17 12:31:31 I'm not sure I follow the reason why this is no lo
whywhat 2017/02/17 16:30:24 So that we respect the user gesture token and unlo
3127 } 3136 }
3128 3137
3129 void HTMLMediaElement::requestSeek(double time) { 3138 void HTMLMediaElement::requestSeek(double time) {
3130 // The player is the source of this seek request. 3139 // The player is the source of this seek request.
3131 setCurrentTime(time); 3140 setCurrentTime(time);
3132 } 3141 }
3133 3142
3134 void HTMLMediaElement::remoteRouteAvailabilityChanged( 3143 void HTMLMediaElement::remoteRouteAvailabilityChanged(
3135 WebRemotePlaybackAvailability availability) { 3144 WebRemotePlaybackAvailability availability) {
3136 if (remotePlaybackClient()) 3145 if (remotePlaybackClient())
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
3178 void HTMLMediaElement::cancelledRemotePlaybackRequest() { 3187 void HTMLMediaElement::cancelledRemotePlaybackRequest() {
3179 if (remotePlaybackClient()) 3188 if (remotePlaybackClient())
3180 remotePlaybackClient()->promptCancelled(); 3189 remotePlaybackClient()->promptCancelled();
3181 } 3190 }
3182 3191
3183 void HTMLMediaElement::remotePlaybackStarted() { 3192 void HTMLMediaElement::remotePlaybackStarted() {
3184 if (remotePlaybackClient()) 3193 if (remotePlaybackClient())
3185 remotePlaybackClient()->stateChanged(WebRemotePlaybackState::Connected); 3194 remotePlaybackClient()->stateChanged(WebRemotePlaybackState::Connected);
3186 } 3195 }
3187 3196
3197 void HTMLMediaElement::wasBackgrounded() {
3198 if (hasVideo() && computeLockedPendingUserGesture(document()))
3199 m_lockedPendingUserGesture = true;
mlamouri (slow - plz ping) 2017/02/17 12:31:31 We should probably discuss this more but I think t
whywhat 2017/02/17 16:30:25 I want to reuse the user gesture lock to enforce t
3200 }
3201
3188 bool HTMLMediaElement::hasSelectedVideoTrack() { 3202 bool HTMLMediaElement::hasSelectedVideoTrack() {
3189 DCHECK(RuntimeEnabledFeatures::backgroundVideoTrackOptimizationEnabled()); 3203 DCHECK(RuntimeEnabledFeatures::backgroundVideoTrackOptimizationEnabled());
3190 3204
3191 return m_videoTracks && m_videoTracks->selectedIndex() != -1; 3205 return m_videoTracks && m_videoTracks->selectedIndex() != -1;
3192 } 3206 }
3193 3207
3194 WebMediaPlayer::TrackId HTMLMediaElement::getSelectedVideoTrackId() { 3208 WebMediaPlayer::TrackId HTMLMediaElement::getSelectedVideoTrackId() {
3195 DCHECK(RuntimeEnabledFeatures::backgroundVideoTrackOptimizationEnabled()); 3209 DCHECK(RuntimeEnabledFeatures::backgroundVideoTrackOptimizationEnabled());
3196 DCHECK(hasSelectedVideoTrack()); 3210 DCHECK(hasSelectedVideoTrack());
3197 3211
3198 int selectedTrackIndex = m_videoTracks->selectedIndex(); 3212 int selectedTrackIndex = m_videoTracks->selectedIndex();
3199 VideoTrack* track = m_videoTracks->anonymousIndexedGetter(selectedTrackIndex); 3213 VideoTrack* track = m_videoTracks->anonymousIndexedGetter(selectedTrackIndex);
3200 return track->id(); 3214 return track->id();
3201 } 3215 }
3202 3216
3203 bool HTMLMediaElement::isAutoplayingMuted() { 3217 bool HTMLMediaElement::isAutoplayingMuted() {
3204 if (!isHTMLVideoElement() || 3218 if (!isHTMLVideoElement() ||
3205 !RuntimeEnabledFeatures::autoplayMutedVideosEnabled()) { 3219 !RuntimeEnabledFeatures::autoplayMutedVideosEnabled()) {
3206 return false; 3220 return false;
3207 } 3221 }
3208 3222
3209 return !paused() && muted() && isLockedPendingUserGesture(); 3223 return !paused() && muted() && isLockedPendingUserGesture();
3210 } 3224 }
3211 3225
3226 bool HTMLMediaElement::isBackgroundVideoPlaybackUnlocked() {
3227 return !isLockedPendingUserGesture();
3228 }
3229
3212 void HTMLMediaElement::requestReload(const WebURL& newUrl) { 3230 void HTMLMediaElement::requestReload(const WebURL& newUrl) {
3213 DCHECK(webMediaPlayer()); 3231 DCHECK(webMediaPlayer());
3214 DCHECK(!m_srcObject); 3232 DCHECK(!m_srcObject);
3215 DCHECK(newUrl.isValid()); 3233 DCHECK(newUrl.isValid());
3216 DCHECK(isSafeToLoadURL(newUrl, Complain)); 3234 DCHECK(isSafeToLoadURL(newUrl, Complain));
3217 resetMediaPlayerAndMediaSource(); 3235 resetMediaPlayerAndMediaSource();
3218 startPlayerLoad(newUrl); 3236 startPlayerLoad(newUrl);
3219 } 3237 }
3220 3238
3221 // MediaPlayerPresentation methods 3239 // MediaPlayerPresentation methods
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
3846 bool HTMLMediaElement::isLockedPendingUserGesture() const { 3864 bool HTMLMediaElement::isLockedPendingUserGesture() const {
3847 return m_lockedPendingUserGesture; 3865 return m_lockedPendingUserGesture;
3848 } 3866 }
3849 3867
3850 void HTMLMediaElement::unlockUserGesture() { 3868 void HTMLMediaElement::unlockUserGesture() {
3851 m_lockedPendingUserGesture = false; 3869 m_lockedPendingUserGesture = false;
3852 m_lockedPendingUserGestureIfCrossOriginExperimentEnabled = false; 3870 m_lockedPendingUserGestureIfCrossOriginExperimentEnabled = false;
3853 } 3871 }
3854 3872
3855 bool HTMLMediaElement::isGestureNeededForPlayback() const { 3873 bool HTMLMediaElement::isGestureNeededForPlayback() const {
3856 if (!m_lockedPendingUserGesture) 3874 if (!isLockedPendingUserGesture())
3857 return false; 3875 return false;
3858 3876
3859 return isGestureNeededForPlaybackIfPendingUserGestureIsLocked(); 3877 return isGestureNeededForPlaybackIfPendingUserGestureIsLocked();
3860 } 3878 }
3861 3879
3862 bool HTMLMediaElement:: 3880 bool HTMLMediaElement::
3863 isGestureNeededForPlaybackIfCrossOriginExperimentEnabled() const { 3881 isGestureNeededForPlaybackIfCrossOriginExperimentEnabled() const {
3864 if (!m_lockedPendingUserGestureIfCrossOriginExperimentEnabled) 3882 if (!m_lockedPendingUserGestureIfCrossOriginExperimentEnabled)
3865 return false; 3883 return false;
3866 3884
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
4148 kMostlyFillViewportBecomeStableSeconds, BLINK_FROM_HERE); 4166 kMostlyFillViewportBecomeStableSeconds, BLINK_FROM_HERE);
4149 } 4167 }
4150 4168
4151 void HTMLMediaElement::viewportFillDebouncerTimerFired(TimerBase*) { 4169 void HTMLMediaElement::viewportFillDebouncerTimerFired(TimerBase*) {
4152 m_mostlyFillingViewport = true; 4170 m_mostlyFillingViewport = true;
4153 if (m_webMediaPlayer) 4171 if (m_webMediaPlayer)
4154 m_webMediaPlayer->becameDominantVisibleContent(m_mostlyFillingViewport); 4172 m_webMediaPlayer->becameDominantVisibleContent(m_mostlyFillingViewport);
4155 } 4173 }
4156 4174
4157 } // namespace blink 4175 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLMediaElement.h ('k') | third_party/WebKit/public/platform/WebMediaPlayerClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698