Title: [215771] trunk
Revision
215771
Author
mra...@apple.com
Date
2017-04-25 17:02:59 -0700 (Tue, 25 Apr 2017)

Log Message

Indicate presence of audio when handling autoplay events.
https://bugs.webkit.org/show_bug.cgi?id=171227

Reviewed by Alex Christensen.

Source/WebCore:

Added API tests.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::handleAutoplayEvent):
(WebCore::HTMLMediaElement::playInternal):
(WebCore::HTMLMediaElement::mediaPlayerTimeChanged):
(WebCore::HTMLMediaElement::stopWithoutDestroyingMediaPlayer):
(WebCore::HTMLMediaElement::userDidInterfereWithAutoplay):
(WebCore::HTMLMediaElement::setPlaybackWithoutUserGesture):
* html/HTMLMediaElement.h:
* page/AutoplayEvent.h:
* page/ChromeClient.h:

Source/WebKit2:

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

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (215770 => 215771)


--- trunk/Source/WebCore/ChangeLog	2017-04-25 23:50:59 UTC (rev 215770)
+++ trunk/Source/WebCore/ChangeLog	2017-04-26 00:02:59 UTC (rev 215771)
@@ -1,3 +1,23 @@
+2017-04-24  Matt Rajca  <mra...@apple.com>
+
+        Indicate presence of audio when handling autoplay events.
+        https://bugs.webkit.org/show_bug.cgi?id=171227
+
+        Reviewed by Alex Christensen.
+
+        Added API tests.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::handleAutoplayEvent):
+        (WebCore::HTMLMediaElement::playInternal):
+        (WebCore::HTMLMediaElement::mediaPlayerTimeChanged):
+        (WebCore::HTMLMediaElement::stopWithoutDestroyingMediaPlayer):
+        (WebCore::HTMLMediaElement::userDidInterfereWithAutoplay):
+        (WebCore::HTMLMediaElement::setPlaybackWithoutUserGesture):
+        * html/HTMLMediaElement.h:
+        * page/AutoplayEvent.h:
+        * page/ChromeClient.h:
+
 2017-04-25  Aakash Jain  <aakash_j...@apple.com>
 
         WebCore.framework should restrict allowable_clients

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (215770 => 215771)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2017-04-25 23:50:59 UTC (rev 215770)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2017-04-26 00:02:59 UTC (rev 215771)
@@ -3242,8 +3242,7 @@
 
     if (ScriptController::processingUserGestureForMedia()) {
         if (m_playbackWithoutUserGesture == PlaybackWithoutUserGesture::Prevented) {
-            if (Page* page = document().page())
-                page->chrome().client().handleAutoplayEvent(AutoplayEvent::DidPlayMediaPreventedFromPlaying);
+            handleAutoplayEvent(AutoplayEvent::DidPlayMediaPreventedFromPlaying);
             setPlaybackWithoutUserGesture(PlaybackWithoutUserGesture::None);
         }
     } else
