Title: [212982] trunk
Revision
212982
Author
mra...@apple.com
Date
2017-02-24 17:17:15 -0800 (Fri, 24 Feb 2017)

Log Message

Media: notify clients when autoplay is denied
https://bugs.webkit.org/show_bug.cgi?id=168840

Reviewed by Alex Christensen.

Source/WebCore:

Added API tests.

* WebCore.xcodeproj/project.pbxproj:
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::setReadyState):
(WebCore::HTMLMediaElement::play):
(WebCore::HTMLMediaElement::playInternal):
* page/AutoplayEvent.h: Added.
* page/ChromeClient.h:

Source/WebKit2:

* UIProcess/API/APIUIClient.h:
(API::UIClient::handleAutoplayEvent):
(API::UIClient::didPlayMediaPreventedFromPlayingWithoutUserGesture): Deleted.
* UIProcess/API/C/WKPage.cpp:
(WKPageSetPageUIClient):
* UIProcess/API/C/WKPageUIClient.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::handleAutoplayEvent):
(WebKit::WebPageProxy::didPlayMediaPreventedFromPlayingWithoutUserGesture): Deleted.
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::handleAutoplayEvent):
(WebKit::WebChromeClient::didPlayMediaPreventedFromPlayingWithoutUserGesture): Deleted.
* WebProcess/WebCoreSupport/WebChromeClient.h:

Tools:

* TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm:
(handleAutoplayEvent):
(runUntilReceivesAutoplayEvent):
(TEST): Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (212981 => 212982)


