<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[191600] trunk/Source/WebKit2</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/191600">191600</a></dd>
<dt>Author</dt> <dd>andersca@apple.com</dd>
<dt>Date</dt> <dd>2015-10-26 14:41:36 -0700 (Mon, 26 Oct 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>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):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPIAPIContextMenuClienth">trunk/Source/WebKit2/UIProcess/API/APIContextMenuClient.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessCocoaUIDelegateh">trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessCocoaUIDelegatemm">trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacWebContextMenuProxyMacmm">trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (191599 => 191600)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,23 @@
</span><ins>+2015-10-26  Anders Carlsson  &lt;andersca@apple.com&gt;
+
+        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):
+
</ins><span class="cx"> 2015-10-26  Alex Christensen  &lt;achristensen@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Build fix when using NETWORK_SESSION after r191457.
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPIAPIContextMenuClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/APIContextMenuClient.h (191599 => 191600)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -32,6 +32,8 @@
</span><span class="cx"> #include &lt;wtf/RefPtr.h&gt;
</span><span class="cx"> #include &lt;wtf/Vector.h&gt;
</span><span class="cx"> 
</span><ins>+OBJC_CLASS NSMenu;
+
</ins><span class="cx"> namespace WebCore {
</span><span class="cx"> class IntPoint;
</span><span class="cx"> }
</span><span class="lines">@@ -52,6 +54,10 @@
</span><span class="cx">     virtual void customContextMenuItemSelected(WebKit::WebPageProxy&amp;, const WebKit::WebContextMenuItemData&amp;) { }
</span><span class="cx">     virtual bool showContextMenu(WebKit::WebPageProxy&amp;, const WebCore::IntPoint&amp;, const Vector&lt;RefPtr&lt;WebKit::WebContextMenuItem&gt;&gt;&amp;) { return false; }
</span><span class="cx">     virtual bool hideContextMenu(WebKit::WebPageProxy&amp;) { return false; }
</span><ins>+
+#if PLATFORM(MAC)
+    virtual RetainPtr&lt;NSMenu&gt; menuFromProposedMenu(WebKit::WebPageProxy&amp;, NSMenu *menu, const WebKit::WebHitTestResultData&amp;) { return menu; }
+#endif
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace API
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (191599 => 191600)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -449,6 +449,9 @@
</span><span class="cx"> 
</span><span class="cx"> - (void)setUIDelegate:(id&lt;WKUIDelegate&gt;)UIDelegate
</span><span class="cx"> {
</span><ins>+#if ENABLE(CONTEXT_MENUS)
+    _page-&gt;setContextMenuClient(_uiDelegate-&gt;createContextMenuClient());
+#endif
</ins><span class="cx">     _page-&gt;setUIClient(_uiDelegate-&gt;createUIClient());
</span><span class="cx">     _uiDelegate-&gt;setDelegate(UIDelegate);
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessCocoaUIDelegateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.h (191599 => 191600)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -30,6 +30,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if WK_API_ENABLED
</span><span class="cx"> 
</span><ins>+#import &quot;APIContextMenuClient.h&quot;
</ins><span class="cx"> #import &quot;APIUIClient.h&quot;
</span><span class="cx"> #import &quot;WeakObjCPtr.h&quot;
</span><span class="cx"> #import &lt;wtf/RetainPtr.h&gt;
</span><span class="lines">@@ -45,12 +46,29 @@
</span><span class="cx">     explicit UIDelegate(WKWebView *);
</span><span class="cx">     ~UIDelegate();
</span><span class="cx"> 
</span><ins>+#if ENABLE(CONTEXT_MENUS)
+    std::unique_ptr&lt;API::ContextMenuClient&gt; createContextMenuClient();
+#endif
</ins><span class="cx">     std::unique_ptr&lt;API::UIClient&gt; createUIClient();
</span><span class="cx"> 
</span><span class="cx">     RetainPtr&lt;id &lt;WKUIDelegate&gt; &gt; delegate();
</span><span class="cx">     void setDelegate(id &lt;WKUIDelegate&gt;);
</span><span class="cx"> 
</span><span class="cx"> private:
</span><ins>+#if ENABLE(CONTEXT_MENUS)
+    class ContextMenuClient : public API::ContextMenuClient {
+    public:
+        explicit ContextMenuClient(UIDelegate&amp;);
+        ~ContextMenuClient();
+
+    private:
+        // API::ContextMenuClient
+        virtual RetainPtr&lt;NSMenu&gt; menuFromProposedMenu(WebKit::WebPageProxy&amp;, NSMenu *, const WebKit::WebHitTestResultData&amp;) override;
+
+        UIDelegate&amp; m_uiDelegate;
+    };
+#endif
+
</ins><span class="cx">     class UIClient : public API::UIClient {
</span><span class="cx">     public:
</span><span class="cx">         explicit UIClient(UIDelegate&amp;);
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessCocoaUIDelegatemm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm (191599 => 191600)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -52,6 +52,13 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if ENABLE(CONTEXT_MENUS)
+std::unique_ptr&lt;API::ContextMenuClient&gt; UIDelegate::createContextMenuClient()
+{
+    return std::make_unique&lt;ContextMenuClient&gt;(*this);
+}
+#endif
+
</ins><span class="cx"> std::unique_ptr&lt;API::UIClient&gt; UIDelegate::createUIClient()
</span><span class="cx"> {
</span><span class="cx">     return std::make_unique&lt;UIClient&gt;(*this);
</span><span class="lines">@@ -88,6 +95,25 @@
</span><span class="cx">     m_delegateMethods.webViewImageOrMediaDocumentSizeChanged = [delegate respondsToSelector:@selector(_webView:imageOrMediaDocumentSizeChanged:)];
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if ENABLE(CONTEXT_MENUS)
+UIDelegate::ContextMenuClient::ContextMenuClient(UIDelegate&amp; uiDelegate)
+    : m_uiDelegate(uiDelegate)
+{
+}
+
+UIDelegate::ContextMenuClient::~ContextMenuClient()
+{
+}
+
+RetainPtr&lt;NSMenu&gt; UIDelegate::ContextMenuClient::menuFromProposedMenu(WebKit::WebPageProxy&amp;, NSMenu *menu, const WebKit::WebHitTestResultData&amp;)
+{
+    // FIXME: Call the UI delegate.
+    (void)m_uiDelegate;
+
+    return menu;
+}
+#endif
+
</ins><span class="cx"> UIDelegate::UIClient::UIClient(UIDelegate&amp; uiDelegate)
</span><span class="cx">     : m_uiDelegate(uiDelegate)
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacWebContextMenuProxyMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm (191599 => 191600)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -367,6 +367,7 @@
</span><span class="cx">     Vector&lt;RefPtr&lt;WebContextMenuItem&gt;&gt; clientItems;
</span><span class="cx">     bool useProposedItems = true;
</span><span class="cx"> 
</span><ins>+    // FIXME: Get rid of this once we don't need the C SPI.
</ins><span class="cx">     if (m_page.contextMenuClient().getContextMenuFromProposedMenu(m_page, proposedAPIItems, clientItems, m_context.webHitTestResultData(), m_page.process().transformHandlesToObjects(m_userData.object()).get()))
</span><span class="cx">         useProposedItems = false;
</span><span class="cx"> 
</span><span class="lines">@@ -377,7 +378,8 @@
</span><span class="cx">     if (items.isEmpty())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    m_menu = createContextMenuFromItems(items);
</del><ins>+    auto menu = createContextMenuFromItems(items);
+    m_menu = m_page.contextMenuClient().menuFromProposedMenu(m_page, menu.get(), m_context.webHitTestResultData());
</ins><span class="cx"> 
</span><span class="cx">     [[WKMenuTarget sharedMenuTarget] setMenuProxy:this];
</span><span class="cx">     [m_menu popUpMenuPositioningItem:nil atLocation:m_context.menuLocation() inView:m_webView];
</span></span></pre>
</div>
</div>

</body>
</html>