Title: [212332] trunk
Revision
212332
Author
[email protected]
Date
2017-02-14 15:37:26 -0800 (Tue, 14 Feb 2017)

Log Message

Website policies: iframes should respect the autoplay policy of the top-level document
https://bugs.webkit.org/show_bug.cgi?id=168333

Reviewed by Alex Christensen.

Source/WebCore:

API tests were added.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::HTMLMediaElement):

Tools:

* TestWebKitAPI/Tests/WebKit2/autoplay-check-frame.html: Added.
* TestWebKitAPI/Tests/WebKit2/autoplay-check-in-iframe.html: Added.
* TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm:
(-[AutoplayPoliciesDelegate _webView:decidePolicyForNavigationAction:decisionHandler:]):
(TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (212331 => 212332)


--- trunk/Source/WebCore/ChangeLog	2017-02-14 23:31:12 UTC (rev 212331)
+++ trunk/Source/WebCore/ChangeLog	2017-02-14 23:37:26 UTC (rev 212332)
@@ -1,3 +1,15 @@
+2017-02-14  Matt Rajca  <[email protected]>
+
+        Website policies: iframes should respect the autoplay policy of the top-level document
+        https://bugs.webkit.org/show_bug.cgi?id=168333
+
+        Reviewed by Alex Christensen.
+
+        API tests were added.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::HTMLMediaElement):
+
 2017-02-14  Dean Jackson  <[email protected]>
 
         Rename preferLowPowerWebGLRendering setting to forceWebGLUsesLowPower

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (212331 => 212332)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2017-02-14 23:31:12 UTC (rev 212331)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2017-02-14 23:37:26 UTC (rev 212332)
@@ -460,8 +460,9 @@
         m_mediaSession->addBehaviorRestriction(MediaElementSession::InvisibleAutoplayNotPermitted);
 
     if (document.ownerElement() || !document.isMediaDocument()) {
-        bool shouldAudioPlaybackRequireUserGesture = document.audioPlaybackRequiresUserGesture();
-        bool shouldVideoPlaybackRequireUserGesture = document.videoPlaybackRequiresUserGesture();
+        const auto& topDocument = document.topDocument();
+        bool shouldAudioPlaybackRequireUserGesture = topDocument.audioPlaybackRequiresUserGesture();
+        bool shouldVideoPlaybackRequireUserGesture = topDocument.videoPlaybackRequiresUserGesture();
 
         if (shouldVideoPlaybackRequireUserGesture) {
             m_mediaSession->addBehaviorRestriction(MediaElementSession::RequireUserGestureForVideoRateChange);

Modified: trunk/Tools/ChangeLog (212331 => 212332)


--- trunk/Tools/ChangeLog	2017-02-14 23:31:12 UTC (rev 212331)
+++ trunk/Tools/ChangeLog	2017-02-14 23:37:26 UTC (rev 212332)
@@ -1,3 +1,16 @@
+2017-02-14  Matt Rajca  <[email protected]>
+
+        Website policies: iframes should respect the autoplay policy of the top-level document
+        https://bugs.webkit.org/show_bug.cgi?id=168333
+
+        Reviewed by Alex Christensen.
+
+        * TestWebKitAPI/Tests/WebKit2/autoplay-check-frame.html: Added.
+        * TestWebKitAPI/Tests/WebKit2/autoplay-check-in-iframe.html: Added.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm:
+        (-[AutoplayPoliciesDelegate _webView:decidePolicyForNavigationAction:decisionHandler:]):
+        (TEST):
+
 2017-02-14  Chris Dumez  <[email protected]>
 
         HTML Form Validation bubble should take minimum font size setting into consideration

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (212331 => 212332)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-02-14 23:31:12 UTC (rev 212331)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-02-14 23:37:26 UTC (rev 212332)
@@ -521,6 +521,8 @@
 		C99B675C1E39721A00FC6C80 /* autoplay-with-controls.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C99B675A1E3971FC00FC6C80 /* autoplay-with-controls.html */; };
 		C99B675D1E39722000FC6C80 /* js-play-with-controls.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C99B675B1E3971FC00FC6C80 /* js-play-with-controls.html */; };
 		C99B675F1E39736F00FC6C80 /* no-autoplay-with-controls.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C99B675E1E39735C00FC6C80 /* no-autoplay-with-controls.html */; };
