Changeset 215771 in webkit
- Timestamp:
- Apr 25, 2017 5:02:59 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r215769 r215771 1 2017-04-24 Matt Rajca <mrajca@apple.com> 2 3 Indicate presence of audio when handling autoplay events. 4 https://bugs.webkit.org/show_bug.cgi?id=171227 5 6 Reviewed by Alex Christensen. 7 8 Added API tests. 9 10 * html/HTMLMediaElement.cpp: 11 (WebCore::HTMLMediaElement::handleAutoplayEvent): 12 (WebCore::HTMLMediaElement::playInternal): 13 (WebCore::HTMLMediaElement::mediaPlayerTimeChanged): 14 (WebCore::HTMLMediaElement::stopWithoutDestroyingMediaPlayer): 15 (WebCore::HTMLMediaElement::userDidInterfereWithAutoplay): 16 (WebCore::HTMLMediaElement::setPlaybackWithoutUserGesture): 17 * html/HTMLMediaElement.h: 18 * page/AutoplayEvent.h: 19 * page/ChromeClient.h: 20 1 21 2017-04-25 Aakash Jain <aakash_jain@apple.com> 2 22 -
trunk/Source/WebCore/html/HTMLMediaElement.cpp
r215649 r215771 3243 3243 if (ScriptController::processingUserGestureForMedia()) { 3244 3244 if (m_playbackWithoutUserGesture == PlaybackWithoutUserGesture::Prevented) { 3245 if (Page* page = document().page()) 3246 page->chrome().client().handleAutoplayEvent(AutoplayEvent::DidPlayMediaPreventedFromPlaying); 3245 handleAutoplayEvent(AutoplayEvent::DidPlayMediaPreventedFromPlaying); 3247 3246 setPlaybackWithoutUserGesture(PlaybackWithoutUserGesture::None); 3248 3247 } … … 3384 3383 bool mutedStateChanged = m_muted != muted; 3385 3384 if (mutedStateChanged || !m_explicitlyMuted) { 3385 if (ScriptController::processingUserGestureForMedia()) { 3386 removeBehaviorsRestrictionsAfterFirstUserGesture(MediaElementSession::AllRestrictions & ~MediaElementSession::RequireUserGestureToControlControlsManager); 3387 3388 if (hasAudio() && muted) 3389 userDidInterfereWithAutoplay(); 3390 } 3391 3386 3392 m_muted = muted; 3387 3393 m_explicitlyMuted = true; 3388 3389 if (ScriptController::processingUserGestureForMedia()) {3390 removeBehaviorsRestrictionsAfterFirstUserGesture(MediaElementSession::AllRestrictions & ~MediaElementSession::RequireUserGestureToControlControlsManager);3391 3392 if (hasAudio() && m_muted)3393 userDidInterfereWithAutoplay();3394 }3395 3394 3396 3395 // Avoid recursion when the player reports volume changes. … … 4468 4467 addBehaviorRestrictionsOnEndIfNecessary(); 4469 4468 4470 if (m_playbackWithoutUserGesture == PlaybackWithoutUserGesture::Started) { 4471 if (Page* page = document().page()) 4472 page->chrome().client().handleAutoplayEvent(AutoplayEvent::DidEndMediaPlaybackWithoutUserInterference); 4473 } 4469 if (m_playbackWithoutUserGesture == PlaybackWithoutUserGesture::Started) 4470 handleAutoplayEvent(AutoplayEvent::DidEndMediaPlaybackWithoutUserInterference); 4471 4474 4472 setPlaybackWithoutUserGesture(PlaybackWithoutUserGesture::None); 4475 4473 } … … 5231 5229 m_mediaSession->clientWillPausePlayback(); 5232 5230 5233 if (Page* page = document().page()) { 5234 switch (m_playbackWithoutUserGesture) { 5235 case PlaybackWithoutUserGesture::Started: 5236 page->chrome().client().handleAutoplayEvent(AutoplayEvent::DidEndMediaPlaybackWithoutUserInterference); 5237 break; 5238 case PlaybackWithoutUserGesture::Prevented: 5239 page->chrome().client().handleAutoplayEvent(AutoplayEvent::UserNeverPlayedMediaPreventedFromPlaying); 5240 break; 5241 case PlaybackWithoutUserGesture::None: 5242 break; 5243 } 5244 } 5231 switch (m_playbackWithoutUserGesture) { 5232 case PlaybackWithoutUserGesture::Started: 5233 handleAutoplayEvent(AutoplayEvent::DidEndMediaPlaybackWithoutUserInterference); 5234 break; 5235 case PlaybackWithoutUserGesture::Prevented: 5236 handleAutoplayEvent(AutoplayEvent::UserNeverPlayedMediaPreventedFromPlaying); 5237 break; 5238 case PlaybackWithoutUserGesture::None: 5239 break; 5240 } 5241 5245 5242 setPlaybackWithoutUserGesture(PlaybackWithoutUserGesture::None); 5246 5243 … … 7185 7182 } 7186 7183 7184 void HTMLMediaElement::handleAutoplayEvent(AutoplayEvent event) 7185 { 7186 if (Page* page = document().page()) { 7187 bool hasAudio = this->hasAudio() && !muted() && volume(); 7188 page->chrome().client().handleAutoplayEvent(event, hasAudio ? AutoplayEventFlags::HasAudio : OptionSet<AutoplayEventFlags>()); 7189 } 7190 } 7191 7187 7192 void HTMLMediaElement::userDidInterfereWithAutoplay() 7188 7193 { … … 7194 7199 return; 7195 7200 7196 if (Page* page = document().page()) 7197 page->chrome().client().handleAutoplayEvent(AutoplayEvent::UserDidInterfereWithPlayback); 7198 7201 handleAutoplayEvent(AutoplayEvent::UserDidInterfereWithPlayback); 7199 7202 setPlaybackWithoutUserGesture(PlaybackWithoutUserGesture::None); 7200 7203 } … … 7215 7218 7216 7219 dispatchPlayPauseEventsIfNeedsQuirks(); 7217 7218 if (Page* page = document().page()) 7219 page->chrome().client().handleAutoplayEvent(AutoplayEvent::DidPreventMediaFromPlaying); 7220 handleAutoplayEvent(AutoplayEvent::DidPreventMediaFromPlaying); 7220 7221 7221 7222 break; -
trunk/Source/WebCore/html/HTMLMediaElement.h
r215649 r215771 29 29 30 30 #include "ActiveDOMObject.h" 31 #include "AutoplayEvent.h" 31 32 #include "GenericEventQueue.h" 32 33 #include "GenericTaskQueue.h" … … 756 757 void setPlaybackWithoutUserGesture(PlaybackWithoutUserGesture); 757 758 void userDidInterfereWithAutoplay(); 759 void handleAutoplayEvent(AutoplayEvent); 758 760 759 761 MediaTime minTimeSeekable() const; -
trunk/Source/WebCore/page/AutoplayEvent.h
r213471 r215771 36 36 }; 37 37 38 enum class AutoplayEventFlags { 39 HasAudio = 1 << 0, 40 }; 41 38 42 } // namespace WebCore -
trunk/Source/WebCore/page/ChromeClient.h
r215425 r215771 423 423 424 424 virtual void isPlayingMediaDidChange(MediaProducer::MediaStateFlags, uint64_t) { } 425 virtual void handleAutoplayEvent(AutoplayEvent ) { }425 virtual void handleAutoplayEvent(AutoplayEvent, OptionSet<AutoplayEventFlags>) { } 426 426 427 427 #if ENABLE(MEDIA_SESSION) -
trunk/Source/WebKit2/ChangeLog
r215753 r215771 1 2017-04-24 Matt Rajca <mrajca@apple.com> 2 3 Indicate presence of audio when handling autoplay events. 4 https://bugs.webkit.org/show_bug.cgi?id=171227 5 6 Reviewed by Alex Christensen. 7 8 * UIProcess/API/APIUIClient.h: 9 (API::UIClient::handleAutoplayEvent): 10 * UIProcess/API/C/WKPage.cpp: 11 (WKPageSetPageUIClient): 12 * UIProcess/API/C/WKPageUIClient.h: 13 * UIProcess/WebPageProxy.cpp: 14 (WebKit::WebPageProxy::handleAutoplayEvent): 15 * UIProcess/WebPageProxy.h: 16 * UIProcess/WebPageProxy.messages.in: 17 * WebProcess/WebCoreSupport/WebChromeClient.cpp: 18 (WebKit::WebChromeClient::handleAutoplayEvent): 19 * WebProcess/WebCoreSupport/WebChromeClient.h: 20 1 21 2017-04-25 Daniel Bates <dabates@apple.com> 2 22 -
trunk/Source/WebKit2/Scripts/webkit/messages.py
r215663 r215771 349 349 special_cases = { 350 350 'String': ['<wtf/text/WTFString.h>'], 351 'WebCore::AutoplayEventFlags': ['<WebCore/AutoplayEvent.h>'], 351 352 'WebCore::CompositionUnderline': ['<WebCore/Editor.h>'], 352 353 'WebCore::ExceptionDetails': ['<WebCore/JSDOMExceptionHandling.h>'], -
trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.h
r215672 r215771 27 27 28 28 #include "ArgumentCoders.h" 29 #include <WebCore/AutoplayEvent.h> 29 30 #include <WebCore/CaptureDevice.h> 30 31 #include <WebCore/ColorSpace.h> … … 687 688 }; 688 689 690 template<> struct EnumTraits<WebCore::AutoplayEvent> { 691 using values = EnumValues< 692 WebCore::AutoplayEvent, 693 WebCore::AutoplayEvent::DidPreventMediaFromPlaying, 694 WebCore::AutoplayEvent::DidPlayMediaPreventedFromPlaying, 695 WebCore::AutoplayEvent::DidEndMediaPlaybackWithoutUserInterference, 696 WebCore::AutoplayEvent::UserDidInterfereWithPlayback, 697 WebCore::AutoplayEvent::UserNeverPlayedMediaPreventedFromPlaying 698 >; 699 }; 700 689 701 template<> struct EnumTraits<WebCore::ShouldSample> { 690 702 using values = EnumValues< -
trunk/Source/WebKit2/UIProcess/API/APIUIClient.h
r215545 r215771 151 151 virtual void isPlayingAudioDidChange(WebKit::WebPageProxy&) { } 152 152 virtual void mediaCaptureStateDidChange(WebCore::MediaProducer::MediaStateFlags) { } 153 virtual void handleAutoplayEvent(WebKit::WebPageProxy&, WebCore::AutoplayEvent ) { }153 virtual void handleAutoplayEvent(WebKit::WebPageProxy&, WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) { } 154 154 155 155 #if ENABLE(MEDIA_SESSION) -
trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp
r215730 r215771 2252 2252 #endif 2253 2253 2254 void handleAutoplayEvent(WebPageProxy& page, WebCore::AutoplayEvent event) override 2254 static WKAutoplayEventFlags toWKAutoplayEventFlags(OptionSet<WebCore::AutoplayEventFlags> flags) 2255 { 2256 WKAutoplayEventFlags wkFlags = kWKAutoplayEventFlagsNone; 2257 if (flags.contains(WebCore::AutoplayEventFlags::HasAudio)) 2258 wkFlags |= kWKAutoplayEventFlagsHasAudio; 2259 2260 return wkFlags; 2261 } 2262 2263 static WKAutoplayEvent toWKAutoplayEvent(WebCore::AutoplayEvent event) 2264 { 2265 switch (event) { 2266 case WebCore::AutoplayEvent::DidEndMediaPlaybackWithoutUserInterference: 2267 return kWKAutoplayEventDidEndMediaPlaybackWithoutUserInterference; 2268 case WebCore::AutoplayEvent::DidPlayMediaPreventedFromPlaying: 2269 return kWKAutoplayEventDidPlayMediaPreventedFromAutoplaying; 2270 case WebCore::AutoplayEvent::DidPreventMediaFromPlaying: 2271 return kWKAutoplayEventDidPreventFromAutoplaying; 2272 case WebCore::AutoplayEvent::UserDidInterfereWithPlayback: 2273 return kWKAutoplayEventUserDidInterfereWithPlayback; 2274 case WebCore::AutoplayEvent::UserNeverPlayedMediaPreventedFromPlaying: 2275 return kWKAutoplayEventUserNeverPlayedMediaPreventedFromPlaying; 2276 } 2277 } 2278 2279 void handleAutoplayEvent(WebPageProxy& page, WebCore::AutoplayEvent event, OptionSet<WebCore::AutoplayEventFlags> flags) override 2255 2280 { 2256 2281 if (!m_client.handleAutoplayEvent) 2257 2282 return; 2258 2283 2259 m_client.handleAutoplayEvent(toAPI(&page), static_cast<WKAutoplayEvent>(event), m_client.base.clientInfo);2284 m_client.handleAutoplayEvent(toAPI(&page), toWKAutoplayEvent(event), toWKAutoplayEventFlags(flags), m_client.base.clientInfo); 2260 2285 } 2261 2286 }; -
trunk/Source/WebKit2/UIProcess/API/C/WKPageUIClient.h
r213471 r215771 57 57 }; 58 58 typedef uint32_t WKAutoplayEvent; 59 60 enum { 61 kWKAutoplayEventFlagsNone = 0, 62 kWKAutoplayEventFlagsHasAudio = 1 << 0, 63 }; 64 typedef uint32_t WKAutoplayEventFlags; 59 65 60 66 WK_EXPORT WKTypeID WKPageRunBeforeUnloadConfirmPanelResultListenerGetTypeID(); … … 112 118 typedef void (*WKPageDidClickAutoFillButtonCallback)(WKPageRef page, WKTypeRef userData, const void *clientInfo); 113 119 typedef void (*WKPageMediaSessionMetadataDidChangeCallback)(WKPageRef page, WKMediaSessionMetadataRef metadata, const void* clientInfo); 114 typedef void (*WKHandleAutoplayEventCallback)(WKPageRef page, WKAutoplayEvent event, const void* clientInfo);120 typedef void (*WKHandleAutoplayEventCallback)(WKPageRef page, WKAutoplayEvent event, WKAutoplayEventFlags flags, const void* clientInfo); 115 121 typedef void (*WKFullscreenMayReturnToInlineCallback)(WKPageRef page, const void* clientInfo); 116 122 -
trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp
r215668 r215771 6568 6568 #endif 6569 6569 6570 void WebPageProxy::handleAutoplayEvent( uint32_t event)6571 { 6572 m_uiClient->handleAutoplayEvent(*this, static_cast<AutoplayEvent>(event));6570 void WebPageProxy::handleAutoplayEvent(WebCore::AutoplayEvent event, OptionSet<AutoplayEventFlags> flags) 6571 { 6572 m_uiClient->handleAutoplayEvent(*this, event, flags); 6573 6573 } 6574 6574 -
trunk/Source/WebKit2/UIProcess/WebPageProxy.h
r215653 r215771 169 169 struct WindowFeatures; 170 170 171 enum class AutoplayEvent; 171 172 enum class HasInsecureContent; 172 173 enum class ShouldSample; … … 1071 1072 bool hasActiveVideoStream() const { return m_mediaState & WebCore::MediaProducer::HasActiveVideoCaptureDevice; } 1072 1073 WebCore::MediaProducer::MediaStateFlags mediaStateFlags() const { return m_mediaState; } 1073 void handleAutoplayEvent( uint32_t);1074 void handleAutoplayEvent(WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>); 1074 1075 1075 1076 #if PLATFORM(MAC) -
trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in
r215653 r215771 439 439 440 440 IsPlayingMediaDidChange(unsigned state, uint64_t sourceElementID) 441 HandleAutoplayEvent( uint32_t event)441 HandleAutoplayEvent(enum WebCore::AutoplayEvent event, OptionSet<WebCore::AutoplayEventFlags> flags) 442 442 443 443 #if ENABLE(MEDIA_SESSION) -
trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp
r215425 r215771 1089 1089 } 1090 1090 1091 void WebChromeClient::handleAutoplayEvent(AutoplayEvent event )1092 { 1093 m_page.send(Messages::WebPageProxy::HandleAutoplayEvent( static_cast<uint32_t>(event)));1091 void WebChromeClient::handleAutoplayEvent(AutoplayEvent event, OptionSet<AutoplayEventFlags> flags) 1092 { 1093 m_page.send(Messages::WebPageProxy::HandleAutoplayEvent(event, flags)); 1094 1094 } 1095 1095 -
trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h
r215425 r215771 298 298 299 299 void isPlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags, uint64_t) final; 300 void handleAutoplayEvent(WebCore::AutoplayEvent ) final;300 void handleAutoplayEvent(WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final; 301 301 302 302 #if ENABLE(MEDIA_SESSION) -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm
r215249 r215771 52 52 #if PLATFORM(MAC) 53 53 static std::optional<WKAutoplayEvent> receivedAutoplayEvent; 54 static std::optional<WKAutoplayEventFlags> receivedAutoplayEventFlags; 54 55 #endif 55 56 … … 281 282 282 283 #if PLATFORM(MAC) 283 static void handleAutoplayEvent(WKPageRef page, WKAutoplayEvent event, const void* clientInfo) 284 { 284 static void handleAutoplayEvent(WKPageRef page, WKAutoplayEvent event, WKAutoplayEventFlags flags, const void* clientInfo) 285 { 286 receivedAutoplayEventFlags = flags; 285 287 receivedAutoplayEvent = event; 286 288 } … … 321 323 [webView mouseUpAtPoint:playButtonClickPoint]; 322 324 runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPlayMediaPreventedFromAutoplaying); 325 ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio); 323 326 324 327 receivedAutoplayEvent = std::nullopt; … … 329 332 [webView waitForMessage:@"loaded"]; 330 333 runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPreventFromAutoplaying); 334 ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio); 331 335 332 336 [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO]; 333 337 [webView mouseUpAtPoint:playButtonClickPoint]; 334 338 runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPlayMediaPreventedFromAutoplaying); 339 ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio); 335 340 336 341 receivedAutoplayEvent = std::nullopt; … … 360 365 [webView mouseUpAtPoint:playButtonClickPoint]; 361 366 runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPlayMediaPreventedFromAutoplaying); 367 ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio); 362 368 } 363 369 … … 390 396 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]]; 391 397 runUntilReceivesAutoplayEvent(kWKAutoplayEventDidEndMediaPlaybackWithoutUserInterference); 398 ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio); 392 399 393 400 receivedAutoplayEvent = std::nullopt; … … 395 402 [webView waitForMessage:@"ended"]; 396 403 runUntilReceivesAutoplayEvent(kWKAutoplayEventDidEndMediaPlaybackWithoutUserInterference); 404 ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio); 397 405 } 398 406 … … 424 432 WKPageSetMuted([webView _pageForTesting], kWKMediaAudioMuted); 425 433 runUntilReceivesAutoplayEvent(kWKAutoplayEventUserDidInterfereWithPlayback); 434 ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio); 426 435 427 436 receivedAutoplayEvent = std::nullopt; … … 434 443 [webView mouseUpAtPoint:muteButtonClickPoint]; 435 444 runUntilReceivesAutoplayEvent(kWKAutoplayEventUserDidInterfereWithPlayback); 445 ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio); 436 446 437 447 receivedAutoplayEvent = std::nullopt; … … 444 454 [webView mouseUpAtPoint:playButtonClickPoint]; 445 455 runUntilReceivesAutoplayEvent(kWKAutoplayEventUserDidInterfereWithPlayback); 456 ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio); 446 457 } 447 458 … … 473 484 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]]; 474 485 runUntilReceivesAutoplayEvent(kWKAutoplayEventUserNeverPlayedMediaPreventedFromPlaying); 486 ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio); 475 487 } 476 488
Note: See TracChangeset
for help on using the changeset viewer.