--- trunk/Source/WebCore/ChangeLog	2017-02-25 01:08:30 UTC (rev 212981)
+++ trunk/Source/WebCore/ChangeLog	2017-02-25 01:17:15 UTC (rev 212982)
@@ -1,3 +1,20 @@
+2017-02-24  Matt Rajca  <mra...@apple.com>
+
+        Media: notify clients when autoplay is denied
+        https://bugs.webkit.org/show_bug.cgi?id=168840
+
+        Reviewed by Alex Christensen.
+
+        Added API tests.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::setReadyState):
+        (WebCore::HTMLMediaElement::play):
+        (WebCore::HTMLMediaElement::playInternal):
+        * page/AutoplayEvent.h: Added.
+        * page/ChromeClient.h:
+
 2017-02-24  Basuke Suzuki  <basuke.suz...@am.sony.com>
 
         curl: Improve errors by including the domain

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (212981 => 212982)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-02-25 01:08:30 UTC (rev 212981)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-02-25 01:17:15 UTC (rev 212982)
@@ -5791,6 +5791,7 @@
 		C96F5EC71B5872260091EA9D /* MediaSessionInterruptionProvider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C96F5EC31B5872260091EA9D /* MediaSessionInterruptionProvider.cpp */; };
 		C96F5EC81B5872260091EA9D /* MediaSessionInterruptionProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = C96F5EC41B5872260091EA9D /* MediaSessionInterruptionProvider.h */; };
 		C99058131E32C75F0073BDDA /* SuccessOr.h in Headers */ = {isa = PBXBuildFile; fileRef = C99058121E32B7340073BDDA /* SuccessOr.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		C9D467051E60C465008195FB /* AutoplayEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = C9D467041E60C3EB008195FB /* AutoplayEvent.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		C9D851F01B39DC780085062E /* MediaSessionMetadata.h in Headers */ = {isa = PBXBuildFile; fileRef = C9D851EE1B39DC780085062E /* MediaSessionMetadata.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		C9DADBCB1B1D3B97001F17D8 /* JSMediaSession.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C9DADBC91B1D3B25001F17D8 /* JSMediaSession.cpp */; };
 		C9F87CFE1B28F40E00979B83 /* MediaSessionEvents.h in Headers */ = {isa = PBXBuildFile; fileRef = C9F87CFD1B28E5F600979B83 /* MediaSessionEvents.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -13876,6 +13877,7 @@
 		C96F5EC31B5872260091EA9D /* MediaSessionInterruptionProvider.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaSessionInterruptionProvider.cpp; sourceTree = "<group>"; };
 		C96F5EC41B5872260091EA9D /* MediaSessionInterruptionProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaSessionInterruptionProvider.h; sourceTree = "<group>"; };
 		C99058121E32B7340073BDDA /* SuccessOr.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SuccessOr.h; sourceTree = "<group>"; };
+		C9D467041E60C3EB008195FB /* AutoplayEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AutoplayEvent.h; sourceTree = "<group>"; };
 		C9D851EE1B39DC780085062E /* MediaSessionMetadata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaSessionMetadata.h; sourceTree = "<group>"; };
 		C9DADBC91B1D3B25001F17D8 /* JSMediaSession.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMediaSession.cpp; sourceTree = "<group>"; };
 		C9DADBCA1B1D3B25001F17D8 /* JSMediaSession.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSMediaSession.h; sourceTree = "<group>"; };
@@ -18201,6 +18203,7 @@
 				724EE54F1DC7F25B00A91FFB /* ActivityStateChangeObserver.h */,
 				BCF48CE61370D114004E87D6 /* AdjustViewSizeOrNot.h */,
 				CEDA12D6152CA1CB00D9E08D /* AlternativeTextClient.h */,
+				C9D467041E60C3EB008195FB /* AutoplayEvent.h */,
 				45830D4B1679B4F800ACF8C3 /* AutoscrollController.cpp */,
 				45830D4C1679B4F800ACF8C3 /* AutoscrollController.h */,
 				BC124EE40C2641CD009E2349 /* BarProp.cpp */,
@@ -27960,6 +27963,7 @@
 				5E2C43611BCEE3230001E2BC /* RTCRtpSender.h in Headers */,
 				5E2C435F1BCEE31E0001E2BC /* RTCRtpSenderReceiverBase.h in Headers */,
 				5E5E2B141CFC3E75000C0D85 /* RTCRtpTransceiver.h in Headers */,
+				C9D467051E60C465008195FB /* AutoplayEvent.h in Headers */,
 				078E092617D14D1C00420AA1 /* RTCSessionDescription.h in Headers */,
 				078E094317D16E1C00420AA1 /* RTCSessionDescriptionDescriptor.h in Headers */,
 				078E094417D16E1C00420AA1 /* RTCSessionDescriptionRequest.h in Headers */,

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (212981 => 212982)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2017-02-25 01:08:30 UTC (rev 212981)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2017-02-25 01:17:15 UTC (rev 212982)
@@ -2419,9 +2419,13 @@
             m_playbackStartedTime = currentMediaTime().toDouble();
             scheduleEvent(eventNames().playEvent);
             scheduleNotifyAboutPlaying();
-        } else if (success.value() == MediaPlaybackDenialReason::UserGestureRequired)
+        } else if (success.value() == MediaPlaybackDenialReason::UserGestureRequired) {
             m_preventedFromPlayingWithoutUserGesture = true;
 
+            if (Page* page = document().page())
+                page->chrome().client().handleAutoplayEvent(AutoplayEvent::DidPreventMediaFromPlaying);
+        }
+
         shouldUpdateDisplayState = true;
     }
 
@@ -3099,8 +3103,12 @@
 
     auto success = m_mediaSession->playbackPermitted(*this);
     if (!success) {
-        if (success.value() == MediaPlaybackDenialReason::UserGestureRequired)
+        if (success.value() == MediaPlaybackDenialReason::UserGestureRequired) {
             m_preventedFromPlayingWithoutUserGesture = true;
+
+            if (Page* page = document().page())
+                page->chrome().client().handleAutoplayEvent(AutoplayEvent::DidPreventMediaFromPlaying);
+        }
         promise.reject(NotAllowedError);
         return;
     }
@@ -3127,8 +3135,12 @@
 
     auto success = m_mediaSession->playbackPermitted(*this);
     if (!success) {
-        if (success.value() == MediaPlaybackDenialReason::UserGestureRequired)
+        if (success.value() == MediaPlaybackDenialReason::UserGestureRequired) {
             m_preventedFromPlayingWithoutUserGesture = true;
+
+            if (Page* page = document().page())
+                page->chrome().client().handleAutoplayEvent(AutoplayEvent::DidPreventMediaFromPlaying);
+        }
         return;
     }
     if (ScriptController::processingUserGestureForMedia())
