Diff
Modified: trunk/Source/WebKit/ChangeLog (221171 => 221172)
--- trunk/Source/WebKit/ChangeLog 2017-08-25 00:05:56 UTC (rev 221171)
+++ trunk/Source/WebKit/ChangeLog 2017-08-25 00:28:56 UTC (rev 221172)
@@ -1,3 +1,22 @@
+2017-08-24 Alex Christensen <achristen...@webkit.org>
+
+ Add WKUIDelegatePrivate equivalent of WKPageUIClient's handleAutoplayEvent
+ https://bugs.webkit.org/show_bug.cgi?id=175965
+ <rdar://problem/29270035>
+
+ Reviewed by Tim Horton.
+
+ Covered by updating API tests to use UIDelegate instead of _pageForTesting and WKPageUIClient.
+
+ * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
+ * UIProcess/Cocoa/UIDelegate.h:
+ * UIProcess/Cocoa/UIDelegate.mm:
+ (WebKit::UIDelegate::setDelegate):
+ (WebKit::toWKFocusDirection):
+ (WebKit::toWKAutoplayEventFlags):
+ (WebKit::toWKAutoplayEvent):
+ (WebKit::UIDelegate::UIClient::handleAutoplayEvent):
+
2017-08-24 Brady Eidson <beid...@apple.com>
Remove duplicate WebCore::URL encoder/decoder
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h (221171 => 221172)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h 2017-08-25 00:05:56 UTC (rev 221171)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h 2017-08-25 00:28:56 UTC (rev 221172)
@@ -47,9 +47,21 @@
@protocol UIDropSession;
#else
typedef NS_ENUM(NSInteger, _WKFocusDirection) {
- WKFocusDirectionBackward,
- WKFocusDirectionForward,
+ _WKFocusDirectionBackward,
+ _WKFocusDirectionForward,
} WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+
+typedef NS_ENUM(NSInteger, _WKAutoplayEvent) {
+ _WKAutoplayEventDidPreventFromAutoplaying,
+ _WKAutoplayEventDidPlayMediaPreventedFromAutoplaying,
+ _WKAutoplayEventDidAutoplayMediaPastThresholdWithoutUserInterference,
+ _WKAutoplayEventUserDidInterfereWithPlayback,
+} WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+
+typedef NS_OPTIONS(NSInteger, _WKAutoplayEventFlags) {
+ _WKAutoplayEventFlagsNone = 0,
+ _WKAutoplayEventFlagsHasAudio = 1 << 0,
+} WK_API_AVAILABLE(macosx(WK_MAC_TBA));
#endif
@protocol WKUIDelegatePrivate <WKUIDelegate>
@@ -130,6 +142,7 @@
- (void)_unfocusWebView:(WKWebView *)webView WK_API_AVAILABLE(macosx(WK_MAC_TBA));
- (void)_webView:(WKWebView *)webView takeFocus:(_WKFocusDirection)direction WK_API_AVAILABLE(macosx(WK_MAC_TBA));
- (void)_webView:(WKWebView *)webView didNotHandleWheelEvent:(NSEvent *)event WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+- (void)_webView:(WKWebView *)webView handleAutoplayEvent:(_WKAutoplayEvent)event withFlags:(_WKAutoplayEventFlags)flags WK_API_AVAILABLE(macosx(WK_MAC_TBA));
- (NSMenu *)_webView:(WKWebView *)webView contextMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element WK_API_AVAILABLE(macosx(10.12));
- (NSMenu *)_webView:(WKWebView *)webView contextMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element userInfo:(id <NSSecureCoding>)userInfo WK_API_AVAILABLE(macosx(10.12));
#endif
Modified: trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h (221171 => 221172)
--- trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h 2017-08-25 00:05:56 UTC (rev 221171)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h 2017-08-25 00:28:56 UTC (rev 221172)
@@ -101,6 +101,7 @@
void focus(WebPageProxy*) final;
void unfocus(WebPageProxy*) final;
void didNotHandleWheelEvent(WebKit::WebPageProxy*, const WebKit::NativeWebWheelEvent&) final;
+ void handleAutoplayEvent(WebKit::WebPageProxy&, WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final;
bool runOpenPanel(WebPageProxy*, WebFrameProxy*, const WebCore::SecurityOriginData&, API::OpenPanelParameters*, WebOpenPanelResultListenerProxy*) final;
#endif
bool decidePolicyForUserMediaPermissionRequest(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, API::SecurityOrigin&, UserMediaPermissionRequestProxy&) final;
@@ -146,6 +147,7 @@
bool unfocusWebView : 1;
bool webViewTakeFocus : 1;
bool webViewDidNotHandleWheelEvent : 1;
+ bool webViewHandleAutoplayEventWithFlags : 1;
bool webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler : 1;
#endif
bool webViewDecideDatabaseQuotaForSecurityOriginCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler : 1;
Modified: trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm (221171 => 221172)
--- trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm 2017-08-25 00:05:56 UTC (rev 221171)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm 2017-08-25 00:28:56 UTC (rev 221172)
@@ -106,6 +106,7 @@
m_delegateMethods.unfocusWebView = [delegate respondsToSelector:@selector(_unfocusWebView:)];
m_delegateMethods.webViewTakeFocus = [delegate respondsToSelector:@selector(_webView:takeFocus:)];
m_delegateMethods.webViewDidNotHandleWheelEvent = [delegate respondsToSelector:@selector(_webView:didNotHandleWheelEvent:)];
+ m_delegateMethods.webViewHandleAutoplayEventWithFlags = [delegate respondsToSelector:@selector(_webView:handleAutoplayEvent:withFlags:)];
m_delegateMethods.webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runOpenPanelWithParameters:initiatedByFrame:completionHandler:)];
#endif
@@ -381,12 +382,12 @@
{
switch (direction) {
case kWKFocusDirectionBackward:
- return WKFocusDirectionBackward;
+ return _WKFocusDirectionBackward;
case kWKFocusDirectionForward:
- return WKFocusDirectionForward;
+ return _WKFocusDirectionForward;
}
ASSERT_NOT_REACHED();
- return WKFocusDirectionForward;
+ return _WKFocusDirectionForward;
}
void UIDelegate::UIClient::takeFocus(WebKit::WebPageProxy*, WKFocusDirection direction)
@@ -437,6 +438,43 @@
[(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView didNotHandleWheelEvent:event.nativeEvent()];
}
+static _WKAutoplayEventFlags toWKAutoplayEventFlags(OptionSet<WebCore::AutoplayEventFlags> flags)
+{
+ _WKAutoplayEventFlags wkFlags = _WKAutoplayEventFlagsNone;
+ if (flags.contains(WebCore::AutoplayEventFlags::HasAudio))
+ wkFlags |= _WKAutoplayEventFlagsHasAudio;
+
+ return wkFlags;
+}
+
+static _WKAutoplayEvent toWKAutoplayEvent(WebCore::AutoplayEvent event)
+{
+ switch (event) {
+ case WebCore::AutoplayEvent::DidPreventMediaFromPlaying:
+ return _WKAutoplayEventDidPreventFromAutoplaying;
+ case WebCore::AutoplayEvent::DidPlayMediaPreventedFromPlaying:
+ return _WKAutoplayEventDidPlayMediaPreventedFromAutoplaying;
+ case WebCore::AutoplayEvent::DidAutoplayMediaPastThresholdWithoutUserInterference:
+ return _WKAutoplayEventDidAutoplayMediaPastThresholdWithoutUserInterference;
+ case WebCore::AutoplayEvent::UserDidInterfereWithPlayback:
+ return _WKAutoplayEventUserDidInterfereWithPlayback;
+ }
+ ASSERT_NOT_REACHED();
+ return _WKAutoplayEventDidPlayMediaPreventedFromAutoplaying;
+}
+
+void UIDelegate::UIClient::handleAutoplayEvent(WebKit::WebPageProxy&, WebCore::AutoplayEvent event, OptionSet<WebCore::AutoplayEventFlags> flags)
+{
+ if (!m_uiDelegate.m_delegateMethods.webViewHandleAutoplayEventWithFlags)
+ return;
+
+ auto delegate = m_uiDelegate.m_delegate.get();
+ if (!delegate)
+ return;
+
+ [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView handleAutoplayEvent:toWKAutoplayEvent(event) withFlags:toWKAutoplayEventFlags(flags)];
+}
+
void UIDelegate::UIClient::showPage(WebPageProxy*)
{
if (!m_uiDelegate.m_delegateMethods.showWebView)
Modified: trunk/Tools/ChangeLog (221171 => 221172)
--- trunk/Tools/ChangeLog 2017-08-25 00:05:56 UTC (rev 221171)
+++ trunk/Tools/ChangeLog 2017-08-25 00:28:56 UTC (rev 221172)
@@ -1,5 +1,20 @@
2017-08-24 Alex Christensen <achristen...@webkit.org>
+ Add WKUIDelegatePrivate equivalent of WKPageUIClient's handleAutoplayEvent
+ https://bugs.webkit.org/show_bug.cgi?id=175965
+ <rdar://problem/29270035>
+
+ Reviewed by Tim Horton.
+
+ * TestWebKitAPI/Tests/WebKit2Cocoa/UIDelegate.mm:
+ (TEST):
+ * TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm:
+ (-[AutoplayPoliciesDelegate _webView:handleAutoplayEvent:withFlags:]):
+ (TEST):
+ (handleAutoplayEvent): Deleted.
+
+2017-08-24 Alex Christensen <achristen...@webkit.org>
+
didNotHandleWheelEvent test times out
https://bugs.webkit.org/show_bug.cgi?id=175967
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UIDelegate.mm (221171 => 221172)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UIDelegate.mm 2017-08-25 00:05:56 UTC (rev 221171)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UIDelegate.mm 2017-08-25 00:28:56 UTC (rev 221172)
@@ -133,7 +133,7 @@
"<body _onload_='loaded()'><input type='text' id='in'></body>";
[webView loadHTMLString:html baseURL:[NSURL URLWithString:@"http://example.com/"]];
TestWebKitAPI::Util::run(&done);
- ASSERT_EQ(takenDirection, WKFocusDirectionBackward);
+ ASSERT_EQ(takenDirection, _WKFocusDirectionBackward);
}
#define RELIABLE_DID_NOT_HANDLE_WHEEL_EVENT 0
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm (221171 => 221172)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm 2017-08-25 00:05:56 UTC (rev 221171)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm 2017-08-25 00:28:56 UTC (rev 221172)
@@ -29,6 +29,7 @@
#import "TestWKWebView.h"
#import <WebKit/WKPagePrivate.h>
#import <WebKit/WKPreferencesRefPrivate.h>
+#import <WebKit/WKUIDelegatePrivate.h>
#import <WebKit/WKURLSchemeTaskPrivate.h>
#import <WebKit/WKUserContentControllerPrivate.h>
#import <WebKit/WKWebViewPrivate.h>
@@ -52,8 +53,8 @@
static bool receivedAlert;
#if PLATFORM(MAC)
-static std::optional<WKAutoplayEvent> receivedAutoplayEvent;
-static std::optional<WKAutoplayEventFlags> receivedAutoplayEventFlags;
+static std::optional<_WKAutoplayEvent> receivedAutoplayEvent;
+static std::optional<_WKAutoplayEventFlags> receivedAutoplayEventFlags;
#endif
static size_t alertCount;
@@ -162,7 +163,7 @@
[[_WKUserContentExtensionStore defaultStore] _removeAllContentExtensions];
}
-@interface AutoplayPoliciesDelegate : NSObject <WKNavigationDelegate, WKUIDelegate>
+@interface AutoplayPoliciesDelegate : NSObject <WKNavigationDelegate, WKUIDelegatePrivate>
@property (nonatomic, copy) _WKWebsiteAutoplayPolicy(^autoplayPolicyForURL)(NSURL *);
@property (nonatomic, copy) _WKWebsiteAutoplayQuirk(^allowedAutoplayQuirksForURL)(NSURL *);
@end
@@ -186,6 +187,14 @@
decisionHandler(WKNavigationActionPolicyAllow, websitePolicies);
}
+#if PLATFORM(MAC)
+- (void)_webView:(WKWebView *)webView handleAutoplayEvent:(_WKAutoplayEvent)event withFlags:(_WKAutoplayEventFlags)flags
+{
+ receivedAutoplayEventFlags = flags;
+ receivedAutoplayEvent = event;
+}
+#endif
+
@end
TEST(WebKit2, WebsitePoliciesAutoplayEnabled)
@@ -283,12 +292,6 @@
}
#if PLATFORM(MAC)
-static void handleAutoplayEvent(WKPageRef page, WKAutoplayEvent event, WKAutoplayEventFlags flags, const void* clientInfo)
-{
- receivedAutoplayEventFlags = flags;
- receivedAutoplayEvent = event;
-}
-
static void runUntilReceivesAutoplayEvent(WKAutoplayEvent event)
{
while (!receivedAutoplayEvent || *receivedAutoplayEvent != event)
@@ -305,14 +308,8 @@
return _WKWebsiteAutoplayPolicyDeny;
}];
[webView setNavigationDelegate:delegate.get()];
+ [webView setUIDelegate:delegate.get()];
- WKPageUIClientV9 uiClient;
- memset(&uiClient, 0, sizeof(uiClient));
-
- uiClient.base.version = 9;
- uiClient.handleAutoplayEvent = handleAutoplayEvent;
-
- WKPageSetPageUIClient([webView _pageForTesting], &uiClient.base);
NSPoint playButtonClickPoint = NSMakePoint(20, 256);
receivedAutoplayEvent = std::nullopt;
@@ -379,15 +376,8 @@
return _WKWebsiteAutoplayPolicyAllow;
}];
[webView setNavigationDelegate:delegate.get()];
+ [webView setUIDelegate: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-autoplay-audio" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
[webView loadRequest:jsPlayRequest];
@@ -405,15 +395,8 @@
return _WKWebsiteAutoplayPolicyAllow;
}];
[webView setNavigationDelegate:delegate.get()];
+ [webView setUIDelegate: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];
@@ -540,14 +523,8 @@
return _WKWebsiteAutoplayPolicyAllow;
}];
[webView setNavigationDelegate:delegate.get()];
+ [webView setUIDelegate:delegate.get()];
- WKPageUIClientV9 uiClient;
- memset(&uiClient, 0, sizeof(uiClient));
- uiClient.base.version = 9;
- uiClient.handleAutoplayEvent = handleAutoplayEvent;
-
- WKPageSetPageUIClient([webView _pageForTesting], &uiClient.base);
-
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"test:///should-redirect"]]];
[webView waitForMessage:@"autoplayed"];
}
@@ -556,17 +533,9 @@
{
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()];
+ [webView setUIDelegate:delegate.get()];
NSURLRequest *requestWithAudio = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"autoplay-check" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];