@@ -3383,16 +3382,16 @@
 
     bool mutedStateChanged = m_muted != muted;
     if (mutedStateChanged || !m_explicitlyMuted) {
-        m_muted = muted;
-        m_explicitlyMuted = true;
-
         if (ScriptController::processingUserGestureForMedia()) {
             removeBehaviorsRestrictionsAfterFirstUserGesture(MediaElementSession::AllRestrictions & ~MediaElementSession::RequireUserGestureToControlControlsManager);
 
-            if (hasAudio() && m_muted)
+            if (hasAudio() && muted)
                 userDidInterfereWithAutoplay();
         }
 
+        m_muted = muted;
+        m_explicitlyMuted = true;
+
         // Avoid recursion when the player reports volume changes.
         if (!processingMediaPlayerCallback()) {
             if (m_player) {
@@ -4467,10 +4466,9 @@
                 if (!wasSeeking)
                     addBehaviorRestrictionsOnEndIfNecessary();
 
-                if (m_playbackWithoutUserGesture == PlaybackWithoutUserGesture::Started) {
-                    if (Page* page = document().page())
-                        page->chrome().client().handleAutoplayEvent(AutoplayEvent::DidEndMediaPlaybackWithoutUserInterference);
-                }
+                if (m_playbackWithoutUserGesture == PlaybackWithoutUserGesture::Started)
+                    handleAutoplayEvent(AutoplayEvent::DidEndMediaPlaybackWithoutUserInterference);
+
                 setPlaybackWithoutUserGesture(PlaybackWithoutUserGesture::None);
             }
             // If the media element has a current media controller, then report the controller state
@@ -5230,18 +5228,17 @@
     setPausedInternal(true);
     m_mediaSession->clientWillPausePlayback();
 
-    if (Page* page = document().page()) {
-        switch (m_playbackWithoutUserGesture) {
-        case PlaybackWithoutUserGesture::Started:
-            page->chrome().client().handleAutoplayEvent(AutoplayEvent::DidEndMediaPlaybackWithoutUserInterference);
-            break;
-        case PlaybackWithoutUserGesture::Prevented:
-            page->chrome().client().handleAutoplayEvent(AutoplayEvent::UserNeverPlayedMediaPreventedFromPlaying);
-            break;
-        case PlaybackWithoutUserGesture::None:
-            break;
-        }
+    switch (m_playbackWithoutUserGesture) {
+    case PlaybackWithoutUserGesture::Started:
+        handleAutoplayEvent(AutoplayEvent::DidEndMediaPlaybackWithoutUserInterference);
+        break;
+    case PlaybackWithoutUserGesture::Prevented:
+        handleAutoplayEvent(AutoplayEvent::UserNeverPlayedMediaPreventedFromPlaying);
+        break;
+    case PlaybackWithoutUserGesture::None:
+        break;
     }
+
     setPlaybackWithoutUserGesture(PlaybackWithoutUserGesture::None);
 
     userCancelledLoad();
@@ -7184,6 +7181,14 @@
     return state;
 }
 
+void HTMLMediaElement::handleAutoplayEvent(AutoplayEvent event)
+{
+    if (Page* page = document().page()) {
+        bool hasAudio = this->hasAudio() && !muted() && volume();
+        page->chrome().client().handleAutoplayEvent(event, hasAudio ? AutoplayEventFlags::HasAudio : OptionSet<AutoplayEventFlags>());
+    }
+}
+
 void HTMLMediaElement::userDidInterfereWithAutoplay()
 {
     if (m_playbackWithoutUserGesture != PlaybackWithoutUserGesture::Started)
@@ -7193,9 +7198,7 @@
     if (currentTime() - m_playbackWithoutUserGestureStartedTime->toDouble() > 10)
         return;
 
-    if (Page* page = document().page())
-        page->chrome().client().handleAutoplayEvent(AutoplayEvent::UserDidInterfereWithPlayback);
-
+    handleAutoplayEvent(AutoplayEvent::UserDidInterfereWithPlayback);
     setPlaybackWithoutUserGesture(PlaybackWithoutUserGesture::None);
 }
 
@@ -7214,10 +7217,8 @@
         m_playbackWithoutUserGestureStartedTime = std::nullopt;
 
         dispatchPlayPauseEventsIfNeedsQuirks();
+        handleAutoplayEvent(AutoplayEvent::DidPreventMediaFromPlaying);
 
-        if (Page* page = document().page())
-            page->chrome().client().handleAutoplayEvent(AutoplayEvent::DidPreventMediaFromPlaying);
-
         break;
     }
 }

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (215770 => 215771)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2017-04-25 23:50:59 UTC (rev 215770)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2017-04-26 00:02:59 UTC (rev 215771)
@@ -28,6 +28,7 @@
 #if ENABLE(VIDEO)
 
 #include "ActiveDOMObject.h"
+#include "AutoplayEvent.h"
 #include "GenericEventQueue.h"
 #include "GenericTaskQueue.h"
 #include "HTMLElement.h"
@@ -755,6 +756,7 @@
     enum class PlaybackWithoutUserGesture { None, Started, Prevented };
     void setPlaybackWithoutUserGesture(PlaybackWithoutUserGesture);
     void userDidInterfereWithAutoplay();
+    void handleAutoplayEvent(AutoplayEvent);
 
     MediaTime minTimeSeekable() const;
     MediaTime maxTimeSeekable() const;

