Skip to content

Commit e198416

Browse files
Notify clients when the user plays media otherwise prevented from autoplaying
https://bugs.webkit.org/show_bug.cgi?id=167390 Patch by Matt Rajca <[email protected]> on 2017-01-26 Reviewed by Alex Christensen. Source/WebCore: The API is tested. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::playInternal): * page/ChromeClient.h: Source/WebKit2: * UIProcess/API/APIUIClient.h: (API::UIClient::didPlayMediaPreventedFromPlayingWithoutUserGesture): * UIProcess/API/C/WKPage.cpp: (WKPageSetPageUIClient): * UIProcess/API/C/WKPageUIClient.h: * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::didPlayMediaPreventedFromPlayingWithoutUserGesture): * UIProcess/WebPageProxy.h: * UIProcess/WebPageProxy.messages.in: * WebProcess/WebCoreSupport/WebChromeClient.cpp: (WebKit::WebChromeClient::didPlayMediaPreventedFromPlayingWithoutUserGesture): * WebProcess/WebCoreSupport/WebChromeClient.h: Tools: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebKit2/autoplay-with-controls.html: Added. * TestWebKitAPI/Tests/WebKit2/js-play-with-controls.html: Added. * TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm: (didPlayMediaPreventedFromPlayingWithoutUserGesture): (TEST): * TestWebKitAPI/cocoa/TestWKWebView.h: * TestWebKitAPI/cocoa/TestWKWebView.mm: (-[TestWKWebViewHostWindow _mouseUpAtPoint:]): (-[TestWKWebView waitForLoad]): (-[TestWKWebView mouseUpAtPoint:]): * WebKitTestRunner/TestController.cpp: (WTR::TestController::createOtherPage): (WTR::TestController::createWebViewWithOptions): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@211226 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent b700f2b commit e198416

20 files changed

+319
-2
lines changed

Source/WebCore/ChangeLog

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
2017-01-26 Matt Rajca <[email protected]>
2+
3+
Notify clients when the user plays media otherwise prevented from autoplaying
4+
https://bugs.webkit.org/show_bug.cgi?id=167390
5+
6+
Reviewed by Alex Christensen.
7+
8+
The API is tested.
9+
10+
* html/HTMLMediaElement.cpp:
11+
(WebCore::HTMLMediaElement::playInternal):
12+
* page/ChromeClient.h:
13+
114
2017-01-26 Enrique Ocaña González <[email protected]>
215

316
[GStreamer] ASSERTION FAILED: !g_object_is_floating(ptr) in adoptGRef(GstContext* ptr)

Source/WebCore/html/HTMLMediaElement.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -3167,7 +3167,8 @@ bool HTMLMediaElement::playInternal()
31673167
scheduleResolvePendingPlayPromises();
31683168

31693169
if (ScriptController::processingUserGestureForMedia() && m_preventedFromPlayingWithoutUserGesture) {
3170-
// FIXME: notify clients a user gesture was made and started playback of an element that was otherwise prevented from playing.
3170+
if (Page* page = document().page())
3171+
page->chrome().client().didPlayMediaPreventedFromPlayingWithoutUserGesture();
31713172
m_preventedFromPlayingWithoutUserGesture = false;
31723173
}
31733174

Source/WebCore/page/ChromeClient.h

