Title: [213246] trunk
Revision
213246
Author
mra...@apple.com
Date
2017-03-01 14:43:04 -0800 (Wed, 01 Mar 2017)

Log Message

Media: notify clients when autoplayed media is muted
https://bugs.webkit.org/show_bug.cgi?id=168987

Reviewed by Alex Christensen.

Source/WebCore:

Added API tests.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::setMuted):
(WebCore::HTMLMediaElement::pageMutedStateDidChange):
* page/AutoplayEvent.h:

Source/WebKit2:

* UIProcess/API/C/WKPageUIClient.h:

Tools:

* TestWebKitAPI/Tests/WebKit2/js-play-with-controls.html:
* TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm:
(TEST): Added.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (213245 => 213246)


--- trunk/Source/WebCore/ChangeLog	2017-03-01 22:39:31 UTC (rev 213245)
+++ trunk/Source/WebCore/ChangeLog	2017-03-01 22:43:04 UTC (rev 213246)
@@ -1,3 +1,17 @@
+2017-02-28  Matt Rajca  <mra...@apple.com>
+
+        Media: notify clients when autoplayed media is muted
+        https://bugs.webkit.org/show_bug.cgi?id=168987
+
+        Reviewed by Alex Christensen.
+
+        Added API tests.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::setMuted):
+        (WebCore::HTMLMediaElement::pageMutedStateDidChange):
+        * page/AutoplayEvent.h:
+
 2017-03-01  Commit Queue  <commit-qu...@webkit.org>
 
         Unreviewed, rolling out r213226.

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (213245 => 213246)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2017-03-01 22:39:31 UTC (rev 213245)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2017-03-01 22:43:04 UTC (rev 213246)
@@ -3350,9 +3350,19 @@
         m_muted = muted;
         m_explicitlyMuted = true;
 
-        if (ScriptController::processingUserGestureForMedia())
+        if (ScriptController::processingUserGestureForMedia()) {
             removeBehaviorsRestrictionsAfterFirstUserGesture(MediaElementSession::AllRestrictions & ~MediaElementSession::RequireUserGestureToControlControlsManager);
 
+            if (hasAudio() && m_muted) {
+                if (m_playbackWithoutUserGesture == PlaybackWithoutUserGesture::Started) {
+                    if (Page* page = document().page())
+                        page->chrome().client().handleAutoplayEvent(AutoplayEvent::UserDidInterfereWithPlayback);
+                }
+
+                m_playbackWithoutUserGesture = PlaybackWithoutUserGesture::None;
+            }
+        }
+
         // Avoid recursion when the player reports volume changes.
         if (!processingMediaPlayerCallback()) {
             if (m_player) {
@@ -7088,6 +7098,17 @@
 void HTMLMediaElement::pageMutedStateDidChange()
 {
     updateVolume();
+
+    if (Page* page = document().page()) {
+        if (hasAudio() && !muted() && page->isAudioMuted()) {
+            if (m_playbackWithoutUserGesture == PlaybackWithoutUserGesture::Started) {
+                if (Page* page = document().page())
+                    page->chrome().client().handleAutoplayEvent(AutoplayEvent::UserDidInterfereWithPlayback);
+            }
+
+            m_playbackWithoutUserGesture = PlaybackWithoutUserGesture::None;
+        }
+    }
 }
 
 bool HTMLMediaElement::effectiveMuted() const

Modified: trunk/Source/WebCore/page/AutoplayEvent.h (213245 => 213246)


--- trunk/Source/WebCore/page/AutoplayEvent.h	2017-03-01 22:39:31 UTC (rev 213245)
+++ trunk/Source/WebCore/page/AutoplayEvent.h	2017-03-01 22:43:04 UTC (rev 213246)
@@ -31,6 +31,7 @@
     DidPreventMediaFromPlaying,
     DidPlayMediaPreventedFromPlaying,
     DidEndMediaPlaybackWithoutUserInterference,
+    UserDidInterfereWithPlayback,
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebKit2/ChangeLog (213245 => 213246)


--- trunk/Source/WebKit2/ChangeLog	2017-03-01 22:39:31 UTC (rev 213245)
+++ trunk/Source/WebKit2/ChangeLog	2017-03-01 22:43:04 UTC (rev 213246)
@@ -1,3 +1,12 @@
+2017-02-28  Matt Rajca  <mra...@apple.com>
+
+        Media: notify clients when autoplayed media is muted
+        https://bugs.webkit.org/show_bug.cgi?id=168987
+
+        Reviewed by Alex Christensen.
+
+        * UIProcess/API/C/WKPageUIClient.h:
+
 2017-03-01  Brady Eidson  <beid...@apple.com>
 
         Add SPI to create WebsiteDataStore objects pointing to custom paths.

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


--- trunk/Source/WebKit2/UIProcess/API/C/WKPageUIClient.h	2017-03-01 22:39:31 UTC (rev 213245)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKPageUIClient.h	2017-03-01 22:43:04 UTC (rev 213246)
@@ -52,6 +52,7 @@
     kWKAutoplayEventDidPreventFromAutoplaying,
     kWKAutoplayEventDidPlayMediaPreventedFromAutoplaying,
     kWKAutoplayEventDidEndMediaPlaybackWithoutUserInterference,
+    kWKAutoplayEventUserDidInterfereWithPlayback,
 };
 typedef uint32_t WKAutoplayEvent;
 

Modified: trunk/Tools/ChangeLog (213245 => 213246)


--- trunk/Tools/ChangeLog	2017-03-01 22:39:31 UTC (rev 213245)
+++ trunk/Tools/ChangeLog	2017-03-01 22:43:04 UTC (rev 213246)
@@ -1,3 +1,14 @@
+2017-02-28  Matt Rajca  <mra...@apple.com>
+
+        Media: notify clients when autoplayed media is muted
+        https://bugs.webkit.org/show_bug.cgi?id=168987
+
+        Reviewed by Alex Christensen.
+
+        * TestWebKitAPI/Tests/WebKit2/js-play-with-controls.html:
+        * TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm:
+        (TEST): Added.
+
 2017-03-01  Brady Eidson  <beid...@apple.com>
 
         Add SPI to create WebsiteDataStore objects pointing to custom paths.

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2/js-play-with-controls.html (213245 => 213246)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/js-play-with-controls.html	2017-03-01 22:39:31 UTC (rev 213245)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/js-play-with-controls.html	2017-03-01 22:43:04 UTC (rev 213246)
@@ -12,6 +12,10 @@
                 document.getElementById("video").play();
             }
 
