<!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
<rdar://problem/16302722> 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 "pasteboard override" 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 "replaceSelectionWithPasteboardData" 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 "replaceSelectionWithPasteboardData".
(WebKit::WebContextMenuProxyMac::WebContextMenuProxyMac):
(WebKit::WebContextMenuProxyMac::replaceControlledImage): Deleted.
Remain other remnants of "replaceControlledImage":
* 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 <beidson@apple.com>
+
+ Change Image Controls replacement to use selection and paste
+ <rdar://problem/16302722> 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 <jer.noble@apple.com>
</span><span class="cx">
</span><span class="cx"> [iOS] Remove workaround for <rdar://problem/16578727>.
</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 "ContextMenuController.h"
</span><span class="cx"> #include "Event.h"
</span><ins>+#include "Frame.h"
+#include "FrameSelection.h"
</ins><span class="cx"> #include "HTMLDivElement.h"
</span><span class="cx"> #include "Page.h"
</span><ins>+#include "Range.h"
</ins><span class="cx"> #include "RenderBlockFlow.h"
</span><span class="cx"> #include "RenderStyle.h"
</span><span class="cx"> #include "RenderTheme.h"
</span><ins>+#include "ShadowRoot.h"
</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->type() == eventNames().clickEvent) {
</span><del>- if (Page* page = document().page())
- page->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->isShadowRoot()) {
+ hostElement = static_cast<ShadowRoot*>(parent)->hostElement();
+ break;
+ }
+ parent = parent->parentNode();
+ }
+
+ if (!hostElement)
+ return;
+ ASSERT(isHTMLImageElement(hostElement));
+
+ RefPtr<Range> range = Range::create(document(), Position(hostElement, Position::PositionIsBeforeAnchor), Position(hostElement, Position::PositionIsAfterAnchor));
+ frame->selection().setSelection(VisibleSelection(range.get()));
+
+ page->contextMenuController().showImageControlsMenu(event);
</ins><span class="cx"> event->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<Image> newImage)
-{
- Node* node = m_context.hitTestResult().innerNonSharedNode();
- if (!node)
- return;
-
- Frame* frame = node->document().frame();
- if (!frame)
- return;
-
- RenderObject* renderer = node->renderer();
- if (!renderer || !renderer->isRenderImage())
- return;
-
- CachedResourceHandle<CachedImage> replacedImage = new CachedImage(URL::fakeURLWithRelativePart("image"), newImage.get(), frame->page()->sessionID());
- toRenderImage(renderer)->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<Image>);
</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 <beidson@apple.com>
+
+ Change Image Controls replacement to use selection and paste
+ <rdar://problem/16302722> 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 <sam@webkit.org>
</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 "WebViewInternal.h"
</span><span class="cx"> #import <AppKit/NSSharingService.h>
</span><span class="cx"> #import <WebCore/BitmapImage.h>
</span><ins>+#import <WebCore/Editor.h>
+#import <WebCore/FocusController.h>
+#import <WebCore/Frame.h>
+#import <WebCore/FrameSelection.h>
</ins><span class="cx"> #import <WebCore/ContextMenuController.h>
</span><span class="cx"> #import <WebCore/Page.h>
</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 = @"WebKitServiceControlsPasteboard";
+
</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<CGImageSourceRef> source = adoptCF(CGImageSourceCreateWithData((CFDataRef)[items objectAtIndex:0], NULL));
</span><span class="cx"> RetainPtr<CGImageRef> cgImage = adoptCF(CGImageSourceCreateImageAtIndex(source.get(), 0, NULL));
</span><del>- RefPtr<Image> image = BitmapImage::create(cgImage.get());
</del><span class="cx">
</span><ins>+ if (!cgImage)
+ return;
+
</ins><span class="cx"> Page* page = [_menuClient->webView() page];
</span><span class="cx"> if (!page)
</span><span class="cx"> return;
</span><span class="cx">
</span><del>- page->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& frame = page->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 <beidson@apple.com>
+
+ Change Image Controls replacement to use selection and paste
+ <rdar://problem/16302722> and https://bugs.webkit.org/show_bug.cgi?id=131992
+
+ Reviewed by Tim Horton.
+
+ Add a "pasteboard override" 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 "replaceSelectionWithPasteboardData" 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 "replaceSelectionWithPasteboardData".
+ (WebKit::WebContextMenuProxyMac::WebContextMenuProxyMac):
+ (WebKit::WebContextMenuProxyMac::replaceControlledImage): Deleted.
+
+ Remain other remnants of "replaceControlledImage":
+ * 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 <timothy_horton@apple.com>
</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<ShareableBitmap> newBitmap)
-{
- RefPtr<ShareableBitmap> bitmap = newBitmap;
- ShareableBitmap::Handle bitmapHandle;
- bitmap->createHandle(bitmapHandle);
- m_process->send(Messages::WebPage::ReplaceControlledImage(bitmapHandle), m_pageID);
-}
-#endif
-
</del><span class="cx"> void WebPageProxy::contextMenuItemSelected(const WebContextMenuItemData& 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& type, const IPC::DataReference&);
+#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<ShareableBitmap>);
-#endif
-
</del><span class="cx"> private:
</span><span class="cx"> WebPageProxy(PageClient&, WebProcessProxy&, uint64_t pageID, const WebPageConfiguration&);
</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& 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 "DataReference.h"
</ins><span class="cx"> #import "PageClientImpl.h"
</span><span class="cx"> #import "ShareableBitmap.h"
</span><span class="cx"> #import "StringUtilities.h"
</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<CGImageSourceRef> source = adoptCF(CGImageSourceCreateWithData((CFDataRef)[items objectAtIndex:0], NULL));
</del><ins>+ NSData *data = [items objectAtIndex:0];
+ RetainPtr<CGImageSourceRef> source = adoptCF(CGImageSourceCreateWithData((CFDataRef)data, NULL));
</ins><span class="cx"> RetainPtr<CGImageRef> image = adoptCF(CGImageSourceCreateImageAtIndex(source.get(), 0, NULL));
</span><del>- _menuProxy->replaceControlledImage(image.get());
</del><ins>+
+ if (!image)
+ return;
+
+ IPC::DataReference dataReference(static_cast<const uint8_t*>([data bytes]), [data length]);
+ _menuProxy->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<ShareableBitmap> newBitmap = ShareableBitmap::createShareable(expandedIntSize(newImageSize), ShareableBitmap::SupportsAlpha);
- newBitmap->createGraphicsContext()->drawNativeImage(newImage, newImageSize, ColorSpaceDeviceRGB, FloatRect(FloatPoint(), newImageSize), FloatRect(FloatPoint(), newImageSize));
-
- m_page->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& type, const IPC::DataReference& 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& clientPosition, const ShareableBitmap::Handle& 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 = "<group>"; };
</span><span class="cx">                 511F8A77138B460900A95F44 /* SecItemShimLibrary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SecItemShimLibrary.h; path = ../../WebProcess/mac/SecItemShimLibrary.h; sourceTree = "<group>"; };
</span><span class="cx">                 511F8A78138B460900A95F44 /* SecItemShimLibrary.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SecItemShimLibrary.mm; path = ../../WebProcess/mac/SecItemShimLibrary.mm; sourceTree = "<group>"; };
</span><ins>+                512127C11908239A00DAF35C /* WebPasteboardOverrides.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebPasteboardOverrides.cpp; sourceTree = "<group>"; };
+                512127C21908239A00DAF35C /* WebPasteboardOverrides.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPasteboardOverrides.h; sourceTree = "<group>"; };
</ins><span class="cx">                 5121745E164C20E30037A5C1 /* ShareableResource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ShareableResource.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 5121745F164C20E30037A5C1 /* ShareableResource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShareableResource.h; sourceTree = "<group>"; };
</span><span class="cx">                 51217462164C21370037A5C1 /* WebResourceBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebResourceBuffer.cpp; sourceTree = "<group>"; };
</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 "config.h"
+#include "WebPasteboardOverrides.h"
+
+namespace WebKit {
+
+WebPasteboardOverrides& WebPasteboardOverrides::sharedPasteboardOverrides()
+{
+ static NeverDestroyed<WebPasteboardOverrides> sharedOverrides;
+ return sharedOverrides;
+}
+
+WebPasteboardOverrides::WebPasteboardOverrides()
+{
+}
+
+void WebPasteboardOverrides::addOverride(const String& pasteboardName, const String& type, const Vector<uint8_t>& data)
+{
+ auto addResult = m_overridesMap.add(pasteboardName, nullptr);
+
+ if (addResult.isNewEntry) {
+ std::unique_ptr<HashMap<String, Vector<uint8_t>>> typeMap = std::make_unique<HashMap<String, Vector<uint8_t>>>();
+ addResult.iterator->value = std::move(typeMap);
+ }
+
+ addResult.iterator->value->set(type, data);
+}
+
+void WebPasteboardOverrides::removeOverride(const String& pasteboardName, const String& type)
+{
+ auto it = m_overridesMap.find(pasteboardName);
+ if (it == m_overridesMap.end())
+ return;
+
+ ASSERT(it->value);
+
+ it->value->remove(type);
+
+ // If this was the last override for this pasteboard, remove its record completely.
+ if (it->value->isEmpty())
+ m_overridesMap.remove(it);
+}
+
+Vector<String> WebPasteboardOverrides::overriddenTypes(const String& pasteboardName)
+{
+ Vector<String> result;
+
+ auto it = m_overridesMap.find(pasteboardName);
+ if (it == m_overridesMap.end())
+ return result;
+
+ ASSERT(it->value);
+
+ for (String& type : it->value->keys())
+ result.append(type);
+
+ return result;
+}
+
+bool WebPasteboardOverrides::getDataForOverride(const String& pasteboardName, const String& type, Vector<uint8_t>& data) const
+{
+ auto pasteboardIterator = m_overridesMap.find(pasteboardName);
+ if (pasteboardIterator == m_overridesMap.end())
+ return false;
+
+ auto typeIterator = pasteboardIterator->value->find(type);
+ if (typeIterator == pasteboardIterator->value->end())
+ return false;
+
+ data = typeIterator->value;
+ return true;
+}
+
+bool WebPasteboardOverrides::getDataForOverride(const String& pasteboardName, const String& type, Vector<char>& data) const
+{
+ Vector<uint8_t> 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 <wtf/HashMap.h>
+#include <wtf/NeverDestroyed.h>
+#include <wtf/Vector.h>
+#include <wtf/text/StringHash.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebKit {
+
+class WebPasteboardOverrides {
+ friend class NeverDestroyed<WebPasteboardOverrides>;
+public:
+ static WebPasteboardOverrides& sharedPasteboardOverrides();
+
+ void addOverride(const String& pasteboardName, const String& type, const Vector<uint8_t>&);
+ void removeOverride(const String& pasteboardName, const String& type);
+
+ Vector<String> overriddenTypes(const String& pasteboardName);
+
+ bool getDataForOverride(const String& pasteboardName, const String& type, Vector<uint8_t>&) const;
+ bool getDataForOverride(const String& pasteboardName, const String& type, Vector<char>&) 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<String, std::unique_ptr<HashMap<String, Vector<uint8_t>>>> 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 "WebFrameNetworkingContext.h"
</span><span class="cx"> #include "WebIDBFactoryBackend.h"
</span><span class="cx"> #include "WebPage.h"
</span><ins>+#include "WebPasteboardOverrides.h"
</ins><span class="cx"> #include "WebProcess.h"
</span><span class="cx"> #include "WebProcessProxyMessages.h"
</span><span class="cx"> #include <WebCore/Color.h>
</span><span class="lines">@@ -374,12 +375,25 @@
</span><span class="cx">
</span><span class="cx"> void WebPlatformStrategies::getTypes(Vector<String>& types, const String& 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()->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<WebCore::SharedBuffer> WebPlatformStrategies::bufferForType(const String& pasteboardType, const String& pasteboardName)
</span><span class="cx"> {
</span><ins>+ // First check the overrides.
+ Vector<char> 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()->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->corePage()->contextMenuController().contextMenuItemSelected(&coreItem);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-#if ENABLE(SERVICE_CONTROLS)
-void WebContextMenu::replaceControlledImage(PassRefPtr<Image> newImage)
-{
- m_page->corePage()->contextMenuController().replaceControlledImage(newImage);
-}
-#endif
-
</del><span class="cx"> void WebContextMenu::menuItemsWithUserData(Vector<WebContextMenuItemData> &menuItems, RefPtr<API::Object>& userData) const
</span><span class="cx"> {
</span><span class="cx"> ContextMenuController& controller = m_page->corePage()->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&);
</span><span class="cx"> Vector<WebContextMenuItemData> items() const;
</span><span class="cx">
</span><del>-#if ENABLE(SERVICE_CONTROLS)
- void replaceControlledImage(PassRefPtr<WebCore::Image>);
-#endif
-
</del><span class="cx"> private:
</span><span class="cx"> WebContextMenu(WebPage*);
</span><span class="cx"> void menuItemsWithUserData(Vector<WebContextMenuItemData>&, RefPtr<API::Object>&) 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& bitmapHandle)
-{
- RefPtr<ShareableBitmap> bitmap = ShareableBitmap::create(bitmapHandle);
- if (bitmap)
- m_contextMenu->replaceControlledImage(bitmap->createImage());
-}
-#endif
-
</del><span class="cx"> void WebPage::replaceSelectionWithText(Frame* frame, const String& 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&, bool& result);
</span><span class="cx"> void acceptsFirstMouse(int eventNumber, const WebKit::WebMouseEvent&, bool& result);
</span><span class="cx"> bool performNonEditingBehaviorForSelector(const String&, WebCore::KeyboardEvent*);
</span><ins>+
+#if ENABLE(SERVICE_CONTROLS)
+ void replaceSelectionWithPasteboardData(const String& type, const IPC::DataReference&);
+#endif
+
</ins><span class="cx"> #elif PLATFORM(EFL)
</span><span class="cx"> void confirmComposition(const String& compositionString);
</span><span class="cx"> void setComposition(const WTF::String& compositionString, const WTF::Vector<WebCore::CompositionUnderline>& underlines, uint64_t cursorPosition);
</span><span class="lines">@@ -773,10 +778,6 @@
</span><span class="cx"> PassRefPtr<WebCore::DocumentLoader> createDocumentLoader(WebCore::Frame&, const WebCore::ResourceRequest&, const WebCore::SubstituteData&);
</span><span class="cx">
</span><span class="cx"> void getBytecodeProfile(uint64_t callbackID);
</span><del>-
-#if ENABLE(SERVICE_CONTROLS)
- void replaceControlledImage(const ShareableBitmap::Handle&);
-#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) -> (WebKit::SharedMemory::Handle handle, uint64_t size)
</span><span class="cx"> ReadSelectionFromPasteboard(String pasteboardName) -> (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) -> (bool result)
</span><span class="cx"> AcceptsFirstMouse(int eventNumber, WebKit::WebMouseEvent event) -> (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 "WebImage.h"
</span><span class="cx"> #import "WebInspector.h"
</span><span class="cx"> #import "WebPageProxyMessages.h"
</span><ins>+#import "WebPasteboardOverrides.h"
</ins><span class="cx"> #import "WebPreferencesStore.h"
</span><span class="cx"> #import "WebProcess.h"
</span><span class="cx"> #import <PDFKit/PDFKit.h>
</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& replaceSelectionPasteboardName()
+{
+ static NeverDestroyed<String> string("ReplaceSelectionPasteboard");
+ return string;
+}
+
+void WebPage::replaceSelectionWithPasteboardData(const String& type, const IPC::DataReference& 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&)
</span><span class="cx"> {
</span><span class="cx"> return false;
</span></span></pre>
</div>
</div>
</body>
</html>