@@ -3197,7 +3209,7 @@
 
     if (ScriptController::processingUserGestureForMedia() && m_preventedFromPlayingWithoutUserGesture) {
         if (Page* page = document().page())
-            page->chrome().client().didPlayMediaPreventedFromPlayingWithoutUserGesture();
+            page->chrome().client().handleAutoplayEvent(AutoplayEvent::DidPlayMediaPreventedFromPlaying);
         m_preventedFromPlayingWithoutUserGesture = false;
     }
 

Added: trunk/Source/WebCore/page/AutoplayEvent.h (0 => 212982)


--- trunk/Source/WebCore/page/AutoplayEvent.h	                        (rev 0)
+++ trunk/Source/WebCore/page/AutoplayEvent.h	2017-02-25 01:17:15 UTC (rev 212982)
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+namespace WebCore {
+
+enum class AutoplayEvent {
+    DidPreventMediaFromPlaying,
+    DidPlayMediaPreventedFromPlaying,
+};
+
+} // namespace WebCore

Modified: trunk/Source/WebCore/page/ChromeClient.h (212981 => 212982)


--- trunk/Source/WebCore/page/ChromeClient.h	2017-02-25 01:08:30 UTC (rev 212981)
+++ trunk/Source/WebCore/page/ChromeClient.h	2017-02-25 01:17:15 UTC (rev 212982)
@@ -22,6 +22,7 @@
 #pragma once
 
 #include "AXObjectCache.h"
+#include "AutoplayEvent.h"
 #include "Cursor.h"
 #include "DatabaseDetails.h"
 #include "DisplayRefreshMonitor.h"
@@ -420,7 +421,7 @@
     virtual bool shouldUseTiledBackingForFrameView(const FrameView&) const { return false; }
 
     virtual void isPlayingMediaDidChange(MediaProducer::MediaStateFlags, uint64_t) { }
-    virtual void didPlayMediaPreventedFromPlayingWithoutUserGesture() { }
+    virtual void handleAutoplayEvent(AutoplayEvent) { }
 
 #if ENABLE(MEDIA_SESSION)
     virtual void hasMediaSessionWithActiveMediaElementsDidChange(bool) { }

Modified: trunk/Source/WebKit2/ChangeLog (212981 => 212982)


--- trunk/Source/WebKit2/ChangeLog	2017-02-25 01:08:30 UTC (rev 212981)
+++ trunk/Source/WebKit2/ChangeLog	2017-02-25 01:17:15 UTC (rev 212982)
@@ -1,3 +1,26 @@
+2017-02-24  Matt Rajca  <mra...@apple.com>
+
+        Media: notify clients when autoplay is denied
+        https://bugs.webkit.org/show_bug.cgi?id=168840
+
+        Reviewed by Alex Christensen.
+
+        * UIProcess/API/APIUIClient.h:
+        (API::UIClient::handleAutoplayEvent):
+        (API::UIClient::didPlayMediaPreventedFromPlayingWithoutUserGesture): Deleted.
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageSetPageUIClient):
+        * UIProcess/API/C/WKPageUIClient.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::handleAutoplayEvent):
+        (WebKit::WebPageProxy::didPlayMediaPreventedFromPlayingWithoutUserGesture): Deleted.
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
+        (WebKit::WebChromeClient::handleAutoplayEvent):
+        (WebKit::WebChromeClient::didPlayMediaPreventedFromPlayingWithoutUserGesture): Deleted.
+        * WebProcess/WebCoreSupport/WebChromeClient.h:
+
 2017-02-20  Wenson Hsieh  <wenson_hs...@apple.com>
 
         Refactor data interaction to use new WKDataInteraction SPI

Modified: trunk/Source/WebKit2/UIProcess/API/APIUIClient.h (212981 => 212982)


--- trunk/Source/WebKit2/UIProcess/API/APIUIClient.h	2017-02-25 01:08:30 UTC (rev 212981)
+++ trunk/Source/WebKit2/UIProcess/API/APIUIClient.h	2017-02-25 01:17:15 UTC (rev 212982)
@@ -152,7 +152,7 @@
     virtual void isPlayingAudioDidChange(WebKit::WebPageProxy&) { }
     virtual void didBeginCaptureSession() { }
     virtual void didEndCaptureSession() { }
