<!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>[167956] trunk/Source</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/167956">167956</a></dd>
<dt>Author</dt> <dd>beidson@apple.com</dd>
<dt>Date</dt> <dd>2014-04-29 14:54:23 -0700 (Tue, 29 Apr 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Change Image Controls replacement to use selection and paste
&lt;rdar://problem/16302722&gt; and https://bugs.webkit.org/show_bug.cgi?id=131992

Reviewed by Tim Horton.

Source/WebCore:
* WebCore.exp.in: Remove deleted symbol.

* html/shadow/mac/ImageControlsButtonElementMac.cpp:
(WebCore::ImageControlsButtonElementMac::defaultEventHandler):

* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::showImageControlsMenu): Select the image element
  before showing the menu.
(WebCore::ContextMenuController::replaceControlledImage): Deleted.
* page/ContextMenuController.h:

Source/WebKit/mac:
* Misc/WebSharingServicePickerController.mm:
(-[WebSharingServicePickerController sharingService:didShareItems:]): Write the
  replacement data to a special pasteboard, then replace the current selection from
  that pasteboard.

Source/WebKit2:
Add a &quot;pasteboard override&quot; mechanism which allows WebKit to keep pasteboard content local
to the WebProcess and access it there without having to message up to the UI process:
* WebProcess/WebCoreSupport/WebPasteboardOverrides.cpp: Added.
(WebKit::WebPasteboardOverrides::sharedPasteboardOverrides):
(WebKit::WebPasteboardOverrides::WebPasteboardOverrides):
(WebKit::WebPasteboardOverrides::addOverride):
(WebKit::WebPasteboardOverrides::removeOverride):
(WebKit::WebPasteboardOverrides::overriddenTypes):
(WebKit::WebPasteboardOverrides::getDataForOverride):
* WebProcess/WebCoreSupport/WebPasteboardOverrides.h: Added.

Change the pasteboard strategy to consult the pasteboard overrides before consulting the native pasteboard:
* WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
(WebKit::WebPlatformStrategies::getTypes):
(WebKit::WebPlatformStrategies::bufferForType):

Add &quot;replaceSelectionWithPasteboardData&quot; which uses the new pasteboard overrides mechanism
and then has WebCore perform the replacement:
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::replaceSelectionPasteboardName):
(WebKit::WebPage::replaceSelectionWithPasteboardData):

* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::replaceSelectionWithPasteboardData):

* UIProcess/mac/WebContextMenuProxyMac.h:
(WebKit::WebContextMenuProxyMac::page):
* UIProcess/mac/WebContextMenuProxyMac.mm:
(-[WKSharingServicePickerDelegate sharingService:didShareItems:]): Use &quot;replaceSelectionWithPasteboardData&quot;.
(WebKit::WebContextMenuProxyMac::WebContextMenuProxyMac):
(WebKit::WebContextMenuProxyMac::replaceControlledImage): Deleted.

Remain other remnants of &quot;replaceControlledImage&quot;:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::replaceControlledImage): Deleted.
* UIProcess/WebPageProxy.h:
* WebProcess/WebPage/WebContextMenu.cpp:
(WebKit::WebContextMenu::replaceControlledImage): Deleted.
* WebProcess/WebPage/WebContextMenu.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::replaceControlledImage): Deleted.