+		C9C60E651E53A9DC006DA181 /* autoplay-check-frame.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C9C60E631E53A9BA006DA181 /* autoplay-check-frame.html */; };
+		C9C60E661E53A9DC006DA181 /* autoplay-check-in-iframe.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C9C60E641E53A9BA006DA181 /* autoplay-check-in-iframe.html */; };
 		CD321B041E3A85FA00EB21C8 /* video-with-muted-audio-and-webaudio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD321B031E3A84B700EB21C8 /* video-with-muted-audio-and-webaudio.html */; };
 		CD59F53419E9110D00CF1835 /* file-with-mse.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD59F53219E910AA00CF1835 /* file-with-mse.html */; };
 		CD59F53519E9110D00CF1835 /* test-mse.mp4 in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD59F53319E910BC00CF1835 /* test-mse.mp4 */; };
@@ -638,6 +640,8 @@
 				F45B960C1E50708800CFAC5D /* autofocus-contenteditable.html in Copy Resources */,
 				F4F93F341E4E918D00E33E2E /* image-and-textarea.html in Copy Resources */,
 				F4D4F3BC1E4E511F00BB2767 /* image-and-contenteditable.html in Copy Resources */,
+				C9C60E651E53A9DC006DA181 /* autoplay-check-frame.html in Copy Resources */,
+				C9C60E661E53A9DC006DA181 /* autoplay-check-in-iframe.html in Copy Resources */,
 				F47728991E4AE3C1007ABF6A /* full-page-contenteditable.html in Copy Resources */,
 				C99B675F1E39736F00FC6C80 /* no-autoplay-with-controls.html in Copy Resources */,
 				C99B675D1E39722000FC6C80 /* js-play-with-controls.html in Copy Resources */,
@@ -1327,6 +1331,8 @@
 		C99B675A1E3971FC00FC6C80 /* autoplay-with-controls.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "autoplay-with-controls.html"; sourceTree = "<group>"; };
 		C99B675B1E3971FC00FC6C80 /* js-play-with-controls.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "js-play-with-controls.html"; sourceTree = "<group>"; };
 		C99B675E1E39735C00FC6C80 /* no-autoplay-with-controls.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "no-autoplay-with-controls.html"; sourceTree = "<group>"; };
+		C9C60E631E53A9BA006DA181 /* autoplay-check-frame.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "autoplay-check-frame.html"; sourceTree = "<group>"; };
+		C9C60E641E53A9BA006DA181 /* autoplay-check-in-iframe.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "autoplay-check-in-iframe.html"; sourceTree = "<group>"; };
 		CD225C071C45A69200140761 /* ParsedContentRange.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParsedContentRange.cpp; sourceTree = "<group>"; };
 		CD321B031E3A84B700EB21C8 /* video-with-muted-audio-and-webaudio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "video-with-muted-audio-and-webaudio.html"; sourceTree = "<group>"; };
 		CD5393C71757BA9700C07123 /* MD5.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MD5.cpp; sourceTree = "<group>"; };
@@ -2050,6 +2056,8 @@
 				93D3D19B17B1A7B000C7C415 /* all-content-in-one-iframe.html */,
 				F6B7BE9617469B7E008A3445 /* associate-form-controls.html */,
 				76E182DE15475A8300F1FADD /* auto-submitting-form.html */,
+				C9C60E631E53A9BA006DA181 /* autoplay-check-frame.html */,
+				C9C60E641E53A9BA006DA181 /* autoplay-check-in-iframe.html */,
 				C95984F21E36BC55002C0D45 /* autoplay-check.html */,
 				C95984F31E36BC55002C0D45 /* autoplay-no-audio-check.html */,
 				C99B675A1E3971FC00FC6C80 /* autoplay-with-controls.html */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/autoplay-check-frame.html (0 => 212332)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/autoplay-check-frame.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/autoplay-check-frame.html	2017-02-14 23:37:26 UTC (rev 212332)
@@ -0,0 +1,16 @@
+<html>
+    <head>
+        <script>
+            function pageLoaded() {
+                document.getElementById("video").play().then(function() {
+                    window.parent.postMessage('autoplayed', '*');
+                }).catch(function() {
+                    window.parent.postMessage('did-not-play', '*');
+                });
+            }
+        </script>
+    </head>
+    <body _onload_="pageLoaded()">
+        <video id="video" playsinline src="" />
+    </body>
+</html>

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/autoplay-check-in-iframe.html (0 => 212332)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/autoplay-check-in-iframe.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/autoplay-check-in-iframe.html	2017-02-14 23:37:26 UTC (rev 212332)
@@ -0,0 +1,16 @@
+<html>
+    <head>
+        <script>
+            function pageLoaded() {
+                window._onmessage_ = function(event) {
+                    try {
+                        window.webkit.messageHandlers.testHandler.postMessage(event.data);
+                    } catch(e) { }
+                };
+            }
+        </script>
+    </head>
+    <body _onload_="pageLoaded()">
+        <iframe src=""
+    </body>
+</html>

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm (212331 => 212332)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm	2017-02-14 23:31:12 UTC (rev 212331)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm	2017-02-14 23:37:26 UTC (rev 212332)
@@ -158,7 +158,7 @@
 }
 
 @interface AutoplayPoliciesDelegate : NSObject <WKNavigationDelegate, WKUIDelegate>
