Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.

Canonical link: https://commits.webkit.org/186235@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213471 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Matt Rajca committed Mar 6, 2017
1 parent f86c345 commit 5153b6c
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 2 deletions.
14 changes: 14 additions & 0 deletions Source/WebCore/ChangeLog
@@ -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
Expand Down
12 changes: 10 additions & 2 deletions Source/WebCore/html/HTMLMediaElement.cpp
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/page/AutoplayEvent.h
Expand Up @@ -32,6 +32,7 @@ enum class AutoplayEvent {
DidPlayMediaPreventedFromPlaying,
DidEndMediaPlaybackWithoutUserInterference,
UserDidInterfereWithPlayback,
UserNeverPlayedMediaPreventedFromPlaying,
};

} // namespace WebCore
9 changes: 9 additions & 0 deletions Source/WebKit2/ChangeLog
@@ -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
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit2/UIProcess/API/C/WKPageUIClient.h
Expand Up @@ -53,6 +53,7 @@ enum {
kWKAutoplayEventDidPlayMediaPreventedFromAutoplaying,
kWKAutoplayEventDidEndMediaPlaybackWithoutUserInterference,
kWKAutoplayEventUserDidInterfereWithPlayback,
kWKAutoplayEventUserNeverPlayedMediaPreventedFromPlaying,
};
typedef uint32_t WKAutoplayEvent;

Expand Down
10 changes: 10 additions & 0 deletions Tools/ChangeLog
@@ -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
Expand Down
29 changes: 29 additions & 0 deletions Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm
Expand Up @@ -401,6 +401,35 @@ static void runUntilReceivesAutoplayEvent(WKAutoplayEvent event)
[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

0 comments on commit 5153b6c

Please sign in to comment.