+            function mute() {
+                document.getElementById("video").muted = true;
+            }
+
             function beganPlaying() {
                 try {
                     window.webkit.messageHandlers.testHandler.postMessage("playing");
@@ -27,6 +31,7 @@
     </head>
     <body _onload_="pageLoaded()">
         <button _onclick_="play()">Play</button>
+        <button _onclick_="mute()">Mute</button>
         <video id="video" _onplaying_=beganPlaying() _onended_=endedPlaying() src="" />
     </body>
 </html>

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm (213245 => 213246)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm	2017-03-01 22:39:31 UTC (rev 213245)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm	2017-03-01 22:43:04 UTC (rev 213246)
@@ -27,6 +27,7 @@
 
 #import "PlatformUtilities.h"
 #import "TestWKWebView.h"
+#import <WebKit/WKPagePrivate.h>
 #import <WebKit/WKUserContentControllerPrivate.h>
 #import <WebKit/WKWebViewPrivate.h>
 #import <WebKit/_WKUserContentExtensionStorePrivate.h>
@@ -351,6 +352,45 @@
     [webView waitForMessage:@"ended"];
     runUntilReceivesAutoplayEvent(kWKAutoplayEventDidEndMediaPlaybackWithoutUserInterference);
 }
+
+TEST(WebKit2, WebsitePoliciesUserInterferenceWithPlaying)
+{
+    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 _WKWebsiteAutoplayPolicyAllow;
+    }];
+    [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:@"playing"];
+    ASSERT_TRUE(receivedAutoplayEvent == std::nullopt);
+
+    WKPageSetMuted([webView _pageForTesting], kWKMediaAudioMuted);
+    runUntilReceivesAutoplayEvent(kWKAutoplayEventUserDidInterfereWithPlayback);
+
+    receivedAutoplayEvent = std::nullopt;
+    [webView loadRequest:jsPlayRequest];
+    [webView waitForMessage:@"playing"];
+    ASSERT_TRUE(receivedAutoplayEvent == std::nullopt);
+
+    const NSPoint muteButtonClickPoint = NSMakePoint(80, 256);
+    [webView mouseDownAtPoint:muteButtonClickPoint simulatePressure:NO];
+    [webView mouseUpAtPoint:muteButtonClickPoint];
+    runUntilReceivesAutoplayEvent(kWKAutoplayEventUserDidInterfereWithPlayback);
+}
 #endif
 
 #endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to