-@property (nonatomic) _WKWebsiteAutoplayPolicy autoplayPolicy;
+@property (nonatomic, copy) _WKWebsiteAutoplayPolicy(^autoplayPolicyForURL)(NSURL *);
 @end
 
 @implementation AutoplayPoliciesDelegate
@@ -173,7 +173,8 @@
 - (void)_webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy, _WKWebsitePolicies *))decisionHandler
 {
     _WKWebsitePolicies *websitePolicies = [[[_WKWebsitePolicies alloc] init] autorelease];
-    websitePolicies.autoplayPolicy = _autoplayPolicy;
+    if (_autoplayPolicyForURL)
+        websitePolicies.autoplayPolicy = _autoplayPolicyForURL(navigationAction.request.URL);
     decisionHandler(WKNavigationActionPolicyAllow, websitePolicies);
 }
 
@@ -195,7 +196,9 @@
     NSURLRequest *requestWithAudio = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"autoplay-check" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     NSURLRequest *requestWithoutAudio = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"autoplay-no-audio-check" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     
-    [delegate setAutoplayPolicy:_WKWebsiteAutoplayPolicyAllowWithoutSound];
+    [delegate setAutoplayPolicyForURL:^(NSURL *) {
+        return _WKWebsiteAutoplayPolicyAllowWithoutSound;
+    }];
     [webView loadRequest:requestWithAudio];
     [webView waitForMessage:@"did-not-play"];
 
@@ -202,7 +205,9 @@
     [webView loadRequest:requestWithoutAudio];
     [webView waitForMessage:@"autoplayed"];
 
-    [delegate setAutoplayPolicy:_WKWebsiteAutoplayPolicyDeny];
+    [delegate setAutoplayPolicyForURL:^(NSURL *) {
+        return _WKWebsiteAutoplayPolicyDeny;
+    }];
     [webView loadRequest:requestWithAudio];
     [webView waitForMessage:@"did-not-play"];
 
@@ -209,12 +214,36 @@
     [webView loadRequest:requestWithoutAudio];
     [webView waitForMessage:@"did-not-play"];
 
-    [delegate setAutoplayPolicy:_WKWebsiteAutoplayPolicyAllow];
+    [delegate setAutoplayPolicyForURL:^(NSURL *) {
+        return _WKWebsiteAutoplayPolicyAllow;
+    }];
     [webView loadRequest:requestWithAudio];
     [webView waitForMessage:@"autoplayed"];
 
     [webView loadRequest:requestWithoutAudio];
     [webView waitForMessage:@"autoplayed"];
+
+    NSURLRequest *requestWithAudioInIFrame = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"autoplay-check-in-iframe" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+
+    // If the top-level document allows autoplay, any iframes should also autoplay.
+    [delegate setAutoplayPolicyForURL:^(NSURL *url) {
+        if ([url.lastPathComponent isEqualToString:@"autoplay-check-in-iframe.html"])
+            return _WKWebsiteAutoplayPolicyAllow;
+        return _WKWebsiteAutoplayPolicyDeny;
+    }];
+
+    [webView loadRequest:requestWithAudioInIFrame];
+    [webView waitForMessage:@"autoplayed"];
+
+    // If the top-level document disallows autoplay, any iframes should also not autoplay.
+    [delegate setAutoplayPolicyForURL:^(NSURL *url) {
+        if ([url.lastPathComponent isEqualToString:@"autoplay-check-in-iframe.html"])
+            return _WKWebsiteAutoplayPolicyDeny;
+        return _WKWebsiteAutoplayPolicyAllow;
+    }];
+
+    [webView loadRequest:requestWithAudioInIFrame];
+    [webView waitForMessage:@"did-not-play"];
 }
 
 #if PLATFORM(MAC)
@@ -230,7 +259,9 @@
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 336, 276) configuration:configuration.get()]);
 
     auto delegate = adoptNS([[AutoplayPoliciesDelegate alloc] init]);
-    [delegate setAutoplayPolicy:_WKWebsiteAutoplayPolicyDeny];
+    [delegate setAutoplayPolicyForURL:^(NSURL *) {
+        return _WKWebsiteAutoplayPolicyDeny;
+    }];
     [webView setNavigationDelegate:delegate.get()];
 
     WKPageUIClientV9 uiClient;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to