Title: [213471] trunk
Revision
213471
Author
[email protected]
Date
2017-03-06 15:06:08 -0800 (Mon, 06 Mar 2017)

Log Message

Media: notify clients when the user never plays a media element that was prevented from auto-playing
https://bugs.webkit.org/show_bug.cgi?id=169150

Reviewed by Alex Christensen.

Source/WebCore:

Added API tests.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::mediaPlayerTimeChanged):
(WebCore::HTMLMediaElement::stopWithoutDestroyingMediaPlayer):
* page/AutoplayEvent.h:

Source/WebKit2:

* UIProcess/API/C/WKPageUIClient.h:

Tools:

* TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm:
(TEST): Added.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (213470 => 213471)


--- trunk/Source/WebCore/ChangeLog	2017-03-06 22:56:43 UTC (rev 213470)
+++ trunk/Source/WebCore/ChangeLog	2017-03-06 23:06:08 UTC (rev 213471)
@@ -1,3 +1,17 @@
+2017-03-03  Matt Rajca  <[email protected]>
+
+        Media: notify clients when the user never plays a media element that was prevented from auto-playing
+        https://bugs.webkit.org/show_bug.cgi?id=169150
+
+        Reviewed by Alex Christensen.
+
+        Added API tests.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::mediaPlayerTimeChanged):
+        (WebCore::HTMLMediaElement::stopWithoutDestroyingMediaPlayer):
+        * page/AutoplayEvent.h:
+
 2017-03-06  Alex Christensen  <[email protected]>
 
         Refactor ContentExtensionParser

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (213470 => 213471)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2017-03-06 22:56:43 UTC (rev 213470)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2017-03-06 23:06:08 UTC (rev 213471)
@@ -5189,9 +5189,17 @@
     setPausedInternal(true);
     m_mediaSession->clientWillPausePlayback();
 
-    if (m_playbackWithoutUserGesture == PlaybackWithoutUserGesture::Started) {
-        if (Page* page = document().page())
+    if (Page* page = document().page()) {
+        switch (m_playbackWithoutUserGesture) {
+        case PlaybackWithoutUserGesture::Started:
             page->chrome().client().handleAutoplayEvent(AutoplayEvent::DidEndMediaPlaybackWithoutUserInterference);
+            break;
+        case PlaybackWithoutUserGesture::Prevented:
+            page->chrome().client().handleAutoplayEvent(AutoplayEvent::UserNeverPlayedMediaPreventedFromPlaying);
+            break;
+        case PlaybackWithoutUserGesture::None:
+            break;
+        }
     }
     m_playbackWithoutUserGesture = PlaybackWithoutUserGesture::None;
 

Modified: trunk/Source/WebCore/page/AutoplayEvent.h (213470 => 213471)


--- trunk/Source/WebCore/page/AutoplayEvent.h	2017-03-06 22:56:43 UTC (rev 213470)
+++ trunk/Source/WebCore/page/AutoplayEvent.h	2017-03-06 23:06:08 UTC (rev 213471)
@@ -32,6 +32,7 @@
     DidPlayMediaPreventedFromPlaying,
     DidEndMediaPlaybackWithoutUserInterference,
     UserDidInterfereWithPlayback,
+    UserNeverPlayedMediaPreventedFromPlaying,
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebKit2/ChangeLog (213470 => 213471)


--- trunk/Source/WebKit2/ChangeLog	2017-03-06 22:56:43 UTC (rev 213470)
+++ trunk/Source/WebKit2/ChangeLog	2017-03-06 23:06:08 UTC (rev 213471)
@@ -1,3 +1,12 @@
+2017-03-03  Matt Rajca  <[email protected]>
+
+        Media: notify clients when the user never plays a media element that was prevented from auto-playing
+        https://bugs.webkit.org/show_bug.cgi?id=169150
+
+        Reviewed by Alex Christensen.
+
+        * UIProcess/API/C/WKPageUIClient.h:
+
 2017-03-06  Myles C. Maxfield  <[email protected]>
 
         Expand font-weight and font-stretch to take any number

Modified: trunk/Source/WebKit2/UIProcess/API/C/WKPageUIClient.h (213470 => 213471)


--- trunk/Source/WebKit2/UIProcess/API/C/WKPageUIClient.h	2017-03-06 22:56:43 UTC (rev 213470)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKPageUIClient.h	2017-03-06 23:06:08 UTC (rev 213471)
@@ -53,6 +53,7 @@
     kWKAutoplayEventDidPlayMediaPreventedFromAutoplaying,
     kWKAutoplayEventDidEndMediaPlaybackWithoutUserInterference,
     kWKAutoplayEventUserDidInterfereWithPlayback,
+    kWKAutoplayEventUserNeverPlayedMediaPreventedFromPlaying,
 };
 typedef uint32_t WKAutoplayEvent;
 

Modified: trunk/Tools/ChangeLog (213470 => 213471)


--- trunk/Tools/ChangeLog	2017-03-06 22:56:43 UTC (rev 213470)
+++ trunk/Tools/ChangeLog	2017-03-06 23:06:08 UTC (rev 213471)
@@ -1,3 +1,13 @@
+2017-03-03  Matt Rajca  <[email protected]>
+
+        Media: notify clients when the user never plays a media element that was prevented from auto-playing
+        https://bugs.webkit.org/show_bug.cgi?id=169150
+
+        Reviewed by Alex Christensen.
+
+        * TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm:
+        (TEST): Added.
+
 2017-03-06  Alex Christensen  <[email protected]>
 
         Fix URLs relative to file URLs with paths beginning with Windows drive letters

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm (213470 => 213471)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm	2017-03-06 22:56:43 UTC (rev 213470)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm	2017-03-06 23:06:08 UTC (rev 213471)
@@ -401,6 +401,35 @@
     [webView mouseUpAtPoint:playButtonClickPoint];
     runUntilReceivesAutoplayEvent(kWKAutoplayEventUserDidInterfereWithPlayback);
 }
+
+TEST(WebKit2, WebsitePoliciesUserNeverPlayedMediaPreventedFromPlaying)
+{
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 336, 276) configuration:configuration.get()]);
+
+    auto delegate = adoptNS([[AutoplayPoliciesDelegate alloc] init]);
+    [delegate setAutoplayPolicyForURL:^(NSURL *) {
+        return _WKWebsiteAutoplayPolicyDeny;
+    }];
+    [webView setNavigationDelegate:delegate.get()];
+
+    WKPageUIClientV9 uiClient;
+    memset(&uiClient, 0, sizeof(uiClient));
+
+    uiClient.base.version = 9;
+    uiClient.handleAutoplayEvent = handleAutoplayEvent;
+
+    WKPageSetPageUIClient([webView _pageForTesting], &uiClient.base);
+
+    receivedAutoplayEvent = std::nullopt;
+    NSURLRequest *jsPlayRequest = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"js-play-with-controls" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+    [webView loadRequest:jsPlayRequest];
+    [webView waitForMessage:@"loaded"];
+    runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPreventFromAutoplaying);
+
+    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];
+    runUntilReceivesAutoplayEvent(kWKAutoplayEventUserNeverPlayedMediaPreventedFromPlaying);
+}
 #endif
 
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to