+1
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ class WEBCORE_EXPORT ChromeClient {
420420
virtual bool shouldUseTiledBackingForFrameView(const FrameView&) const { return false; }
421421

422422
virtual void isPlayingMediaDidChange(MediaProducer::MediaStateFlags, uint64_t) { }
423+
virtual void didPlayMediaPreventedFromPlayingWithoutUserGesture() { }
423424

424425
#if ENABLE(MEDIA_SESSION)
425426
virtual void hasMediaSessionWithActiveMediaElementsDidChange(bool) { }

Source/WebKit2/ChangeLog

+20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
2017-01-26 Matt Rajca <[email protected]>
2+
3+
Notify clients when the user plays media otherwise prevented from autoplaying
4+
https://bugs.webkit.org/show_bug.cgi?id=167390
5+
6+
Reviewed by Alex Christensen.
7+
8+
* UIProcess/API/APIUIClient.h:
9+
(API::UIClient::didPlayMediaPreventedFromPlayingWithoutUserGesture):
10+
* UIProcess/API/C/WKPage.cpp:
11+
(WKPageSetPageUIClient):
12+
* UIProcess/API/C/WKPageUIClient.h:
13+
* UIProcess/WebPageProxy.cpp:
14+
(WebKit::WebPageProxy::didPlayMediaPreventedFromPlayingWithoutUserGesture):
15+
* UIProcess/WebPageProxy.h:
16+
* UIProcess/WebPageProxy.messages.in:
17+
* WebProcess/WebCoreSupport/WebChromeClient.cpp:
18+
(WebKit::WebChromeClient::didPlayMediaPreventedFromPlayingWithoutUserGesture):
19+
* WebProcess/WebCoreSupport/WebChromeClient.h:
20+
121
2017-01-26 Anders Carlsson <[email protected]>
222

323
Don't use _CFBundleCreateUnique on Yosemite, it's not available there

Source/WebKit2/UIProcess/API/APIUIClient.h

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ class UIClient {
152152
virtual void isPlayingAudioDidChange(WebKit::WebPageProxy&) { }
153153
virtual void didBeginCaptureSession() { }
154154
virtual void didEndCaptureSession() { }
155+
virtual void didPlayMediaPreventedFromPlayingWithoutUserGesture(WebKit::WebPageProxy&) { }
155156

156157
#if ENABLE(MEDIA_SESSION)
157158
virtual void mediaSessionMetadataDidChange(WebKit::WebPageProxy&, WebKit::WebMediaSessionMetadata*) { }

Source/WebKit2/UIProcess/API/C/WKPage.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ template<> struct ClientTraits<WKPagePolicyClientBase> {
110110
};
111111

112112
template<> struct ClientTraits<WKPageUIClientBase> {
113-
typedef std::tuple<WKPageUIClientV0, WKPageUIClientV1, WKPageUIClientV2, WKPageUIClientV3, WKPageUIClientV4, WKPageUIClientV5, WKPageUIClientV6, WKPageUIClientV7, WKPageUIClientV8> Versions;
113+
typedef std::tuple<WKPageUIClientV0, WKPageUIClientV1, WKPageUIClientV2, WKPageUIClientV3, WKPageUIClientV4, WKPageUIClientV5, WKPageUIClientV6, WKPageUIClientV7, WKPageUIClientV8, WKPageUIClientV9> Versions;
114114
};
115115

116116
#if ENABLE(CONTEXT_MENUS)
@@ -2241,6 +2241,14 @@ void WKPageSetPageUIClient(WKPageRef pageRef, const WKPageUIClientBase* wkClient
22412241
m_client.didLosePointerLock(toAPI(page), m_client.base.clientInfo);
22422242
}
22432243
#endif
2244+
2245+
void didPlayMediaPreventedFromPlayingWithoutUserGesture(WebPageProxy& page) override
2246+
{
2247+
if (!m_client.didPlayMediaPreventedFromPlayingWithoutUserGesture)
2248+
return;
2249+
2250+
m_client.didPlayMediaPreventedFromPlayingWithoutUserGesture(toAPI(&page), m_client.base.clientInfo);
2251+
}
22442252
};
22452253

22462254
toImpl(pageRef)->setUIClient(std::make_unique<UIClient>(wkClient));

Source/WebKit2/UIProcess/API/C/WKPageUIClient.h

+92
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ typedef void (*WKPageDecidePolicyForUserMediaPermissionRequestCallback)(WKPageRe
102102
typedef void (*WKCheckUserMediaPermissionCallback)(WKPageRef page, WKFrameRef frame, WKSecurityOriginRef userMediaDocumentOrigin, WKSecurityOriginRef topLevelDocumentOrigin, WKUserMediaPermissionCheckRef devicesRequest, const void *clientInfo);
103103
typedef void (*WKPageDidClickAutoFillButtonCallback)(WKPageRef page, WKTypeRef userData, const void *clientInfo);
104104
typedef void (*WKPageMediaSessionMetadataDidChangeCallback)(WKPageRef page, WKMediaSessionMetadataRef metadata, const void* clientInfo);
105+
typedef void (*WKDidPlayMediaPreventedFromPlayingWithoutUserGesture)(WKPageRef page, const void* clientInfo);
105106
typedef void (*WKFullscreenMayReturnToInlineCallback)(WKPageRef page, const void* clientInfo);
106107

107108
typedef void (*WKRequestPointerLockCallback)(WKPageRef page, const void* clientInfo);
@@ -726,6 +727,97 @@ typedef struct WKPageUIClientV8 {
726727
WKRequestPointerLockCallback requestPointerLock;
727728
WKDidLosePointerLockCallback didLosePointerLock;
728729
} WKPageUIClientV8;
730+
731+
typedef struct WKPageUIClientV9 {
732+
WKPageUIClientBase base;
733+
734+
// Version 0.
735+
WKPageCreateNewPageCallback_deprecatedForUseWithV0 createNewPage_deprecatedForUseWithV0;
736+
WKPageUIClientCallback showPage;
737+
WKPageUIClientCallback close;
738+
WKPageTakeFocusCallback takeFocus;
739+
WKPageFocusCallback focus;
740+
WKPageUnfocusCallback unfocus;
741+
WKPageRunJavaScriptAlertCallback_deprecatedForUseWithV0 runJavaScriptAlert_deprecatedForUseWithV0;
742+
WKPageRunJavaScriptConfirmCallback_deprecatedForUseWithV0 runJavaScriptConfirm_deprecatedForUseWithV0;
743+
WKPageRunJavaScriptPromptCallback_deprecatedForUseWithV0 runJavaScriptPrompt_deprecatedForUseWithV0;
744+
WKPageSetStatusTextCallback setStatusText;
745+
WKPageMouseDidMoveOverElementCallback_deprecatedForUseWithV0 mouseDidMoveOverElement_deprecatedForUseWithV0;
746+
WKPageMissingPluginButtonClickedCallback_deprecatedForUseWithV0 missingPluginButtonClicked_deprecatedForUseWithV0;
747+
WKPageDidNotHandleKeyEventCallback didNotHandleKeyEvent;
748+
WKPageDidNotHandleWheelEventCallback didNotHandleWheelEvent;
749+
WKPageGetToolbarsAreVisibleCallback toolbarsAreVisible;
750+
WKPageSetToolbarsAreVisibleCallback setToolbarsAreVisible;
751+
WKPageGetMenuBarIsVisibleCallback menuBarIsVisible;
752+
WKPageSetMenuBarIsVisibleCallback setMenuBarIsVisible;
753+
WKPageGetStatusBarIsVisibleCallback statusBarIsVisible;
754+
WKPageSetStatusBarIsVisibleCallback setStatusBarIsVisible;
755+
WKPageGetIsResizableCallback isResizable;
756+
WKPageSetIsResizableCallback setIsResizable;
757+
WKPageGetWindowFrameCallback getWindowFrame;
758+
WKPageSetWindowFrameCallback setWindowFrame;
759+
WKPageRunBeforeUnloadConfirmPanelCallback_deprecatedForUseWithV6 runBeforeUnloadConfirmPanel_deprecatedForUseWithV6;
760+
WKPageUIClientCallback didDraw;
761+
WKPageUIClientCallback pageDidScroll;
762+
WKPageExceededDatabaseQuotaCallback exceededDatabaseQuota;
763+
WKPageRunOpenPanelCallback runOpenPanel;
764+
WKPageDecidePolicyForGeolocationPermissionRequestCallback decidePolicyForGeolocationPermissionRequest;
765+
WKPageHeaderHeightCallback headerHeight;
766+
WKPageFooterHeightCallback footerHeight;
767+
WKPageDrawHeaderCallback drawHeader;
768+
WKPageDrawFooterCallback drawFooter;
769+
WKPagePrintFrameCallback printFrame;
770+
WKPageUIClientCallback runModal;
771+
void* unused1; // Used to be didCompleteRubberBandForMainFrame
772+
WKPageSaveDataToFileInDownloadsFolderCallback saveDataToFileInDownloadsFolder;
773+
void* shouldInterruptJavaScript_unavailable;
774+
775+
// Version 1.
776+
WKPageCreateNewPageCallback_deprecatedForUseWithV1 createNewPage_deprecatedForUseWithV1;
777+
WKPageMouseDidMoveOverElementCallback mouseDidMoveOverElement;
778+
WKPageDecidePolicyForNotificationPermissionRequestCallback decidePolicyForNotificationPermissionRequest;
779+
WKPageUnavailablePluginButtonClickedCallback_deprecatedForUseWithV1 unavailablePluginButtonClicked_deprecatedForUseWithV1;
780+
781+
// Version 2.
782+
WKPageShowColorPickerCallback showColorPicker;
783+
WKPageHideColorPickerCallback hideColorPicker;
784+
WKPageUnavailablePluginButtonClickedCallback unavailablePluginButtonClicked;
785+
786+
// Version 3.
787+
WKPagePinnedStateDidChangeCallback pinnedStateDidChange;
788+
789+
// Version 4.
790+
void* unused2; // Used to be didBeginTrackingPotentialLongMousePress.
791+
void* unused3; // Used to be didRecognizeLongMousePress.
792+
void* unused4; // Used to be didCancelTrackingPotentialLongMousePress.
793+
WKPageIsPlayingAudioDidChangeCallback isPlayingAudioDidChange;
794+
795+
// Version 5.
796+
WKPageDecidePolicyForUserMediaPermissionRequestCallback decidePolicyForUserMediaPermissionRequest;
797+
WKPageDidClickAutoFillButtonCallback didClickAutoFillButton;
798+
WKPageRunJavaScriptAlertCallback_deprecatedForUseWithV5 runJavaScriptAlert_deprecatedForUseWithV5;
799+
WKPageRunJavaScriptConfirmCallback_deprecatedForUseWithV5 runJavaScriptConfirm_deprecatedForUseWithV5;
800+
WKPageRunJavaScriptPromptCallback_deprecatedForUseWithV5 runJavaScriptPrompt_deprecatedForUseWithV5;
801+
WKPageMediaSessionMetadataDidChangeCallback mediaSessionMetadataDidChange;
802+
803+
// Version 6.
804+
WKPageCreateNewPageCallback createNewPage;
805+
WKPageRunJavaScriptAlertCallback runJavaScriptAlert;
806+
WKPageRunJavaScriptConfirmCallback runJavaScriptConfirm;
807+
WKPageRunJavaScriptPromptCallback runJavaScriptPrompt;
808+
WKCheckUserMediaPermissionCallback checkUserMediaPermissionForOrigin;
809+
810+
// Version 7.
811+
WKPageRunBeforeUnloadConfirmPanelCallback runBeforeUnloadConfirmPanel;
812+
WKFullscreenMayReturnToInlineCallback fullscreenMayReturnToInline;
813+
814+
// Version 8.
815+
WKRequestPointerLockCallback requestPointerLock;
816+
WKDidLosePointerLockCallback didLosePointerLock;
817+
818+
// Version 9.
819+
WKDidPlayMediaPreventedFromPlayingWithoutUserGesture didPlayMediaPreventedFromPlayingWithoutUserGesture;
820+
} WKPageUIClientV9;
729821

730822
#ifdef __cplusplus
731823
}

Source/WebKit2/UIProcess/WebPageProxy.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -6532,6 +6532,11 @@ void WebPageProxy::focusedContentMediaElementDidChange(uint64_t elementID)
65326532
}
65336533
#endif
65346534

