<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[212982] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/212982">212982</a></dd>
<dt>Author</dt> <dd>mrajca@apple.com</dd>
<dt>Date</dt> <dd>2017-02-24 17:17:15 -0800 (Fri, 24 Feb 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>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.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLMediaElementcpp">trunk/Source/WebCore/html/HTMLMediaElement.cpp</a></li>
<li><a href="#trunkSourceWebCorepageChromeClienth">trunk/Source/WebCore/page/ChromeClient.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPIAPIUIClienth">trunk/Source/WebKit2/UIProcess/API/APIUIClient.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICWKPagecpp">trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICWKPageUIClienth">trunk/Source/WebKit2/UIProcess/API/C/WKPageUIClient.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxycpp">trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxyh">trunk/Source/WebKit2/UIProcess/WebPageProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxymessagesin">trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebCoreSupportWebChromeClientcpp">trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebCoreSupportWebChromeClienth">trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2CocoaWebsitePoliciesmm">trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCorepageAutoplayEventh">trunk/Source/WebCore/page/AutoplayEvent.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (212981 => 212982)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2017-02-24  Matt Rajca  &lt;mrajca@apple.com&gt;
+
+        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:
+
</ins><span class="cx"> 2017-02-24  Basuke Suzuki  &lt;Basuke.Suzuki@am.sony.com&gt;
</span><span class="cx"> 
</span><span class="cx">         curl: Improve errors by including the domain
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (212981 => 212982)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -5791,6 +5791,7 @@
</span><span class="cx">                 C96F5EC71B5872260091EA9D /* MediaSessionInterruptionProvider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C96F5EC31B5872260091EA9D /* MediaSessionInterruptionProvider.cpp */; };
</span><span class="cx">                 C96F5EC81B5872260091EA9D /* MediaSessionInterruptionProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = C96F5EC41B5872260091EA9D /* MediaSessionInterruptionProvider.h */; };
</span><span class="cx">                 C99058131E32C75F0073BDDA /* SuccessOr.h in Headers */ = {isa = PBXBuildFile; fileRef = C99058121E32B7340073BDDA /* SuccessOr.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><ins>+                C9D467051E60C465008195FB /* AutoplayEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = C9D467041E60C3EB008195FB /* AutoplayEvent.h */; settings = {ATTRIBUTES = (Private, ); }; };
</ins><span class="cx">                 C9D851F01B39DC780085062E /* MediaSessionMetadata.h in Headers */ = {isa = PBXBuildFile; fileRef = C9D851EE1B39DC780085062E /* MediaSessionMetadata.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 C9DADBCB1B1D3B97001F17D8 /* JSMediaSession.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C9DADBC91B1D3B25001F17D8 /* JSMediaSession.cpp */; };
</span><span class="cx">                 C9F87CFE1B28F40E00979B83 /* MediaSessionEvents.h in Headers */ = {isa = PBXBuildFile; fileRef = C9F87CFD1B28E5F600979B83 /* MediaSessionEvents.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="lines">@@ -13876,6 +13877,7 @@
</span><span class="cx">                 C96F5EC31B5872260091EA9D /* MediaSessionInterruptionProvider.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaSessionInterruptionProvider.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 C96F5EC41B5872260091EA9D /* MediaSessionInterruptionProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaSessionInterruptionProvider.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 C99058121E32B7340073BDDA /* SuccessOr.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SuccessOr.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                C9D467041E60C3EB008195FB /* AutoplayEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AutoplayEvent.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 C9D851EE1B39DC780085062E /* MediaSessionMetadata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaSessionMetadata.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 C9DADBC91B1D3B25001F17D8 /* JSMediaSession.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMediaSession.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 C9DADBCA1B1D3B25001F17D8 /* JSMediaSession.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSMediaSession.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -18201,6 +18203,7 @@
</span><span class="cx">                                 724EE54F1DC7F25B00A91FFB /* ActivityStateChangeObserver.h */,
</span><span class="cx">                                 BCF48CE61370D114004E87D6 /* AdjustViewSizeOrNot.h */,
</span><span class="cx">                                 CEDA12D6152CA1CB00D9E08D /* AlternativeTextClient.h */,
</span><ins>+                                C9D467041E60C3EB008195FB /* AutoplayEvent.h */,
</ins><span class="cx">                                 45830D4B1679B4F800ACF8C3 /* AutoscrollController.cpp */,
</span><span class="cx">                                 45830D4C1679B4F800ACF8C3 /* AutoscrollController.h */,
</span><span class="cx">                                 BC124EE40C2641CD009E2349 /* BarProp.cpp */,
</span><span class="lines">@@ -27960,6 +27963,7 @@
</span><span class="cx">                                 5E2C43611BCEE3230001E2BC /* RTCRtpSender.h in Headers */,
</span><span class="cx">                                 5E2C435F1BCEE31E0001E2BC /* RTCRtpSenderReceiverBase.h in Headers */,
</span><span class="cx">                                 5E5E2B141CFC3E75000C0D85 /* RTCRtpTransceiver.h in Headers */,
</span><ins>+                                C9D467051E60C465008195FB /* AutoplayEvent.h in Headers */,
</ins><span class="cx">                                 078E092617D14D1C00420AA1 /* RTCSessionDescription.h in Headers */,
</span><span class="cx">                                 078E094317D16E1C00420AA1 /* RTCSessionDescriptionDescriptor.h in Headers */,
</span><span class="cx">                                 078E094417D16E1C00420AA1 /* RTCSessionDescriptionRequest.h in Headers */,
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLMediaElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (212981 => 212982)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -2419,9 +2419,13 @@
</span><span class="cx">             m_playbackStartedTime = currentMediaTime().toDouble();
</span><span class="cx">             scheduleEvent(eventNames().playEvent);
</span><span class="cx">             scheduleNotifyAboutPlaying();
</span><del>-        } else if (success.value() == MediaPlaybackDenialReason::UserGestureRequired)
</del><ins>+        } else if (success.value() == MediaPlaybackDenialReason::UserGestureRequired) {
</ins><span class="cx">             m_preventedFromPlayingWithoutUserGesture = true;
</span><span class="cx"> 
</span><ins>+            if (Page* page = document().page())
+                page-&gt;chrome().client().handleAutoplayEvent(AutoplayEvent::DidPreventMediaFromPlaying);
+        }
+
</ins><span class="cx">         shouldUpdateDisplayState = true;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -3099,8 +3103,12 @@
</span><span class="cx"> 
</span><span class="cx">     auto success = m_mediaSession-&gt;playbackPermitted(*this);
</span><span class="cx">     if (!success) {
</span><del>-        if (success.value() == MediaPlaybackDenialReason::UserGestureRequired)
</del><ins>+        if (success.value() == MediaPlaybackDenialReason::UserGestureRequired) {
</ins><span class="cx">             m_preventedFromPlayingWithoutUserGesture = true;
</span><ins>+
+            if (Page* page = document().page())
+                page-&gt;chrome().client().handleAutoplayEvent(AutoplayEvent::DidPreventMediaFromPlaying);
+        }
</ins><span class="cx">         promise.reject(NotAllowedError);
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="lines">@@ -3127,8 +3135,12 @@
</span><span class="cx"> 
</span><span class="cx">     auto success = m_mediaSession-&gt;playbackPermitted(*this);
</span><span class="cx">     if (!success) {
</span><del>-        if (success.value() == MediaPlaybackDenialReason::UserGestureRequired)
</del><ins>+        if (success.value() == MediaPlaybackDenialReason::UserGestureRequired) {
</ins><span class="cx">             m_preventedFromPlayingWithoutUserGesture = true;
</span><ins>+
+            if (Page* page = document().page())
+                page-&gt;chrome().client().handleAutoplayEvent(AutoplayEvent::DidPreventMediaFromPlaying);
+        }
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx">     if (ScriptController::processingUserGestureForMedia())
</span><span class="lines">@@ -3197,7 +3209,7 @@
</span><span class="cx"> 
</span><span class="cx">     if (ScriptController::processingUserGestureForMedia() &amp;&amp; m_preventedFromPlayingWithoutUserGesture) {
</span><span class="cx">         if (Page* page = document().page())
</span><del>-            page-&gt;chrome().client().didPlayMediaPreventedFromPlayingWithoutUserGesture();
</del><ins>+            page-&gt;chrome().client().handleAutoplayEvent(AutoplayEvent::DidPlayMediaPreventedFromPlaying);
</ins><span class="cx">         m_preventedFromPlayingWithoutUserGesture = false;
</span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorepageAutoplayEventh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/page/AutoplayEvent.h (0 => 212982)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/AutoplayEvent.h                                (rev 0)
+++ trunk/Source/WebCore/page/AutoplayEvent.h        2017-02-25 01:17:15 UTC (rev 212982)
</span><span class="lines">@@ -0,0 +1,35 @@
</span><ins>+/*
+ * 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
</ins></span></pre></div>
<a id="trunkSourceWebCorepageChromeClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/ChromeClient.h (212981 => 212982)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -22,6 +22,7 @@
</span><span class="cx"> #pragma once
</span><span class="cx"> 
</span><span class="cx"> #include &quot;AXObjectCache.h&quot;
</span><ins>+#include &quot;AutoplayEvent.h&quot;
</ins><span class="cx"> #include &quot;Cursor.h&quot;
</span><span class="cx"> #include &quot;DatabaseDetails.h&quot;
</span><span class="cx"> #include &quot;DisplayRefreshMonitor.h&quot;
</span><span class="lines">@@ -420,7 +421,7 @@
</span><span class="cx">     virtual bool shouldUseTiledBackingForFrameView(const FrameView&amp;) const { return false; }
</span><span class="cx"> 
</span><span class="cx">     virtual void isPlayingMediaDidChange(MediaProducer::MediaStateFlags, uint64_t) { }
</span><del>-    virtual void didPlayMediaPreventedFromPlayingWithoutUserGesture() { }
</del><ins>+    virtual void handleAutoplayEvent(AutoplayEvent) { }
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_SESSION)
</span><span class="cx">     virtual void hasMediaSessionWithActiveMediaElementsDidChange(bool) { }
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (212981 => 212982)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2017-02-24  Matt Rajca  &lt;mrajca@apple.com&gt;
+
+        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:
+
</ins><span class="cx"> 2017-02-20  Wenson Hsieh  &lt;wenson_hsieh@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Refactor data interaction to use new WKDataInteraction SPI
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPIAPIUIClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/APIUIClient.h (212981 => 212982)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -152,7 +152,7 @@
</span><span class="cx">     virtual void isPlayingAudioDidChange(WebKit::WebPageProxy&amp;) { }
</span><span class="cx">     virtual void didBeginCaptureSession() { }
</span><span class="cx">     virtual void didEndCaptureSession() { }
</span><del>-    virtual void didPlayMediaPreventedFromPlayingWithoutUserGesture(WebKit::WebPageProxy&amp;) { }
</del><ins>+    virtual void handleAutoplayEvent(WebKit::WebPageProxy&amp;, WebCore::AutoplayEvent) { }
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_SESSION)
</span><span class="cx">     virtual void mediaSessionMetadataDidChange(WebKit::WebPageProxy&amp;, WebKit::WebMediaSessionMetadata*) { }
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICWKPagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp (212981 => 212982)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -2242,12 +2242,12 @@
</span><span class="cx">         }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-        void didPlayMediaPreventedFromPlayingWithoutUserGesture(WebPageProxy&amp; page) override
</del><ins>+        void handleAutoplayEvent(WebPageProxy&amp; page, WebCore::AutoplayEvent event) override
</ins><span class="cx">         {
</span><del>-            if (!m_client.didPlayMediaPreventedFromPlayingWithoutUserGesture)
</del><ins>+            if (!m_client.handleAutoplayEvent)
</ins><span class="cx">                 return;
</span><span class="cx"> 
</span><del>-            m_client.didPlayMediaPreventedFromPlayingWithoutUserGesture(toAPI(&amp;page), m_client.base.clientInfo);
</del><ins>+            m_client.handleAutoplayEvent(toAPI(&amp;page), static_cast&lt;WKAutoplayEvent&gt;(event), m_client.base.clientInfo);
</ins><span class="cx">         }
</span><span class="cx">     };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICWKPageUIClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/C/WKPageUIClient.h (212981 => 212982)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -48,6 +48,12 @@
</span><span class="cx"> };
</span><span class="cx"> typedef uint32_t WKPluginUnavailabilityReason;
</span><span class="cx"> 
</span><ins>+enum {
+    kWKAutoplayEventDidPreventFromAutoplaying,
+    kWKAutoplayEventDidPlayMediaPreventedFromAutoplaying,
+};
+typedef uint32_t WKAutoplayEvent;
+
</ins><span class="cx"> WK_EXPORT WKTypeID WKPageRunBeforeUnloadConfirmPanelResultListenerGetTypeID();
</span><span class="cx"> WK_EXPORT void WKPageRunBeforeUnloadConfirmPanelResultListenerCall(WKPageRunBeforeUnloadConfirmPanelResultListenerRef listener, bool result);
</span><span class="cx"> 
</span><span class="lines">@@ -102,7 +108,7 @@
</span><span class="cx"> typedef void (*WKCheckUserMediaPermissionCallback)(WKPageRef page, WKFrameRef frame, WKSecurityOriginRef userMediaDocumentOrigin, WKSecurityOriginRef topLevelDocumentOrigin, WKUserMediaPermissionCheckRef devicesRequest, const void *clientInfo);
</span><span class="cx"> typedef void (*WKPageDidClickAutoFillButtonCallback)(WKPageRef page, WKTypeRef userData, const void *clientInfo);
</span><span class="cx"> typedef void (*WKPageMediaSessionMetadataDidChangeCallback)(WKPageRef page, WKMediaSessionMetadataRef metadata, const void* clientInfo);
</span><del>-typedef void (*WKDidPlayMediaPreventedFromPlayingWithoutUserGesture)(WKPageRef page, const void* clientInfo);
</del><ins>+typedef void (*WKHandleAutoplayEventCallback)(WKPageRef page, WKAutoplayEvent event, const void* clientInfo);
</ins><span class="cx"> typedef void (*WKFullscreenMayReturnToInlineCallback)(WKPageRef page, const void* clientInfo);
</span><span class="cx"> 
</span><span class="cx"> typedef void (*WKRequestPointerLockCallback)(WKPageRef page, const void* clientInfo);
</span><span class="lines">@@ -816,7 +822,7 @@
</span><span class="cx">     WKDidLosePointerLockCallback                                        didLosePointerLock;
</span><span class="cx"> 
</span><span class="cx">     // Version 9.
</span><del>-    WKDidPlayMediaPreventedFromPlayingWithoutUserGesture                didPlayMediaPreventedFromPlayingWithoutUserGesture;
</del><ins>+    WKHandleAutoplayEventCallback                                       handleAutoplayEvent;
</ins><span class="cx"> } WKPageUIClientV9;
</span><span class="cx">     
</span><span class="cx"> #ifdef __cplusplus
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (212981 => 212982)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -6528,9 +6528,9 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-void WebPageProxy::didPlayMediaPreventedFromPlayingWithoutUserGesture()
</del><ins>+void WebPageProxy::handleAutoplayEvent(uint32_t event)
</ins><span class="cx"> {
</span><del>-    m_uiClient-&gt;didPlayMediaPreventedFromPlayingWithoutUserGesture(*this);
</del><ins>+    m_uiClient-&gt;handleAutoplayEvent(*this, static_cast&lt;AutoplayEvent&gt;(event));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(MAC)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (212981 => 212982)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -62,6 +62,7 @@
</span><span class="cx"> #include &quot;WebProcessLifetimeTracker.h&quot;
</span><span class="cx"> #include &quot;WebsitePolicies.h&quot;
</span><span class="cx"> #include &lt;WebCore/ActivityState.h&gt;
</span><ins>+#include &lt;WebCore/AutoplayEvent.h&gt;
</ins><span class="cx"> #include &lt;WebCore/Color.h&gt;
</span><span class="cx"> #include &lt;WebCore/DragActions.h&gt;
</span><span class="cx"> #include &lt;WebCore/EventTrackingRegions.h&gt;
</span><span class="lines">@@ -1062,7 +1063,7 @@
</span><span class="cx">     bool hasActiveAudioStream() const { return m_mediaState &amp; WebCore::MediaProducer::HasActiveAudioCaptureDevice; }
</span><span class="cx">     bool hasActiveVideoStream() const { return m_mediaState &amp; WebCore::MediaProducer::HasActiveVideoCaptureDevice; }
</span><span class="cx">     WebCore::MediaProducer::MediaStateFlags mediaStateFlags() const { return m_mediaState; }
</span><del>-    void didPlayMediaPreventedFromPlayingWithoutUserGesture();
</del><ins>+    void handleAutoplayEvent(uint32_t);
</ins><span class="cx"> 
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">     void videoControlsManagerDidChange();
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxymessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in (212981 => 212982)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -440,7 +440,7 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     IsPlayingMediaDidChange(unsigned state, uint64_t sourceElementID)
</span><del>-    DidPlayMediaPreventedFromPlayingWithoutUserGesture()
</del><ins>+    HandleAutoplayEvent(uint32_t event)
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_SESSION)
</span><span class="cx">     HasMediaSessionWithActiveMediaElementsDidChange(bool state)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebCoreSupportWebChromeClientcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp (212981 => 212982)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1083,9 +1083,9 @@
</span><span class="cx">     m_page.send(Messages::WebPageProxy::IsPlayingMediaDidChange(state, sourceElementID));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebChromeClient::didPlayMediaPreventedFromPlayingWithoutUserGesture()
</del><ins>+void WebChromeClient::handleAutoplayEvent(AutoplayEvent event)
</ins><span class="cx"> {
</span><del>-    m_page.send(Messages::WebPageProxy::DidPlayMediaPreventedFromPlayingWithoutUserGesture());
</del><ins>+    m_page.send(Messages::WebPageProxy::HandleAutoplayEvent(static_cast&lt;uint32_t&gt;(event)));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_SESSION)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebCoreSupportWebChromeClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h (212981 => 212982)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -297,7 +297,7 @@
</span><span class="cx">     bool shouldUseTiledBackingForFrameView(const WebCore::FrameView&amp;) const final;
</span><span class="cx"> 
</span><span class="cx">     void isPlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags, uint64_t) final;
</span><del>-    void didPlayMediaPreventedFromPlayingWithoutUserGesture() final;
</del><ins>+    void handleAutoplayEvent(WebCore::AutoplayEvent) final;
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(MEDIA_SESSION)
</span><span class="cx">     void hasMediaSessionWithActiveMediaElementsDidChange(bool) final;
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (212981 => 212982)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2017-02-25 01:08:30 UTC (rev 212981)
+++ trunk/Tools/ChangeLog        2017-02-25 01:17:15 UTC (rev 212982)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2017-02-24  Matt Rajca  &lt;mrajca@apple.com&gt;
+
+        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.
+
</ins><span class="cx"> 2017-02-23  Matt Rajca  &lt;mrajca@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         API test WebKit2.WebsitePoliciesPlayAfterPreventedAutoplay is timing out
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2CocoaWebsitePoliciesmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm (212981 => 212982)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -45,6 +45,11 @@
</span><span class="cx"> 
</span><span class="cx"> static bool doneCompiling;
</span><span class="cx"> static bool receivedAlert;
</span><ins>+
+#if PLATFORM(MAC)
+static std::optional&lt;WKAutoplayEvent&gt; receivedAutoplayEvent;
+#endif
+
</ins><span class="cx"> static size_t alertCount;
</span><span class="cx"> 
</span><span class="cx"> @interface ContentBlockingWebsitePoliciesDelegate : NSObject &lt;WKNavigationDelegate, WKUIDelegate&gt;
</span><span class="lines">@@ -247,11 +252,17 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(MAC)
</span><del>-static void didPlayMediaPreventedFromPlayingWithoutUserGesture(WKPageRef page, const void* clientInfo)
</del><ins>+static void handleAutoplayEvent(WKPageRef page, WKAutoplayEvent event, const void* clientInfo)
</ins><span class="cx"> {
</span><del>-    receivedAlert = true;
</del><ins>+    receivedAutoplayEvent = event;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static void runUntilReceivesAutoplayEvent(WKAutoplayEvent event)
+{
+    while (!receivedAutoplayEvent || *receivedAutoplayEvent != event)
+        CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, true);
+}
+
</ins><span class="cx"> TEST(WebKit2, WebsitePoliciesPlayAfterPreventedAutoplay)
</span><span class="cx"> {
</span><span class="cx">     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
</span><span class="lines">@@ -267,30 +278,34 @@
</span><span class="cx">     memset(&amp;uiClient, 0, sizeof(uiClient));
</span><span class="cx"> 
</span><span class="cx">     uiClient.base.version = 9;
</span><del>-    uiClient.didPlayMediaPreventedFromPlayingWithoutUserGesture = didPlayMediaPreventedFromPlayingWithoutUserGesture;
</del><ins>+    uiClient.handleAutoplayEvent = handleAutoplayEvent;
</ins><span class="cx"> 
</span><span class="cx">     WKPageSetPageUIClient([webView _pageForTesting], &amp;uiClient.base);
</span><span class="cx">     NSPoint playButtonClickPoint = NSMakePoint(20, 256);
</span><span class="cx"> 
</span><del>-    receivedAlert = false;
</del><ins>+    receivedAutoplayEvent = std::nullopt;
</ins><span class="cx">     NSURLRequest *jsPlayRequest = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@&quot;js-play-with-controls&quot; withExtension:@&quot;html&quot; subdirectory:@&quot;TestWebKitAPI.resources&quot;]];
</span><span class="cx">     [webView loadRequest:jsPlayRequest];
</span><span class="cx">     [webView waitForMessage:@&quot;loaded&quot;];
</span><ins>+    runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPreventFromAutoplaying);
+
</ins><span class="cx">     [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
</span><span class="cx">     [webView mouseUpAtPoint:playButtonClickPoint];
</span><del>-    TestWebKitAPI::Util::run(&amp;receivedAlert);
</del><ins>+    runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPlayMediaPreventedFromAutoplaying);
</ins><span class="cx"> 
</span><del>-    receivedAlert = false;
</del><ins>+    receivedAutoplayEvent = std::nullopt;
</ins><span class="cx">     [webView loadHTMLString:@&quot;&quot; baseURL:nil];
</span><span class="cx"> 
</span><span class="cx">     NSURLRequest *autoplayRequest = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@&quot;autoplay-with-controls&quot; withExtension:@&quot;html&quot; subdirectory:@&quot;TestWebKitAPI.resources&quot;]];
</span><span class="cx">     [webView loadRequest:autoplayRequest];
</span><span class="cx">     [webView waitForMessage:@&quot;loaded&quot;];
</span><ins>+    runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPreventFromAutoplaying);
+
</ins><span class="cx">     [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
</span><span class="cx">     [webView mouseUpAtPoint:playButtonClickPoint];
</span><del>-    TestWebKitAPI::Util::run(&amp;receivedAlert);
</del><ins>+    runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPlayMediaPreventedFromAutoplaying);
</ins><span class="cx"> 
</span><del>-    receivedAlert = false;
</del><ins>+    receivedAutoplayEvent = std::nullopt;
</ins><span class="cx">     [webView loadHTMLString:@&quot;&quot; baseURL:nil];
</span><span class="cx"> 
</span><span class="cx">     NSURLRequest *noAutoplayRequest = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@&quot;no-autoplay-with-controls&quot; withExtension:@&quot;html&quot; subdirectory:@&quot;TestWebKitAPI.resources&quot;]];
</span><span class="lines">@@ -299,7 +314,7 @@
</span><span class="cx">     [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
</span><span class="cx">     [webView mouseUpAtPoint:playButtonClickPoint];
</span><span class="cx">     [webView waitForMessage:@&quot;played&quot;];
</span><del>-    ASSERT_FALSE(receivedAlert);
</del><ins>+    ASSERT_TRUE(receivedAutoplayEvent == std::nullopt);
</ins><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>