-    virtual void didPlayMediaPreventedFromPlayingWithoutUserGesture(WebKit::WebPageProxy&) { }
+    virtual void handleAutoplayEvent(WebKit::WebPageProxy&, WebCore::AutoplayEvent) { }
 
 #if ENABLE(MEDIA_SESSION)
     virtual void mediaSessionMetadataDidChange(WebKit::WebPageProxy&, WebKit::WebMediaSessionMetadata*) { }

Modified: trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp (212981 => 212982)


--- trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp	2017-02-25 01:08:30 UTC (rev 212981)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp	2017-02-25 01:17:15 UTC (rev 212982)
@@ -2242,12 +2242,12 @@
         }
 #endif
 
-        void didPlayMediaPreventedFromPlayingWithoutUserGesture(WebPageProxy& page) override
+        void handleAutoplayEvent(WebPageProxy& page, WebCore::AutoplayEvent event) override
         {
-            if (!m_client.didPlayMediaPreventedFromPlayingWithoutUserGesture)
+            if (!m_client.handleAutoplayEvent)
                 return;
 
-            m_client.didPlayMediaPreventedFromPlayingWithoutUserGesture(toAPI(&page), m_client.base.clientInfo);
+            m_client.handleAutoplayEvent(toAPI(&page), static_cast<WKAutoplayEvent>(event), m_client.base.clientInfo);
         }
     };
 

Modified: trunk/Source/WebKit2/UIProcess/API/C/WKPageUIClient.h (212981 => 212982)


--- trunk/Source/WebKit2/UIProcess/API/C/WKPageUIClient.h	2017-02-25 01:08:30 UTC (rev 212981)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKPageUIClient.h	2017-02-25 01:17:15 UTC (rev 212982)
@@ -48,6 +48,12 @@
 };
 typedef uint32_t WKPluginUnavailabilityReason;
 
+enum {
+    kWKAutoplayEventDidPreventFromAutoplaying,
+    kWKAutoplayEventDidPlayMediaPreventedFromAutoplaying,
+};
+typedef uint32_t WKAutoplayEvent;
+
 WK_EXPORT WKTypeID WKPageRunBeforeUnloadConfirmPanelResultListenerGetTypeID();
 WK_EXPORT void WKPageRunBeforeUnloadConfirmPanelResultListenerCall(WKPageRunBeforeUnloadConfirmPanelResultListenerRef listener, bool result);
 
@@ -102,7 +108,7 @@
 typedef void (*WKCheckUserMediaPermissionCallback)(WKPageRef page, WKFrameRef frame, WKSecurityOriginRef userMediaDocumentOrigin, WKSecurityOriginRef topLevelDocumentOrigin, WKUserMediaPermissionCheckRef devicesRequest, const void *clientInfo);
 typedef void (*WKPageDidClickAutoFillButtonCallback)(WKPageRef page, WKTypeRef userData, const void *clientInfo);
 typedef void (*WKPageMediaSessionMetadataDidChangeCallback)(WKPageRef page, WKMediaSessionMetadataRef metadata, const void* clientInfo);
-typedef void (*WKDidPlayMediaPreventedFromPlayingWithoutUserGesture)(WKPageRef page, const void* clientInfo);
+typedef void (*WKHandleAutoplayEventCallback)(WKPageRef page, WKAutoplayEvent event, const void* clientInfo);
 typedef void (*WKFullscreenMayReturnToInlineCallback)(WKPageRef page, const void* clientInfo);
 
 typedef void (*WKRequestPointerLockCallback)(WKPageRef page, const void* clientInfo);
@@ -816,7 +822,7 @@
     WKDidLosePointerLockCallback                                        didLosePointerLock;
 
     // Version 9.
