Add a context menu delegate method that takes a userInfo parameter
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Nov 2015 00:49:17 +0000 (00:49 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Nov 2015 00:49:17 +0000 (00:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=151232

Reviewed by Tim Horton.

* 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::showContextMenu):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@192397 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/APIContextMenuClient.h
Source/WebKit2/UIProcess/API/Cocoa/WKUIDelegatePrivate.h
Source/WebKit2/UIProcess/Cocoa/UIDelegate.h
Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm
Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm

index 28582a3..cb1a73c 100644 (file)
@@ -1,5 +1,22 @@
 2015-11-12  Anders Carlsson  <andersca@apple.com>
 
+        Add a context menu delegate method that takes a userInfo parameter
+        https://bugs.webkit.org/show_bug.cgi?id=151232
+
+        Reviewed by Tim Horton.
+
+        * 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::showContextMenu):
+
+2015-11-12  Anders Carlsson  <andersca@apple.com>
+
         ContextMenuAction and WebMenuItemTag shouldn't have to be in sync
         https://bugs.webkit.org/show_bug.cgi?id=151226
 
index f253c36..f8f2023 100644 (file)
@@ -56,7 +56,7 @@ public:
     virtual bool hideContextMenu(WebKit::WebPageProxy&) { return false; }
 
 #if PLATFORM(MAC)
-    virtual RetainPtr<NSMenu> menuFromProposedMenu(WebKit::WebPageProxy&, NSMenu *menu, const WebKit::WebHitTestResultData&) { return menu; }
+    virtual RetainPtr<NSMenu> menuFromProposedMenu(WebKit::WebPageProxy&, NSMenu *menu, const WebKit::WebHitTestResultData&, API::Object*) { return menu; }
 #endif
 };
 
index 36bb7f0..f1c7f63 100644 (file)
@@ -74,6 +74,7 @@ struct UIEdgeInsets;
 - (UIViewController *)_webView:(WKWebView *)webView previewViewControllerForAnimatedImageAtURL:(NSURL *)url defaultActions:(WK_ARRAY(_WKElementAction *) *)actions elementInfo:(_WKActivatedElementInfo *)elementInfo imageSize:(CGSize)imageSize WK_AVAILABLE(NA, 9_0);
 #else
 - (NSMenu *)_webView:(WKWebView *)webView contextMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element WK_AVAILABLE(WK_MAC_TBA, NA);
+- (NSMenu *)_webView:(WKWebView *)webView contextMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element userInfo:(id <NSSecureCoding>)userInfo WK_AVAILABLE(WK_MAC_TBA, NA);
 #endif
 
 @end
index b8d81ba..7496ffb 100644 (file)
@@ -63,7 +63,7 @@ private:
 
     private:
         // API::ContextMenuClient
-        virtual RetainPtr<NSMenu> menuFromProposedMenu(WebKit::WebPageProxy&, NSMenu *, const WebKit::WebHitTestResultData&) override;
+        virtual RetainPtr<NSMenu> menuFromProposedMenu(WebKit::WebPageProxy&, NSMenu *, const WebKit::WebHitTestResultData&, API::Object*) override;
 
         UIDelegate& m_uiDelegate;
     };
@@ -126,6 +126,7 @@ private:
 
 #if ENABLE(CONTEXT_MENUS)
         bool webViewContextMenuForElement : 1;
+        bool webViewContextMenuForElementUserInfo : 1;
 #endif
     } m_delegateMethods;
 };
index e52e0ab..f382c48 100644 (file)
@@ -97,6 +97,7 @@ void UIDelegate::setDelegate(id <WKUIDelegate> delegate)
 
 #if ENABLE(CONTEXT_MENUS)
     m_delegateMethods.webViewContextMenuForElement = [delegate respondsToSelector:@selector(_webView:contextMenu:forElement:)];
+    m_delegateMethods.webViewContextMenuForElementUserInfo = [delegate respondsToSelector:@selector(_webView:contextMenu:forElement:userInfo:)];
 #endif
 }
 
@@ -110,9 +111,9 @@ UIDelegate::ContextMenuClient::~ContextMenuClient()
 {
 }
 
-RetainPtr<NSMenu> UIDelegate::ContextMenuClient::menuFromProposedMenu(WebKit::WebPageProxy&, NSMenu *menu, const WebKit::WebHitTestResultData&)
+RetainPtr<NSMenu> UIDelegate::ContextMenuClient::menuFromProposedMenu(WebKit::WebPageProxy&, NSMenu *menu, const WebKit::WebHitTestResultData&, API::Object* userInfo)
 {
-    if (!m_uiDelegate.m_delegateMethods.webViewContextMenuForElement)
+    if (!m_uiDelegate.m_delegateMethods.webViewContextMenuForElement && !m_uiDelegate.m_delegateMethods.webViewContextMenuForElementUserInfo)
         return menu;
 
     auto delegate = m_uiDelegate.m_delegate.get();
@@ -121,7 +122,10 @@ RetainPtr<NSMenu> UIDelegate::ContextMenuClient::menuFromProposedMenu(WebKit::We
 
     auto contextMenuElementInfo = adoptNS([[_WKContextMenuElementInfo alloc] init]);
 
-    return [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView contextMenu:menu forElement:contextMenuElementInfo.get()];
+    if (m_uiDelegate.m_delegateMethods.webViewContextMenuForElement)
+        return [(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:static_cast<id <NSSecureCoding>>(userInfo->wrapper())];
 }
 #endif
 
index f9fc8f0..edccf73 100644 (file)
@@ -388,7 +388,7 @@ void WebContextMenuProxyMac::showContextMenu()
         return;
 
     auto menu = createContextMenuFromItems(items);
-    m_menu = m_page.contextMenuClient().menuFromProposedMenu(m_page, menu.get(), m_context.webHitTestResultData());
+    m_menu = m_page.contextMenuClient().menuFromProposedMenu(m_page, menu.get(), m_context.webHitTestResultData(), m_userData.object());
 
     [[WKMenuTarget sharedMenuTarget] setMenuProxy:this];