Modified: trunk/Source/WebCore/page/AutoplayEvent.h (215770 => 215771)


--- trunk/Source/WebCore/page/AutoplayEvent.h	2017-04-25 23:50:59 UTC (rev 215770)
+++ trunk/Source/WebCore/page/AutoplayEvent.h	2017-04-26 00:02:59 UTC (rev 215771)
@@ -35,4 +35,8 @@
     UserNeverPlayedMediaPreventedFromPlaying,
 };
 
+enum class AutoplayEventFlags {
+    HasAudio = 1 << 0,
+};
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/page/ChromeClient.h (215770 => 215771)


--- trunk/Source/WebCore/page/ChromeClient.h	2017-04-25 23:50:59 UTC (rev 215770)
+++ trunk/Source/WebCore/page/ChromeClient.h	2017-04-26 00:02:59 UTC (rev 215771)
@@ -422,7 +422,7 @@
     virtual bool shouldUseTiledBackingForFrameView(const FrameView&) const { return false; }
 
     virtual void isPlayingMediaDidChange(MediaProducer::MediaStateFlags, uint64_t) { }
-    virtual void handleAutoplayEvent(AutoplayEvent) { }
+    virtual void handleAutoplayEvent(AutoplayEvent, OptionSet<AutoplayEventFlags>) { }
 
 #if ENABLE(MEDIA_SESSION)
     virtual void hasMediaSessionWithActiveMediaElementsDidChange(bool) { }

Modified: trunk/Source/WebKit2/ChangeLog (215770 => 215771)


--- trunk/Source/WebKit2/ChangeLog	2017-04-25 23:50:59 UTC (rev 215770)
+++ trunk/Source/WebKit2/ChangeLog	2017-04-26 00:02:59 UTC (rev 215771)
@@ -1,3 +1,23 @@
+2017-04-24  Matt Rajca  <mra...@apple.com>
+
+        Indicate presence of audio when handling autoplay events.
+        https://bugs.webkit.org/show_bug.cgi?id=171227
+
+        Reviewed by Alex Christensen.
+
+        * UIProcess/API/APIUIClient.h:
+        (API::UIClient::handleAutoplayEvent):
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageSetPageUIClient):
+        * UIProcess/API/C/WKPageUIClient.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::handleAutoplayEvent):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
+        (WebKit::WebChromeClient::handleAutoplayEvent):
+        * WebProcess/WebCoreSupport/WebChromeClient.h:
+
 2017-04-25  Daniel Bates  <daba...@apple.com>
 
         [Cocoa][Win] Enable of X-Content-Type-Options: nosniff header

Modified: trunk/Source/WebKit2/Scripts/webkit/messages.py (215770 => 215771)


--- trunk/Source/WebKit2/Scripts/webkit/messages.py	2017-04-25 23:50:59 UTC (rev 215770)
+++ trunk/Source/WebKit2/Scripts/webkit/messages.py	2017-04-26 00:02:59 UTC (rev 215771)
@@ -348,6 +348,7 @@
 
     special_cases = {
         'String': ['<wtf/text/WTFString.h>'],
+        'WebCore::AutoplayEventFlags': ['<WebCore/AutoplayEvent.h>'],
         'WebCore::CompositionUnderline': ['<WebCore/Editor.h>'],
         'WebCore::ExceptionDetails': ['<WebCore/JSDOMExceptionHandling.h>'],
         'WebCore::FileChooserSettings': ['<WebCore/FileChooser.h>'],

Modified: trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.h (215770 => 215771)


--- trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.h	2017-04-25 23:50:59 UTC (rev 215770)
+++ trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.h	2017-04-26 00:02:59 UTC (rev 215771)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include "ArgumentCoders.h"
+#include <WebCore/AutoplayEvent.h>
 #include <WebCore/CaptureDevice.h>
 #include <WebCore/ColorSpace.h>
 #include <WebCore/DiagnosticLoggingClient.h>
@@ -686,6 +687,17 @@
     >;
 };
 
