- Revision
- 252438
- Author
- [email protected]
- Date
- 2019-11-13 16:25:27 -0800 (Wed, 13 Nov 2019)
Log Message
Link mediaDataLoadsAutomatically setting to AutoplayPolicy
https://bugs.webkit.org/show_bug.cgi?id=201738
<rdar://problem/55315194>
Reviewed by Eric Carlson.
Source/WebCore:
This change has two effects: on Mac, when the embedding app sets an AutoplayPolicy to
deny autoplay, this will also deny the ability to load media data beyond "preload"; on iOS
when the embedding app sets an AutoplayPolicy to allow autoplay, this will also allow media
data to load beyond "preload".
* dom/Document.cpp:
(WebCore::Document::mediaDataLoadsAutomatically const):
* dom/Document.h:
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::finishInitialization):
* html/MediaElementSession.cpp:
(WebCore::MediaElementSession::allowsAutomaticMediaDataLoading const):
Tools:
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit/media-loading.html: Added.
* TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm:
(TEST):
Modified Paths
Added Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (252437 => 252438)
--- trunk/Source/WebCore/ChangeLog 2019-11-14 00:17:42 UTC (rev 252437)
+++ trunk/Source/WebCore/ChangeLog 2019-11-14 00:25:27 UTC (rev 252438)
@@ -1,3 +1,24 @@
+2019-11-13 Jer Noble <[email protected]>
+
+ Link mediaDataLoadsAutomatically setting to AutoplayPolicy
+ https://bugs.webkit.org/show_bug.cgi?id=201738
+ <rdar://problem/55315194>
+
+ Reviewed by Eric Carlson.
+
+ This change has two effects: on Mac, when the embedding app sets an AutoplayPolicy to
+ deny autoplay, this will also deny the ability to load media data beyond "preload"; on iOS
+ when the embedding app sets an AutoplayPolicy to allow autoplay, this will also allow media
+ data to load beyond "preload".
+
+ * dom/Document.cpp:
+ (WebCore::Document::mediaDataLoadsAutomatically const):
+ * dom/Document.h:
+ * html/HTMLMediaElement.cpp:
+ (WebCore::HTMLMediaElement::finishInitialization):
+ * html/MediaElementSession.cpp:
+ (WebCore::MediaElementSession::allowsAutomaticMediaDataLoading const):
+
2019-11-13 Devin Rousso <[email protected]>
Web Inspector: DOM.highlightSelector should work for "a:visited"
Modified: trunk/Source/WebCore/dom/Document.cpp (252437 => 252438)
--- trunk/Source/WebCore/dom/Document.cpp 2019-11-14 00:17:42 UTC (rev 252437)
+++ trunk/Source/WebCore/dom/Document.cpp 2019-11-14 00:25:27 UTC (rev 252438)
@@ -5361,6 +5361,17 @@
return settings().videoPlaybackRequiresUserGesture();
}
+bool Document::mediaDataLoadsAutomatically() const
+{
+ if (auto* loader = this->loader()) {
+ AutoplayPolicy policy = loader->autoplayPolicy();
+ if (policy != AutoplayPolicy::Default)
+ return policy != AutoplayPolicy::Deny;
+ }
+
+ return settings().mediaDataLoadsAutomatically();
+}
+
void Document::storageBlockingStateDidChange()
{
securityOrigin().setStorageBlockingPolicy(settings().storageBlockingPolicy());
Modified: trunk/Source/WebCore/dom/Document.h (252437 => 252438)
--- trunk/Source/WebCore/dom/Document.h 2019-11-14 00:17:42 UTC (rev 252437)
+++ trunk/Source/WebCore/dom/Document.h 2019-11-14 00:25:27 UTC (rev 252438)
@@ -1094,6 +1094,7 @@
bool audioPlaybackRequiresUserGesture() const;
bool videoPlaybackRequiresUserGesture() const;
+ bool mediaDataLoadsAutomatically() const;
#if ENABLE(MEDIA_SESSION)
MediaSession& defaultMediaSession();
Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (252437 => 252438)
--- trunk/Source/WebCore/html/HTMLMediaElement.cpp 2019-11-14 00:17:42 UTC (rev 252437)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp 2019-11-14 00:25:27 UTC (rev 252438)
@@ -525,7 +525,7 @@
m_mediaSession->addBehaviorRestriction(MediaElementSession::RequireUserGestureToShowPlaybackTargetPicker);
#endif
- if (!document.settings().mediaDataLoadsAutomatically() && !document.quirks().needsPreloadAutoQuirk())
+ if (!document.mediaDataLoadsAutomatically() && !document.quirks().needsPreloadAutoQuirk())
m_mediaSession->addBehaviorRestriction(MediaElementSession::AutoPreloadingNotPermitted);
if (document.settings().mainContentUserGestureOverrideEnabled())
Modified: trunk/Tools/ChangeLog (252437 => 252438)
--- trunk/Tools/ChangeLog 2019-11-14 00:17:42 UTC (rev 252437)
+++ trunk/Tools/ChangeLog 2019-11-14 00:25:27 UTC (rev 252438)
@@ -1,3 +1,16 @@
+2019-11-13 Jer Noble <[email protected]>
+
+ Link mediaDataLoadsAutomatically setting to AutoplayPolicy
+ https://bugs.webkit.org/show_bug.cgi?id=201738
+ <rdar://problem/55315194>
+
+ Reviewed by Eric Carlson.
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WebKit/media-loading.html: Added.
+ * TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm:
+ (TEST):
+
2019-11-13 Carlos Alberto Lopez Perez <[email protected]>
test262-runner: use NUMBER_OF_PROCESSORS and stop multiplying the number of cores.
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (252437 => 252438)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2019-11-14 00:17:42 UTC (rev 252437)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2019-11-14 00:25:27 UTC (rev 252438)
@@ -905,6 +905,7 @@
CD78E11D1DB7EA660014A2DE /* FullscreenDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD78E11A1DB7EA360014A2DE /* FullscreenDelegate.mm */; };
CD78E11E1DB7EE2A0014A2DE /* FullscreenDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD78E11B1DB7EA360014A2DE /* FullscreenDelegate.html */; };
CD7F89DC22A86CDA00D683AE /* WKWebViewSuspendAllMediaPlayback.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD7F89DB22A86CDA00D683AE /* WKWebViewSuspendAllMediaPlayback.mm */; };
+ CD8394DF232AF7C000149495 /* media-loading.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD8394DE232AF15E00149495 /* media-loading.html */; };
CD9E292E1C90C33F000BB800 /* audio-only.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD9E292D1C90C1BA000BB800 /* audio-only.html */; };
CDA29B2920FD2A9900F15CED /* ExitFullscreenOnEnterPiP.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDA29B2820FD2A9900F15CED /* ExitFullscreenOnEnterPiP.mm */; };
CDA29B2B20FD358400F15CED /* ExitFullscreenOnEnterPiP.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CDA29B2A20FD344E00F15CED /* ExitFullscreenOnEnterPiP.html */; };
@@ -1138,6 +1139,7 @@
dstPath = TestWebKitAPI.resources;
dstSubfolderSpec = 7;
files = (
+ CD8394DF232AF7C000149495 /* media-loading.html in Copy Resources */,
55A817FF2181021A0004A39A /* 100x100-red.tga in Copy Resources */,
1A9E52C913E65EF4006917F5 /* 18-characters.html in Copy Resources */,
55A81800218102210004A39A /* 400x400-green.png in Copy Resources */,
@@ -2409,6 +2411,7 @@
CD78E11A1DB7EA360014A2DE /* FullscreenDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FullscreenDelegate.mm; sourceTree = "<group>"; };
CD78E11B1DB7EA360014A2DE /* FullscreenDelegate.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = FullscreenDelegate.html; sourceTree = "<group>"; };
CD7F89DB22A86CDA00D683AE /* WKWebViewSuspendAllMediaPlayback.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewSuspendAllMediaPlayback.mm; sourceTree = "<group>"; };
+ CD8394DE232AF15E00149495 /* media-loading.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "media-loading.html"; sourceTree = "<group>"; };
CD89D0381C4EDB2A00040A04 /* WebCoreNSURLSession.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreNSURLSession.mm; sourceTree = "<group>"; };
CD9E292B1C90A71F000BB800 /* RequiresUserActionForPlayback.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RequiresUserActionForPlayback.mm; sourceTree = "<group>"; };
CD9E292D1C90C1BA000BB800 /* audio-only.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "audio-only.html"; sourceTree = "<group>"; };
@@ -3869,6 +3872,7 @@
07CD32F72065B72A0064A4BE /* video.html */,
1C2B81841C8924A200A5529F /* webfont.html */,
468F2F932368DAA700F4B864 /* window-open-then-document-open.html */,
+ CD8394DE232AF15E00149495 /* media-loading.html */,
);
name = Resources;
sourceTree = "<group>";
Added: trunk/Tools/TestWebKitAPI/Tests/WebKit/media-loading.html (0 => 252438)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit/media-loading.html (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/media-loading.html 2019-11-14 00:25:27 UTC (rev 252438)
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <script>
+ function postMessage(event) {
+ window.webkit.messageHandlers.testHandler.postMessage(event.type);
+
+ }
+ window.addEventListener('load', event => {
+ video.addEventListener('loadeddata', postMessage);
+ video.addEventListener('suspend', postMessage);
+ video.src = '';
+ });
+ </script>
+ <body>
+ <video id=video></video>
+</script></body></html>"
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm (252437 => 252438)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm 2019-11-14 00:17:42 UTC (rev 252437)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm 2019-11-14 00:25:27 UTC (rev 252438)
@@ -174,7 +174,7 @@
[[_WKUserContentExtensionStore defaultStore] _removeAllContentExtensions];
}
-@interface AutoplayPoliciesDelegate : NSObject <WKNavigationDelegate, WKUIDelegatePrivate>
+@interface AutoplayPoliciesDelegate : TestNavigationDelegate <WKNavigationDelegate, WKUIDelegatePrivate>
@property (nonatomic, copy) _WKWebsiteAutoplayPolicy(^autoplayPolicyForURL)(NSURL *);
@property (nonatomic, copy) _WKWebsiteAutoplayQuirk(^allowedAutoplayQuirksForURL)(NSURL *);
@end
@@ -537,6 +537,46 @@
ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
}
+TEST(WebKit, WebsitePoliciesPerDocumentAutoplayBehaviorMediaLoading)
+{
+ 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()];
+
+ __block bool receivedLoadedEvent = false;
+ __block bool receivedSuspendEvent = false;
+
+ [webView performAfterReceivingMessage:@"loadeddata" action:^{ receivedLoadedEvent = true; }];
+ [webView performAfterReceivingMessage:@"suspend" action:^{ receivedSuspendEvent = true; }];
+
+ [delegate setAutoplayPolicyForURL:^(NSURL *) {
+ return _WKWebsiteAutoplayPolicyDeny;
+ }];
+
+ [webView loadTestPageNamed:@"media-loading"];
+
+ TestWebKitAPI::Util::run(&receivedSuspendEvent);
+ EXPECT_FALSE(receivedLoadedEvent);
+
+ [webView loadHTMLString:@"" baseURL:nil];
+ [delegate waitForDidFinishNavigation];
+
+ [webView setNavigationDelegate:delegate.get()];
+
+ receivedLoadedEvent = false;
+ receivedSuspendEvent = false;
+
+ [delegate setAutoplayPolicyForURL:^(NSURL *) {
+ return _WKWebsiteAutoplayPolicyAllow;
+ }];
+
+ [webView loadTestPageNamed:@"media-loading"];
+
+ TestWebKitAPI::Util::run(&receivedLoadedEvent);
+}
+
TEST(WebKit, WebsitePoliciesWithBridgingCast)
{
auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);