<!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>[165856] 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/165856">165856</a></dd>
<dt>Author</dt> <dd>beidson@apple.com</dd>
<dt>Date</dt> <dd>2014-03-18 16:54:30 -0700 (Tue, 18 Mar 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Make image controls menu work in WK2
&lt;rdar://problem/16294412&gt; and https://bugs.webkit.org/show_bug.cgi?id=130424

Reviewed by Tim Horton.

* Platform/SharedMemory.h:
* Platform/mac/SharedMemoryMac.cpp:
(WebKit::SharedMemory::Handle::~Handle):
(WebKit::SharedMemory::Handle::clear):

* Platform/unix/SharedMemoryUnix.cpp:
(WebKit::SharedMemory::Handle::~Handle):
(WebKit::SharedMemory::Handle::clear):

* Shared/ContextMenuContextData.cpp:
(WebKit::ContextMenuContextData::ContextMenuContextData):
(WebKit::ContextMenuContextData::operator=):
(WebKit::ContextMenuContextData::encode):
(WebKit::ContextMenuContextData::decode):
* Shared/ContextMenuContextData.h:
(WebKit::ContextMenuContextData::controlledImageHandle):

* Shared/ShareableBitmap.cpp:
(WebKit::ShareableBitmap::Handle::clear):
* Shared/ShareableBitmap.h:
* UIProcess/WebContextMenuProxy.h:

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::internalShowContextMenu):
(WebKit::WebPageProxy::replaceControlledImage):
* UIProcess/WebPageProxy.h:

* UIProcess/efl/WebContextMenuProxyEfl.cpp:
(WebKit::WebContextMenuProxyEfl::showContextMenu):
* UIProcess/efl/WebContextMenuProxyEfl.h:

* UIProcess/gtk/WebContextMenuProxyGtk.cpp:
(WebKit::WebContextMenuProxyGtk::showContextMenu):
* UIProcess/gtk/WebContextMenuProxyGtk.h:

Add a sharing service context menu that lives side-by-side with the normal one:
* UIProcess/mac/WebContextMenuProxyMac.h:
* UIProcess/mac/WebContextMenuProxyMac.mm:
(+[WKSharingServicePickerDelegate sharedSharingServicePickerDelegate]):
(-[WKSharingServicePickerDelegate setMenuProxy:WebKit::]):
(-[WKSharingServicePickerDelegate setPicker:]):
(-[WKSharingServicePickerDelegate sharingServicePicker:delegateForSharingService:]):
(-[WKSharingServicePickerDelegate sharingService:willShareItems:]):
(-[WKSharingServicePickerDelegate sharingService:didShareItems:]):
(-[WKSharingServicePickerDelegate sharingService:sourceFrameOnScreenForShareItem:]):
(-[WKSharingServicePickerDelegate sharingService:transitionImageForShareItem:contentRect:]):
(-[WKSharingServicePickerDelegate sharingService:sourceWindowForShareItems:sharingContentScope:]):
(WebKit::WebContextMenuProxyMac::contextMenuItemSelected):
(WebKit::WebContextMenuProxyMac::setupImageServicesMenu):
(WebKit::WebContextMenuProxyMac::clearImageServicesMenu):
(WebKit::WebContextMenuProxyMac::populate):
(WebKit::WebContextMenuProxyMac::showContextMenu):
(WebKit::WebContextMenuProxyMac::window):
(WebKit::WebContextMenuProxyMac::replaceControlledImage):

* WebProcess/WebPage/WebContextMenu.cpp:
(WebKit::WebContextMenu::show):
(WebKit::WebContextMenu::replaceControlledImage):
* WebProcess/WebPage/WebContextMenu.h:

