Diff
Modified: trunk/Source/WebKit2/ChangeLog (191599 => 191600)
--- trunk/Source/WebKit2/ChangeLog 2015-10-26 21:09:31 UTC (rev 191599)
+++ trunk/Source/WebKit2/ChangeLog 2015-10-26 21:41:36 UTC (rev 191600)
@@ -1,3 +1,23 @@
+2015-10-26 Anders Carlsson <ander...@apple.com>
+
+ Pipe custom context menu handling through to the UIDelegate object
+ https://bugs.webkit.org/show_bug.cgi?id=150572
+
+ Reviewed by Tim Horton.
+
+ * UIProcess/API/APIContextMenuClient.h:
+ (API::ContextMenuClient::menuFromProposedMenu):
+ * UIProcess/API/Cocoa/WKWebView.mm:
+ (-[WKWebView setUIDelegate:]):
+ * UIProcess/Cocoa/UIDelegate.h:
+ * UIProcess/Cocoa/UIDelegate.mm:
+ (WebKit::UIDelegate::createContextMenuClient):
+ (WebKit::UIDelegate::ContextMenuClient::ContextMenuClient):
+ (WebKit::UIDelegate::ContextMenuClient::~ContextMenuClient):
+ (WebKit::UIDelegate::ContextMenuClient::menuFromProposedMenu):
+ * UIProcess/mac/WebContextMenuProxyMac.mm:
+ (WebKit::WebContextMenuProxyMac::showContextMenu):
+
2015-10-26 Alex Christensen <achristen...@webkit.org>
Build fix when using NETWORK_SESSION after r191457.
Modified: trunk/Source/WebKit2/UIProcess/API/APIContextMenuClient.h (191599 => 191600)
--- trunk/Source/WebKit2/UIProcess/API/APIContextMenuClient.h 2015-10-26 21:09:31 UTC (rev 191599)
+++ trunk/Source/WebKit2/UIProcess/API/APIContextMenuClient.h 2015-10-26 21:41:36 UTC (rev 191600)
@@ -32,6 +32,8 @@
#include <wtf/RefPtr.h>
#include <wtf/Vector.h>
+OBJC_CLASS NSMenu;
+
namespace WebCore {
class IntPoint;
}
@@ -52,6 +54,10 @@
virtual void customContextMenuItemSelected(WebKit::WebPageProxy&, const WebKit::WebContextMenuItemData&) { }
virtual bool showContextMenu(WebKit::WebPageProxy&, const WebCore::IntPoint&, const Vector<RefPtr<WebKit::WebContextMenuItem>>&) { return false; }
virtual bool hideContextMenu(WebKit::WebPageProxy&) { return false; }
+
+#if PLATFORM(MAC)
+ virtual RetainPtr<NSMenu> menuFromProposedMenu(WebKit::WebPageProxy&, NSMenu *menu, const WebKit::WebHitTestResultData&) { return menu; }
+#endif
};
} // namespace API
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (191599 => 191600)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm 2015-10-26 21:09:31 UTC (rev 191599)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm 2015-10-26 21:41:36 UTC (rev 191600)
@@ -449,6 +449,9 @@
- (void)setUIDelegate:(id<WKUIDelegate>)UIDelegate
{
+#if ENABLE(CONTEXT_MENUS)
+ _page->setContextMenuClient(_uiDelegate->createContextMenuClient());
+#endif
_page->setUIClient(_uiDelegate->createUIClient());
_uiDelegate->setDelegate(UIDelegate);
}
Modified: trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.h (191599 => 191600)
--- trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.h 2015-10-26 21:09:31 UTC (rev 191599)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.h 2015-10-26 21:41:36 UTC (rev 191600)
@@ -30,6 +30,7 @@
#if WK_API_ENABLED
+#import "APIContextMenuClient.h"
#import "APIUIClient.h"
#import "WeakObjCPtr.h"
#import <wtf/RetainPtr.h>
@@ -45,12 +46,29 @@
explicit UIDelegate(WKWebView *);
~UIDelegate();
+#if ENABLE(CONTEXT_MENUS)
+ std::unique_ptr<API::ContextMenuClient> createContextMenuClient();
+#endif
std::unique_ptr<API::UIClient> createUIClient();
RetainPtr<id <WKUIDelegate> > delegate();
void setDelegate(id <WKUIDelegate>);
private:
+#if ENABLE(CONTEXT_MENUS)
+ class ContextMenuClient : public API::ContextMenuClient {
+ public:
+ explicit ContextMenuClient(UIDelegate&);
+ ~ContextMenuClient();
+
+ private:
+ // API::ContextMenuClient
+ virtual RetainPtr<NSMenu> menuFromProposedMenu(WebKit::WebPageProxy&, NSMenu *, const WebKit::WebHitTestResultData&) override;
+
+ UIDelegate& m_uiDelegate;
+ };
+#endif
+
class UIClient : public API::UIClient {
public:
explicit UIClient(UIDelegate&);
Modified: trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm (191599 => 191600)
--- trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm 2015-10-26 21:09:31 UTC (rev 191599)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm 2015-10-26 21:41:36 UTC (rev 191600)
@@ -52,6 +52,13 @@
{
}
+#if ENABLE(CONTEXT_MENUS)
+std::unique_ptr<API::ContextMenuClient> UIDelegate::createContextMenuClient()
+{
+ return std::make_unique<ContextMenuClient>(*this);
+}
+#endif
+
std::unique_ptr<API::UIClient> UIDelegate::createUIClient()
{
return std::make_unique<UIClient>(*this);
@@ -88,6 +95,25 @@
m_delegateMethods.webViewImageOrMediaDocumentSizeChanged = [delegate respondsToSelector:@selector(_webView:imageOrMediaDocumentSizeChanged:)];
}
+#if ENABLE(CONTEXT_MENUS)
+UIDelegate::ContextMenuClient::ContextMenuClient(UIDelegate& uiDelegate)
+ : m_uiDelegate(uiDelegate)
+{
+}
+
+UIDelegate::ContextMenuClient::~ContextMenuClient()
+{
+}
+
+RetainPtr<NSMenu> UIDelegate::ContextMenuClient::menuFromProposedMenu(WebKit::WebPageProxy&, NSMenu *menu, const WebKit::WebHitTestResultData&)
+{
+ // FIXME: Call the UI delegate.
+ (void)m_uiDelegate;
+
+ return menu;
+}
+#endif
+
UIDelegate::UIClient::UIClient(UIDelegate& uiDelegate)
: m_uiDelegate(uiDelegate)
{
Modified: trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm (191599 => 191600)
--- trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm 2015-10-26 21:09:31 UTC (rev 191599)
+++ trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm 2015-10-26 21:41:36 UTC (rev 191600)
@@ -367,6 +367,7 @@
Vector<RefPtr<WebContextMenuItem>> clientItems;
bool useProposedItems = true;
+ // FIXME: Get rid of this once we don't need the C SPI.
if (m_page.contextMenuClient().getContextMenuFromProposedMenu(m_page, proposedAPIItems, clientItems, m_context.webHitTestResultData(), m_page.process().transformHandlesToObjects(m_userData.object()).get()))
useProposedItems = false;
@@ -377,7 +378,8 @@
if (items.isEmpty())
return;
- m_menu = createContextMenuFromItems(items);
+ auto menu = createContextMenuFromItems(items);
+ m_menu = m_page.contextMenuClient().menuFromProposedMenu(m_page, menu.get(), m_context.webHitTestResultData());
[[WKMenuTarget sharedMenuTarget] setMenuProxy:this];
[m_menu popUpMenuPositioningItem:nil atLocation:m_context.menuLocation() inView:m_webView];