Media: notify clients when the user never plays a media element that was prevented...
authormrajca@apple.com <mrajca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 6 Mar 2017 23:06:08 +0000 (23:06 +0000)
committermrajca@apple.com <mrajca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 6 Mar 2017 23:06:08 +0000 (23:06 +0000)
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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213471 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/page/AutoplayEvent.h
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/C/WKPageUIClient.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm

index ad679e7..a73b4f3 100644 (file)
@@ -1,3 +1,17 @@
+2017-03-03  Matt Rajca  <mrajca@apple.com>
+
+        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  <achristensen@webkit.org>
 
         Refactor ContentExtensionParser
index be9b2b4..e62f147 100644 (file)
@@ -5189,9 +5189,17 @@ void HTMLMediaElement::stopWithoutDestroyingMediaPlayer()
     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;
 
index b5569b7..866f437 100644 (file)
@@ -32,6 +32,7 @@ enum class AutoplayEvent {
     DidPlayMediaPreventedFromPlaying,
     DidEndMediaPlaybackWithoutUserInterference,
     UserDidInterfereWithPlayback,
+    UserNeverPlayedMediaPreventedFromPlaying,
 };
 
 } // namespace WebCore
index 1f8e471..9b86313 100644 (file)
@@ -1,3 +1,12 @@
+2017-03-03  Matt Rajca  <mrajca@apple.com>
+
+        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  <mmaxfield@apple.com>
 
         Expand font-weight and font-stretch to take any number
index 8dcfb98..23c9988 100644 (file)
@@ -53,6 +53,7 @@ enum {
     kWKAutoplayEventDidPlayMediaPreventedFromAutoplaying,
     kWKAutoplayEventDidEndMediaPlaybackWithoutUserInterference,
     kWKAutoplayEventUserDidInterfereWithPlayback,
+    kWKAutoplayEventUserNeverPlayedMediaPreventedFromPlaying,
 };
 typedef uint32_t WKAutoplayEvent;
 
index 9c3442b..a3f4f0f 100644 (file)
@@ -1,3 +1,13 @@
+2017-03-03  Matt Rajca  <mrajca@apple.com>
+
+        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  <achristensen@webkit.org>
 
         Fix URLs relative to file URLs with paths beginning with Windows drive letters
index eca9b7a..9167511 100644 (file)
@@ -401,6 +401,35 @@ TEST(WebKit2, WebsitePoliciesUserInterferenceWithPlaying)
     [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