Teach the WebProcess how to accept the replaced image.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::replaceControlledImage):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2PlatformSharedMemoryh">trunk/Source/WebKit2/Platform/SharedMemory.h</a></li>
<li><a href="#trunkSourceWebKit2PlatformmacSharedMemoryMaccpp">trunk/Source/WebKit2/Platform/mac/SharedMemoryMac.cpp</a></li>
<li><a href="#trunkSourceWebKit2PlatformunixSharedMemoryUnixcpp">trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp</a></li>
<li><a href="#trunkSourceWebKit2SharedContextMenuContextDatacpp">trunk/Source/WebKit2/Shared/ContextMenuContextData.cpp</a></li>
<li><a href="#trunkSourceWebKit2SharedContextMenuContextDatah">trunk/Source/WebKit2/Shared/ContextMenuContextData.h</a></li>
<li><a href="#trunkSourceWebKit2SharedShareableBitmapcpp">trunk/Source/WebKit2/Shared/ShareableBitmap.cpp</a></li>
<li><a href="#trunkSourceWebKit2SharedShareableBitmaph">trunk/Source/WebKit2/Shared/ShareableBitmap.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebContextMenuProxyh">trunk/Source/WebKit2/UIProcess/WebContextMenuProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxycpp">trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxyh">trunk/Source/WebKit2/UIProcess/WebPageProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcesseflWebContextMenuProxyEflcpp">trunk/Source/WebKit2/UIProcess/efl/WebContextMenuProxyEfl.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcesseflWebContextMenuProxyEflh">trunk/Source/WebKit2/UIProcess/efl/WebContextMenuProxyEfl.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessgtkWebContextMenuProxyGtkcpp">trunk/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessgtkWebContextMenuProxyGtkh">trunk/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacWebContextMenuProxyMach">trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacWebContextMenuProxyMacmm">trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebContextMenucpp">trunk/Source/WebKit2/WebProcess/WebPage/WebContextMenu.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebContextMenuh">trunk/Source/WebKit2/WebProcess/WebPage/WebContextMenu.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPagecpp">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPageh">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPagemessagesin">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/ChangeLog        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -1,3 +1,76 @@
</span><ins>+2014-03-18  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        Make image controls menu work in WK2
+        &lt;rdar://problem/16294412&gt; and https://bugs.webkit.org/show_bug.cgi?id=130424
+
+        Reviewed by Tim Horton.
+
+        * Platform/SharedMemory.h:
+        * Platform/mac/SharedMemoryMac.cpp:
+        (WebKit::SharedMemory::Handle::~Handle):
+        (WebKit::SharedMemory::Handle::clear):
+
+        * Platform/unix/SharedMemoryUnix.cpp:
+        (WebKit::SharedMemory::Handle::~Handle):
+        (WebKit::SharedMemory::Handle::clear):
+
+        * Shared/ContextMenuContextData.cpp:
+        (WebKit::ContextMenuContextData::ContextMenuContextData):
+        (WebKit::ContextMenuContextData::operator=):
+        (WebKit::ContextMenuContextData::encode):
+        (WebKit::ContextMenuContextData::decode):
+        * Shared/ContextMenuContextData.h:
+        (WebKit::ContextMenuContextData::controlledImageHandle):
+
+        * Shared/ShareableBitmap.cpp:
+        (WebKit::ShareableBitmap::Handle::clear):
+        * Shared/ShareableBitmap.h:
+        * UIProcess/WebContextMenuProxy.h:
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::internalShowContextMenu):
+        (WebKit::WebPageProxy::replaceControlledImage):
+        * UIProcess/WebPageProxy.h:
+
+        * UIProcess/efl/WebContextMenuProxyEfl.cpp:
+        (WebKit::WebContextMenuProxyEfl::showContextMenu):
+        * UIProcess/efl/WebContextMenuProxyEfl.h:
+
+        * UIProcess/gtk/WebContextMenuProxyGtk.cpp:
+        (WebKit::WebContextMenuProxyGtk::showContextMenu):
+        * UIProcess/gtk/WebContextMenuProxyGtk.h:
+
+        Add a sharing service context menu that lives side-by-side with the normal one:
+        * UIProcess/mac/WebContextMenuProxyMac.h:
+        * UIProcess/mac/WebContextMenuProxyMac.mm:
+        (+[WKSharingServicePickerDelegate sharedSharingServicePickerDelegate]):
+        (-[WKSharingServicePickerDelegate setMenuProxy:WebKit::]):
+        (-[WKSharingServicePickerDelegate setPicker:]):
+        (-[WKSharingServicePickerDelegate sharingServicePicker:delegateForSharingService:]):
+        (-[WKSharingServicePickerDelegate sharingService:willShareItems:]):
+        (-[WKSharingServicePickerDelegate sharingService:didShareItems:]):
+        (-[WKSharingServicePickerDelegate sharingService:sourceFrameOnScreenForShareItem:]):
+        (-[WKSharingServicePickerDelegate sharingService:transitionImageForShareItem:contentRect:]):
+        (-[WKSharingServicePickerDelegate sharingService:sourceWindowForShareItems:sharingContentScope:]):
+        (WebKit::WebContextMenuProxyMac::contextMenuItemSelected):
+        (WebKit::WebContextMenuProxyMac::setupImageServicesMenu):
+        (WebKit::WebContextMenuProxyMac::clearImageServicesMenu):
+        (WebKit::WebContextMenuProxyMac::populate):
+        (WebKit::WebContextMenuProxyMac::showContextMenu):
+        (WebKit::WebContextMenuProxyMac::window):
+        (WebKit::WebContextMenuProxyMac::replaceControlledImage):
+
+        * WebProcess/WebPage/WebContextMenu.cpp:
+        (WebKit::WebContextMenu::show):
+        (WebKit::WebContextMenu::replaceControlledImage):
+        * WebProcess/WebPage/WebContextMenu.h:
+
+        Teach the WebProcess how to accept the replaced image.
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::replaceControlledImage):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
</ins><span class="cx"> 2014-03-18  Anders Carlsson  &lt;andersca@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Begin cleaning up KeyedDecoder and KeyedEncoder
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformSharedMemoryh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/SharedMemory.h (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/SharedMemory.h        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/Platform/SharedMemory.h        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -57,6 +57,8 @@
</span><span class="cx"> 
</span><span class="cx">         bool isNull() const;
</span><span class="cx"> 
</span><ins>+        void clear();
+
</ins><span class="cx">         void encode(IPC::ArgumentEncoder&amp;) const;
</span><span class="cx">         static bool decode(IPC::ArgumentDecoder&amp;, Handle&amp;);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformmacSharedMemoryMaccpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/mac/SharedMemoryMac.cpp (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/mac/SharedMemoryMac.cpp        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/Platform/mac/SharedMemoryMac.cpp        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -46,8 +46,7 @@
</span><span class="cx"> 
</span><span class="cx"> SharedMemory::Handle::~Handle()
</span><span class="cx"> {
</span><del>-    if (m_port)
-        mach_port_deallocate(mach_task_self(), m_port);
</del><ins>+    clear();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool SharedMemory::Handle::isNull() const
</span><span class="lines">@@ -55,6 +54,15 @@
</span><span class="cx">     return !m_port;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void SharedMemory::Handle::clear()
+{
+    if (m_port)
+        mach_port_deallocate(mach_task_self(), m_port);
+
+    m_port = MACH_PORT_NULL;
+    m_size = 0;
+}
+
</ins><span class="cx"> void SharedMemory::Handle::encode(IPC::ArgumentEncoder&amp; encoder) const
</span><span class="cx"> {
</span><span class="cx">     encoder &lt;&lt; static_cast&lt;uint64_t&gt;(m_size);
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformunixSharedMemoryUnixcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -54,6 +54,11 @@
</span><span class="cx"> 
</span><span class="cx"> SharedMemory::Handle::~Handle()
</span><span class="cx"> {
</span><ins>+    clear();
+}
+
+void SharedMemory::Handle::clear()
+{
</ins><span class="cx">     if (!isNull())
</span><span class="cx">         closeWithRetry(m_fileDescriptor);
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedContextMenuContextDatacpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/ContextMenuContextData.cpp (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/ContextMenuContextData.cpp        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/Shared/ContextMenuContextData.cpp        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -31,31 +31,55 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;WebCoreArgumentCoders.h&quot;
</span><span class="cx"> #include &lt;WebCore/ContextMenuContext.h&gt;
</span><ins>+#include &lt;WebCore/GraphicsContext.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> using namespace WebCore;
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><span class="cx"> ContextMenuContextData::ContextMenuContextData()
</span><del>-#if ENABLE(IMAGE_CONTROLS)
-    : m_isImageControl(false)
-#endif
</del><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> ContextMenuContextData::ContextMenuContextData(const ContextMenuContext&amp; context)
</span><span class="cx">     : m_webHitTestResultData(WebHitTestResult::Data(context.hitTestResult()))
</span><ins>+{
</ins><span class="cx"> #if ENABLE(IMAGE_CONTROLS)
</span><del>-    , m_isImageControl(context.controlledImage())
</del><ins>+    Image* image = context.controlledImage();
+    if (!image)
+        return;
+
+    RefPtr&lt;ShareableBitmap&gt; bitmap = ShareableBitmap::createShareable(image-&gt;size(), ShareableBitmap::SupportsAlpha);
+    bitmap-&gt;createGraphicsContext()-&gt;drawImage(image, ColorSpaceDeviceRGB, IntPoint());
+    bitmap-&gt;createHandle(m_controlledImageHandle);
</ins><span class="cx"> #endif
</span><ins>+}
+
+ContextMenuContextData::ContextMenuContextData(const ContextMenuContextData&amp; other)
</ins><span class="cx"> {
</span><ins>+    *this = other;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+ContextMenuContextData&amp; ContextMenuContextData::operator=(const ContextMenuContextData&amp; other)
+{
+    m_webHitTestResultData = other.m_webHitTestResultData;
+#if ENABLE(IMAGE_CONTROLS)
+    m_controlledImageHandle.clear();
+
+    if (!other.m_controlledImageHandle.isNull()) {
+        RefPtr&lt;ShareableBitmap&gt; bitmap = ShareableBitmap::create(other.m_controlledImageHandle);
+        bitmap-&gt;createHandle(m_controlledImageHandle);
+    }
+#endif
+
+    return *this;
+}
+
</ins><span class="cx"> void ContextMenuContextData::encode(IPC::ArgumentEncoder&amp; encoder) const
</span><span class="cx"> {
</span><span class="cx">     encoder &lt;&lt; m_webHitTestResultData;
</span><span class="cx"> #if ENABLE(IMAGE_CONTROLS)
</span><del>-    encoder &lt;&lt; m_isImageControl;
</del><ins>+    encoder &lt;&lt; m_controlledImageHandle;
</ins><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -65,7 +89,7 @@
</span><span class="cx">         return false;
</span><span class="cx">         
</span><span class="cx"> #if ENABLE(IMAGE_CONTROLS)
</span><del>-    if (!decoder.decode(contextMenuContextData.m_isImageControl))
</del><ins>+    if (!decoder.decode(contextMenuContextData.m_controlledImageHandle))
</ins><span class="cx">         return false;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedContextMenuContextDatah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/ContextMenuContextData.h (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/ContextMenuContextData.h        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/Shared/ContextMenuContextData.h        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -29,6 +29,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(CONTEXT_MENUS)
</span><span class="cx"> 
</span><ins>+#include &quot;ShareableBitmap.h&quot;
</ins><span class="cx"> #include &quot;WebHitTestResult.h&quot;
</span><span class="cx"> 
</span><span class="cx"> namespace IPC {
</span><span class="lines">@@ -46,11 +47,14 @@
</span><span class="cx"> public:
</span><span class="cx">     ContextMenuContextData();
</span><span class="cx">     ContextMenuContextData(const WebCore::ContextMenuContext&amp;);
</span><ins>+
+    ContextMenuContextData(const ContextMenuContextData&amp;);
+    ContextMenuContextData&amp; operator=(const ContextMenuContextData&amp;);
</ins><span class="cx">     
</span><span class="cx">     const WebHitTestResult::Data&amp; webHitTestResultData() const { return m_webHitTestResultData; }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(IMAGE_CONTROLS)
</span><del>-    bool isImageControl() const { return m_isImageControl; }
</del><ins>+    const ShareableBitmap::Handle&amp; controlledImageHandle() const { return m_controlledImageHandle; }
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     void encode(IPC::ArgumentEncoder&amp;) const;
</span><span class="lines">@@ -61,7 +65,7 @@
</span><span class="cx">     WebHitTestResult::Data m_webHitTestResultData;
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(IMAGE_CONTROLS)
</span><del>-    bool m_isImageControl;
</del><ins>+    ShareableBitmap::Handle m_controlledImageHandle;
</ins><span class="cx"> #endif
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedShareableBitmapcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/ShareableBitmap.cpp (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/ShareableBitmap.cpp        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/Shared/ShareableBitmap.cpp        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -57,6 +57,13 @@
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void ShareableBitmap::Handle::clear()
+{
+    m_handle.clear();
+    m_size = IntSize();
+    m_flags = Flag::NoFlags;
+}
+
</ins><span class="cx"> PassRefPtr&lt;ShareableBitmap&gt; ShareableBitmap::create(const IntSize&amp; size, Flags flags)
</span><span class="cx"> {
</span><span class="cx">     size_t numBytes = numBytesForSize(size);
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedShareableBitmaph"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/ShareableBitmap.h (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/ShareableBitmap.h        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/Shared/ShareableBitmap.h        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -63,6 +63,8 @@
</span><span class="cx"> 
</span><span class="cx">         bool isNull() const { return m_handle.isNull(); }
</span><span class="cx"> 
</span><ins>+        void clear();
+
</ins><span class="cx">         void encode(IPC::ArgumentEncoder&amp;) const;
</span><span class="cx">         static bool decode(IPC::ArgumentDecoder&amp;, Handle&amp;);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebContextMenuProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebContextMenuProxy.h (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebContextMenuProxy.h        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/UIProcess/WebContextMenuProxy.h        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -36,13 +36,14 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><ins>+class ContextMenuContextData;
</ins><span class="cx"> class WebContextMenuItemData;
</span><span class="cx"> 
</span><span class="cx"> class WebContextMenuProxy : public RefCounted&lt;WebContextMenuProxy&gt; {
</span><span class="cx"> public:
</span><span class="cx">     virtual ~WebContextMenuProxy();
</span><span class="cx"> 
</span><del>-    virtual void showContextMenu(const WebCore::IntPoint&amp;, const Vector&lt;WebContextMenuItemData&gt;&amp; items) = 0;
</del><ins>+    virtual void showContextMenu(const WebCore::IntPoint&amp;, const Vector&lt;WebContextMenuItemData&gt;&amp;, const ContextMenuContextData&amp;) = 0;
</ins><span class="cx">     virtual void hideContextMenu() = 0;
</span><span class="cx"> 
</span><span class="cx"> protected:
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -3309,22 +3309,32 @@
</span><span class="cx">     // Unless this is an image control, give the PageContextMenuClient one last swipe at changing the menu.
</span><span class="cx">     Vector&lt;WebContextMenuItemData&gt; items;
</span><span class="cx">     bool useProposedItems = true;
</span><del>-
</del><ins>+    bool askClientToChangeMenu = true;
</ins><span class="cx"> #if ENABLE(IMAGE_CONTROLS)
</span><del>-    if (!contextMenuContextData.isImageControl() &amp;&amp; m_contextMenuClient.getContextMenuFromProposedMenu(this, proposedItems, items, contextMenuContextData.webHitTestResultData(), userData.get())) {
-#else
-    if (m_contextMenuClient.getContextMenuFromProposedMenu(this, proposedItems, items, contextMenuContextData.webHitTestResultData(), userData.get())) {
</del><ins>+    if (!contextMenuContextData.controlledImageHandle().isNull())
+        askClientToChangeMenu = false;
</ins><span class="cx"> #endif
</span><ins>+
+    if (askClientToChangeMenu &amp;&amp; m_contextMenuClient.getContextMenuFromProposedMenu(this, proposedItems, items, contextMenuContextData.webHitTestResultData(), userData.get()))
</ins><span class="cx">         useProposedItems = false;
</span><del>-    }
</del><span class="cx">     
</span><span class="cx">     const Vector&lt;WebContextMenuItemData&gt;&amp; itemsToShow = useProposedItems ? proposedItems : items;
</span><span class="cx">     if (!m_contextMenuClient.showContextMenu(this, menuLocation, itemsToShow))
</span><del>-        m_activeContextMenu-&gt;showContextMenu(menuLocation, itemsToShow);
-    
</del><ins>+        m_activeContextMenu-&gt;showContextMenu(menuLocation, itemsToShow, contextMenuContextData);
+
</ins><span class="cx">     m_contextMenuClient.contextMenuDismissed(this);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+void WebPageProxy::replaceControlledImage(PassRefPtr&lt;ShareableBitmap&gt; newBitmap)
+{
+    RefPtr&lt;ShareableBitmap&gt; bitmap = newBitmap;
+    ShareableBitmap::Handle bitmapHandle;
+    bitmap-&gt;createHandle(bitmapHandle);
+    m_process-&gt;send(Messages::WebPage::ReplaceControlledImage(bitmapHandle), m_pageID);
+}
+#endif
+
</ins><span class="cx"> void WebPageProxy::contextMenuItemSelected(const WebContextMenuItemData&amp; item)
</span><span class="cx"> {
</span><span class="cx">     // Application custom items don't need to round-trip through to WebCore in the WebProcess.
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -925,6 +925,10 @@
</span><span class="cx"> 
</span><span class="cx">     void takeThumbnailSnapshot(ImageCallback::CallbackFunction);
</span><span class="cx"> 
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+    void replaceControlledImage(PassRefPtr&lt;ShareableBitmap&gt;);
+#endif
+
</ins><span class="cx"> private:
</span><span class="cx">     WebPageProxy(PageClient&amp;, WebProcessProxy&amp;, uint64_t pageID, const WebPageConfiguration&amp;);
</span><span class="cx">     void platformInitialize();
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcesseflWebContextMenuProxyEflcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/efl/WebContextMenuProxyEfl.cpp (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/efl/WebContextMenuProxyEfl.cpp        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/UIProcess/efl/WebContextMenuProxyEfl.cpp        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -47,7 +47,7 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebContextMenuProxyEfl::showContextMenu(const WebCore::IntPoint&amp;, const Vector&lt;WebContextMenuItemData&gt;&amp;)
</del><ins>+void WebContextMenuProxyEfl::showContextMenu(const WebCore::IntPoint&amp;, const Vector&lt;WebContextMenuItemData&gt;&amp;, const ContextMenuContextData&amp;)
</ins><span class="cx"> {
</span><span class="cx">     notImplemented();
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcesseflWebContextMenuProxyEflh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/efl/WebContextMenuProxyEfl.h (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/efl/WebContextMenuProxyEfl.h        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/UIProcess/efl/WebContextMenuProxyEfl.h        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -48,7 +48,7 @@
</span><span class="cx"> 
</span><span class="cx">     ~WebContextMenuProxyEfl();
</span><span class="cx"> 
</span><del>-    void showContextMenu(const WebCore::IntPoint&amp;, const Vector&lt;WebContextMenuItemData&gt;&amp;);
</del><ins>+    void showContextMenu(const WebCore::IntPoint&amp;, const Vector&lt;WebContextMenuItemData&gt;&amp;, const ContextMenuContextData&amp;);
</ins><span class="cx">     void hideContextMenu();
</span><span class="cx"> 
</span><span class="cx"> private:
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessgtkWebContextMenuProxyGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.cpp (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.cpp        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.cpp        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -138,7 +138,7 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebContextMenuProxyGtk::showContextMenu(const WebCore::IntPoint&amp; position, const Vector&lt;WebContextMenuItemData&gt;&amp; items)
</del><ins>+void WebContextMenuProxyGtk::showContextMenu(const WebCore::IntPoint&amp; position, const Vector&lt;WebContextMenuItemData&gt;&amp; items, const ContextMenuContextData&amp;)
</ins><span class="cx"> {
</span><span class="cx">     if (!items.isEmpty())
</span><span class="cx">         populate(items);
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessgtkWebContextMenuProxyGtkh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.h (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.h        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.h        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -46,7 +46,7 @@
</span><span class="cx">     }
</span><span class="cx">     ~WebContextMenuProxyGtk();
</span><span class="cx"> 
</span><del>-    virtual void showContextMenu(const WebCore::IntPoint&amp;, const Vector&lt;WebContextMenuItemData&gt;&amp;);
</del><ins>+    virtual void showContextMenu(const WebCore::IntPoint&amp;, const Vector&lt;WebContextMenuItemData&gt;&amp;, const ContextMenuContextData&amp;);
</ins><span class="cx">     virtual void hideContextMenu();
</span><span class="cx"> 
</span><span class="cx">     void populate(Vector&lt;WebCore::ContextMenuItem&gt;&amp;);
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacWebContextMenuProxyMach"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.h (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.h        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.h        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -32,10 +32,12 @@
</span><span class="cx"> #include &lt;wtf/RetainPtr.h&gt;
</span><span class="cx"> 
</span><span class="cx"> OBJC_CLASS NSPopUpButtonCell;
</span><ins>+OBJC_CLASS NSWindow;
</ins><span class="cx"> OBJC_CLASS WKView;
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><ins>+class ShareableBitmap;
</ins><span class="cx"> class WebPageProxy;
</span><span class="cx"> 
</span><span class="cx"> class WebContextMenuProxyMac : public WebContextMenuProxy {
</span><span class="lines">@@ -46,17 +48,31 @@
</span><span class="cx">     }
</span><span class="cx">     ~WebContextMenuProxyMac();
</span><span class="cx"> 
</span><del>-    virtual void showContextMenu(const WebCore::IntPoint&amp;, const Vector&lt;WebContextMenuItemData&gt;&amp;);
-    virtual void hideContextMenu();
</del><ins>+    virtual void showContextMenu(const WebCore::IntPoint&amp;, const Vector&lt;WebContextMenuItemData&gt;&amp;, const ContextMenuContextData&amp;) override;
+    virtual void hideContextMenu() override;
</ins><span class="cx">     
</span><span class="cx">     void contextMenuItemSelected(const WebContextMenuItemData&amp;);
</span><span class="cx"> 
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+    void clearImageServicesMenu();
+    void replaceControlledImage(CGImageRef newImage);
+#endif
+
+    NSWindow *window() const;
+
</ins><span class="cx"> private:
</span><span class="cx">     WebContextMenuProxyMac(WKView*, WebPageProxy*);
</span><span class="cx"> 
</span><del>-    void populate(const Vector&lt;WebContextMenuItemData&gt;&amp;);
</del><ins>+    void populate(const Vector&lt;WebContextMenuItemData&gt;&amp;, const ContextMenuContextData&amp;);
</ins><span class="cx"> 
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+    void setupImageServicesMenu(ShareableBitmap&amp;);
+#endif
+
</ins><span class="cx">     RetainPtr&lt;NSPopUpButtonCell&gt; m_popup;
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+    RetainPtr&lt;NSMenu&gt; m_servicesMenu;
+#endif
</ins><span class="cx">     WKView* m_webView;
</span><span class="cx">     WebPageProxy* m_page;
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacWebContextMenuProxyMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -29,12 +29,35 @@
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx"> 
</span><span class="cx"> #import &quot;PageClientImpl.h&quot;
</span><ins>+#import &quot;ShareableBitmap.h&quot;
</ins><span class="cx"> #import &quot;StringUtilities.h&quot;
</span><span class="cx"> #import &quot;WebContextMenuItemData.h&quot;
</span><span class="cx"> #import &quot;WKView.h&quot;
</span><ins>+#import &lt;WebCore/GraphicsContext.h&gt;
</ins><span class="cx"> #import &lt;WebCore/IntRect.h&gt;
</span><ins>+#import &lt;WebCore/NotImplemented.h&gt;
</ins><span class="cx"> #import &lt;WebKitSystemInterface.h&gt;
</span><ins>+#import &lt;wtf/RetainPtr.h&gt;
</ins><span class="cx"> 
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+#import &lt;AppKit/NSSharingService.h&gt;
+
+#if __has_include(&lt;AppKit/NSSharingService_Private.h&gt;)
+#import &lt;AppKit/NSSharingService_Private.h&gt;
+#else
+typedef enum {
+    NSSharingServicePickerStyleMenu = 0,
+    NSSharingServicePickerStyleRollover = 1,
+    NSSharingServicePickerStyleTextSelection = 2
+} NSSharingServicePickerStyle;
+#endif
+
+@interface NSSharingServicePicker (Details)
+@property NSSharingServicePickerStyle style;
+- (NSMenu *)menu;
+@end
+#endif
+
</ins><span class="cx"> using namespace WebCore;
</span><span class="cx"> 
</span><span class="cx"> @interface WKUserDataWrapper : NSObject {
</span><span class="lines">@@ -66,7 +89,7 @@
</span><span class="cx"> @interface WKMenuTarget : NSObject {
</span><span class="cx">     WebKit::WebContextMenuProxyMac* _menuProxy;
</span><span class="cx"> }
</span><del>-+ (WKMenuTarget*)sharedMenuTarget;
</del><ins>++ (WKMenuTarget *)sharedMenuTarget;
</ins><span class="cx"> - (WebKit::WebContextMenuProxyMac*)menuProxy;
</span><span class="cx"> - (void)setMenuProxy:(WebKit::WebContextMenuProxyMac*)menuProxy;
</span><span class="cx"> - (void)forwardContextMenuAction:(id)sender;
</span><span class="lines">@@ -104,6 +127,67 @@
</span><span class="cx"> 
</span><span class="cx"> @end
</span><span class="cx"> 
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+@interface WKSharingServicePickerDelegate : NSObject &lt;NSSharingServiceDelegate, NSSharingServicePickerDelegate&gt; {
+    WebKit::WebContextMenuProxyMac* _menuProxy;
+    RetainPtr&lt;NSSharingServicePicker&gt; _picker;
+}
+
++ (WKSharingServicePickerDelegate *)sharedSharingServicePickerDelegate;
+- (WebKit::WebContextMenuProxyMac*)menuProxy;
+- (void)setMenuProxy:(WebKit::WebContextMenuProxyMac*)menuProxy;
+- (void)setPicker:(NSSharingServicePicker *)picker;
+@end
+
+// FIXME: We probably need to hang on the picker itself until the context menu operation is done, and this object will probably do that.
+@implementation WKSharingServicePickerDelegate
++ (WKSharingServicePickerDelegate*)sharedSharingServicePickerDelegate
+{
+    static WKSharingServicePickerDelegate* delegate = [[WKSharingServicePickerDelegate alloc] init];
+    return delegate;
+}
+
+- (WebKit::WebContextMenuProxyMac*)menuProxy
+{
+    return _menuProxy;
+}
+
+- (void)setMenuProxy:(WebKit::WebContextMenuProxyMac*)menuProxy
+{
+    _menuProxy = menuProxy;
+}
+
+- (void)setPicker:(NSSharingServicePicker *)picker
+{
+    _picker = picker;
+}
+
+- (id &lt;NSSharingServiceDelegate&gt;)sharingServicePicker:(NSSharingServicePicker *)sharingServicePicker delegateForSharingService:(NSSharingService *)sharingService
+{
+    return self;
+}
+
+- (void)sharingService:(NSSharingService *)sharingService willShareItems:(NSArray *)items
+{
+    _menuProxy-&gt;clearImageServicesMenu();
+}
+
+- (void)sharingService:(NSSharingService *)sharingService didShareItems:(NSArray *)items
+{
+    RetainPtr&lt;CGImageSourceRef&gt; source = adoptCF(CGImageSourceCreateWithData((CFDataRef)[items objectAtIndex:0], NULL));
+    RetainPtr&lt;CGImageRef&gt; image = adoptCF(CGImageSourceCreateImageAtIndex(source.get(), 0, NULL));
+    _menuProxy-&gt;replaceControlledImage(image.get());
+}
+
+- (NSWindow *)sharingService:(NSSharingService *)sharingService sourceWindowForShareItems:(NSArray *)items sharingContentScope:(NSSharingContentScope *)sharingContentScope
+{
+    return _menuProxy-&gt;window();
+}
+
+@end
+
+#endif
+
</ins><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><span class="cx"> WebContextMenuProxyMac::WebContextMenuProxyMac(WKView* webView, WebPageProxy* page)
</span><span class="lines">@@ -120,6 +204,10 @@
</span><span class="cx"> 
</span><span class="cx"> void WebContextMenuProxyMac::contextMenuItemSelected(const WebContextMenuItemData&amp; item)
</span><span class="cx"> {
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+    clearImageServicesMenu();
+#endif
+
</ins><span class="cx">     m_page-&gt;contextMenuItemSelected(item);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -185,8 +273,36 @@
</span><span class="cx">     return result;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebContextMenuProxyMac::populate(const Vector&lt;WebContextMenuItemData&gt;&amp; items)
</del><ins>+#if ENABLE(IMAGE_CONTROLS)
+void WebContextMenuProxyMac::setupImageServicesMenu(ShareableBitmap&amp; image)
</ins><span class="cx"> {
</span><ins>+    RetainPtr&lt;CGImageRef&gt; cgImage = image.makeCGImage();
+    RetainPtr&lt;NSImage&gt; nsImage = adoptNS([[NSImage alloc] initWithCGImage:cgImage.get() size:image.size()]);
+
+    RetainPtr&lt;NSSharingServicePicker&gt; picker = adoptNS([[NSSharingServicePicker alloc] initWithItems:@[ nsImage.get() ]]);
+    [picker setStyle:NSSharingServicePickerStyleRollover];
+    [picker setDelegate:[WKSharingServicePickerDelegate sharedSharingServicePickerDelegate]];
+    [[WKSharingServicePickerDelegate sharedSharingServicePickerDelegate] setPicker:picker.get()];
+
+    m_servicesMenu = [picker menu];
+}
+
+void WebContextMenuProxyMac::clearImageServicesMenu()
+{
+    [[WKSharingServicePickerDelegate sharedSharingServicePickerDelegate] setPicker:nullptr];
+    m_servicesMenu = nullptr;
+}
+#endif
+
+void WebContextMenuProxyMac::populate(const Vector&lt;WebContextMenuItemData&gt;&amp; items, const ContextMenuContextData&amp; context)
+{
+#if ENABLE(IMAGE_CONTROLS)
+    if (RefPtr&lt;ShareableBitmap&gt; image = ShareableBitmap::create(context.controlledImageHandle())) {
+        setupImageServicesMenu(*image);
+        return;
+    }
+#endif
+
</ins><span class="cx">     if (m_popup)
</span><span class="cx">         [m_popup removeAllItems];
</span><span class="cx">     else {
</span><span class="lines">@@ -199,22 +315,38 @@
</span><span class="cx">     populateNSMenu(menu, nsMenuItemVector(items));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebContextMenuProxyMac::showContextMenu(const IntPoint&amp; menuLocation, const Vector&lt;WebContextMenuItemData&gt;&amp; items)
</del><ins>+void WebContextMenuProxyMac::showContextMenu(const IntPoint&amp; menuLocation, const Vector&lt;WebContextMenuItemData&gt;&amp; items, const ContextMenuContextData&amp; context)
</ins><span class="cx"> {
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+    if (items.isEmpty() &amp;&amp; context.controlledImageHandle().isNull())
+        return;
+#else
</ins><span class="cx">     if (items.isEmpty())
</span><span class="cx">         return;
</span><del>-    
-    populate(items);
</del><ins>+#endif
+
+    populate(items, context);
+
</ins><span class="cx">     [[WKMenuTarget sharedMenuTarget] setMenuProxy:this];
</span><del>-    
</del><ins>+
</ins><span class="cx">     NSRect menuRect = NSMakeRect(menuLocation.x(), menuLocation.y(), 0, 0);
</span><del>-    
</del><ins>+
+#if ENABLE(IMAGE_CONTROLS)
+    if (!context.controlledImageHandle().isNull())
+        [[WKSharingServicePickerDelegate sharedSharingServicePickerDelegate] setMenuProxy:this];
+
+    if (!m_servicesMenu)
+        [m_popup attachPopUpWithFrame:menuRect inView:m_webView];
+
+    NSMenu *menu = m_servicesMenu ? m_servicesMenu.get() : [m_popup menu];
+#else
</ins><span class="cx">     [m_popup attachPopUpWithFrame:menuRect inView:m_webView];
</span><span class="cx"> 
</span><del>-    NSMenu* menu = [m_popup menu];
</del><ins>+    NSMenu *menu = [m_popup menu];
+#endif
</ins><span class="cx"> 
</span><span class="cx">     // These values were borrowed from AppKit to match their placement of the menu.
</span><del>-    NSRect titleFrame = [m_popup  titleRectForBounds:menuRect];
</del><ins>+    NSRect titleFrame = [m_popup titleRectForBounds:menuRect];
</ins><span class="cx">     if (titleFrame.size.width &lt;= 0 || titleFrame.size.height &lt;= 0)
</span><span class="cx">         titleFrame = menuRect;
</span><span class="cx">     float vertOffset = roundf((NSMaxY(menuRect) - NSMaxY(titleFrame)) + NSHeight(titleFrame));
</span><span class="lines">@@ -228,7 +360,7 @@
</span><span class="cx"> 
</span><span class="cx">     WKPopupContextMenu(menu, location);
</span><span class="cx"> 
</span><del>-    [m_popup dismissPopUp];
</del><ins>+    hideContextMenu();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebContextMenuProxyMac::hideContextMenu()
</span><span class="lines">@@ -236,6 +368,22 @@
</span><span class="cx">     [m_popup dismissPopUp];
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+NSWindow *WebContextMenuProxyMac::window() const
+{
+    return [m_webView window];
+}
+
+#if ENABLE(IMAGE_CONTROLS)
+void WebContextMenuProxyMac::replaceControlledImage(CGImageRef newImage)
+{
+    FloatSize newImageSize(CGImageGetWidth(newImage), CGImageGetHeight(newImage));
+    RefPtr&lt;ShareableBitmap&gt; newBitmap = ShareableBitmap::createShareable(expandedIntSize(newImageSize), ShareableBitmap::SupportsAlpha);
+    newBitmap-&gt;createGraphicsContext()-&gt;drawNativeImage(newImage, newImageSize, ColorSpaceDeviceRGB, FloatRect(FloatPoint(), newImageSize), FloatRect(FloatPoint(), newImageSize));
+
+    m_page-&gt;replaceControlledImage(newBitmap.release());
+}
+#endif
+
</ins><span class="cx"> } // namespace WebKit
</span><span class="cx"> 
</span><span class="cx"> #endif // PLATFORM(MAC)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebContextMenucpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebContextMenu.cpp (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebContextMenu.cpp        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebContextMenu.cpp        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -54,9 +54,6 @@
</span><span class="cx"> void WebContextMenu::show()
</span><span class="cx"> {
</span><span class="cx">     ContextMenuController&amp; controller = m_page-&gt;corePage()-&gt;contextMenuController();
</span><del>-    ContextMenu* menu = controller.contextMenu();
-    if (!menu)
-        return;
</del><span class="cx">     Frame* frame = controller.hitTestResult().innerNodeFrame();
</span><span class="cx">     if (!frame)
</span><span class="cx">         return;
</span><span class="lines">@@ -80,6 +77,13 @@
</span><span class="cx">     m_page-&gt;corePage()-&gt;contextMenuController().contextMenuItemSelected(&amp;coreItem);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+void WebContextMenu::replaceControlledImage(PassRefPtr&lt;Image&gt; newImage)
+{
+    m_page-&gt;corePage()-&gt;contextMenuController().replaceControlledImage(newImage);
+}
+#endif
+
</ins><span class="cx"> void WebContextMenu::menuItemsWithUserData(Vector&lt;WebContextMenuItemData&gt; &amp;menuItems, RefPtr&lt;API::Object&gt;&amp; userData) const
</span><span class="cx"> {
</span><span class="cx">     ContextMenuController&amp; controller = m_page-&gt;corePage()-&gt;contextMenuController();
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebContextMenuh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebContextMenu.h (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebContextMenu.h        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebContextMenu.h        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -28,8 +28,13 @@
</span><span class="cx"> #include &lt;wtf/PassRefPtr.h&gt;
</span><span class="cx"> #include &lt;wtf/RefCounted.h&gt;
</span><span class="cx"> 
</span><ins>+namespace WebCore {
+class Image;
+}
+
</ins><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><ins>+class ShareableBitmap;
</ins><span class="cx"> class WebPage;
</span><span class="cx"> 
</span><span class="cx"> class WebContextMenu : public RefCounted&lt;WebContextMenu&gt; {
</span><span class="lines">@@ -45,6 +50,10 @@
</span><span class="cx">     void itemSelected(const WebContextMenuItemData&amp;);
</span><span class="cx">     Vector&lt;WebContextMenuItemData&gt; items() const;
</span><span class="cx"> 
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+    void replaceControlledImage(PassRefPtr&lt;WebCore::Image&gt;);
+#endif
+
</ins><span class="cx"> private:
</span><span class="cx">     WebContextMenu(WebPage*);
</span><span class="cx">     void menuItemsWithUserData(Vector&lt;WebContextMenuItemData&gt;&amp;, RefPtr&lt;API::Object&gt;&amp;) const;
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -3088,6 +3088,15 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+void WebPage::replaceControlledImage(const ShareableBitmap::Handle&amp; bitmapHandle)
+{
+    RefPtr&lt;ShareableBitmap&gt; bitmap = ShareableBitmap::create(bitmapHandle);
+    if (bitmap)
+        m_contextMenu-&gt;replaceControlledImage(bitmap-&gt;createImage());
+}
+#endif
+
</ins><span class="cx"> void WebPage::replaceSelectionWithText(Frame* frame, const String&amp; text)
</span><span class="cx"> {
</span><span class="cx">     bool selectReplacement = true;
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -742,6 +742,10 @@
</span><span class="cx"> 
</span><span class="cx">     void getBytecodeProfile(uint64_t callbackID);
</span><span class="cx"> 
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+    void replaceControlledImage(const ShareableBitmap::Handle&amp;);
+#endif
+
</ins><span class="cx"> private:
</span><span class="cx">     WebPage(uint64_t pageID, const WebPageCreationParameters&amp;);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPagemessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -343,4 +343,7 @@
</span><span class="cx">     
</span><span class="cx">     TakeThumbnailSnapshot(uint64_t callbackID)
</span><span class="cx"> 
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+    ReplaceControlledImage(WebKit::ShareableBitmap::Handle newBitmapHandle)
+#endif
</ins><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>