<!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>[211062] 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/211062">211062</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2017-01-23 14:25:59 -0800 (Mon, 23 Jan 2017)</dd>
</dl>
<h3>Log Message</h3>
<pre>Pass down website autoplay policies to media elements
https://bugs.webkit.org/show_bug.cgi?id=167132
Patch by Matt Rajca <mrajca@apple.com> on 2017-01-23
Reviewed by Alex Christensen.
The playbackRequiresUserGesture APIs are already covered by tests. This patch adds API tests
for autoplay website policies.
* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebCoreSupportWebFrameLoaderClientcpp">trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp</a></li>
<li><a href="#trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj">trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2CocoaWebsitePoliciesmm">trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2autoplayCheckhtml">trunk/Tools/TestWebKitAPI/Tests/WebKit2/autoplayCheck.html</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (211061 => 211062)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2017-01-23 22:24:01 UTC (rev 211061)
+++ trunk/Source/WebKit2/ChangeLog        2017-01-23 22:25:59 UTC (rev 211062)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2017-01-23 Matt Rajca <mrajca@apple.com>
+
+ Pass down website autoplay policies to media elements
+ https://bugs.webkit.org/show_bug.cgi?id=167132
+
+ Reviewed by Alex Christensen.
+
+ The playbackRequiresUserGesture APIs are already covered by tests. This patch adds API tests
+ for autoplay website policies.
+
+ * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
+ (WebKit::WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction):
+
</ins><span class="cx"> 2017-01-23 Joseph Pecoraro <pecoraro@apple.com>
</span><span class="cx">
</span><span class="cx"> Web Inspector: Asserts seen opening and closing Remote Web Inspector windows
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebCoreSupportWebFrameLoaderClientcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp (211061 => 211062)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp        2017-01-23 22:24:01 UTC (rev 211061)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp        2017-01-23 22:25:59 UTC (rev 211062)
</span><span class="lines">@@ -817,6 +817,10 @@
</span><span class="cx"> if (documentLoader->userContentExtensionsEnabled())
</span><span class="cx"> documentLoader->setUserContentExtensionsEnabled(websitePolicies.contentBlockersEnabled);
</span><span class="cx">
</span><ins>+#if PLATFORM(MAC)
+ coreFrame->settings().setAudioPlaybackRequiresUserGesture(!websitePolicies.autoplayEnabled);
+#endif
+
</ins><span class="cx"> // We call this synchronously because WebCore cannot gracefully handle a frame load without a synchronous navigation policy reply.
</span><span class="cx"> if (receivedPolicyAction)
</span><span class="cx"> m_frame->didReceivePolicyDecision(listenerID, static_cast<PolicyAction>(policyAction), newNavigationID, downloadID);
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (211061 => 211062)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2017-01-23 22:24:01 UTC (rev 211061)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2017-01-23 22:25:59 UTC (rev 211062)
</span><span class="lines">@@ -506,6 +506,7 @@
</span><span class="cx">                 C540F784152E5A9A00A40C8C /* verboseMarkup.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C540F783152E5A7800A40C8C /* verboseMarkup.html */; };
</span><span class="cx">                 C54237F116B8957D00E638FC /* PasteboardNotifications_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C54237ED16B8955800E638FC /* PasteboardNotifications_Bundle.cpp */; };
</span><span class="cx">                 C5E1AFFE16B221F1006CC1F2 /* execCopy.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C5E1AFFD16B22179006CC1F2 /* execCopy.html */; };
</span><ins>+                C9CB7DE11E2ED6F900B26082 /* autoplayCheck.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C9CB7DE01E2ED2A700B26082 /* autoplayCheck.html */; };
</ins><span class="cx">                 CD59F53419E9110D00CF1835 /* file-with-mse.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD59F53219E910AA00CF1835 /* file-with-mse.html */; };
</span><span class="cx">                 CD59F53519E9110D00CF1835 /* test-mse.mp4 in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD59F53319E910BC00CF1835 /* test-mse.mp4 */; };
</span><span class="cx">                 CD78E11D1DB7EA660014A2DE /* FullscreenDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD78E11A1DB7EA360014A2DE /* FullscreenDelegate.mm */; };
</span><span class="lines">@@ -604,6 +605,7 @@
</span><span class="cx">                         dstPath = TestWebKitAPI.resources;
</span><span class="cx">                         dstSubfolderSpec = 7;
</span><span class="cx">                         files = (
</span><ins>+                                C9CB7DE11E2ED6F900B26082 /* autoplayCheck.html in Copy Resources */,
</ins><span class="cx">                                 7AEAD4811E20122700416EFE /* CrossPartitionFileSchemeAccess.html in Copy Resources */,
</span><span class="cx">                                 CDB4115A1E0B00DB00EAD352 /* video-with-muted-audio.html in Copy Resources */,
</span><span class="cx">                                 9BD4239C1E04C01C00200395 /* chinese-character-with-image.html in Copy Resources */,
</span><span class="lines">@@ -1265,6 +1267,7 @@
</span><span class="cx">                 C54237EE16B8955800E638FC /* PasteboardNotifications.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PasteboardNotifications.mm; sourceTree = "<group>"; };
</span><span class="cx">                 C5E1AFFD16B22179006CC1F2 /* execCopy.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = execCopy.html; sourceTree = "<group>"; };
</span><span class="cx">                 C95501BE19AD2FAF0049BE3E /* Preferences.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Preferences.mm; sourceTree = "<group>"; };
</span><ins>+                C9CB7DE01E2ED2A700B26082 /* autoplayCheck.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = autoplayCheck.html; sourceTree = "<group>"; };
</ins><span class="cx">                 CD225C071C45A69200140761 /* ParsedContentRange.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParsedContentRange.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 CD5393C71757BA9700C07123 /* MD5.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MD5.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 CD5393C91757BAC400C07123 /* SHA1.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SHA1.cpp; sourceTree = "<group>"; };
</span><span class="lines">@@ -1945,18 +1948,19 @@
</span><span class="cx">                 BC90977B125571AE00083756 /* Resources */ = {
</span><span class="cx">                         isa = PBXGroup;
</span><span class="cx">                         children = (
</span><del>-                                9BD4239B1E04BFD000200395 /* chinese-character-with-image.html */,
-                                07492B391DF8ADA400633DE1 /* enumerateMediaDevices.html */,
</del><span class="cx">                                 C045F9461385C2F800C0F3CD /* 18-characters.html */,
</span><span class="cx">                                 1C2B81851C89252300A5529F /* Ahem.ttf */,
</span><span class="cx">                                 93D3D19B17B1A7B000C7C415 /* all-content-in-one-iframe.html */,
</span><span class="cx">                                 F6B7BE9617469B7E008A3445 /* associate-form-controls.html */,
</span><span class="cx">                                 76E182DE15475A8300F1FADD /* auto-submitting-form.html */,
</span><ins>+                                C9CB7DE01E2ED2A700B26082 /* autoplayCheck.html */,
</ins><span class="cx">                                 7C486BA01AA1254B003F6F9B /* bundle-file.html */,
</span><ins>+                                9BD4239B1E04BFD000200395 /* chinese-character-with-image.html */,
</ins><span class="cx">                                 1A50AA1F1A2A4EA500F4C345 /* close-from-within-create-page.html */,
</span><span class="cx">                                 9B270FED1DDC25FD002D53F3 /* closed-shadow-tree-test.html */,
</span><span class="cx">                                 5C9E56861DF9148E00C9EE33 /* contentBlockerCheck.html */,
</span><span class="cx">                                 290F4274172A1FDE00939FF0 /* custom-protocol-sync-xhr.html */,
</span><ins>+                                07492B391DF8ADA400633DE1 /* enumerateMediaDevices.html */,
</ins><span class="cx">                                 C5E1AFFD16B22179006CC1F2 /* execCopy.html */,
</span><span class="cx">                                 BC2D004A12A9FEB300E732A3 /* file-with-anchor.html */,
</span><span class="cx">                                 CD59F53219E910AA00CF1835 /* file-with-mse.html */,
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2autoplayCheckhtml"></a>
<div class="addfile"><h4>Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/autoplayCheck.html (0 => 211062)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/autoplayCheck.html         (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/autoplayCheck.html        2017-01-23 22:25:59 UTC (rev 211062)
</span><span class="lines">@@ -0,0 +1,22 @@
</span><ins>+<html>
+ <head>
+ <script>
+ function pageLoaded() {
+ setTimeout(function() {
+ try {
+ window.webkit.messageHandlers.testHandler.postMessage("did-not-play");
+ } catch(e) { }
+ }, 100);
+ }
+
+ function beganPlaying() {
+ try {
+ window.webkit.messageHandlers.testHandler.postMessage("autoplayed");
+ } catch(e) { }
+ }
+ </script>
+ </head>
+ <body onload="pageLoaded()">
+ <video id="video" autoplay onplaying=beganPlaying() src="test.mp4" />
+ </body>
+</html>
</ins></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2CocoaWebsitePoliciesmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm (211061 => 211062)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm        2017-01-23 22:24:01 UTC (rev 211061)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm        2017-01-23 22:25:59 UTC (rev 211062)
</span><span class="lines">@@ -26,6 +26,7 @@
</span><span class="cx"> #include "config.h"
</span><span class="cx">
</span><span class="cx"> #import "PlatformUtilities.h"
</span><ins>+#import "TestWKWebView.h"
</ins><span class="cx"> #import <WebKit/WKUserContentControllerPrivate.h>
</span><span class="cx"> #import <WebKit/WKWebViewPrivate.h>
</span><span class="cx"> #import <WebKit/_WKUserContentExtensionStorePrivate.h>
</span><span class="lines">@@ -38,10 +39,10 @@
</span><span class="cx"> static bool receivedAlert;
</span><span class="cx"> static size_t alertCount;
</span><span class="cx">
</span><del>-@interface WebsitePoliciesDelegate : NSObject <WKNavigationDelegate, WKUIDelegate>
</del><ins>+@interface ContentBlockingWebsitePoliciesDelegate : NSObject <WKNavigationDelegate, WKUIDelegate>
</ins><span class="cx"> @end
</span><span class="cx">
</span><del>-@implementation WebsitePoliciesDelegate
</del><ins>+@implementation ContentBlockingWebsitePoliciesDelegate
</ins><span class="cx">
</span><span class="cx"> - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
</span><span class="cx"> {
</span><span class="lines">@@ -123,7 +124,7 @@
</span><span class="cx">
</span><span class="cx"> auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
</span><span class="cx">
</span><del>- auto delegate = adoptNS([[WebsitePoliciesDelegate alloc] init]);
</del><ins>+ auto delegate = adoptNS([[ContentBlockingWebsitePoliciesDelegate alloc] init]);
</ins><span class="cx"> [webView setNavigationDelegate:delegate.get()];
</span><span class="cx"> [webView setUIDelegate:delegate.get()];
</span><span class="cx">
</span><span class="lines">@@ -148,4 +149,53 @@
</span><span class="cx"> [[_WKUserContentExtensionStore defaultStore] _removeAllContentExtensions];
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+#if PLATFORM(MAC)
+
+@interface AutoplayPoliciesDelegate : NSObject <WKNavigationDelegate, WKUIDelegate>
+@property (nonatomic) BOOL allowAutoplay;
+@end
+
+@implementation AutoplayPoliciesDelegate
+
+- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
+{
+ // _webView:decidePolicyForNavigationAction:decisionHandler: should be called instead if it is implemented.
+ EXPECT_TRUE(false);
+ decisionHandler(WKNavigationActionPolicyAllow);
+}
+
+- (void)_webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy, _WKWebsitePolicies *))decisionHandler
+{
+ _WKWebsitePolicies *websitePolicies = [[[_WKWebsitePolicies alloc] init] autorelease];
+ websitePolicies.autoplayEnabled = _allowAutoplay;
+ decisionHandler(WKNavigationActionPolicyAllow, websitePolicies);
+}
+
+@end
+
+TEST(WebKit2, WebsitePoliciesAutoplayEnabled)
+{
+ auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+ auto delegate = adoptNS([[AutoplayPoliciesDelegate alloc] init]);
+ [webView setNavigationDelegate:delegate.get()];
+
+ NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"autoplayCheck" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+
+ [delegate setAllowAutoplay:YES];
+ [webView loadRequest:request];
+ [webView waitForMessage:@"autoplayed"];
+
+ [delegate setAllowAutoplay:NO];
+ [webView loadRequest:request];
+ [webView waitForMessage:@"did-not-play"];
+
+ [delegate setAllowAutoplay:YES];
+ [webView loadRequest:request];
+ [webView waitForMessage:@"autoplayed"];
+}
+
+#endif // PLATFORM(MAC)
+
</ins><span class="cx"> #endif
</span></span></pre>
</div>
</div>
</body>
</html>