* WebKit2.xcodeproj/project.pbxproj:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCoreexpin">trunk/Source/WebCore/WebCore.exp.in</a></li>
<li><a href="#trunkSourceWebCorehtmlshadowmacImageControlsButtonElementMaccpp">trunk/Source/WebCore/html/shadow/mac/ImageControlsButtonElementMac.cpp</a></li>
<li><a href="#trunkSourceWebCorepageContextMenuControllercpp">trunk/Source/WebCore/page/ContextMenuController.cpp</a></li>
<li><a href="#trunkSourceWebCorepageContextMenuControllerh">trunk/Source/WebCore/page/ContextMenuController.h</a></li>
<li><a href="#trunkSourceWebKitmacChangeLog">trunk/Source/WebKit/mac/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitmacMiscWebSharingServicePickerControllermm">trunk/Source/WebKit/mac/Misc/WebSharingServicePickerController.mm</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</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="#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="#trunkSourceWebKit2UIProcessmacWebPageProxyMacmm">trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm</a></li>
<li><a href="#trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj">trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebCoreSupportWebPlatformStrategiescpp">trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp</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>
<li><a href="#trunkSourceWebKit2WebProcessWebPagemacWebPageMacmm">trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2WebProcessWebCoreSupportWebPasteboardOverridescpp">trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPasteboardOverrides.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebCoreSupportWebPasteboardOverridesh">trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPasteboardOverrides.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (167955 => 167956)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-04-29 20:51:47 UTC (rev 167955)
+++ trunk/Source/WebCore/ChangeLog        2014-04-29 21:54:23 UTC (rev 167956)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2014-04-29  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        Change Image Controls replacement to use selection and paste
+        &lt;rdar://problem/16302722&gt; and https://bugs.webkit.org/show_bug.cgi?id=131992
+
+        Reviewed by Tim Horton.
+
+        * WebCore.exp.in: Remove deleted symbol.
+
+        * html/shadow/mac/ImageControlsButtonElementMac.cpp:
+        (WebCore::ImageControlsButtonElementMac::defaultEventHandler):
+
+        * page/ContextMenuController.cpp:
+        (WebCore::ContextMenuController::showImageControlsMenu): Select the image element
+          before showing the menu.
+        (WebCore::ContextMenuController::replaceControlledImage): Deleted.
+        * page/ContextMenuController.h:
+
</ins><span class="cx"> 2014-04-29  Jer Noble  &lt;jer.noble@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [iOS] Remove workaround for &lt;rdar://problem/16578727&gt;.
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCoreexpin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.exp.in (167955 => 167956)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.exp.in        2014-04-29 20:51:47 UTC (rev 167955)
+++ trunk/Source/WebCore/WebCore.exp.in        2014-04-29 21:54:23 UTC (rev 167956)
</span><span class="lines">@@ -229,6 +229,7 @@
</span><span class="cx"> __ZN7WebCore12SQLResultRowE
</span><span class="cx"> __ZN7WebCore12SharedBuffer10wrapCFDataEPK8__CFData
</span><span class="cx"> __ZN7WebCore12SharedBuffer10wrapNSDataEP6NSData
</span><ins>+__ZN7WebCore12SharedBuffer11adoptVectorERN3WTF6VectorIcLm0ENS1_15CrashOnOverflowEEE
</ins><span class="cx"> __ZN7WebCore12SharedBuffer12createCFDataEv
</span><span class="cx"> __ZN7WebCore12SharedBuffer12createNSDataEv
</span><span class="cx"> __ZN7WebCore12SharedBuffer24createWithContentsOfFileERKN3WTF6StringE
</span><span class="lines">@@ -2987,10 +2988,6 @@
</span><span class="cx"> __ZNK7WebCore12IconDatabase9isEnabledEv
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-#if ENABLE(SERVICE_CONTROLS)
-__ZN7WebCore21ContextMenuController22replaceControlledImageEN3WTF10PassRefPtrINS_5ImageEEE
-#endif
-
</del><span class="cx"> #if ENABLE(INDEXED_DATABASE)
</span><span class="cx"> __ZN7WebCore10IDBKeyData14setNumberValueEd
</span><span class="cx"> __ZN7WebCore10IDBKeyData6decodeERNS_12KeyedDecoderERS0_
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlshadowmacImageControlsButtonElementMaccpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/shadow/mac/ImageControlsButtonElementMac.cpp (167955 => 167956)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/shadow/mac/ImageControlsButtonElementMac.cpp        2014-04-29 20:51:47 UTC (rev 167955)
+++ trunk/Source/WebCore/html/shadow/mac/ImageControlsButtonElementMac.cpp        2014-04-29 21:54:23 UTC (rev 167956)
</span><span class="lines">@@ -30,11 +30,15 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;ContextMenuController.h&quot;
</span><span class="cx"> #include &quot;Event.h&quot;
</span><ins>+#include &quot;Frame.h&quot;
+#include &quot;FrameSelection.h&quot;
</ins><span class="cx"> #include &quot;HTMLDivElement.h&quot;
</span><span class="cx"> #include &quot;Page.h&quot;
</span><ins>+#include &quot;Range.h&quot;
</ins><span class="cx"> #include &quot;RenderBlockFlow.h&quot;
</span><span class="cx"> #include &quot;RenderStyle.h&quot;
</span><span class="cx"> #include &quot;RenderTheme.h&quot;
</span><ins>+#include &quot;ShadowRoot.h&quot;
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="lines">@@ -99,8 +103,32 @@
</span><span class="cx"> void ImageControlsButtonElementMac::defaultEventHandler(Event* event)
</span><span class="cx"> {
</span><span class="cx">     if (event-&gt;type() == eventNames().clickEvent) {
</span><del>-        if (Page* page = document().page())
-            page-&gt;contextMenuController().showImageControlsMenu(event);
</del><ins>+        Frame* frame = document().frame();
+        if (!frame)
+            return;
+
+        Page* page = document().page();
+        if (!page)
+            return;
+
+        ContainerNode* parent = parentNode();
+        Element* hostElement = nullptr;
+        while (parent) {
+            if (parent-&gt;isShadowRoot()) {
+                hostElement = static_cast&lt;ShadowRoot*&gt;(parent)-&gt;hostElement();
+                break;
+            }
+            parent = parent-&gt;parentNode();
+        }
+
+        if (!hostElement)
+            return;
+        ASSERT(isHTMLImageElement(hostElement));
+
+        RefPtr&lt;Range&gt; range = Range::create(document(), Position(hostElement, Position::PositionIsBeforeAnchor), Position(hostElement, Position::PositionIsAfterAnchor));
+        frame-&gt;selection().setSelection(VisibleSelection(range.get()));
+
+        page-&gt;contextMenuController().showImageControlsMenu(event);
</ins><span class="cx">         event-&gt;setDefaultHandled();
</span><span class="cx">         return;
</span><span class="cx">     }
</span></span></pre></div>
<a id="trunkSourceWebCorepageContextMenuControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/ContextMenuController.cpp (167955 => 167956)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/ContextMenuController.cpp        2014-04-29 20:51:47 UTC (rev 167955)
+++ trunk/Source/WebCore/page/ContextMenuController.cpp        2014-04-29 21:54:23 UTC (rev 167956)
</span><span class="lines">@@ -1452,24 +1452,6 @@
</span><span class="cx">     handleContextMenuEvent(event);
</span><span class="cx">     m_client.showContextMenu();
</span><span class="cx"> }
</span><del>-
-void ContextMenuController::replaceControlledImage(PassRefPtr&lt;Image&gt; newImage)
-{
-    Node* node = m_context.hitTestResult().innerNonSharedNode();
-    if (!node)
-        return;
-
-    Frame* frame = node-&gt;document().frame();
-    if (!frame)
-        return;
-
-    RenderObject* renderer = node-&gt;renderer();
-    if (!renderer || !renderer-&gt;isRenderImage())
-        return;
-
-    CachedResourceHandle&lt;CachedImage&gt; replacedImage = new CachedImage(URL::fakeURLWithRelativePart(&quot;image&quot;), newImage.get(), frame-&gt;page()-&gt;sessionID());
-    toRenderImage(renderer)-&gt;imageResource().setCachedImage(replacedImage.get());
-}
</del><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCorepageContextMenuControllerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/ContextMenuController.h (167955 => 167956)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/ContextMenuController.h        2014-04-29 20:51:47 UTC (rev 167955)
+++ trunk/Source/WebCore/page/ContextMenuController.h        2014-04-29 21:54:23 UTC (rev 167956)
</span><span class="lines">@@ -71,7 +71,6 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(SERVICE_CONTROLS)
</span><span class="cx">     void showImageControlsMenu(Event*);
</span><del>-    void replaceControlledImage(PassRefPtr&lt;Image&gt;);
</del><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> private:
</span></span></pre></div>
<a id="trunkSourceWebKitmacChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/ChangeLog (167955 => 167956)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/ChangeLog        2014-04-29 20:51:47 UTC (rev 167955)
+++ trunk/Source/WebKit/mac/ChangeLog        2014-04-29 21:54:23 UTC (rev 167956)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2014-04-29  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        Change Image Controls replacement to use selection and paste
+        &lt;rdar://problem/16302722&gt; and https://bugs.webkit.org/show_bug.cgi?id=131992
+
+        Reviewed by Tim Horton.
+
+        * Misc/WebSharingServicePickerController.mm:
+        (-[WebSharingServicePickerController sharingService:didShareItems:]): Write the
+          replacement data to a special pasteboard, then replace the current selection from
+          that pasteboard.
+
</ins><span class="cx"> 2014-04-27  Sam Weinig  &lt;sam@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         [iOS WebKit2] Add support for text autosizing
</span></span></pre></div>
<a id="trunkSourceWebKitmacMiscWebSharingServicePickerControllermm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/Misc/WebSharingServicePickerController.mm (167955 => 167956)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/Misc/WebSharingServicePickerController.mm        2014-04-29 20:51:47 UTC (rev 167955)
+++ trunk/Source/WebKit/mac/Misc/WebSharingServicePickerController.mm        2014-04-29 21:54:23 UTC (rev 167956)
</span><span class="lines">@@ -31,6 +31,10 @@
</span><span class="cx"> #import &quot;WebViewInternal.h&quot;
</span><span class="cx"> #import &lt;AppKit/NSSharingService.h&gt;
</span><span class="cx"> #import &lt;WebCore/BitmapImage.h&gt;
</span><ins>+#import &lt;WebCore/Editor.h&gt;
+#import &lt;WebCore/FocusController.h&gt;
+#import &lt;WebCore/Frame.h&gt;
+#import &lt;WebCore/FrameSelection.h&gt;
</ins><span class="cx"> #import &lt;WebCore/ContextMenuController.h&gt;
</span><span class="cx"> #import &lt;WebCore/Page.h&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -48,6 +52,8 @@
</span><span class="cx"> 
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+static NSString *serviceControlsPasteboardName = @&quot;WebKitServiceControlsPasteboard&quot;;
+
</ins><span class="cx"> using namespace WebCore;
</span><span class="cx"> 
</span><span class="cx"> @implementation WebSharingServicePickerController
</span><span class="lines">@@ -119,14 +125,22 @@
</span><span class="cx"> 
</span><span class="cx">     RetainPtr&lt;CGImageSourceRef&gt; source = adoptCF(CGImageSourceCreateWithData((CFDataRef)[items objectAtIndex:0], NULL));
</span><span class="cx">     RetainPtr&lt;CGImageRef&gt; cgImage = adoptCF(CGImageSourceCreateImageAtIndex(source.get(), 0, NULL));
</span><del>-    RefPtr&lt;Image&gt; image = BitmapImage::create(cgImage.get());
</del><span class="cx"> 
</span><ins>+    if (!cgImage)
+        return;
+
</ins><span class="cx">     Page* page = [_menuClient-&gt;webView() page];
</span><span class="cx">     if (!page)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    page-&gt;contextMenuController().replaceControlledImage(image.get());
</del><ins>+    NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:serviceControlsPasteboardName];
+    [pasteboard declareTypes:@[ NSPasteboardTypeTIFF ] owner:nil];
+    [pasteboard setData:[items objectAtIndex:0] forType:NSPasteboardTypeTIFF];
</ins><span class="cx"> 
</span><ins>+    Frame&amp; frame = page-&gt;focusController().focusedOrMainFrame();
+    if (!frame.selection().isNone())
+        frame.editor().readSelectionFromPasteboard(serviceControlsPasteboardName);
+
</ins><span class="cx">     [self clear];
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (167955 => 167956)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-04-29 20:51:47 UTC (rev 167955)
+++ trunk/Source/WebKit2/ChangeLog        2014-04-29 21:54:23 UTC (rev 167956)
</span><span class="lines">@@ -1,3 +1,56 @@
</span><ins>+2014-04-29  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        Change Image Controls replacement to use selection and paste
+        &lt;rdar://problem/16302722&gt; and https://bugs.webkit.org/show_bug.cgi?id=131992
+
+        Reviewed by Tim Horton.
+
+        Add a &quot;pasteboard override&quot; mechanism which allows WebKit to keep pasteboard content local
+        to the WebProcess and access it there without having to message up to the UI process:
+        * WebProcess/WebCoreSupport/WebPasteboardOverrides.cpp: Added.
+        (WebKit::WebPasteboardOverrides::sharedPasteboardOverrides):
+        (WebKit::WebPasteboardOverrides::WebPasteboardOverrides):
+        (WebKit::WebPasteboardOverrides::addOverride):
+        (WebKit::WebPasteboardOverrides::removeOverride):
+        (WebKit::WebPasteboardOverrides::overriddenTypes):
+        (WebKit::WebPasteboardOverrides::getDataForOverride):
+        * WebProcess/WebCoreSupport/WebPasteboardOverrides.h: Added.
+
+        Change the pasteboard strategy to consult the pasteboard overrides before consulting the native pasteboard:
+        * WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
+        (WebKit::WebPlatformStrategies::getTypes):
+        (WebKit::WebPlatformStrategies::bufferForType):
+
+        Add &quot;replaceSelectionWithPasteboardData&quot; which uses the new pasteboard overrides mechanism
+        and then has WebCore perform the replacement:
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::replaceSelectionPasteboardName):
+        (WebKit::WebPage::replaceSelectionWithPasteboardData):
+
+        * UIProcess/mac/WebPageProxyMac.mm:
+        (WebKit::WebPageProxy::replaceSelectionWithPasteboardData):
+
+        * UIProcess/mac/WebContextMenuProxyMac.h:
+        (WebKit::WebContextMenuProxyMac::page):
+        * UIProcess/mac/WebContextMenuProxyMac.mm:
+        (-[WKSharingServicePickerDelegate sharingService:didShareItems:]): Use &quot;replaceSelectionWithPasteboardData&quot;.
+        (WebKit::WebContextMenuProxyMac::WebContextMenuProxyMac):
+        (WebKit::WebContextMenuProxyMac::replaceControlledImage): Deleted.
+
+        Remain other remnants of &quot;replaceControlledImage&quot;:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::replaceControlledImage): Deleted.
+        * UIProcess/WebPageProxy.h:
+        * WebProcess/WebPage/WebContextMenu.cpp:
+        (WebKit::WebContextMenu::replaceControlledImage): Deleted.
+        * WebProcess/WebPage/WebContextMenu.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::replaceControlledImage): Deleted.
+
+        * WebKit2.xcodeproj/project.pbxproj:
+
</ins><span class="cx"> 2014-04-29  Tim Horton  &lt;timothy_horton@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Build fix.
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (167955 => 167956)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2014-04-29 20:51:47 UTC (rev 167955)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2014-04-29 21:54:23 UTC (rev 167956)
</span><span class="lines">@@ -3484,16 +3484,6 @@
</span><span class="cx">     m_contextMenuClient.contextMenuDismissed(this);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#if ENABLE(SERVICE_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
-
</del><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 (167955 => 167956)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2014-04-29 20:51:47 UTC (rev 167955)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2014-04-29 21:54:23 UTC (rev 167956)
</span><span class="lines">@@ -812,6 +812,10 @@
</span><span class="cx">     ColorSpaceData colorSpace();
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if ENABLE(SERVICE_CONTROLS)
+    void replaceSelectionWithPasteboardData(const String&amp; type, const IPC::DataReference&amp;);
+#endif
+
</ins><span class="cx">     void pageScaleFactorDidChange(double);
</span><span class="cx">     void pageZoomFactorDidChange(double);
</span><span class="cx"> 
</span><span class="lines">@@ -1064,10 +1068,6 @@
</span><span class="cx"> 
</span><span class="cx">     void takeSnapshot(WebCore::IntRect, WebCore::IntSize bitmapSize, SnapshotOptions, ImageCallback::CallbackFunction);
</span><span class="cx"> 
</span><del>-#if ENABLE(SERVICE_CONTROLS)
-    void replaceControlledImage(PassRefPtr&lt;ShareableBitmap&gt;);
-#endif
-
</del><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="trunkSourceWebKit2UIProcessmacWebContextMenuProxyMach"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.h (167955 => 167956)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.h        2014-04-29 20:51:47 UTC (rev 167955)
+++ trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.h        2014-04-29 21:54:23 UTC (rev 167956)
</span><span class="lines">@@ -55,9 +55,9 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(SERVICE_CONTROLS)
</span><span class="cx">     void clearImageServicesMenu();
</span><del>-    void replaceControlledImage(CGImageRef newImage);
</del><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+    WebPageProxy&amp; page() const { return *m_page; }
</ins><span class="cx">     NSWindow *window() const;
</span><span class="cx"> 
</span><span class="cx"> private:
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacWebContextMenuProxyMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm (167955 => 167956)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm        2014-04-29 20:51:47 UTC (rev 167955)
+++ trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm        2014-04-29 21:54:23 UTC (rev 167956)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx"> 
</span><ins>+#import &quot;DataReference.h&quot;
</ins><span class="cx"> #import &quot;PageClientImpl.h&quot;
</span><span class="cx"> #import &quot;ShareableBitmap.h&quot;
</span><span class="cx"> #import &quot;StringUtilities.h&quot;
</span><span class="lines">@@ -56,8 +57,9 @@
</span><span class="cx"> @property NSSharingServicePickerStyle style;
</span><span class="cx"> - (NSMenu *)menu;
</span><span class="cx"> @end
</span><del>-#endif
</del><span class="cx"> 
</span><ins>+#endif // ENABLE(SERVICE_CONTROLS)
+
</ins><span class="cx"> using namespace WebCore;
</span><span class="cx"> 
</span><span class="cx"> @interface WKUserDataWrapper : NSObject {
</span><span class="lines">@@ -229,9 +231,15 @@
</span><span class="cx"> 
</span><span class="cx"> - (void)sharingService:(NSSharingService *)sharingService didShareItems:(NSArray *)items
</span><span class="cx"> {
</span><del>-    RetainPtr&lt;CGImageSourceRef&gt; source = adoptCF(CGImageSourceCreateWithData((CFDataRef)[items objectAtIndex:0], NULL));
</del><ins>+    NSData *data = [items objectAtIndex:0];
+    RetainPtr&lt;CGImageSourceRef&gt; source = adoptCF(CGImageSourceCreateWithData((CFDataRef)data, NULL));
</ins><span class="cx">     RetainPtr&lt;CGImageRef&gt; image = adoptCF(CGImageSourceCreateImageAtIndex(source.get(), 0, NULL));
</span><del>-    _menuProxy-&gt;replaceControlledImage(image.get());
</del><ins>+
+    if (!image)
+        return;
+
+    IPC::DataReference dataReference(static_cast&lt;const uint8_t*&gt;([data bytes]), [data length]);
+    _menuProxy-&gt;page().replaceSelectionWithPasteboardData(NSPasteboardTypeTIFF, dataReference);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (NSWindow *)sharingService:(NSSharingService *)sharingService sourceWindowForShareItems:(NSArray *)items sharingContentScope:(NSSharingContentScope *)sharingContentScope
</span><span class="lines">@@ -249,6 +257,7 @@
</span><span class="cx">     : m_webView(webView)
</span><span class="cx">     , m_page(page)
</span><span class="cx"> {
</span><ins>+    ASSERT(m_page);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> WebContextMenuProxyMac::~WebContextMenuProxyMac()
</span><span class="lines">@@ -433,17 +442,6 @@
</span><span class="cx">     return [m_webView window];
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#if ENABLE(SERVICE_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
-
</del><span class="cx"> } // namespace WebKit
</span><span class="cx"> 
</span><span class="cx"> #endif // PLATFORM(MAC)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacWebPageProxyMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm (167955 => 167956)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm        2014-04-29 20:51:47 UTC (rev 167955)
+++ trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm        2014-04-29 21:54:23 UTC (rev 167956)
</span><span class="lines">@@ -395,6 +395,13 @@
</span><span class="cx">     return result;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if ENABLE(SERVICE_CONTROLS)
+void WebPageProxy::replaceSelectionWithPasteboardData(const String&amp; type, const IPC::DataReference&amp; data)
+{
+    process().send(Messages::WebPage::ReplaceSelectionWithPasteboardData(type, data), m_pageID);
+}
+#endif
+
</ins><span class="cx"> #if ENABLE(DRAG_SUPPORT)
</span><span class="cx"> void WebPageProxy::setDragImage(const WebCore::IntPoint&amp; clientPosition, const ShareableBitmap::Handle&amp; dragImageHandle, bool isLinkDrag)
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (167955 => 167956)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2014-04-29 20:51:47 UTC (rev 167955)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2014-04-29 21:54:23 UTC (rev 167956)
</span><span class="lines">@@ -735,6 +735,8 @@
</span><span class="cx">                 511D8201185BC217001AED56 /* SQLiteIDBTransaction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 511D8200185BC217001AED56 /* SQLiteIDBTransaction.cpp */; };
</span><span class="cx">                 511F8A7B138B460900A95F44 /* SecItemShimLibrary.h in Headers */ = {isa = PBXBuildFile; fileRef = 511F8A77138B460900A95F44 /* SecItemShimLibrary.h */; };
</span><span class="cx">                 511F8A81138B485D00A95F44 /* SecItemShimLibrary.mm in Sources */ = {isa = PBXBuildFile; fileRef = 511F8A78138B460900A95F44 /* SecItemShimLibrary.mm */; };
</span><ins>+                512127C31908239A00DAF35C /* WebPasteboardOverrides.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 512127C11908239A00DAF35C /* WebPasteboardOverrides.cpp */; };
+                512127C41908239A00DAF35C /* WebPasteboardOverrides.h in Headers */ = {isa = PBXBuildFile; fileRef = 512127C21908239A00DAF35C /* WebPasteboardOverrides.h */; };
</ins><span class="cx">                 51217460164C20E30037A5C1 /* ShareableResource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5121745E164C20E30037A5C1 /* ShareableResource.cpp */; };
</span><span class="cx">                 51217461164C20E30037A5C1 /* ShareableResource.h in Headers */ = {isa = PBXBuildFile; fileRef = 5121745F164C20E30037A5C1 /* ShareableResource.h */; };
</span><span class="cx">                 51217464164C21370037A5C1 /* WebResourceBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51217462164C21370037A5C1 /* WebResourceBuffer.cpp */; };
</span><span class="lines">@@ -2580,6 +2582,8 @@
</span><span class="cx">                 511D8200185BC217001AED56 /* SQLiteIDBTransaction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SQLiteIDBTransaction.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 511F8A77138B460900A95F44 /* SecItemShimLibrary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SecItemShimLibrary.h; path = ../../WebProcess/mac/SecItemShimLibrary.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 511F8A78138B460900A95F44 /* SecItemShimLibrary.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SecItemShimLibrary.mm; path = ../../WebProcess/mac/SecItemShimLibrary.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                512127C11908239A00DAF35C /* WebPasteboardOverrides.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebPasteboardOverrides.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
+                512127C21908239A00DAF35C /* WebPasteboardOverrides.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPasteboardOverrides.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 5121745E164C20E30037A5C1 /* ShareableResource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ShareableResource.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 5121745F164C20E30037A5C1 /* ShareableResource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShareableResource.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 51217462164C21370037A5C1 /* WebResourceBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebResourceBuffer.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -5299,6 +5303,8 @@
</span><span class="cx">                                 1C8E256A1270DE3800BC7BD0 /* WebInspectorFrontendClient.h */,
</span><span class="cx">                                 31099971146C759B0029DEB9 /* WebNotificationClient.cpp */,
</span><span class="cx">                                 31099968146C71F50029DEB9 /* WebNotificationClient.h */,
</span><ins>+                                512127C11908239A00DAF35C /* WebPasteboardOverrides.cpp */,
+                                512127C21908239A00DAF35C /* WebPasteboardOverrides.h */,
</ins><span class="cx">                                 1A3E736011CC2659007BD539 /* WebPlatformStrategies.cpp */,
</span><span class="cx">                                 1A3E735F11CC2659007BD539 /* WebPlatformStrategies.h */,
</span><span class="cx">                                 31D5929C166E05FF00E6BF02 /* WebPlugInClient.cpp */,
</span><span class="lines">@@ -7134,6 +7140,7 @@
</span><span class="cx">                                 1A3E736111CC2659007BD539 /* WebPlatformStrategies.h in Headers */,
</span><span class="cx">                                 31D5929F166E060000E6BF02 /* WebPlugInClient.h in Headers */,
</span><span class="cx">                                 1AC8702D130B49A2002C1257 /* WebPluginSiteDataManager.h in Headers */,
</span><ins>+                                512127C41908239A00DAF35C /* WebPasteboardOverrides.h in Headers */,
</ins><span class="cx">                                 518353DB1885BF8C00D9FE44 /* IDBSerialization.h in Headers */,
</span><span class="cx">                                 1ADF591B1890528E0043C145 /* WKWebViewConfiguration.h in Headers */,
</span><span class="cx">                                 BC5744F012638FB3006F0F12 /* WebPopupItem.h in Headers */,
</span><span class="lines">@@ -8614,6 +8621,7 @@
</span><span class="cx">                                 BC306825125A6B9400E71278 /* WebProcessCreationParameters.cpp in Sources */,
</span><span class="cx">                                 1F7506B01859162C00EC0FF7 /* WKWebProcessPlugInScriptWorld.mm in Sources */,
</span><span class="cx">                                 75E749EB180DBB9800088BA6 /* WebOriginDataManagerProxyMessageReceiver.cpp in Sources */,
</span><ins>+                                512127C31908239A00DAF35C /* WebPasteboardOverrides.cpp in Sources */,
</ins><span class="cx">                                 BC3066BE125A442100E71278 /* WebProcessMessageReceiver.cpp in Sources */,
</span><span class="cx">                                 BC111B11112F5E4F00337BAB /* WebProcessProxy.cpp in Sources */,
</span><span class="cx">                                 51032F18180F73BB00961BB7 /* WebToDatabaseProcessConnection.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebCoreSupportWebPasteboardOverridescpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPasteboardOverrides.cpp (0 => 167956)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPasteboardOverrides.cpp                                (rev 0)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPasteboardOverrides.cpp        2014-04-29 21:54:23 UTC (rev 167956)
</span><span class="lines">@@ -0,0 +1,111 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include &quot;config.h&quot;
+#include &quot;WebPasteboardOverrides.h&quot;
+
+namespace WebKit {
+
+WebPasteboardOverrides&amp; WebPasteboardOverrides::sharedPasteboardOverrides()
+{
+    static NeverDestroyed&lt;WebPasteboardOverrides&gt; sharedOverrides;
+    return sharedOverrides;
+}
+
+WebPasteboardOverrides::WebPasteboardOverrides()
+{
+}
+
+void WebPasteboardOverrides::addOverride(const String&amp; pasteboardName, const String&amp; type, const Vector&lt;uint8_t&gt;&amp; data)
+{
+    auto addResult = m_overridesMap.add(pasteboardName, nullptr);
+
+    if (addResult.isNewEntry) {
+        std::unique_ptr&lt;HashMap&lt;String, Vector&lt;uint8_t&gt;&gt;&gt; typeMap = std::make_unique&lt;HashMap&lt;String, Vector&lt;uint8_t&gt;&gt;&gt;();
+        addResult.iterator-&gt;value = std::move(typeMap);
+    }
+
+    addResult.iterator-&gt;value-&gt;set(type, data);
+}
+
+void WebPasteboardOverrides::removeOverride(const String&amp; pasteboardName, const String&amp; type)
+{
+    auto it = m_overridesMap.find(pasteboardName);
+    if (it == m_overridesMap.end())
+        return;
+
+    ASSERT(it-&gt;value);
+
+    it-&gt;value-&gt;remove(type);
+
+    // If this was the last override for this pasteboard, remove its record completely.
+    if (it-&gt;value-&gt;isEmpty())
+        m_overridesMap.remove(it);
+}
+
+Vector&lt;String&gt; WebPasteboardOverrides::overriddenTypes(const String&amp; pasteboardName)
+{
+    Vector&lt;String&gt; result;
+
+    auto it = m_overridesMap.find(pasteboardName);
+    if (it == m_overridesMap.end())
+        return result;
+
+    ASSERT(it-&gt;value);
+
+    for (String&amp; type : it-&gt;value-&gt;keys())
+        result.append(type);
+
+    return result;
+}
+
+bool WebPasteboardOverrides::getDataForOverride(const String&amp; pasteboardName, const String&amp; type, Vector&lt;uint8_t&gt;&amp; data) const
+{
+    auto pasteboardIterator = m_overridesMap.find(pasteboardName);
+    if (pasteboardIterator == m_overridesMap.end())
+        return false;
+
+    auto typeIterator = pasteboardIterator-&gt;value-&gt;find(type);
+    if (typeIterator == pasteboardIterator-&gt;value-&gt;end())
+        return false;
+
+    data = typeIterator-&gt;value;
+    return true;
+}
+
+bool WebPasteboardOverrides::getDataForOverride(const String&amp; pasteboardName, const String&amp; type, Vector&lt;char&gt;&amp; data) const
+{
+    Vector&lt;uint8_t&gt; foundBuffer;
+    if (!getDataForOverride(pasteboardName, type, foundBuffer))
+        return false;
+
+    data.clear();
+    data.reserveCapacity(foundBuffer.size());
+    memcpy(data.data(), foundBuffer.data(), foundBuffer.size());
+
+    return true;
+}
+
+} // namespace WebKit
</ins></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebCoreSupportWebPasteboardOverridesh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPasteboardOverrides.h (0 => 167956)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPasteboardOverrides.h                                (rev 0)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPasteboardOverrides.h        2014-04-29 21:54:23 UTC (rev 167956)
</span><span class="lines">@@ -0,0 +1,60 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebPasteboardOverrides_h
+#define WebPasteboardOverrides_h
+
+#include &lt;wtf/HashMap.h&gt;
+#include &lt;wtf/NeverDestroyed.h&gt;
+#include &lt;wtf/Vector.h&gt;
+#include &lt;wtf/text/StringHash.h&gt;
+#include &lt;wtf/text/WTFString.h&gt;
+
+namespace WebKit {
+
+class WebPasteboardOverrides {
+    friend class NeverDestroyed&lt;WebPasteboardOverrides&gt;;
+public:
+    static WebPasteboardOverrides&amp; sharedPasteboardOverrides();
+
+    void addOverride(const String&amp; pasteboardName, const String&amp; type, const Vector&lt;uint8_t&gt;&amp;);
+    void removeOverride(const String&amp; pasteboardName, const String&amp; type);
+
+    Vector&lt;String&gt; overriddenTypes(const String&amp; pasteboardName);
+
+    bool getDataForOverride(const String&amp; pasteboardName, const String&amp; type, Vector&lt;uint8_t&gt;&amp;) const;
+    bool getDataForOverride(const String&amp; pasteboardName, const String&amp; type, Vector&lt;char&gt;&amp;) const;
+
+private:
+    WebPasteboardOverrides();
+
+    // The m_overridesMap maps string pasteboard names to pasteboard entries.
+    // Each pasteboard entry is a map of a string type to a data buffer.
+    HashMap&lt;String, std::unique_ptr&lt;HashMap&lt;String, Vector&lt;uint8_t&gt;&gt;&gt;&gt; m_overridesMap;
+};
+
+} // namespace WebKit
+
+#endif // WebPasteboardOverrides_h
</ins></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebCoreSupportWebPlatformStrategiescpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp (167955 => 167956)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp        2014-04-29 20:51:47 UTC (rev 167955)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp        2014-04-29 21:54:23 UTC (rev 167956)
</span><span class="lines">@@ -41,6 +41,7 @@
</span><span class="cx"> #include &quot;WebFrameNetworkingContext.h&quot;
</span><span class="cx"> #include &quot;WebIDBFactoryBackend.h&quot;
</span><span class="cx"> #include &quot;WebPage.h&quot;
</span><ins>+#include &quot;WebPasteboardOverrides.h&quot;
</ins><span class="cx"> #include &quot;WebProcess.h&quot;
</span><span class="cx"> #include &quot;WebProcessProxyMessages.h&quot;
</span><span class="cx"> #include &lt;WebCore/Color.h&gt;
</span><span class="lines">@@ -374,12 +375,25 @@
</span><span class="cx"> 
</span><span class="cx"> void WebPlatformStrategies::getTypes(Vector&lt;String&gt;&amp; types, const String&amp; pasteboardName)
</span><span class="cx"> {
</span><ins>+    // First check the overrides.
+    // The purpose of the overrides is to avoid messaging back to the UI process.
+    // Therefore, if there are any overridden types, we return just those.
+    types = WebPasteboardOverrides::sharedPasteboardOverrides().overriddenTypes(pasteboardName);
+    if (!types.isEmpty())
+        return;
+
</ins><span class="cx">     WebProcess::shared().parentProcessConnection()-&gt;sendSync(Messages::WebContext::GetPasteboardTypes(pasteboardName),
</span><span class="cx">                                                 Messages::WebContext::GetPasteboardTypes::Reply(types), 0);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> PassRefPtr&lt;WebCore::SharedBuffer&gt; WebPlatformStrategies::bufferForType(const String&amp; pasteboardType, const String&amp; pasteboardName)
</span><span class="cx"> {
</span><ins>+    // First check the overrides.
+    Vector&lt;char&gt; overrideBuffer;
+    if (WebPasteboardOverrides::sharedPasteboardOverrides().getDataForOverride(pasteboardName, pasteboardType, overrideBuffer))
+        return SharedBuffer::adoptVector(overrideBuffer);
+
+    // Fallback to messaging the UI process for native pasteboard content.
</ins><span class="cx">     SharedMemory::Handle handle;
</span><span class="cx">     uint64_t size = 0;
</span><span class="cx">     WebProcess::shared().parentProcessConnection()-&gt;sendSync(Messages::WebContext::GetPasteboardBufferForType(pasteboardName, pasteboardType),
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebContextMenucpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebContextMenu.cpp (167955 => 167956)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebContextMenu.cpp        2014-04-29 20:51:47 UTC (rev 167955)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebContextMenu.cpp        2014-04-29 21:54:23 UTC (rev 167956)
</span><span class="lines">@@ -77,13 +77,6 @@
</span><span class="cx">     m_page-&gt;corePage()-&gt;contextMenuController().contextMenuItemSelected(&amp;coreItem);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#if ENABLE(SERVICE_CONTROLS)
-void WebContextMenu::replaceControlledImage(PassRefPtr&lt;Image&gt; newImage)
-{
-    m_page-&gt;corePage()-&gt;contextMenuController().replaceControlledImage(newImage);
-}
-#endif
-
</del><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 (167955 => 167956)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebContextMenu.h        2014-04-29 20:51:47 UTC (rev 167955)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebContextMenu.h        2014-04-29 21:54:23 UTC (rev 167956)
</span><span class="lines">@@ -50,10 +50,6 @@
</span><span class="cx">     void itemSelected(const WebContextMenuItemData&amp;);
</span><span class="cx">     Vector&lt;WebContextMenuItemData&gt; items() const;
</span><span class="cx"> 
</span><del>-#if ENABLE(SERVICE_CONTROLS)
-    void replaceControlledImage(PassRefPtr&lt;WebCore::Image&gt;);
-#endif
-
</del><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 (167955 => 167956)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2014-04-29 20:51:47 UTC (rev 167955)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2014-04-29 21:54:23 UTC (rev 167956)
</span><span class="lines">@@ -3162,15 +3162,6 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-#if ENABLE(SERVICE_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
-
</del><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 (167955 => 167956)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2014-04-29 20:51:47 UTC (rev 167955)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2014-04-29 21:54:23 UTC (rev 167956)
</span><span class="lines">@@ -587,6 +587,11 @@
</span><span class="cx">     void shouldDelayWindowOrderingEvent(const WebKit::WebMouseEvent&amp;, bool&amp; result);
</span><span class="cx">     void acceptsFirstMouse(int eventNumber, const WebKit::WebMouseEvent&amp;, bool&amp; result);
</span><span class="cx">     bool performNonEditingBehaviorForSelector(const String&amp;, WebCore::KeyboardEvent*);
</span><ins>+
+#if ENABLE(SERVICE_CONTROLS)
+    void replaceSelectionWithPasteboardData(const String&amp; type, const IPC::DataReference&amp;);
+#endif
+
</ins><span class="cx"> #elif PLATFORM(EFL)
</span><span class="cx">     void confirmComposition(const String&amp; compositionString);
</span><span class="cx">     void setComposition(const WTF::String&amp; compositionString, const WTF::Vector&lt;WebCore::CompositionUnderline&gt;&amp; underlines, uint64_t cursorPosition);
</span><span class="lines">@@ -773,10 +778,6 @@
</span><span class="cx">     PassRefPtr&lt;WebCore::DocumentLoader&gt; createDocumentLoader(WebCore::Frame&amp;, const WebCore::ResourceRequest&amp;, const WebCore::SubstituteData&amp;);
</span><span class="cx"> 
</span><span class="cx">     void getBytecodeProfile(uint64_t callbackID);
</span><del>-
-#if ENABLE(SERVICE_CONTROLS)
-    void replaceControlledImage(const ShareableBitmap::Handle&amp;);
-#endif
</del><span class="cx">     
</span><span class="cx">     // Some platforms require accessibility-enabled processes to spin the run loop so that the WebProcess doesn't hang.
</span><span class="cx">     // While this is not ideal, it does not have to be applied to every platform at the moment.
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPagemessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (167955 => 167956)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in        2014-04-29 20:51:47 UTC (rev 167955)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in        2014-04-29 21:54:23 UTC (rev 167956)
</span><span class="lines">@@ -303,6 +303,10 @@
</span><span class="cx">     GetDataSelectionForPasteboard(String pasteboardType) -&gt; (WebKit::SharedMemory::Handle handle, uint64_t size)
</span><span class="cx">     ReadSelectionFromPasteboard(String pasteboardName) -&gt; (bool result)
</span><span class="cx"> 
</span><ins>+#if ENABLE(SERVICE_CONTROLS)
+    ReplaceSelectionWithPasteboardData(String type, IPC::DataReference data)
+#endif
+
</ins><span class="cx">     ShouldDelayWindowOrderingEvent(WebKit::WebMouseEvent event) -&gt; (bool result)
</span><span class="cx">     AcceptsFirstMouse(int eventNumber, WebKit::WebMouseEvent event) -&gt; (bool result)
</span><span class="cx"> 
</span><span class="lines">@@ -363,8 +367,4 @@
</span><span class="cx">     GetBytecodeProfile(uint64_t callbackID)
</span><span class="cx">     
</span><span class="cx">     TakeSnapshot(WebCore::IntRect snapshotRect, WebCore::IntSize bitmapSize, uint32_t options, uint64_t callbackID)
</span><del>-
-#if ENABLE(SERVICE_CONTROLS)
-    ReplaceControlledImage(WebKit::ShareableBitmap::Handle newBitmapHandle)
-#endif
</del><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPagemacWebPageMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm (167955 => 167956)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm        2014-04-29 20:51:47 UTC (rev 167955)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm        2014-04-29 21:54:23 UTC (rev 167956)
</span><span class="lines">@@ -45,6 +45,7 @@
</span><span class="cx"> #import &quot;WebImage.h&quot;
</span><span class="cx"> #import &quot;WebInspector.h&quot;
</span><span class="cx"> #import &quot;WebPageProxyMessages.h&quot;
</span><ins>+#import &quot;WebPasteboardOverrides.h&quot;
</ins><span class="cx"> #import &quot;WebPreferencesStore.h&quot;
</span><span class="cx"> #import &quot;WebProcess.h&quot;
</span><span class="cx"> #import &lt;PDFKit/PDFKit.h&gt;
</span><span class="lines">@@ -670,6 +671,24 @@
</span><span class="cx">     return didPerformAction;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if ENABLE(SERVICE_CONTROLS)
+static String&amp; replaceSelectionPasteboardName()
+{
+    static NeverDestroyed&lt;String&gt; string(&quot;ReplaceSelectionPasteboard&quot;);
+    return string;
+}
+
+void WebPage::replaceSelectionWithPasteboardData(const String&amp; type, const IPC::DataReference&amp; data)
+{
+    WebPasteboardOverrides::sharedPasteboardOverrides().addOverride(replaceSelectionPasteboardName(), type, data.vector());
+
+    bool result;
+    readSelectionFromPasteboard(replaceSelectionPasteboardName(), result);
+
+    WebPasteboardOverrides::sharedPasteboardOverrides().removeOverride(replaceSelectionPasteboardName(), type);
+}
+#endif
+
</ins><span class="cx"> bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent&amp;)
</span><span class="cx"> {
</span><span class="cx">     return false;
</span></span></pre>
</div>
</div>

</body>
</html>