+template<> struct EnumTraits<WebCore::AutoplayEvent> {
+    using values = EnumValues<
+        WebCore::AutoplayEvent,
+        WebCore::AutoplayEvent::DidPreventMediaFromPlaying,
+        WebCore::AutoplayEvent::DidPlayMediaPreventedFromPlaying,
+        WebCore::AutoplayEvent::DidEndMediaPlaybackWithoutUserInterference,
+        WebCore::AutoplayEvent::UserDidInterfereWithPlayback,
+        WebCore::AutoplayEvent::UserNeverPlayedMediaPreventedFromPlaying
+    >;
+};
+
 template<> struct EnumTraits<WebCore::ShouldSample> {
     using values = EnumValues<
         WebCore::ShouldSample,

Modified: trunk/Source/WebKit2/UIProcess/API/APIUIClient.h (215770 => 215771)


--- trunk/Source/WebKit2/UIProcess/API/APIUIClient.h	2017-04-25 23:50:59 UTC (rev 215770)
+++ trunk/Source/WebKit2/UIProcess/API/APIUIClient.h	2017-04-26 00:02:59 UTC (rev 215771)
@@ -150,7 +150,7 @@
 
     virtual void isPlayingAudioDidChange(WebKit::WebPageProxy&) { }
     virtual void mediaCaptureStateDidChange(WebCore::MediaProducer::MediaStateFlags) { }
-    virtual void handleAutoplayEvent(WebKit::WebPageProxy&, WebCore::AutoplayEvent) { }
+    virtual void handleAutoplayEvent(WebKit::WebPageProxy&, WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) { }
 
 #if ENABLE(MEDIA_SESSION)
     virtual void mediaSessionMetadataDidChange(WebKit::WebPageProxy&, WebKit::WebMediaSessionMetadata*) { }

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


--- trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp	2017-04-25 23:50:59 UTC (rev 215770)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp	2017-04-26 00:02:59 UTC (rev 215771)
@@ -2251,12 +2251,37 @@
         }
 #endif
 
-        void handleAutoplayEvent(WebPageProxy& page, WebCore::AutoplayEvent event) override
+        static WKAutoplayEventFlags toWKAutoplayEventFlags(OptionSet<WebCore::AutoplayEventFlags> flags)
         {
+            WKAutoplayEventFlags wkFlags = kWKAutoplayEventFlagsNone;
+            if (flags.contains(WebCore::AutoplayEventFlags::HasAudio))
+                wkFlags |= kWKAutoplayEventFlagsHasAudio;
+
+            return wkFlags;
+        }
+
+        static WKAutoplayEvent toWKAutoplayEvent(WebCore::AutoplayEvent event)
+        {
+            switch (event) {
+            case WebCore::AutoplayEvent::DidEndMediaPlaybackWithoutUserInterference:
+                return kWKAutoplayEventDidEndMediaPlaybackWithoutUserInterference;
+            case WebCore::AutoplayEvent::DidPlayMediaPreventedFromPlaying:
+                return kWKAutoplayEventDidPlayMediaPreventedFromAutoplaying;
+            case WebCore::AutoplayEvent::DidPreventMediaFromPlaying:
+                return kWKAutoplayEventDidPreventFromAutoplaying;
+            case WebCore::AutoplayEvent::UserDidInterfereWithPlayback:
+                return kWKAutoplayEventUserDidInterfereWithPlayback;
+            case WebCore::AutoplayEvent::UserNeverPlayedMediaPreventedFromPlaying:
+                return kWKAutoplayEventUserNeverPlayedMediaPreventedFromPlaying;
+            }
+        }
+
+        void handleAutoplayEvent(WebPageProxy& page, WebCore::AutoplayEvent event, OptionSet<WebCore::AutoplayEventFlags> flags) override
+        {
             if (!m_client.handleAutoplayEvent)
                 return;
 
-            m_client.handleAutoplayEvent(toAPI(&page), static_cast<WKAutoplayEvent>(event), m_client.base.clientInfo);
+            m_client.handleAutoplayEvent(toAPI(&page), toWKAutoplayEvent(event), toWKAutoplayEventFlags(flags), m_client.base.clientInfo);
         }
     };
 

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


--- trunk/Source/WebKit2/UIProcess/API/C/WKPageUIClient.h	2017-04-25 23:50:59 UTC (rev 215770)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKPageUIClient.h	2017-04-26 00:02:59 UTC (rev 215771)
@@ -57,6 +57,12 @@
 };
 typedef uint32_t WKAutoplayEvent;
 