-    WKDidPlayMediaPreventedFromPlayingWithoutUserGesture                didPlayMediaPreventedFromPlayingWithoutUserGesture;
+    WKHandleAutoplayEventCallback                                       handleAutoplayEvent;
 } WKPageUIClientV9;
     
 #ifdef __cplusplus

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (212981 => 212982)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2017-02-25 01:08:30 UTC (rev 212981)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2017-02-25 01:17:15 UTC (rev 212982)
@@ -6528,9 +6528,9 @@
 }
 #endif
 
-void WebPageProxy::didPlayMediaPreventedFromPlayingWithoutUserGesture()
+void WebPageProxy::handleAutoplayEvent(uint32_t event)
 {
-    m_uiClient->didPlayMediaPreventedFromPlayingWithoutUserGesture(*this);
+    m_uiClient->handleAutoplayEvent(*this, static_cast<AutoplayEvent>(event));
 }
 
 #if PLATFORM(MAC)

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (212981 => 212982)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2017-02-25 01:08:30 UTC (rev 212981)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2017-02-25 01:17:15 UTC (rev 212982)
@@ -62,6 +62,7 @@
 #include "WebProcessLifetimeTracker.h"
 #include "WebsitePolicies.h"
 #include <WebCore/ActivityState.h>
+#include <WebCore/AutoplayEvent.h>
 #include <WebCore/Color.h>
 #include <WebCore/DragActions.h>
 #include <WebCore/EventTrackingRegions.h>
@@ -1062,7 +1063,7 @@
     bool hasActiveAudioStream() const { return m_mediaState & WebCore::MediaProducer::HasActiveAudioCaptureDevice; }
     bool hasActiveVideoStream() const { return m_mediaState & WebCore::MediaProducer::HasActiveVideoCaptureDevice; }
     WebCore::MediaProducer::MediaStateFlags mediaStateFlags() const { return m_mediaState; }
-    void didPlayMediaPreventedFromPlayingWithoutUserGesture();
+    void handleAutoplayEvent(uint32_t);
 
 #if PLATFORM(MAC)
     void videoControlsManagerDidChange();

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in (212981 => 212982)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2017-02-25 01:08:30 UTC (rev 212981)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2017-02-25 01:17:15 UTC (rev 212982)
@@ -440,7 +440,7 @@
 #endif
 
     IsPlayingMediaDidChange(unsigned state, uint64_t sourceElementID)
-    DidPlayMediaPreventedFromPlayingWithoutUserGesture()
+    HandleAutoplayEvent(uint32_t event)
 
 #if ENABLE(MEDIA_SESSION)
     HasMediaSessionWithActiveMediaElementsDidChange(bool state)

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp (212981 => 212982)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp	2017-02-25 01:08:30 UTC (rev 212981)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp	2017-02-25 01:17:15 UTC (rev 212982)
@@ -1083,9 +1083,9 @@
     m_page.send(Messages::WebPageProxy::IsPlayingMediaDidChange(state, sourceElementID));
 }
 
-void WebChromeClient::didPlayMediaPreventedFromPlayingWithoutUserGesture()
+void WebChromeClient::handleAutoplayEvent(AutoplayEvent event)
 {
-    m_page.send(Messages::WebPageProxy::DidPlayMediaPreventedFromPlayingWithoutUserGesture());
+    m_page.send(Messages::WebPageProxy::HandleAutoplayEvent(static_cast<uint32_t>(event)));
 }
 
 #if ENABLE(MEDIA_SESSION)

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h (212981 => 212982)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h	2017-02-25 01:08:30 UTC (rev 212981)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h	2017-02-25 01:17:15 UTC (rev 212982)
@@ -297,7 +297,7 @@
     bool shouldUseTiledBackingForFrameView(const WebCore::FrameView&) const final;
 
     void isPlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags, uint64_t) final;
-    void didPlayMediaPreventedFromPlayingWithoutUserGesture() final;
+    void handleAutoplayEvent(WebCore::AutoplayEvent) final;
 
 #if ENABLE(MEDIA_SESSION)
     void hasMediaSessionWithActiveMediaElementsDidChange(bool) final;

Modified: trunk/Tools/ChangeLog (212981 => 212982)


