Title: [223451] trunk
Revision
223451
Author
mra...@apple.com
Date
2017-10-16 17:30:24 -0700 (Mon, 16 Oct 2017)

Log Message

Add API support for quirk that lets an arbitrary click allow auto-play.
https://bugs.webkit.org/show_bug.cgi?id=178227

Reviewed by Alex Christensen.

Source/WebCore:

Added API test.

Instead of hardcoding sites in WebCore, let API clients control which websites opt into the quirk that lets
an arbitrary click allow auto-play via website policies.

* html/MediaElementSession.cpp:
(WebCore::needsArbitraryUserGestureAutoplayQuirk):
* loader/DocumentLoader.h:

Source/WebKit:

Instead of hardcoding sites in WebCore, let API clients control which websites opt into the quirk that lets
an arbitrary click allow auto-play via website policies.

* Shared/WebsitePolicies.h:
* UIProcess/API/C/WKWebsitePolicies.cpp:
(WKWebsitePoliciesSetAllowedAutoplayQuirks):
(WKWebsitePoliciesGetAllowedAutoplayQuirks):
* UIProcess/API/C/WKWebsitePolicies.h:
* UIProcess/API/Cocoa/_WKWebsitePolicies.h:
* UIProcess/API/Cocoa/_WKWebsitePolicies.mm:
(-[_WKWebsitePolicies setAllowedAutoplayQuirks:]):
(-[_WKWebsitePolicies allowedAutoplayQuirks]):
* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::applyToDocumentLoader):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::updateWebsitePolicies):

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm:
(TEST): Added API test.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (223450 => 223451)


--- trunk/Source/WebCore/ChangeLog	2017-10-17 00:15:06 UTC (rev 223450)
+++ trunk/Source/WebCore/ChangeLog	2017-10-17 00:30:24 UTC (rev 223451)
@@ -1,3 +1,19 @@
+2017-10-12  Matt Rajca  <mra...@apple.com>
+
+        Add API support for quirk that lets an arbitrary click allow auto-play.
+        https://bugs.webkit.org/show_bug.cgi?id=178227
+
+        Reviewed by Alex Christensen.
+
+        Added API test.
+        
+        Instead of hardcoding sites in WebCore, let API clients control which websites opt into the quirk that lets
+        an arbitrary click allow auto-play via website policies.
+
+        * html/MediaElementSession.cpp:
+        (WebCore::needsArbitraryUserGestureAutoplayQuirk):
+        * loader/DocumentLoader.h:
+
 2017-10-16  Chris Dumez  <cdu...@apple.com>
 
         DOMQuad.p1 / p2 / p3 / p4 should behave as [SameObject]

Modified: trunk/Source/WebCore/html/MediaElementSession.cpp (223450 => 223451)


--- trunk/Source/WebCore/html/MediaElementSession.cpp	2017-10-17 00:15:06 UTC (rev 223450)
+++ trunk/Source/WebCore/html/MediaElementSession.cpp	2017-10-17 00:30:24 UTC (rev 223451)
@@ -30,6 +30,7 @@
 #include "MediaElementSession.h"
 
 #include "Document.h"
+#include "DocumentLoader.h"
 #include "Frame.h"
 #include "FrameView.h"
 #include "HTMLAudioElement.h"
@@ -154,8 +155,8 @@
     if (!document.settings().needsSiteSpecificQuirks())
         return false;
 
-    auto host = document.url().host();
-    return equalLettersIgnoringASCIICase(host, "washingtonpost.com") || host.endsWithIgnoringASCIICase(".washingtonpost.com");
+    auto* loader = document.loader();
+    return loader && loader->allowedAutoplayQuirks().contains(AutoplayQuirk::ArbitraryUserGestures);
 }
 #endif // PLATFORM(MAC)
 

Modified: trunk/Source/WebCore/loader/DocumentLoader.h (223450 => 223451)