6535+
void WebPageProxy::didPlayMediaPreventedFromPlayingWithoutUserGesture()
6536+
{
6537+
m_uiClient->didPlayMediaPreventedFromPlayingWithoutUserGesture(*this);
6538+
}
6539+
65356540
#if PLATFORM(MAC)
65366541
void WebPageProxy::removeNavigationGestureSnapshot()
65376542
{

Source/WebKit2/UIProcess/WebPageProxy.h

+1
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,7 @@ class WebPageProxy : public API::ObjectImpl<API::Object::Type::Page>
10641064
bool hasActiveAudioStream() const { return m_mediaState & WebCore::MediaProducer::HasActiveAudioCaptureDevice; }
10651065
bool hasActiveVideoStream() const { return m_mediaState & WebCore::MediaProducer::HasActiveVideoCaptureDevice; }
10661066
WebCore::MediaProducer::MediaStateFlags mediaStateFlags() const { return m_mediaState; }
1067+
void didPlayMediaPreventedFromPlayingWithoutUserGesture();
10671068

10681069
#if PLATFORM(MAC)
10691070
void videoControlsManagerDidChange();

Source/WebKit2/UIProcess/WebPageProxy.messages.in

+1
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ messages -> WebPageProxy {
443443
#endif
444444

445445
IsPlayingMediaDidChange(unsigned state, uint64_t sourceElementID)
446+
DidPlayMediaPreventedFromPlayingWithoutUserGesture()
446447

447448
#if ENABLE(MEDIA_SESSION)
448449
HasMediaSessionWithActiveMediaElementsDidChange(bool state)

Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,11 @@ void WebChromeClient::isPlayingMediaDidChange(MediaProducer::MediaStateFlags sta
10841084
m_page.send(Messages::WebPageProxy::IsPlayingMediaDidChange(state, sourceElementID));
10851085
}
10861086

1087+
void WebChromeClient::didPlayMediaPreventedFromPlayingWithoutUserGesture()
1088+
{
1089+
m_page.send(Messages::WebPageProxy::DidPlayMediaPreventedFromPlayingWithoutUserGesture());
1090+
}
1091+
10871092
#if ENABLE(MEDIA_SESSION)
10881093

10891094
void WebChromeClient::hasMediaSessionWithActiveMediaElementsDidChange(bool state)

Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h

+1
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ class WebChromeClient final : public WebCore::ChromeClient {
297297
bool shouldUseTiledBackingForFrameView(const WebCore::FrameView&) const final;
298298

299299
void isPlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags, uint64_t) final;
300+
void didPlayMediaPreventedFromPlayingWithoutUserGesture() final;
300301

301302
#if ENABLE(MEDIA_SESSION)
302303
void hasMediaSessionWithActiveMediaElementsDidChange(bool) final;

Tools/ChangeLog

+22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
2017-01-26 Matt Rajca <[email protected]>
2+
3+
Notify clients when the user plays media otherwise prevented from autoplaying
4+
https://bugs.webkit.org/show_bug.cgi?id=167390
5+
6+
Reviewed by Alex Christensen.
7+
8+
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
9+
* TestWebKitAPI/Tests/WebKit2/autoplay-with-controls.html: Added.
10+
* TestWebKitAPI/Tests/WebKit2/js-play-with-controls.html: Added.
11+
* TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm:
12+
(didPlayMediaPreventedFromPlayingWithoutUserGesture):
13+
(TEST):
14+
* TestWebKitAPI/cocoa/TestWKWebView.h:
15+
* TestWebKitAPI/cocoa/TestWKWebView.mm:
16+
(-[TestWKWebViewHostWindow _mouseUpAtPoint:]):
17+
(-[TestWKWebView waitForLoad]):
18+
(-[TestWKWebView mouseUpAtPoint:]):
19+
* WebKitTestRunner/TestController.cpp:
20+
(WTR::TestController::createOtherPage):
21+
(WTR::TestController::createWebViewWithOptions):
22+
123
2017-01-26 Per Arne Vollan <[email protected]>
224

325
Crash when setting custom scale factor.

0 commit comments

Comments
 (0)