--- trunk/Tools/ChangeLog	2017-02-25 01:08:30 UTC (rev 212981)
+++ trunk/Tools/ChangeLog	2017-02-25 01:17:15 UTC (rev 212982)
@@ -1,3 +1,15 @@
+2017-02-24  Matt Rajca  <mra...@apple.com>
+
+        Media: notify clients when autoplay is denied
+        https://bugs.webkit.org/show_bug.cgi?id=168840
+
+        Reviewed by Alex Christensen.
+
+        * TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm:
+        (handleAutoplayEvent):
+        (runUntilReceivesAutoplayEvent):
+        (TEST): Added.
+
 2017-02-23  Matt Rajca  <mra...@apple.com>
 
         API test WebKit2.WebsitePoliciesPlayAfterPreventedAutoplay is timing out

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm (212981 => 212982)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm	2017-02-25 01:08:30 UTC (rev 212981)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm	2017-02-25 01:17:15 UTC (rev 212982)
@@ -45,6 +45,11 @@
 
 static bool doneCompiling;
 static bool receivedAlert;
+
+#if PLATFORM(MAC)
+static std::optional<WKAutoplayEvent> receivedAutoplayEvent;
+#endif
+
 static size_t alertCount;
 
 @interface ContentBlockingWebsitePoliciesDelegate : NSObject <WKNavigationDelegate, WKUIDelegate>
@@ -247,11 +252,17 @@
 }
 
 #if PLATFORM(MAC)
-static void didPlayMediaPreventedFromPlayingWithoutUserGesture(WKPageRef page, const void* clientInfo)
+static void handleAutoplayEvent(WKPageRef page, WKAutoplayEvent event, const void* clientInfo)
 {
-    receivedAlert = true;
+    receivedAutoplayEvent = event;
 }
 
+static void runUntilReceivesAutoplayEvent(WKAutoplayEvent event)
+{
+    while (!receivedAutoplayEvent || *receivedAutoplayEvent != event)
+        CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, true);
+}
+
 TEST(WebKit2, WebsitePoliciesPlayAfterPreventedAutoplay)
 {
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
@@ -267,30 +278,34 @@
     memset(&uiClient, 0, sizeof(uiClient));
 
     uiClient.base.version = 9;
-    uiClient.didPlayMediaPreventedFromPlayingWithoutUserGesture = didPlayMediaPreventedFromPlayingWithoutUserGesture;
+    uiClient.handleAutoplayEvent = handleAutoplayEvent;
 
     WKPageSetPageUIClient([webView _pageForTesting], &uiClient.base);
     NSPoint playButtonClickPoint = NSMakePoint(20, 256);
 
-    receivedAlert = false;
+    receivedAutoplayEvent = std::nullopt;
     NSURLRequest *jsPlayRequest = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"js-play-with-controls" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     [webView loadRequest:jsPlayRequest];
     [webView waitForMessage:@"loaded"];
+    runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPreventFromAutoplaying);
+
     [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
     [webView mouseUpAtPoint:playButtonClickPoint];
-    TestWebKitAPI::Util::run(&receivedAlert);
+    runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPlayMediaPreventedFromAutoplaying);
 
-    receivedAlert = false;
+    receivedAutoplayEvent = std::nullopt;
     [webView loadHTMLString:@"" baseURL:nil];
 
     NSURLRequest *autoplayRequest = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"autoplay-with-controls" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     [webView loadRequest:autoplayRequest];
     [webView waitForMessage:@"loaded"];
+    runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPreventFromAutoplaying);
+
     [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
     [webView mouseUpAtPoint:playButtonClickPoint];
-    TestWebKitAPI::Util::run(&receivedAlert);
+    runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPlayMediaPreventedFromAutoplaying);
 
-    receivedAlert = false;
+    receivedAutoplayEvent = std::nullopt;
     [webView loadHTMLString:@"" baseURL:nil];
 
     NSURLRequest *noAutoplayRequest = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"no-autoplay-with-controls" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
@@ -299,7 +314,7 @@
     [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
     [webView mouseUpAtPoint:playButtonClickPoint];
     [webView waitForMessage:@"played"];
-    ASSERT_FALSE(receivedAlert);
+    ASSERT_TRUE(receivedAutoplayEvent == std::nullopt);
 }
 #endif
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to