Diff
Modified: trunk/Source/WebKit/ChangeLog (231173 => 231174)
--- trunk/Source/WebKit/ChangeLog 2018-04-30 22:17:03 UTC (rev 231173)
+++ trunk/Source/WebKit/ChangeLog 2018-04-30 22:21:42 UTC (rev 231174)
@@ -1,3 +1,20 @@
+2018-04-30 Alex Christensen <[email protected]>
+
+ Add WKUIDelegatePrivate equivalent of WKPageContextMenuClient getContextMenuFromProposedMenuAsync
+ https://bugs.webkit.org/show_bug.cgi?id=180955
+
+ Reviewed by Andy Estes.
+
+ * UIProcess/API/APIContextMenuClient.h:
+ (API::ContextMenuClient::menuFromProposedMenu):
+ * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
+ * UIProcess/Cocoa/UIDelegate.h:
+ * UIProcess/Cocoa/UIDelegate.mm:
+ (WebKit::UIDelegate::setDelegate):
+ (WebKit::UIDelegate::ContextMenuClient::menuFromProposedMenu):
+ * UIProcess/mac/WebContextMenuProxyMac.mm:
+ (WebKit::WebContextMenuProxyMac::showContextMenuWithItems):
+
2018-04-30 JF Bastien <[email protected]>
Use some C++17 features
Modified: trunk/Source/WebKit/UIProcess/API/APIContextMenuClient.h (231173 => 231174)
--- trunk/Source/WebKit/UIProcess/API/APIContextMenuClient.h 2018-04-30 22:17:03 UTC (rev 231173)
+++ trunk/Source/WebKit/UIProcess/API/APIContextMenuClient.h 2018-04-30 22:21:42 UTC (rev 231174)
@@ -31,6 +31,7 @@
#include "WebContextMenuListenerProxy.h"
#include "WebHitTestResultData.h"
#include <WebKit/WKBase.h>
+#include <wtf/CompletionHandler.h>
#include <wtf/Forward.h>
#include <wtf/RefPtr.h>
@@ -57,7 +58,7 @@
virtual bool hideContextMenu(WebKit::WebPageProxy&) { return false; }
#if PLATFORM(MAC)
- virtual RetainPtr<NSMenu> menuFromProposedMenu(WebKit::WebPageProxy&, NSMenu *menu, const WebKit::WebHitTestResultData&, API::Object*) { return menu; }
+ virtual void menuFromProposedMenu(WebKit::WebPageProxy&, NSMenu *menu, const WebKit::WebHitTestResultData&, API::Object*, CompletionHandler<void(RetainPtr<NSMenu>&&)>&& completionHandler) { completionHandler(menu); }
#endif
};
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h (231173 => 231174)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h 2018-04-30 22:17:03 UTC (rev 231173)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h 2018-04-30 22:21:42 UTC (rev 231174)
@@ -185,6 +185,7 @@
- (void)_webView:(WKWebView *)webView unavailablePlugInButtonClickedWithReason:(_WKPlugInUnavailabilityReason)reason plugInInfo:(NSDictionary *)plugInInfo;
- (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));
+- (void)_webView:(WKWebView *)webView getContextMenuFromProposedMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element userInfo:(id <NSSecureCoding>)userInfo completionHandler:(void (^)(NSMenu *))completionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA));
#endif // TARGET_OS_IPHONE
@end
Modified: trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h (231173 => 231174)
--- trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h 2018-04-30 22:17:03 UTC (rev 231173)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h 2018-04-30 22:21:42 UTC (rev 231174)
@@ -67,7 +67,7 @@
private:
// API::ContextMenuClient
- RetainPtr<NSMenu> menuFromProposedMenu(WebPageProxy&, NSMenu *, const WebHitTestResultData&, API::Object*) override;
+ void menuFromProposedMenu(WebPageProxy&, NSMenu *, const WebHitTestResultData&, API::Object*, CompletionHandler<void(RetainPtr<NSMenu>&&)>&&) override;
UIDelegate& m_uiDelegate;
};
@@ -212,6 +212,7 @@
#if ENABLE(CONTEXT_MENUS)
bool webViewContextMenuForElement : 1;
bool webViewContextMenuForElementUserInfo : 1;
+ bool webViewGetContextMenuFromProposedMenuForElementUserInfoCompletionHandler : 1;
#endif
bool webViewHasVideoInPictureInPictureDidChange : 1;
} m_delegateMethods;
Modified: trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm (231173 => 231174)
--- trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm 2018-04-30 22:17:03 UTC (rev 231173)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm 2018-04-30 22:21:42 UTC (rev 231174)
@@ -160,6 +160,7 @@
#if ENABLE(CONTEXT_MENUS)
m_delegateMethods.webViewContextMenuForElement = [delegate respondsToSelector:@selector(_webView:contextMenu:forElement:)];
m_delegateMethods.webViewContextMenuForElementUserInfo = [delegate respondsToSelector:@selector(_webView:contextMenu:forElement:userInfo:)];
+ m_delegateMethods.webViewGetContextMenuFromProposedMenuForElementUserInfoCompletionHandler = [delegate respondsToSelector:@selector(_webView:getContextMenuFromProposedMenu:forElement:userInfo:completionHandler:)];
#endif
m_delegateMethods.webViewHasVideoInPictureInPictureDidChange = [delegate respondsToSelector:@selector(_webView:hasVideoInPictureInPictureDidChange:)];
@@ -175,21 +176,34 @@
{
}
-RetainPtr<NSMenu> UIDelegate::ContextMenuClient::menuFromProposedMenu(WebPageProxy&, NSMenu *menu, const WebHitTestResultData&, API::Object* userInfo)
+void UIDelegate::ContextMenuClient::menuFromProposedMenu(WebPageProxy&, NSMenu *menu, const WebHitTestResultData&, API::Object* userInfo, CompletionHandler<void(RetainPtr<NSMenu>&&)>&& completionHandler)
{
- if (!m_uiDelegate.m_delegateMethods.webViewContextMenuForElement && !m_uiDelegate.m_delegateMethods.webViewContextMenuForElementUserInfo)
- return menu;
+ if (!m_uiDelegate.m_delegateMethods.webViewContextMenuForElement
+ && !m_uiDelegate.m_delegateMethods.webViewContextMenuForElementUserInfo
+ && !m_uiDelegate.m_delegateMethods.webViewGetContextMenuFromProposedMenuForElementUserInfoCompletionHandler)
+ return completionHandler(menu);
auto delegate = m_uiDelegate.m_delegate.get();
if (!delegate)
- return menu;
+ return completionHandler(menu);
auto contextMenuElementInfo = adoptNS([[_WKContextMenuElementInfo alloc] init]);
+ if (m_uiDelegate.m_delegateMethods.webViewGetContextMenuFromProposedMenuForElementUserInfoCompletionHandler) {
+ auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:getContextMenuFromProposedMenu:forElement:userInfo:completionHandler:));
+ [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView getContextMenuFromProposedMenu:menu forElement:contextMenuElementInfo.get() userInfo:userInfo ? static_cast<id <NSSecureCoding>>(userInfo->wrapper()) : nil completionHandler:BlockPtr<void(NSMenu *)>::fromCallable([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)] (NSMenu *menu) {
+ if (checker->completionHandlerHasBeenCalled())
+ return;
+ checker->didCallCompletionHandler();
+ completionHandler(menu);
+ }).get()];
+ return;
+ }
+
if (m_uiDelegate.m_delegateMethods.webViewContextMenuForElement)
- return [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView contextMenu:menu forElement:contextMenuElementInfo.get()];
+ return completionHandler([(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView contextMenu:menu forElement:contextMenuElementInfo.get()]);
- return [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView contextMenu:menu forElement:contextMenuElementInfo.get() userInfo:userInfo ? static_cast<id <NSSecureCoding>>(userInfo->wrapper()) : nil];
+ completionHandler([(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView contextMenu:menu forElement:contextMenuElementInfo.get() userInfo:userInfo ? static_cast<id <NSSecureCoding>>(userInfo->wrapper()) : nil]);
}
#endif
Modified: trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm (231173 => 231174)
--- trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm 2018-04-30 22:17:03 UTC (rev 231173)
+++ trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm 2018-04-30 22:21:42 UTC (rev 231174)
@@ -466,16 +466,17 @@
auto menu = createContextMenuFromItems(data);
[[WKMenuTarget sharedMenuTarget] setMenuProxy:this];
- m_menu = m_page.contextMenuClient().menuFromProposedMenu(m_page, menu.get(), m_context.webHitTestResultData(), m_userData.object());
-
- NSPoint menuLocation = [m_webView convertPoint:m_context.menuLocation() toView:nil];
- NSEvent *event = [NSEvent mouseEventWithType:NSEventTypeRightMouseUp location:menuLocation modifierFlags:0 timestamp:0 windowNumber:m_webView.window.windowNumber context:nil eventNumber:0 clickCount:0 pressure:0];
- [NSMenu popUpContextMenu:m_menu.get() withEvent:event forView:m_webView];
-
- if (m_contextMenuListener) {
- m_contextMenuListener->invalidate();
- m_contextMenuListener = nullptr;
- }
+ m_page.contextMenuClient().menuFromProposedMenu(m_page, menu.get(), m_context.webHitTestResultData(), m_userData.object(), [this, protectedThis = makeRef(*this)] (RetainPtr<NSMenu>&& menu) {
+ m_menu = WTFMove(menu);
+ NSPoint menuLocation = [m_webView convertPoint:m_context.menuLocation() toView:nil];
+ NSEvent *event = [NSEvent mouseEventWithType:NSEventTypeRightMouseUp location:menuLocation modifierFlags:0 timestamp:0 windowNumber:m_webView.window.windowNumber context:nil eventNumber:0 clickCount:0 pressure:0];
+ [NSMenu popUpContextMenu:m_menu.get() withEvent:event forView:m_webView];
+
+ if (m_contextMenuListener) {
+ m_contextMenuListener->invalidate();
+ m_contextMenuListener = nullptr;
+ }
+ });
}
void WebContextMenuProxyMac::showContextMenu()
Modified: trunk/Tools/ChangeLog (231173 => 231174)
--- trunk/Tools/ChangeLog 2018-04-30 22:17:03 UTC (rev 231173)
+++ trunk/Tools/ChangeLog 2018-04-30 22:21:42 UTC (rev 231174)
@@ -1,3 +1,14 @@
+2018-04-30 Alex Christensen <[email protected]>
+
+ Add WKUIDelegatePrivate equivalent of WKPageContextMenuClient getContextMenuFromProposedMenuAsync
+ https://bugs.webkit.org/show_bug.cgi?id=180955
+
+ Reviewed by Andy Estes.
+
+ * TestWebKitAPI/Tests/WebKit/mac/ContextMenuImgWithVideo.mm:
+ (-[ContextMenuImgWithVideoDelegate _webView:contextMenu:forElement:]):
+ (-[ContextMenuImgWithVideoDelegate _webView:getContextMenuFromProposedMenu:forElement:userInfo:completionHandler:]):
+
2018-04-30 JF Bastien <[email protected]>
Use some C++17 features
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit/mac/ContextMenuImgWithVideo.mm (231173 => 231174)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit/mac/ContextMenuImgWithVideo.mm 2018-04-30 22:17:03 UTC (rev 231173)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/mac/ContextMenuImgWithVideo.mm 2018-04-30 22:21:42 UTC (rev 231174)
@@ -42,9 +42,15 @@
@implementation ContextMenuImgWithVideoDelegate
- (NSMenu*)_webView:(WKWebView*)webView contextMenu:(NSMenu*)menu forElement:(_WKContextMenuElementInfo*)element
{
- contextMenuShown = true;
return nil;
}
+
+- (void)_webView:(WKWebView *)webView getContextMenuFromProposedMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element userInfo:(id <NSSecureCoding>)userInfo completionHandler:(void (^)(NSMenu *))completionHandler
+{
+ contextMenuShown = true;
+ completionHandler(nil);
+}
+
@end
namespace TestWebKitAPI {