+enum {
+    kWKAutoplayEventFlagsNone = 0,
+    kWKAutoplayEventFlagsHasAudio = 1 << 0,
+};
+typedef uint32_t WKAutoplayEventFlags;
+
 WK_EXPORT WKTypeID WKPageRunBeforeUnloadConfirmPanelResultListenerGetTypeID();
 WK_EXPORT void WKPageRunBeforeUnloadConfirmPanelResultListenerCall(WKPageRunBeforeUnloadConfirmPanelResultListenerRef listener, bool result);
 
@@ -111,7 +117,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 (*WKHandleAutoplayEventCallback)(WKPageRef page, WKAutoplayEvent event, const void* clientInfo);
+typedef void (*WKHandleAutoplayEventCallback)(WKPageRef page, WKAutoplayEvent event, WKAutoplayEventFlags flags, const void* clientInfo);
 typedef void (*WKFullscreenMayReturnToInlineCallback)(WKPageRef page, const void* clientInfo);
 
 typedef void (*WKRequestPointerLockCallback)(WKPageRef page, const void* clientInfo);

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (215770 => 215771)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2017-04-25 23:50:59 UTC (rev 215770)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2017-04-26 00:02:59 UTC (rev 215771)
@@ -6567,9 +6567,9 @@
 }
 #endif
 
-void WebPageProxy::handleAutoplayEvent(uint32_t event)
+void WebPageProxy::handleAutoplayEvent(WebCore::AutoplayEvent event, OptionSet<AutoplayEventFlags> flags)
 {
-    m_uiClient->handleAutoplayEvent(*this, static_cast<AutoplayEvent>(event));
+    m_uiClient->handleAutoplayEvent(*this, event, flags);
 }
 
 #if PLATFORM(MAC)

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (215770 => 215771)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2017-04-25 23:50:59 UTC (rev 215770)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2017-04-26 00:02:59 UTC (rev 215771)
@@ -168,6 +168,7 @@
 struct ViewportAttributes;
 struct WindowFeatures;
 
+enum class AutoplayEvent;
 enum class HasInsecureContent;
 enum class ShouldSample;
 
@@ -1070,7 +1071,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 handleAutoplayEvent(uint32_t);
+    void handleAutoplayEvent(WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>);
 
 #if PLATFORM(MAC)
     void videoControlsManagerDidChange();

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in (215770 => 215771)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2017-04-25 23:50:59 UTC (rev 215770)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2017-04-26 00:02:59 UTC (rev 215771)
@@ -438,7 +438,7 @@
 #endif
 
     IsPlayingMediaDidChange(unsigned state, uint64_t sourceElementID)
-    HandleAutoplayEvent(uint32_t event)
+    HandleAutoplayEvent(enum WebCore::AutoplayEvent event, OptionSet<WebCore::AutoplayEventFlags> flags)
 
 #if ENABLE(MEDIA_SESSION)
     HasMediaSessionWithActiveMediaElementsDidChange(bool state)

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp (215770 => 215771)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp	2017-04-25 23:50:59 UTC (rev 215770)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp	2017-04-26 00:02:59 UTC (rev 215771)
@@ -1088,9 +1088,9 @@
     m_page.send(Messages::WebPageProxy::IsPlayingMediaDidChange(state, sourceElementID));
 }
 
-void WebChromeClient::handleAutoplayEvent(AutoplayEvent event)
+void WebChromeClient::handleAutoplayEvent(AutoplayEvent event, OptionSet<AutoplayEventFlags> flags)
 {
-    m_page.send(Messages::WebPageProxy::HandleAutoplayEvent(static_cast<uint32_t>(event)));
+    m_page.send(Messages::WebPageProxy::HandleAutoplayEvent(event, flags));
 }
 
 #if ENABLE(MEDIA_SESSION)

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h (215770 => 215771)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h	2017-04-25 23:50:59 UTC (rev 215770)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h	2017-04-26 00:02:59 UTC (rev 215771)
@@ -297,7 +297,7 @@
     bool shouldUseTiledBackingForFrameView(const WebCore::FrameView&) const final;
 
     void isPlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags, uint64_t) final;
