Diff
Modified: trunk/Source/WebCore/ChangeLog (219105 => 219106)
--- trunk/Source/WebCore/ChangeLog 2017-07-03 23:12:40 UTC (rev 219105)
+++ trunk/Source/WebCore/ChangeLog 2017-07-03 23:19:31 UTC (rev 219106)
@@ -1,3 +1,22 @@
+2017-07-03 Matt Rajca <mra...@apple.com>
+
+ Add/remove appropriate media element behavior restrictions when updateWebsitePolicies is called
+ https://bugs.webkit.org/show_bug.cgi?id=174103
+
+ Reviewed by Alex Christensen.
+
+ Test: Added API test.
+
+ Added support for updating rate change behavior restrictions on media elements that have already
+ been created.
+
+ * html/HTMLMediaElement.cpp:
+ (WebCore::HTMLMediaElement::updateRateChangeRestrictions):
+ * html/HTMLMediaElement.h:
+ * page/Page.cpp:
+ (WebCore::Page::updateMediaElementRateChangeRestrictions):
+ * page/Page.h:
+
2017-07-03 Matt Lewis <jlew...@apple.com>
Unreviewed, rolling out r219103.
Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (219105 => 219106)
--- trunk/Source/WebCore/html/HTMLMediaElement.cpp 2017-07-03 23:12:40 UTC (rev 219105)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp 2017-07-03 23:19:31 UTC (rev 219106)
@@ -6693,6 +6693,24 @@
m_mediaSession->removeBehaviorRestriction(restrictionsToRemove);
}
+void HTMLMediaElement::updateRateChangeRestrictions()
+{
+ const auto& document = this->document();
+ if (!document.ownerElement() && document.isMediaDocument())
+ return;
+
+ const auto& topDocument = document.topDocument();
+ if (topDocument.videoPlaybackRequiresUserGesture())
+ m_mediaSession->addBehaviorRestriction(MediaElementSession::RequireUserGestureForVideoRateChange);
+ else
+ m_mediaSession->removeBehaviorRestriction(MediaElementSession::RequireUserGestureForVideoRateChange);
+
+ if (topDocument.audioPlaybackRequiresUserGesture())
+ m_mediaSession->addBehaviorRestriction(MediaElementSession::RequireUserGestureForAudioRateChange);
+ else
+ m_mediaSession->removeBehaviorRestriction(MediaElementSession::RequireUserGestureForAudioRateChange);
+}
+
#if ENABLE(MEDIA_SOURCE)
RefPtr<VideoPlaybackQuality> HTMLMediaElement::getVideoPlaybackQuality()
{
Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (219105 => 219106)
--- trunk/Source/WebCore/html/HTMLMediaElement.h 2017-07-03 23:12:40 UTC (rev 219105)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h 2017-07-03 23:19:31 UTC (rev 219106)
@@ -512,6 +512,7 @@
bool isTemporarilyAllowingInlinePlaybackAfterFullscreen() const {return m_temporarilyAllowingInlinePlaybackAfterFullscreen; }
void isVisibleInViewportChanged();
+ void updateRateChangeRestrictions();
WEBCORE_EXPORT const MediaResourceLoader* lastMediaResourceLoaderForTesting() const;
Modified: trunk/Source/WebCore/page/Page.cpp (219105 => 219106)
--- trunk/Source/WebCore/page/Page.cpp 2017-07-03 23:12:40 UTC (rev 219105)
+++ trunk/Source/WebCore/page/Page.cpp 2017-07-03 23:19:31 UTC (rev 219106)
@@ -53,6 +53,7 @@
#include "FrameTree.h"
#include "FrameView.h"
#include "HTMLElement.h"
+#include "HTMLMediaElement.h"
#include "HistoryController.h"
#include "HistoryItem.h"
#include "InspectorController.h"
@@ -992,6 +993,12 @@
#endif
}
+void Page::updateMediaElementRateChangeRestrictions()
+{
+ for (auto* mediaElement : HTMLMediaElement::allMediaElements())
+ mediaElement->updateRateChangeRestrictions();
+}
+
void Page::didStartProvisionalLoad()
{
if (m_performanceMonitor)
Modified: trunk/Source/WebCore/page/Page.h (219105 => 219106)
--- trunk/Source/WebCore/page/Page.h 2017-07-03 23:12:40 UTC (rev 219105)
+++ trunk/Source/WebCore/page/Page.h 2017-07-03 23:19:31 UTC (rev 219106)
@@ -311,6 +311,8 @@
UserInterfaceLayoutDirection userInterfaceLayoutDirection() const { return m_userInterfaceLayoutDirection; }
WEBCORE_EXPORT void setUserInterfaceLayoutDirection(UserInterfaceLayoutDirection);
+ WEBCORE_EXPORT void updateMediaElementRateChangeRestrictions();
+
void didStartProvisionalLoad();
void didFinishLoad(); // Called when the load has been committed in the main frame.
Modified: trunk/Source/WebKit2/ChangeLog (219105 => 219106)
--- trunk/Source/WebKit2/ChangeLog 2017-07-03 23:12:40 UTC (rev 219105)
+++ trunk/Source/WebKit2/ChangeLog 2017-07-03 23:19:31 UTC (rev 219106)
@@ -1,3 +1,30 @@
+2017-07-03 Matt Rajca <mra...@apple.com>
+
+ Add/remove appropriate media element behavior restrictions when updateWebsitePolicies is called
+ https://bugs.webkit.org/show_bug.cgi?id=174103
+
+ Reviewed by Alex Christensen.
+
+ Currently, when -[WKWebView evaluateJavaScript:completionHandler:] is invoked, we end up simulating
+ a user gesture unconditionally. This is not desireable for some tests, so I added a private variant
+ of this method that takes a boolean that is ultimately passed to `executeScript` for the
+ `forceUserGesture` parameter (instead of unconditionally passing `true`).
+
+ * UIProcess/API/C/WKPage.cpp:
+ (WKPageRunJavaScriptInMainFrame):
+ * UIProcess/API/Cocoa/WKWebView.mm:
+ (-[WKWebView evaluateJavaScript:completionHandler:]):
+ (-[WKWebView _evaluateJavaScript:forceUserGesture:completionHandler:]):
+ * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+ * UIProcess/WebPageProxy.cpp:
+ (WebKit::WebPageProxy::runJavaScriptInMainFrame):
+ * UIProcess/WebPageProxy.h:
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::runJavaScriptInMainFrame):
+ (WebKit::WebPage::updateWebsitePolicies): Update behavior restrictions on any existing media elements.
+ * WebProcess/WebPage/WebPage.h:
+ * WebProcess/WebPage/WebPage.messages.in:
+
2017-07-03 Matt Lewis <jlew...@apple.com>
Unreviewed, rolling out r219103.
Modified: trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp (219105 => 219106)
--- trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp 2017-07-03 23:12:40 UTC (rev 219105)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp 2017-07-03 23:19:31 UTC (rev 219106)
@@ -2339,7 +2339,7 @@
void WKPageRunJavaScriptInMainFrame(WKPageRef pageRef, WKStringRef scriptRef, void* context, WKPageRunJavaScriptFunction callback)
{
- toImpl(pageRef)->runJavaScriptInMainFrame(toImpl(scriptRef)->string(), [context, callback](API::SerializedScriptValue* returnValue, bool, const WebCore::ExceptionDetails&, CallbackBase::Error error) {
+ toImpl(pageRef)->runJavaScriptInMainFrame(toImpl(scriptRef)->string(), true, [context, callback](API::SerializedScriptValue* returnValue, bool, const WebCore::ExceptionDetails&, CallbackBase::Error error) {
callback(toAPI(returnValue), (error != CallbackBase::Error::None) ? toAPI(API::Error::create().ptr()) : 0, context);
});
}
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (219105 => 219106)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm 2017-07-03 23:12:40 UTC (rev 219105)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm 2017-07-03 23:19:31 UTC (rev 219106)
@@ -899,9 +899,14 @@
- (void)evaluateJavaScript:(NSString *)_javascript_String completionHandler:(void (^)(id, NSError *))completionHandler
{
+ [self _evaluateJavaScript:_javascript_String forceUserGesture:YES completionHandler:completionHandler];
+}
+
+- (void)_evaluateJavaScript:(NSString *)_javascript_String forceUserGesture:(BOOL)forceUserGesture completionHandler:(void (^)(id, NSError *))completionHandler
+{
auto handler = adoptNS([completionHandler copy]);
- _page->runJavaScriptInMainFrame(_javascript_String, [handler](API::SerializedScriptValue* serializedScriptValue, bool hadException, const WebCore::ExceptionDetails& details, WebKit::ScriptValueCallback::Error errorCode) {
+ _page->runJavaScriptInMainFrame(_javascript_String, forceUserGesture, [handler](API::SerializedScriptValue* serializedScriptValue, bool hadException, const WebCore::ExceptionDetails& details, WebKit::ScriptValueCallback::Error errorCode) {
if (!handler)
return;
@@ -3950,6 +3955,11 @@
_page->close();
}
+- (void)_evaluateJavaScriptWithoutUserGesture:(NSString *)_javascript_String completionHandler:(void (^)(id, NSError *))completionHandler
+{
+ [self _evaluateJavaScript:_javascript_String forceUserGesture:NO completionHandler:completionHandler];
+}
+
- (void)_updateWebsitePolicies:(_WKWebsitePolicies *)websitePolicies
{
_page->updateWebsitePolicies(websitePolicies->_websitePolicies->websitePolicies());
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h (219105 => 219106)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h 2017-07-03 23:12:40 UTC (rev 219105)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h 2017-07-03 23:19:31 UTC (rev 219106)
@@ -141,6 +141,8 @@
- (void)_updateWebsitePolicies:(_WKWebsitePolicies *)websitePolicies WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_evaluateJavaScriptWithoutUserGesture:(NSString *)_javascript_String completionHandler:(void (^)(id, NSError *))completionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+
@property (nonatomic, setter=_setLayoutMode:) _WKLayoutMode _layoutMode;
// For use with _layoutMode = _WKLayoutModeFixedSize:
@property (nonatomic, setter=_setFixedLayoutSize:) CGSize _fixedLayoutSize;
Modified: trunk/Source/WebKit2/UIProcess/API/glib/WebKitWebView.cpp (219105 => 219106)
--- trunk/Source/WebKit2/UIProcess/API/glib/WebKitWebView.cpp 2017-07-03 23:12:40 UTC (rev 219105)
+++ trunk/Source/WebKit2/UIProcess/API/glib/WebKitWebView.cpp 2017-07-03 23:19:31 UTC (rev 219106)
@@ -3144,7 +3144,7 @@
g_return_if_fail(script);
GTask* task = g_task_new(webView, cancellable, callback, userData);
- getPage(webView).runJavaScriptInMainFrame(String::fromUTF8(script), [task](API::SerializedScriptValue* serializedScriptValue, bool, const WebCore::ExceptionDetails& exceptionDetails, WebKit::CallbackBase::Error) {
+ getPage(webView).runJavaScriptInMainFrame(String::fromUTF8(script), true, [task](API::SerializedScriptValue* serializedScriptValue, bool, const WebCore::ExceptionDetails& exceptionDetails, WebKit::CallbackBase::Error) {
webkitWebViewRunJavaScriptCallback(serializedScriptValue, exceptionDetails, adoptGRef(task).get());
});
}
@@ -3234,7 +3234,7 @@
WebKitWebView* webView = WEBKIT_WEB_VIEW(g_task_get_source_object(task.get()));
gpointer outputStreamData = g_memory_output_stream_get_data(G_MEMORY_OUTPUT_STREAM(object));
- getPage(webView).runJavaScriptInMainFrame(String::fromUTF8(reinterpret_cast<const gchar*>(outputStreamData)),
+ getPage(webView).runJavaScriptInMainFrame(String::fromUTF8(reinterpret_cast<const gchar*>(outputStreamData)), true,
[task](API::SerializedScriptValue* serializedScriptValue, bool, const WebCore::ExceptionDetails& exceptionDetails, WebKit::CallbackBase::Error) {
webkitWebViewRunJavaScriptCallback(serializedScriptValue, exceptionDetails, task.get());
});
Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (219105 => 219106)
--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp 2017-07-03 23:12:40 UTC (rev 219105)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp 2017-07-03 23:19:31 UTC (rev 219106)
@@ -2833,7 +2833,7 @@
m_process->send(Messages::WebPage::CountStringMatches(string, options, maxMatchCount), m_pageID);
}
-void WebPageProxy::runJavaScriptInMainFrame(const String& script, WTF::Function<void (API::SerializedScriptValue*, bool hadException, const ExceptionDetails&, CallbackBase::Error)>&& callbackFunction)
+void WebPageProxy::runJavaScriptInMainFrame(const String& script, bool forceUserGesture, WTF::Function<void (API::SerializedScriptValue*, bool hadException, const ExceptionDetails&, CallbackBase::Error)>&& callbackFunction)
{
if (!isValid()) {
callbackFunction(nullptr, false, { }, CallbackBase::Error::Unknown);
@@ -2841,7 +2841,7 @@
}
auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivityToken());
- m_process->send(Messages::WebPage::RunJavaScriptInMainFrame(script, callbackID), m_pageID);
+ m_process->send(Messages::WebPage::RunJavaScriptInMainFrame(script, forceUserGesture, callbackID), m_pageID);
}
void WebPageProxy::getRenderTreeExternalRepresentation(WTF::Function<void (const String&, CallbackBase::Error)>&& callbackFunction)
Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (219105 => 219106)
--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h 2017-07-03 23:12:40 UTC (rev 219105)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h 2017-07-03 23:19:31 UTC (rev 219106)
@@ -802,7 +802,7 @@
void getSelectionAsWebArchiveData(Function<void (API::Data*, CallbackBase::Error)>&&);
void getSourceForFrame(WebFrameProxy*, WTF::Function<void (const String&, CallbackBase::Error)>&&);
void getWebArchiveOfFrame(WebFrameProxy*, Function<void (API::Data*, CallbackBase::Error)>&&);
- void runJavaScriptInMainFrame(const String&, WTF::Function<void (API::SerializedScriptValue*, bool hadException, const WebCore::ExceptionDetails&, CallbackBase::Error)>&& callbackFunction);
+ void runJavaScriptInMainFrame(const String&, bool, WTF::Function<void (API::SerializedScriptValue*, bool hadException, const WebCore::ExceptionDetails&, CallbackBase::Error)>&& callbackFunction);
void forceRepaint(RefPtr<VoidCallback>&&);
float headerHeight(WebFrameProxy*);
Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (219105 => 219106)
--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp 2017-07-03 23:12:40 UTC (rev 219105)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp 2017-07-03 23:19:31 UTC (rev 219106)
@@ -2835,7 +2835,7 @@
return static_cast<KeyboardUIMode>((fullKeyboardAccessEnabled ? KeyboardAccessFull : KeyboardAccessDefault) | (m_tabToLinks ? KeyboardAccessTabsToLinks : 0));
}
-void WebPage::runJavaScriptInMainFrame(const String& script, CallbackID callbackID)
+void WebPage::runJavaScriptInMainFrame(const String& script, bool forceUserGesture, CallbackID callbackID)
{
// NOTE: We need to be careful when running scripts that the objects we depend on don't
// disappear during script execution.
@@ -2844,7 +2844,7 @@
JSLockHolder lock(commonVM());
bool hadException = true;
ExceptionDetails details;
- if (JSValue resultValue = m_mainFrame->coreFrame()->script().executeScript(script, true, &details)) {
+ if (JSValue resultValue = m_mainFrame->coreFrame()->script().executeScript(script, forceUserGesture, &details)) {
hadException = false;
serializedResultValue = SerializedScriptValue::create(m_mainFrame->jsContext(),
toRef(m_mainFrame->coreFrame()->script().globalObject(mainThreadNormalWorld())->globalExec(), resultValue), nullptr);
@@ -5615,20 +5615,26 @@
documentLoader->setAllowedAutoplayQuirks(quirks);
+ AutoplayPolicy autoplayPolicy = AutoplayPolicy::Default;
switch (websitePolicies.autoplayPolicy) {
case WebsiteAutoplayPolicy::Default:
- documentLoader->setAutoplayPolicy(AutoplayPolicy::Default);
break;
case WebsiteAutoplayPolicy::Allow:
- documentLoader->setAutoplayPolicy(AutoplayPolicy::Allow);
+ autoplayPolicy = AutoplayPolicy::Allow;
break;
case WebsiteAutoplayPolicy::AllowWithoutSound:
- documentLoader->setAutoplayPolicy(AutoplayPolicy::AllowWithoutSound);
+ autoplayPolicy = AutoplayPolicy::AllowWithoutSound;
break;
case WebsiteAutoplayPolicy::Deny:
- documentLoader->setAutoplayPolicy(AutoplayPolicy::Deny);
+ autoplayPolicy = AutoplayPolicy::Deny;
break;
}
+
+ if (documentLoader->autoplayPolicy() == autoplayPolicy)
+ return;
+
+ documentLoader->setAutoplayPolicy(autoplayPolicy);
+ m_page->updateMediaElementRateChangeRestrictions();
}
unsigned WebPage::extendIncrementalRenderingSuppression()
Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (219105 => 219106)
--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h 2017-07-03 23:12:40 UTC (rev 219105)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h 2017-07-03 23:19:31 UTC (rev 219106)
@@ -1117,7 +1117,7 @@
void getSelectionAsWebArchiveData(CallbackID);
void getSourceForFrame(uint64_t frameID, CallbackID);
void getWebArchiveOfFrame(uint64_t frameID, CallbackID);
- void runJavaScriptInMainFrame(const String&, CallbackID);
+ void runJavaScriptInMainFrame(const String&, bool forceUserGesture, CallbackID);
void forceRepaint(CallbackID);
void takeSnapshot(WebCore::IntRect snapshotRect, WebCore::IntSize bitmapSize, uint32_t options, CallbackID);
Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (219105 => 219106)
--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in 2017-07-03 23:12:40 UTC (rev 219105)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in 2017-07-03 23:19:31 UTC (rev 219106)
@@ -167,7 +167,7 @@
GetSelectionAsWebArchiveData(WebKit::CallbackID callbackID)
GetSourceForFrame(uint64_t frameID, WebKit::CallbackID callbackID)
GetWebArchiveOfFrame(uint64_t frameID, WebKit::CallbackID callbackID)
- RunJavaScriptInMainFrame(String script, WebKit::CallbackID callbackID)
+ RunJavaScriptInMainFrame(String script, bool forceUserGesture, WebKit::CallbackID callbackID)
ForceRepaint(WebKit::CallbackID callbackID)
#if PLATFORM(COCOA)
Modified: trunk/Tools/ChangeLog (219105 => 219106)
--- trunk/Tools/ChangeLog 2017-07-03 23:12:40 UTC (rev 219105)
+++ trunk/Tools/ChangeLog 2017-07-03 23:19:31 UTC (rev 219106)
@@ -1,3 +1,19 @@
+2017-07-03 Matt Rajca <mra...@apple.com>
+
+ Add/remove appropriate media element behavior restrictions when updateWebsitePolicies is called
+ https://bugs.webkit.org/show_bug.cgi?id=174103
+
+ Reviewed by Alex Christensen.
+
+ Added an API test.
+
+ * TestWebKitAPI/Tests/WebKit2/autoplay-check.html: Expose a pause method.
+ * TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm:
+ (TEST): Added test.
+ * TestWebKitAPI/cocoa/TestWKWebView.h:
+ * TestWebKitAPI/cocoa/TestWKWebView.mm:
+ (-[TestWKWebView stringByEvaluatingJavaScript:]): Don't simulate a user gesture when invoking the script.
+
2017-07-03 Matt Lewis <jlew...@apple.com>
Unreviewed, rolling out r219103.
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2/autoplay-check.html (219105 => 219106)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/autoplay-check.html 2017-07-03 23:12:40 UTC (rev 219105)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/autoplay-check.html 2017-07-03 23:19:31 UTC (rev 219106)
@@ -13,6 +13,10 @@
});
}
+ function pauseVideo() {
+ document.getElementById("video").pause();
+ }
+
function videoDidPause() {
try {
window.webkit.messageHandlers.testHandler.postMessage("on-pause");
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm (219105 => 219106)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm 2017-07-03 23:12:40 UTC (rev 219105)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm 2017-07-03 23:19:31 UTC (rev 219106)
@@ -552,6 +552,50 @@
[webView waitForMessage:@"autoplayed"];
}
+TEST(WebKit2, WebsitePoliciesUpdates)
+{
+ auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+ WKPageUIClientV9 uiClient;
+ memset(&uiClient, 0, sizeof(uiClient));
+
+ uiClient.base.version = 9;
+ uiClient.handleAutoplayEvent = handleAutoplayEvent;
+
+ WKPageSetPageUIClient([webView _pageForTesting], &uiClient.base);
+
+ auto delegate = adoptNS([[AutoplayPoliciesDelegate alloc] init]);
+ [webView setNavigationDelegate:delegate.get()];
+
+ NSURLRequest *requestWithAudio = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"autoplay-check" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+
+ [delegate setAutoplayPolicyForURL:^(NSURL *) {
+ return _WKWebsiteAutoplayPolicyDeny;
+ }];
+ [webView loadRequest:requestWithAudio];
+ [webView waitForMessage:@"did-not-play"];
+
+ _WKWebsitePolicies *policies = [[[_WKWebsitePolicies alloc] init] autorelease];
+ policies.autoplayPolicy = _WKWebsiteAutoplayPolicyAllow;
+ [webView _updateWebsitePolicies:policies];
+
+ // Now that we updated our policies, a script should be able to autoplay media.
+ [webView stringByEvaluatingJavaScript:@"playVideo()"];
+ [webView waitForMessage:@"autoplayed"];
+
+ [webView stringByEvaluatingJavaScript:@"pauseVideo()"];
+
+ policies = [[[_WKWebsitePolicies alloc] init] autorelease];
+ policies.autoplayPolicy = _WKWebsiteAutoplayPolicyDeny;
+ [webView _updateWebsitePolicies:policies];
+
+ // A script should no longer be able to autoplay media.
+ receivedAutoplayEvent = std::nullopt;
+ [webView stringByEvaluatingJavaScript:@"playVideo()"];
+ runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPreventFromAutoplaying);
+}
+
TEST(WebKit2, WebsitePoliciesAutoplayQuirks)
{
auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
@@ -585,7 +629,7 @@
if ([url.lastPathComponent isEqualToString:@"autoplay-check-frame.html"])
return _WKWebsiteAutoplayQuirkInheritedUserGestures;
- return _WKWebsiteAutoplayQuirkSynthesizedPauseEvents;
+ return _WKWebsiteAutoplayQuirkSynthesizedPauseEvents | _WKWebsiteAutoplayQuirkInheritedUserGestures;
}];
[delegate setAutoplayPolicyForURL:^(NSURL *) {
return _WKWebsiteAutoplayPolicyDeny;
Modified: trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm (219105 => 219106)
--- trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm 2017-07-03 23:12:40 UTC (rev 219105)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm 2017-07-03 23:19:31 UTC (rev 219106)
@@ -233,7 +233,7 @@
{
__block bool isWaitingForJavaScript = false;
__block NSString *evalResult = nil;
- [self evaluateJavaScript:script completionHandler:^(id result, NSError *error)
+ [self _evaluateJavaScriptWithoutUserGesture:script completionHandler:^(id result, NSError *error)
{
evalResult = [[NSString alloc] initWithFormat:@"%@", result];
isWaitingForJavaScript = true;