--- trunk/Source/WebCore/loader/DocumentLoader.h	2017-10-17 00:15:06 UTC (rev 223450)
+++ trunk/Source/WebCore/loader/DocumentLoader.h	2017-10-17 00:30:24 UTC (rev 223451)
@@ -90,6 +90,7 @@
 enum class AutoplayQuirk {
     SynthesizedPauseEvents = 1 << 0,
     InheritedUserGestures = 1 << 1,
+    ArbitraryUserGestures = 1 << 2,
 };
 
 class DocumentLoader : public RefCounted<DocumentLoader>, public FrameDestructionObserver, private CachedRawResourceClient {

Modified: trunk/Source/WebKit/ChangeLog (223450 => 223451)


--- trunk/Source/WebKit/ChangeLog	2017-10-17 00:15:06 UTC (rev 223450)
+++ trunk/Source/WebKit/ChangeLog	2017-10-17 00:30:24 UTC (rev 223451)
@@ -1,3 +1,27 @@
+2017-10-12  Matt Rajca  <mra...@apple.com>
+
+        Add API support for quirk that lets an arbitrary click allow auto-play.
+        https://bugs.webkit.org/show_bug.cgi?id=178227
+
+        Reviewed by Alex Christensen.
+
+        Instead of hardcoding sites in WebCore, let API clients control which websites opt into the quirk that lets
+        an arbitrary click allow auto-play via website policies.
+
+        * Shared/WebsitePolicies.h:
+        * UIProcess/API/C/WKWebsitePolicies.cpp:
+        (WKWebsitePoliciesSetAllowedAutoplayQuirks):
+        (WKWebsitePoliciesGetAllowedAutoplayQuirks):
+        * UIProcess/API/C/WKWebsitePolicies.h:
+        * UIProcess/API/Cocoa/_WKWebsitePolicies.h:
+        * UIProcess/API/Cocoa/_WKWebsitePolicies.mm:
+        (-[_WKWebsitePolicies setAllowedAutoplayQuirks:]):
+        (-[_WKWebsitePolicies allowedAutoplayQuirks]):
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
+        (WebKit::WebFrameLoaderClient::applyToDocumentLoader):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::updateWebsitePolicies):
+
 2017-10-16  Andy Estes  <aes...@apple.com>
 
         [Apple Pay] Add subLocality and subAdministrativeArea to ApplePayPaymentContact and ApplePayError

Modified: trunk/Source/WebKit/Shared/WebsitePolicies.h (223450 => 223451)


--- trunk/Source/WebKit/Shared/WebsitePolicies.h	2017-10-17 00:15:06 UTC (rev 223450)
+++ trunk/Source/WebKit/Shared/WebsitePolicies.h	2017-10-17 00:30:24 UTC (rev 223451)
@@ -43,6 +43,7 @@
 enum class WebsiteAutoplayQuirk {
     SynthesizedPauseEvents = 1 << 0,
     InheritedUserGestures = 1 << 1,
+    ArbitraryUserGestures = 1 << 2,
 };
 
 struct WebsitePolicies {

Modified: trunk/Source/WebKit/UIProcess/API/C/WKWebsitePolicies.cpp (223450 => 223451)


--- trunk/Source/WebKit/UIProcess/API/C/WKWebsitePolicies.cpp	2017-10-17 00:15:06 UTC (rev 223450)
+++ trunk/Source/WebKit/UIProcess/API/C/WKWebsitePolicies.cpp	2017-10-17 00:30:24 UTC (rev 223451)
@@ -88,6 +88,9 @@
     if (allowedQuirks & kWKWebsiteAutoplayQuirkSynthesizedPauseEvents)
         quirks |= WebsiteAutoplayQuirk::SynthesizedPauseEvents;
 
+    if (allowedQuirks & kWKWebsiteAutoplayQuirkArbitraryUserGestures)
+        quirks |= WebsiteAutoplayQuirk::ArbitraryUserGestures;
+
     toImpl(websitePolicies)->setAllowedAutoplayQuirks(quirks);
 }
 
@@ -102,6 +105,9 @@
     if (allowedQuirks.contains(WebsiteAutoplayQuirk::InheritedUserGestures))
         quirks |= kWKWebsiteAutoplayQuirkInheritedUserGestures;
 
+    if (allowedQuirks.contains(WebsiteAutoplayQuirk::ArbitraryUserGestures))
+        quirks |= kWKWebsiteAutoplayQuirkArbitraryUserGestures;
+
     return quirks;
 }
 

Modified: trunk/Source/WebKit/UIProcess/API/C/WKWebsitePolicies.h (223450 => 223451)


--- trunk/Source/WebKit/UIProcess/API/C/WKWebsitePolicies.h	2017-10-17 00:15:06 UTC (rev 223450)
+++ trunk/Source/WebKit/UIProcess/API/C/WKWebsitePolicies.h	2017-10-17 00:30:24 UTC (rev 223451)
@@ -44,6 +44,7 @@
 enum {
     kWKWebsiteAutoplayQuirkSynthesizedPauseEvents = 1 << 0,
     kWKWebsiteAutoplayQuirkInheritedUserGestures = 1 << 1,
+    kWKWebsiteAutoplayQuirkArbitraryUserGestures = 1 << 2,
 };
 
 WK_EXPORT WKWebsitePoliciesRef WKWebsitePoliciesCreate();

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h (223450 => 223451)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h	2017-10-17 00:15:06 UTC (rev 223450)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h	2017-10-17 00:30:24 UTC (rev 223451)
@@ -37,6 +37,7 @@
 typedef NS_OPTIONS(NSUInteger, _WKWebsiteAutoplayQuirk) {
     _WKWebsiteAutoplayQuirkSynthesizedPauseEvents = 1 << 0,
     _WKWebsiteAutoplayQuirkInheritedUserGestures = 1 << 1,
+    _WKWebsiteAutoplayQuirkArbitraryUserGestures = 1 << 2,
 } WK_API_AVAILABLE(macosx(10.13), ios(11.0));
 
 WK_CLASS_AVAILABLE(macosx(10.12.3), ios(10.3))

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm (223450 => 223451)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm	2017-10-17 00:15:06 UTC (rev 223450)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm	2017-10-17 00:30:24 UTC (rev 223451)
@@ -67,6 +67,9 @@
     if (allowedQuirks & _WKWebsiteAutoplayQuirkSynthesizedPauseEvents)
         quirks |= WebKit::WebsiteAutoplayQuirk::SynthesizedPauseEvents;
 