-    void handleAutoplayEvent(WebCore::AutoplayEvent) final;
+    void handleAutoplayEvent(WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final;
 
 #if ENABLE(MEDIA_SESSION)
     void hasMediaSessionWithActiveMediaElementsDidChange(bool) final;

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm (215770 => 215771)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm	2017-04-25 23:50:59 UTC (rev 215770)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm	2017-04-26 00:02:59 UTC (rev 215771)
@@ -51,6 +51,7 @@
 
 #if PLATFORM(MAC)
 static std::optional<WKAutoplayEvent> receivedAutoplayEvent;
+static std::optional<WKAutoplayEventFlags> receivedAutoplayEventFlags;
 #endif
 
 static size_t alertCount;
@@ -280,8 +281,9 @@
 }
 
 #if PLATFORM(MAC)
-static void handleAutoplayEvent(WKPageRef page, WKAutoplayEvent event, const void* clientInfo)
+static void handleAutoplayEvent(WKPageRef page, WKAutoplayEvent event, WKAutoplayEventFlags flags, const void* clientInfo)
 {
+    receivedAutoplayEventFlags = flags;
     receivedAutoplayEvent = event;
 }
 
@@ -320,6 +322,7 @@
     [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
     [webView mouseUpAtPoint:playButtonClickPoint];
     runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPlayMediaPreventedFromAutoplaying);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
 
     receivedAutoplayEvent = std::nullopt;
     [webView loadHTMLString:@"" baseURL:nil];
@@ -328,10 +331,12 @@
     [webView loadRequest:autoplayRequest];
     [webView waitForMessage:@"loaded"];
     runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPreventFromAutoplaying);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
 
     [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
     [webView mouseUpAtPoint:playButtonClickPoint];
     runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPlayMediaPreventedFromAutoplaying);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
 
     receivedAutoplayEvent = std::nullopt;
     [webView loadHTMLString:@"" baseURL:nil];
@@ -359,6 +364,7 @@
     [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
     [webView mouseUpAtPoint:playButtonClickPoint];
     runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPlayMediaPreventedFromAutoplaying);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
 }
 
 TEST(WebKit2, WebsitePoliciesPlayingWithoutInterference)
@@ -389,11 +395,13 @@
 
     [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];
     runUntilReceivesAutoplayEvent(kWKAutoplayEventDidEndMediaPlaybackWithoutUserInterference);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
 
     receivedAutoplayEvent = std::nullopt;
     [webView loadRequest:jsPlayRequest];
     [webView waitForMessage:@"ended"];
     runUntilReceivesAutoplayEvent(kWKAutoplayEventDidEndMediaPlaybackWithoutUserInterference);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
 }
 
 TEST(WebKit2, WebsitePoliciesUserInterferenceWithPlaying)
@@ -423,6 +431,7 @@
 
     WKPageSetMuted([webView _pageForTesting], kWKMediaAudioMuted);
     runUntilReceivesAutoplayEvent(kWKAutoplayEventUserDidInterfereWithPlayback);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
 
     receivedAutoplayEvent = std::nullopt;
     [webView loadRequest:jsPlayRequest];
@@ -433,6 +442,7 @@
     [webView mouseDownAtPoint:muteButtonClickPoint simulatePressure:NO];
     [webView mouseUpAtPoint:muteButtonClickPoint];
     runUntilReceivesAutoplayEvent(kWKAutoplayEventUserDidInterfereWithPlayback);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
 
     receivedAutoplayEvent = std::nullopt;
     [webView loadRequest:jsPlayRequest];
@@ -443,6 +453,7 @@
     [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
     [webView mouseUpAtPoint:playButtonClickPoint];
     runUntilReceivesAutoplayEvent(kWKAutoplayEventUserDidInterfereWithPlayback);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
 }
 
 TEST(WebKit2, WebsitePoliciesUserNeverPlayedMediaPreventedFromPlaying)
@@ -472,6 +483,7 @@
 
     [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];
     runUntilReceivesAutoplayEvent(kWKAutoplayEventUserNeverPlayedMediaPreventedFromPlaying);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
 }
 
 TEST(WebKit2, WebsitePoliciesAutoplayQuirks)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to