Changeset 213161 in webkit
- Timestamp:
- Feb 28, 2017 11:42:20 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r213149 r213161 1 2017-02-24 Matt Rajca <mrajca@apple.com> 2 3 Media: notify clients when autoplayed media ends without being paused 4 https://bugs.webkit.org/show_bug.cgi?id=168852 5 6 Reviewed by Alex Christensen. 7 8 Added API tests. 9 10 * html/HTMLMediaElement.cpp: 11 (WebCore::HTMLMediaElement::setReadyState): 12 Set state accordingly if we autoplayed or if playback was prevented. 13 (WebCore::HTMLMediaElement::play): 14 Update state if playback was prevented. 15 (WebCore::HTMLMediaElement::playInternal): 16 Update state if playback began without user interaction. 17 (WebCore::HTMLMediaElement::pauseInternal): 18 Update state. 19 (WebCore::HTMLMediaElement::mediaPlayerTimeChanged): 20 If playback ends and it began without user interaction, send a DidPlayMediaWithoutInterference event. 21 (WebCore::HTMLMediaElement::stopWithoutDestroyingMediaPlayer): Ditto. 22 * html/HTMLMediaElement.h: 23 * page/AutoplayEvent.h: 24 1 25 2017-02-27 Dave Hyatt <hyatt@apple.com> 2 26 -
trunk/Source/WebCore/html/HTMLMediaElement.cpp
r212994 r213161 2417 2417 m_paused = false; 2418 2418 invalidateCachedTime(); 2419 m_playbackWithoutUserGesture = PlaybackWithoutUserGesture::Started; 2419 2420 m_playbackStartedTime = currentMediaTime().toDouble(); 2420 2421 scheduleEvent(eventNames().playEvent); 2421 2422 scheduleNotifyAboutPlaying(); 2422 2423 } else if (success.value() == MediaPlaybackDenialReason::UserGestureRequired) { 2423 m_p reventedFromPlayingWithoutUserGesture = true;2424 m_playbackWithoutUserGesture = PlaybackWithoutUserGesture::Prevented; 2424 2425 2425 2426 if (Page* page = document().page()) … … 3105 3106 if (!success) { 3106 3107 if (success.value() == MediaPlaybackDenialReason::UserGestureRequired) { 3107 m_p reventedFromPlayingWithoutUserGesture = true;3108 m_playbackWithoutUserGesture = PlaybackWithoutUserGesture::Prevented; 3108 3109 3109 3110 if (Page* page = document().page()) … … 3137 3138 if (!success) { 3138 3139 if (success.value() == MediaPlaybackDenialReason::UserGestureRequired) { 3139 m_p reventedFromPlayingWithoutUserGesture = true;3140 m_playbackWithoutUserGesture = PlaybackWithoutUserGesture::Prevented; 3140 3141 3141 3142 if (Page* page = document().page()) … … 3208 3209 scheduleResolvePendingPlayPromises(); 3209 3210 3210 if (ScriptController::processingUserGestureForMedia() && m_preventedFromPlayingWithoutUserGesture) { 3211 if (Page* page = document().page()) 3212 page->chrome().client().handleAutoplayEvent(AutoplayEvent::DidPlayMediaPreventedFromPlaying); 3213 m_preventedFromPlayingWithoutUserGesture = false; 3214 } 3211 if (ScriptController::processingUserGestureForMedia()) { 3212 if (m_playbackWithoutUserGesture == PlaybackWithoutUserGesture::Prevented) { 3213 if (Page* page = document().page()) 3214 page->chrome().client().handleAutoplayEvent(AutoplayEvent::DidPlayMediaPreventedFromPlaying); 3215 m_playbackWithoutUserGesture = PlaybackWithoutUserGesture::None; 3216 } 3217 } else 3218 m_playbackWithoutUserGesture = PlaybackWithoutUserGesture::Started; 3215 3219 3216 3220 m_autoplaying = false; … … 3253 3257 3254 3258 m_autoplaying = false; 3259 m_playbackWithoutUserGesture = PlaybackWithoutUserGesture::None; 3255 3260 3256 3261 if (!m_paused) { … … 4402 4407 if (!wasSeeking) 4403 4408 addBehaviorRestrictionsOnEndIfNecessary(); 4409 4410 if (m_playbackWithoutUserGesture == PlaybackWithoutUserGesture::Started) { 4411 if (Page* page = document().page()) 4412 page->chrome().client().handleAutoplayEvent(AutoplayEvent::DidEndMediaPlaybackWithoutUserInterference); 4413 } 4414 m_playbackWithoutUserGesture = PlaybackWithoutUserGesture::None; 4404 4415 } 4405 4416 // If the media element has a current media controller, then report the controller state … … 5157 5168 setPausedInternal(true); 5158 5169 m_mediaSession->clientWillPausePlayback(); 5170 5171 if (m_playbackWithoutUserGesture == PlaybackWithoutUserGesture::Started) { 5172 if (Page* page = document().page()) 5173 page->chrome().client().handleAutoplayEvent(AutoplayEvent::DidEndMediaPlaybackWithoutUserInterference); 5174 } 5175 m_playbackWithoutUserGesture = PlaybackWithoutUserGesture::None; 5159 5176 5160 5177 userCancelledLoad(); -
trunk/Source/WebCore/html/HTMLMediaElement.h
r212314 r213161 975 975 bool m_receivedLayoutSizeChanged : 1; 976 976 bool m_hasEverNotifiedAboutPlaying : 1; 977 bool m_preventedFromPlayingWithoutUserGesture : 1;978 977 979 978 bool m_hasEverHadAudio : 1; … … 991 990 bool m_haveVisibleTextTrack : 1; 992 991 bool m_processingPreferenceChange : 1; 992 993 enum class PlaybackWithoutUserGesture { None, Started, Prevented }; 994 PlaybackWithoutUserGesture m_playbackWithoutUserGesture; 993 995 994 996 String m_subtitleTrackLanguage; -
trunk/Source/WebCore/page/AutoplayEvent.h
r212982 r213161 31 31 DidPreventMediaFromPlaying, 32 32 DidPlayMediaPreventedFromPlaying, 33 DidEndMediaPlaybackWithoutUserInterference, 33 34 }; 34 35 -
trunk/Source/WebKit2/ChangeLog
r213127 r213161 1 2017-02-24 Matt Rajca <mrajca@apple.com> 2 3 Media: notify clients when autoplayed media ends without being paused 4 https://bugs.webkit.org/show_bug.cgi?id=168852 5 6 Reviewed by Alex Christensen. 7 8 * UIProcess/API/C/WKPageUIClient.h: 9 1 10 2017-02-28 Csaba Osztrogonác <ossy@webkit.org> 2 11 -
trunk/Source/WebKit2/UIProcess/API/C/WKPageUIClient.h
r212982 r213161 52 52 kWKAutoplayEventDidPreventFromAutoplaying, 53 53 kWKAutoplayEventDidPlayMediaPreventedFromAutoplaying, 54 kWKAutoplayEventDidEndMediaPlaybackWithoutUserInterference, 54 55 }; 55 56 typedef uint32_t WKAutoplayEvent; -
trunk/Tools/ChangeLog
r213150 r213161 1 2017-02-24 Matt Rajca <mrajca@apple.com> 2 3 Media: notify clients when autoplayed media ends without being paused 4 https://bugs.webkit.org/show_bug.cgi?id=168852 5 6 Reviewed by Alex Christensen. 7 8 * TestWebKitAPI/Tests/WebKit2/js-play-with-controls.html: 9 * TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm: 10 (TEST): Added. 11 1 12 2017-02-28 Jonathan Bedard <jbedard@apple.com> 2 13 -
trunk/Tools/TestWebKitAPI/Tests/WebKit2/js-play-with-controls.html
r211226 r213161 12 12 document.getElementById("video").play(); 13 13 } 14 15 function beganPlaying() { 16 try { 17 window.webkit.messageHandlers.testHandler.postMessage("playing"); 18 } catch(e) { } 19 } 20 21 function endedPlaying() { 22 try { 23 window.webkit.messageHandlers.testHandler.postMessage("ended"); 24 } catch(e) { } 25 } 14 26 </script> 15 27 </head> 16 28 <body onload="pageLoaded()"> 17 29 <button onclick="play()">Play</button> 18 <video id="video" src="test.mp4" />30 <video id="video" onplaying=beganPlaying() onended=endedPlaying() src="test.mp4" /> 19 31 </body> 20 32 </html> -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm
r212982 r213161 317 317 ASSERT_TRUE(receivedAutoplayEvent == std::nullopt); 318 318 } 319 #endif 320 321 #endif 319 320 TEST(WebKit2, WebsitePoliciesPlayingWithoutInterference) 321 { 322 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 323 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 336, 276) configuration:configuration.get()]); 324 325 auto delegate = adoptNS([[AutoplayPoliciesDelegate alloc] init]); 326 [delegate setAutoplayPolicyForURL:^(NSURL *) { 327 return _WKWebsiteAutoplayPolicyAllow; 328 }]; 329 [webView setNavigationDelegate:delegate.get()]; 330 331 WKPageUIClientV9 uiClient; 332 memset(&uiClient, 0, sizeof(uiClient)); 333 334 uiClient.base.version = 9; 335 uiClient.handleAutoplayEvent = handleAutoplayEvent; 336 337 WKPageSetPageUIClient([webView _pageForTesting], &uiClient.base); 338 339 receivedAutoplayEvent = std::nullopt; 340 NSURLRequest *jsPlayRequest = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"js-play-with-controls" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 341 [webView loadRequest:jsPlayRequest]; 342 [webView waitForMessage:@"playing"]; 343 344 ASSERT_TRUE(receivedAutoplayEvent == std::nullopt); 345 346 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]]; 347 runUntilReceivesAutoplayEvent(kWKAutoplayEventDidEndMediaPlaybackWithoutUserInterference); 348 349 receivedAutoplayEvent = std::nullopt; 350 [webView loadRequest:jsPlayRequest]; 351 [webView waitForMessage:@"ended"]; 352 runUntilReceivesAutoplayEvent(kWKAutoplayEventDidEndMediaPlaybackWithoutUserInterference); 353 } 354 #endif 355 356 #endif
Note: See TracChangeset
for help on using the changeset viewer.