+    if (allowedQuirks & _WKWebsiteAutoplayQuirkArbitraryUserGestures)
+        quirks |= WebKit::WebsiteAutoplayQuirk::ArbitraryUserGestures;
+
     _websitePolicies->setAllowedAutoplayQuirks(quirks);
 }
 
@@ -81,6 +84,9 @@
     if (allowedQuirks.contains(WebKit::WebsiteAutoplayQuirk::SynthesizedPauseEvents))
         quirks |= _WKWebsiteAutoplayQuirkSynthesizedPauseEvents;
 
+    if (allowedQuirks.contains(WebKit::WebsiteAutoplayQuirk::ArbitraryUserGestures))
+        quirks |= _WKWebsiteAutoplayQuirkArbitraryUserGestures;
+
     return quirks;
 }
 

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp (223450 => 223451)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp	2017-10-17 00:15:06 UTC (rev 223450)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp	2017-10-17 00:30:24 UTC (rev 223451)
@@ -781,6 +781,9 @@
     if (allowedQuirks.contains(WebsiteAutoplayQuirk::SynthesizedPauseEvents))
         quirks |= AutoplayQuirk::SynthesizedPauseEvents;
 
+    if (allowedQuirks.contains(WebsiteAutoplayQuirk::ArbitraryUserGestures))
+        quirks |= AutoplayQuirk::ArbitraryUserGestures;
+
     documentLoader->setAllowedAutoplayQuirks(quirks);
 
     switch (websitePolicies.autoplayPolicy) {

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (223450 => 223451)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2017-10-17 00:15:06 UTC (rev 223450)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2017-10-17 00:30:24 UTC (rev 223451)
@@ -5698,6 +5698,9 @@
     if (allowedQuirks.contains(WebsiteAutoplayQuirk::SynthesizedPauseEvents))
         quirks |= AutoplayQuirk::SynthesizedPauseEvents;
 
+    if (allowedQuirks.contains(WebsiteAutoplayQuirk::ArbitraryUserGestures))
+        quirks |= AutoplayQuirk::ArbitraryUserGestures;
+
     documentLoader->setAllowedAutoplayQuirks(quirks);
 
     AutoplayPolicy autoplayPolicy = AutoplayPolicy::Default;

Modified: trunk/Tools/ChangeLog (223450 => 223451)


--- trunk/Tools/ChangeLog	2017-10-17 00:15:06 UTC (rev 223450)
+++ trunk/Tools/ChangeLog	2017-10-17 00:30:24 UTC (rev 223451)
@@ -1,3 +1,13 @@
+2017-10-12  Matt Rajca  <mra...@apple.com>
+
+        Add API support for quirk that lets an arbitrary click allow auto-play.
+        https://bugs.webkit.org/show_bug.cgi?id=178227
+
+        Reviewed by Alex Christensen.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm:
+        (TEST): Added API test.
+
 2017-10-16  Maureen Daum  <md...@apple.com>
 
         If an origin doesn't have databases in the Databases table we should still remove its information from disk in DatabaseTracker::deleteOrigin()

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm (223450 => 223451)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm	2017-10-17 00:15:06 UTC (rev 223450)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm	2017-10-17 00:30:24 UTC (rev 223451)
@@ -566,6 +566,39 @@
     runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPreventFromAutoplaying);
 }
 
+TEST(WebKit, WebsitePoliciesArbitraryUserGestureQuirk)
+{
+    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()];
+
+    WKRetainPtr<WKPreferencesRef> preferences(AdoptWK, WKPreferencesCreate());
+    WKPreferencesSetNeedsSiteSpecificQuirks(preferences.get(), true);
+    WKPageGroupSetPreferences(WKPageGetPageGroup([webView _pageForTesting]), preferences.get());
+
+    [delegate setAllowedAutoplayQuirksForURL:^_WKWebsiteAutoplayQuirk(NSURL *url)
+    {
+        return _WKWebsiteAutoplayQuirkArbitraryUserGestures;
+    }];
+    [delegate setAutoplayPolicyForURL:^(NSURL *)
+    {
+        return _WKWebsiteAutoplayPolicyDeny;
+    }];
+
+    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"autoplay-check" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+    [webView loadRequest:request];
+    [webView waitForMessage:@"did-not-play"];
+
+    const NSPoint clickPoint = NSMakePoint(760, 560);
+    [webView mouseDownAtPoint:clickPoint simulatePressure:NO];
+    [webView mouseUpAtPoint:clickPoint];
+
+    [webView stringByEvaluatingJavaScript:@"playVideo()"];
+    [webView waitForMessage:@"autoplayed"];
+}
+
 TEST(WebKit, WebsitePoliciesAutoplayQuirks)
 {
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to