<!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>[205909] 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/205909">205909</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-09-14 09:45:48 -0700 (Wed, 14 Sep 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>[GTK][Wayland] Implement clipboard support
https://bugs.webkit.org/show_bug.cgi?id=146574

Patch by Carlos Garnacho &lt;carlosg@gnome.org&gt; on 2016-09-14
Reviewed by Carlos Garcia Campos.

Source/WebCore:

Implement PlatformPasteboard in the GTK+ platform, and move Pasteboard
to using PasteboardStrategy so clipboard management is left to the
UIProcess.

DataObjectGtk is still used in the Pasteboard GTK implementation, it's
now just never backed by a GtkClipboard, this object is instead
serialized through PasteboardStrategy, so the UIProcess side can mirror
the content in a GtkClipboard-backed DataObjectGtk, which is then
exposed to the windowing through PlatformPasteboard/PasteboardHelper.

When requesting clipboard content, it works similarly, the UIProcess
side first updates its DataObjectGtk, which is then mirrored by the
WebProcess through the PasteboardStrategy requests.

* PlatformGTK.cmake: Added PlatformPasteboardGtk.cpp
* editing/gtk/EditorGtk.cpp:
(WebCore::Editor::writeSelectionToPasteboard): Eliminate usage of
PasteboardWebContent callback argument. This is done differently as
we have to signal back the WebProcess.
* platform/Pasteboard.h: Cleaned up of direct GTK+ dependency.
* platform/PasteboardStrategy.h: Added plumbing towards the pasteboard
proxy.
* platform/PlatformPasteboard.h:
* platform/gtk/DataObjectGtk.cpp:
(WebCore::DataObjectGtk::clearAllExceptFilenames): Clear the &quot;smart
paste&quot; flag if set, now that this is DataObjectGtk data.
* platform/gtk/DataObjectGtk.h:
(WebCore::DataObjectGtk::canSmartReplace):
(WebCore::DataObjectGtk::setCanSmartReplace): Added functions, in order
to flag whether a DataObjectGtk has the &quot;smart paste&quot; feature enabled
or not.
* platform/gtk/PasteboardGtk.cpp:
(WebCore::Pasteboard::createForCopyAndPaste):
(WebCore::Pasteboard::createForGlobalSelection):
(WebCore::Pasteboard::Pasteboard):
(WebCore::Pasteboard::writeToClipboard):
(WebCore::Pasteboard::readFromClipboard):
(WebCore::Pasteboard::writePlainText):
(WebCore::Pasteboard::write):
(WebCore::Pasteboard::writePasteboard):
(WebCore::Pasteboard::clear):
(WebCore::Pasteboard::canSmartReplace):
(WebCore::Pasteboard::read):
(WebCore::Pasteboard::hasData):
(WebCore::Pasteboard::types):
(WebCore::Pasteboard::readString):
(WebCore::Pasteboard::readFilenames): Made to use the
PasteboardStrategy instead of PasteboardHelper/GTK+ API.
* platform/gtk/PasteboardHelper.cpp:
(WebCore::PasteboardHelper::~PasteboardHelper):
(WebCore::ClipboardSetData::ClipboardSetData):
(WebCore::clearClipboardContentsCallback):
(WebCore::PasteboardHelper::writeClipboardContents): Remove the GClosure
to notify whether the global selection has been replaced. Use std:function
instead. Remove SmartPasteInclusion argument, now figured out through
DataObjectGtk canSmartPaste() member.
* platform/gtk/PasteboardHelper.h:
* platform/gtk/PlatformPasteboardGtk.cpp: Added.
(WebCore::PlatformPasteboard::PlatformPasteboard):
(WebCore::PlatformPasteboard::writeToClipboard):
(WebCore::PlatformPasteboard::readFromClipboard): Implemented
PlatformPasteboard using PasteboardHelper/GTK+ API.

Source/WebKit2:

Add the necessary plumbing for the GTK+ backend to use the
PlatformPasteboard in WebCore. All selection data is transmitted
at once through the serialization of PasteboardContentGtk/DataObjectGtk.

* PlatformGTK.cmake: Add PasteboardContentGtk.cpp and
WebPasteboardProxyGtk.cpp
* Shared/gtk/ArgumentCodersGtk.cpp:
(IPC::encode):
(IPC::decode): Renamed from encodeDataObject/decodeDataObject
and made public.
(IPC::ArgumentCoder&lt;DragData&gt;::encode):
(IPC::ArgumentCoder&lt;DragData&gt;::decode): Update DataObjectGtk
encode/decode callers. Encode the extra canSmartReplace field.
* Shared/gtk/ArgumentCodersGtk.h: Expose encode/decode methods for
DataObjectGtk.
* Shared/gtk/PasteboardContent.cpp: Added. Wraps a DataObjectGtk
so it can be serialized on WebProcess/UIProcess messaging.
(WebKit::PasteboardContent::PasteboardContent):
(WebKit::PasteboardContent::encode):
(WebKit::PasteboardContent::decode): Methods to encode/decode a
PasteboardContent.
* Shared/gtk/PasteboardContent.h: Added.
* UIProcess/WebFrameProxy.cpp:
(WebKit::WebFrameProxy::collapseSelection): Added plumbing to allow
collapsing the global selection from the UI process side.
* UIProcess/WebFrameProxy.h:
* UIProcess/WebPasteboardProxy.h:
* UIProcess/WebPasteboardProxy.messages.in: Added plumbing for the
GTK+ pasteboard proxy functions.
* UIProcess/gtk/WebPageProxyGtk.cpp:
(WebKit::WebPageProxy::editorStateChanged):
* UIProcess/gtk/WebPasteboardProxyGtk.cpp: Added.
(WebKit::WebPasteboardProxy::writeToClipboard):
(WebKit::WebPasteboardProxy::readFromClipboard): Implemented functions
hooking into the PlatformPasteboard. Per-selection (ie.
primary/clipboard) PlatformPasteboards are kept at this level, so those
are independently set and dealt with.
(WebKit::WebPasteboardProxy::setPrimarySelectionOwner):
(WebKit::WebPasteboardProxy::didDestroyFrame): Implemented functions
to manage the frame currently being currently interacted, so we can
signal back when the global selection has been replaced.
* WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
(WebKit::WebPlatformStrategies::writeToClipboard):
(WebKit::WebPlatformStrategies::readFromClipboard): Added methods to
send the WebProcess-&gt;UIProcess messages.
* WebProcess/WebCoreSupport/WebPlatformStrategies.h:
* WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:
(WebKit::WebEditorClient::updateGlobalSelection): Remove GClosure to
get notifications about changes in global selection ownership. This
is done through a WebPage message now, as the UI process manages the
clipboard.
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/gtk/WebPageGtk.cpp:
(WebKit::WebPage::collapseSelectionInFrame): Added methods to send
the UIProcess-&gt;WebProcess notification that the global selection has
been replaced.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorePlatformGTKcmake">trunk/Source/WebCore/PlatformGTK.cmake</a></li>
<li><a href="#trunkSourceWebCoreeditinggtkEditorGtkcpp">trunk/Source/WebCore/editing/gtk/EditorGtk.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformPasteboardh">trunk/Source/WebCore/platform/Pasteboard.h</a></li>
<li><a href="#trunkSourceWebCoreplatformPasteboardStrategyh">trunk/Source/WebCore/platform/PasteboardStrategy.h</a></li>
<li><a href="#trunkSourceWebCoreplatformPlatformPasteboardh">trunk/Source/WebCore/platform/PlatformPasteboard.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgtkDataObjectGtkcpp">trunk/Source/WebCore/platform/gtk/DataObjectGtk.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgtkDataObjectGtkh">trunk/Source/WebCore/platform/gtk/DataObjectGtk.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgtkPasteboardGtkcpp">trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgtkPasteboardHelpercpp">trunk/Source/WebCore/platform/gtk/PasteboardHelper.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgtkPasteboardHelperh">trunk/Source/WebCore/platform/gtk/PasteboardHelper.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2PlatformGTKcmake">trunk/Source/WebKit2/PlatformGTK.cmake</a></li>
<li><a href="#trunkSourceWebKit2SharedgtkArgumentCodersGtkcpp">trunk/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.cpp</a></li>
<li><a href="#trunkSourceWebKit2SharedgtkArgumentCodersGtkh">trunk/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebFrameProxycpp">trunk/Source/WebKit2/UIProcess/WebFrameProxy.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebFrameProxyh">trunk/Source/WebKit2/UIProcess/WebFrameProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPasteboardProxyh">trunk/Source/WebKit2/UIProcess/WebPasteboardProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPasteboardProxymessagesin">trunk/Source/WebKit2/UIProcess/WebPasteboardProxy.messages.in</a></li>
<li><a href="#trunkSourceWebKit2UIProcessgtkWebPageProxyGtkcpp">trunk/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebCoreSupportWebPlatformStrategiescpp">trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebCoreSupportWebPlatformStrategiesh">trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebCoreSupportgtkWebEditorClientGtkcpp">trunk/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.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="#trunkSourceWebKit2WebProcessWebPagegtkWebPageGtkcpp">trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPageGtk.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreplatformgtkPlatformPasteboardGtkcpp">trunk/Source/WebCore/platform/gtk/PlatformPasteboardGtk.cpp</a></li>
<li><a href="#trunkSourceWebKit2SharedgtkPasteboardContentcpp">trunk/Source/WebKit2/Shared/gtk/PasteboardContent.cpp</a></li>
<li><a href="#trunkSourceWebKit2SharedgtkPasteboardContenth">trunk/Source/WebKit2/Shared/gtk/PasteboardContent.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessgtkWebPasteboardProxyGtkcpp">trunk/Source/WebKit2/UIProcess/gtk/WebPasteboardProxyGtk.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebCore/ChangeLog        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -1,3 +1,73 @@
</span><ins>+2016-09-14  Carlos Garnacho &lt;carlosg@gnome.org&gt;
+
+        [GTK][Wayland] Implement clipboard support
+        https://bugs.webkit.org/show_bug.cgi?id=146574
+
+        Reviewed by Carlos Garcia Campos.
+
+        Implement PlatformPasteboard in the GTK+ platform, and move Pasteboard
+        to using PasteboardStrategy so clipboard management is left to the
+        UIProcess.
+
+        DataObjectGtk is still used in the Pasteboard GTK implementation, it's
+        now just never backed by a GtkClipboard, this object is instead
+        serialized through PasteboardStrategy, so the UIProcess side can mirror
+        the content in a GtkClipboard-backed DataObjectGtk, which is then
+        exposed to the windowing through PlatformPasteboard/PasteboardHelper.
+
+        When requesting clipboard content, it works similarly, the UIProcess
+        side first updates its DataObjectGtk, which is then mirrored by the
+        WebProcess through the PasteboardStrategy requests.
+
+        * PlatformGTK.cmake: Added PlatformPasteboardGtk.cpp
+        * editing/gtk/EditorGtk.cpp:
+        (WebCore::Editor::writeSelectionToPasteboard): Eliminate usage of
+        PasteboardWebContent callback argument. This is done differently as
+        we have to signal back the WebProcess.
+        * platform/Pasteboard.h: Cleaned up of direct GTK+ dependency.
+        * platform/PasteboardStrategy.h: Added plumbing towards the pasteboard
+        proxy.
+        * platform/PlatformPasteboard.h:
+        * platform/gtk/DataObjectGtk.cpp:
+        (WebCore::DataObjectGtk::clearAllExceptFilenames): Clear the &quot;smart
+        paste&quot; flag if set, now that this is DataObjectGtk data.
+        * platform/gtk/DataObjectGtk.h:
+        (WebCore::DataObjectGtk::canSmartReplace):
+        (WebCore::DataObjectGtk::setCanSmartReplace): Added functions, in order
+        to flag whether a DataObjectGtk has the &quot;smart paste&quot; feature enabled
+        or not.
+        * platform/gtk/PasteboardGtk.cpp:
+        (WebCore::Pasteboard::createForCopyAndPaste):
+        (WebCore::Pasteboard::createForGlobalSelection):
+        (WebCore::Pasteboard::Pasteboard):
+        (WebCore::Pasteboard::writeToClipboard):
+        (WebCore::Pasteboard::readFromClipboard):
+        (WebCore::Pasteboard::writePlainText):
+        (WebCore::Pasteboard::write):
+        (WebCore::Pasteboard::writePasteboard):
+        (WebCore::Pasteboard::clear):
+        (WebCore::Pasteboard::canSmartReplace):
+        (WebCore::Pasteboard::read):
+        (WebCore::Pasteboard::hasData):
+        (WebCore::Pasteboard::types):
+        (WebCore::Pasteboard::readString):
+        (WebCore::Pasteboard::readFilenames): Made to use the
+        PasteboardStrategy instead of PasteboardHelper/GTK+ API.
+        * platform/gtk/PasteboardHelper.cpp:
+        (WebCore::PasteboardHelper::~PasteboardHelper):
+        (WebCore::ClipboardSetData::ClipboardSetData):
+        (WebCore::clearClipboardContentsCallback):
+        (WebCore::PasteboardHelper::writeClipboardContents): Remove the GClosure
+        to notify whether the global selection has been replaced. Use std:function
+        instead. Remove SmartPasteInclusion argument, now figured out through
+        DataObjectGtk canSmartPaste() member.
+        * platform/gtk/PasteboardHelper.h:
+        * platform/gtk/PlatformPasteboardGtk.cpp: Added.
+        (WebCore::PlatformPasteboard::PlatformPasteboard):
+        (WebCore::PlatformPasteboard::writeToClipboard):
+        (WebCore::PlatformPasteboard::readFromClipboard): Implemented
+        PlatformPasteboard using PasteboardHelper/GTK+ API.
+
</ins><span class="cx"> 2016-09-13  Dave Hyatt  &lt;hyatt@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [CSS Parser] Enable the new sizes parser by default
</span></span></pre></div>
<a id="trunkSourceWebCorePlatformGTKcmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/PlatformGTK.cmake (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/PlatformGTK.cmake        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebCore/PlatformGTK.cmake        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -221,6 +221,7 @@
</span><span class="cx">     platform/gtk/PasteboardHelper.cpp
</span><span class="cx">     platform/gtk/PlatformKeyboardEventGtk.cpp
</span><span class="cx">     platform/gtk/PlatformMouseEventGtk.cpp
</span><ins>+    platform/gtk/PlatformPasteboardGtk.cpp
</ins><span class="cx">     platform/gtk/PlatformScreenGtk.cpp
</span><span class="cx">     platform/gtk/PlatformWheelEventGtk.cpp
</span><span class="cx">     platform/gtk/RenderThemeGadget.cpp
</span></span></pre></div>
<a id="trunkSourceWebCoreeditinggtkEditorGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/gtk/EditorGtk.cpp (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/gtk/EditorGtk.cpp        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebCore/editing/gtk/EditorGtk.cpp        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -125,7 +125,6 @@
</span><span class="cx">     pasteboardContent.canSmartCopyOrDelete = canSmartCopyOrDelete();
</span><span class="cx">     pasteboardContent.text = selectedTextForDataTransfer();
</span><span class="cx">     pasteboardContent.markup = createMarkup(*selectedRange(), nullptr, AnnotateForInterchange, false, ResolveNonLocalURLs);
</span><del>-    pasteboardContent.callback = nullptr;
</del><span class="cx">     pasteboard.write(pasteboardContent);
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformPasteboardh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/Pasteboard.h (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/Pasteboard.h        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebCore/platform/Pasteboard.h        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -32,11 +32,6 @@
</span><span class="cx"> #include &lt;wtf/Vector.h&gt;
</span><span class="cx"> #include &lt;wtf/text/WTFString.h&gt;
</span><span class="cx"> 
</span><del>-#if PLATFORM(GTK)
-typedef struct _GtkClipboard GtkClipboard;
-#include &lt;wtf/glib/GRefPtr.h&gt;
-#endif
-
</del><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx"> OBJC_CLASS NSArray;
</span><span class="cx"> OBJC_CLASS NSString;
</span><span class="lines">@@ -83,7 +78,6 @@
</span><span class="cx">     bool canSmartCopyOrDelete;
</span><span class="cx">     String text;
</span><span class="cx">     String markup;
</span><del>-    GRefPtr&lt;GClosure&gt; callback;
</del><span class="cx"> #endif
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="lines">@@ -143,8 +137,8 @@
</span><span class="cx">     ~Pasteboard();
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(GTK)
</span><ins>+    explicit Pasteboard(const String&amp; name);
</ins><span class="cx">     explicit Pasteboard(RefPtr&lt;DataObjectGtk&gt;&amp;&amp;);
</span><del>-    explicit Pasteboard(GtkClipboard*);
</del><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(WIN)
</span><span class="lines">@@ -226,8 +220,11 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(GTK)
</span><ins>+    enum class ShouldIncludeSmartPaste { No, Yes };
+    void writeToClipboard(ShouldIncludeSmartPaste = ShouldIncludeSmartPaste::No);
+    void readFromClipboard();
</ins><span class="cx">     RefPtr&lt;DataObjectGtk&gt; m_dataObject;
</span><del>-    GtkClipboard* m_gtkClipboard;
</del><ins>+    String m_name;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformPasteboardStrategyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/PasteboardStrategy.h (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/PasteboardStrategy.h        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebCore/platform/PasteboardStrategy.h        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -38,6 +38,10 @@
</span><span class="cx"> struct PasteboardImage;
</span><span class="cx"> struct PasteboardWebContent;
</span><span class="cx"> 
</span><ins>+#if PLATFORM(GTK)
+class DataObjectGtk;
+#endif
+
</ins><span class="cx"> class PasteboardStrategy {
</span><span class="cx"> public:
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="lines">@@ -68,6 +72,10 @@
</span><span class="cx">     virtual long setPathnamesForType(const Vector&lt;String&gt;&amp;, const String&amp; pasteboardType, const String&amp; pasteboardName) = 0;
</span><span class="cx">     virtual long setStringForType(const String&amp;, const String&amp; pasteboardType, const String&amp; pasteboardName) = 0;
</span><span class="cx"> #endif
</span><ins>+#if PLATFORM(GTK)
+    virtual void writeToClipboard(const String&amp; pasteboardName, const RefPtr&lt;DataObjectGtk&gt;&amp;) = 0;
+    virtual RefPtr&lt;DataObjectGtk&gt; readFromClipboard(const String&amp; pasteboardName) = 0;
+#endif // PLATFORM(GTK)
</ins><span class="cx"> protected:
</span><span class="cx">     virtual ~PasteboardStrategy()
</span><span class="cx">     {
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformPlatformPasteboardh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/PlatformPasteboard.h (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/PlatformPasteboard.h        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebCore/platform/PlatformPasteboard.h        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -47,6 +47,10 @@
</span><span class="cx"> struct PasteboardImage;
</span><span class="cx"> struct PasteboardWebContent;
</span><span class="cx"> 
</span><ins>+#if PLATFORM(GTK)
+class DataObjectGtk;
+#endif
+
</ins><span class="cx"> class PlatformPasteboard {
</span><span class="cx"> public:
</span><span class="cx">     // FIXME: probably we don't need a constructor that takes a pasteboard name for iOS.
</span><span class="lines">@@ -81,6 +85,11 @@
</span><span class="cx">     WEBCORE_EXPORT URL readURL(int index, const String&amp; pasteboardType);
</span><span class="cx">     WEBCORE_EXPORT int count();
</span><span class="cx"> 
</span><ins>+#if PLATFORM(GTK)
+    WEBCORE_EXPORT void writeToClipboard(const RefPtr&lt;DataObjectGtk&gt;&amp;, std::function&lt;void()&gt;&amp;&amp; primarySelectionCleared);
+    WEBCORE_EXPORT RefPtr&lt;DataObjectGtk&gt; readFromClipboard();
+#endif
+
</ins><span class="cx"> private:
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">     RetainPtr&lt;NSPasteboard&gt; m_pasteboard;
</span><span class="lines">@@ -88,6 +97,9 @@
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx">     RetainPtr&lt;UIPasteboard&gt; m_pasteboard;
</span><span class="cx"> #endif
</span><ins>+#if PLATFORM(GTK)
+    GtkClipboard* m_clipboard;
+#endif
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgtkDataObjectGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/gtk/DataObjectGtk.cpp (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/gtk/DataObjectGtk.cpp        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebCore/platform/gtk/DataObjectGtk.cpp        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -139,6 +139,7 @@
</span><span class="cx">     m_url = URL();
</span><span class="cx">     m_image = nullptr;
</span><span class="cx">     m_unknownTypeData.clear();
</span><ins>+    m_canSmartReplace = false;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void DataObjectGtk::clearAll()
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgtkDataObjectGtkh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/gtk/DataObjectGtk.h (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/gtk/DataObjectGtk.h        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebCore/platform/gtk/DataObjectGtk.h        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -47,6 +47,7 @@
</span><span class="cx">     bool hasURL() const { return !m_url.isEmpty() &amp;&amp; m_url.isValid(); }
</span><span class="cx">     bool hasFilenames() const { return !m_filenames.isEmpty(); }
</span><span class="cx">     bool hasImage() const { return m_image; }
</span><ins>+    bool canSmartReplace() const { return m_canSmartReplace; }
</ins><span class="cx">     void clearURIList() { m_uriList = emptyString(); }
</span><span class="cx">     void clearURL() { m_url = URL(); }
</span><span class="cx">     void clearImage() { m_image = nullptr; }
</span><span class="lines">@@ -59,6 +60,7 @@
</span><span class="cx">     void setMarkup(const String&amp;);
</span><span class="cx">     void setUnknownTypeData(const String&amp; type, const String&amp; data) { m_unknownTypeData.set(type, data); }
</span><span class="cx">     void setURIList(const String&amp;);
</span><ins>+    void setCanSmartReplace(bool canSmartReplace) { m_canSmartReplace = canSmartReplace; }
</ins><span class="cx">     String urlLabel() const;
</span><span class="cx"> 
</span><span class="cx">     void clearAllExceptFilenames();
</span><span class="lines">@@ -74,6 +76,7 @@
</span><span class="cx">     Vector&lt;String&gt; m_filenames;
</span><span class="cx">     GRefPtr&lt;GdkPixbuf&gt; m_image;
</span><span class="cx">     HashMap&lt;String, String&gt; m_unknownTypeData;
</span><ins>+    bool m_canSmartReplace { false };
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgtkPasteboardGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -23,9 +23,10 @@
</span><span class="cx"> #include &quot;DataObjectGtk.h&quot;
</span><span class="cx"> #include &quot;DragData.h&quot;
</span><span class="cx"> #include &quot;Image.h&quot;
</span><ins>+#include &quot;PasteboardStrategy.h&quot;
+#include &quot;PlatformStrategies.h&quot;
</ins><span class="cx"> #include &quot;URL.h&quot;
</span><del>-#include &quot;PasteboardHelper.h&quot;
-#include &lt;gtk/gtk.h&gt;
</del><ins>+#include &lt;wtf/NeverDestroyed.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="lines">@@ -40,12 +41,12 @@
</span><span class="cx"> 
</span><span class="cx"> std::unique_ptr&lt;Pasteboard&gt; Pasteboard::createForCopyAndPaste()
</span><span class="cx"> {
</span><del>-    return std::make_unique&lt;Pasteboard&gt;(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
</del><ins>+    return std::make_unique&lt;Pasteboard&gt;(&quot;CLIPBOARD&quot;);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> std::unique_ptr&lt;Pasteboard&gt; Pasteboard::createForGlobalSelection()
</span><span class="cx"> {
</span><del>-    return std::make_unique&lt;Pasteboard&gt;(gtk_clipboard_get(GDK_SELECTION_PRIMARY));
</del><ins>+    return std::make_unique&lt;Pasteboard&gt;(&quot;PRIMARY&quot;);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> std::unique_ptr&lt;Pasteboard&gt; Pasteboard::createPrivate()
</span><span class="lines">@@ -76,17 +77,14 @@
</span><span class="cx"> 
</span><span class="cx"> Pasteboard::Pasteboard(RefPtr&lt;DataObjectGtk&gt;&amp;&amp; dataObject)
</span><span class="cx">     : m_dataObject(WTFMove(dataObject))
</span><del>-    , m_gtkClipboard(nullptr)
</del><span class="cx"> {
</span><span class="cx">     ASSERT(m_dataObject);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-Pasteboard::Pasteboard(GtkClipboard* gtkClipboard)
</del><ins>+Pasteboard::Pasteboard(const String&amp; name)
</ins><span class="cx">     : m_dataObject(DataObjectGtk::create())
</span><del>-    , m_gtkClipboard(gtkClipboard)
</del><ins>+    , m_name(name)
</ins><span class="cx"> {
</span><del>-    ASSERT(m_dataObject);
-    PasteboardHelper::singleton().registerClipboard(gtkClipboard);
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> Pasteboard::~Pasteboard()
</span><span class="lines">@@ -121,6 +119,21 @@
</span><span class="cx">     return ClipboardDataTypeUnknown;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void Pasteboard::writeToClipboard(ShouldIncludeSmartPaste shouldIncludeSmartPaste)
+{
+    if (m_name.isNull())
+        return;
+    m_dataObject-&gt;setCanSmartReplace(shouldIncludeSmartPaste == ShouldIncludeSmartPaste::Yes);
+    platformStrategies()-&gt;pasteboardStrategy()-&gt;writeToClipboard(m_name, m_dataObject);
+}
+
+void Pasteboard::readFromClipboard()
+{
+    if (m_name.isNull())
+        return;
+    m_dataObject = platformStrategies()-&gt;pasteboardStrategy()-&gt;readFromClipboard(m_name);
+}
+
</ins><span class="cx"> void Pasteboard::writeString(const String&amp; type, const String&amp; data)
</span><span class="cx"> {
</span><span class="cx">     switch (dataObjectTypeFromHTMLClipboardType(type)) {
</span><span class="lines">@@ -147,8 +160,7 @@
</span><span class="cx">     m_dataObject-&gt;clearAll();
</span><span class="cx">     m_dataObject-&gt;setText(text);
</span><span class="cx"> 
</span><del>-    if (m_gtkClipboard)
-        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject, (smartReplaceOption == CanSmartReplace) ? PasteboardHelper::IncludeSmartPaste : PasteboardHelper::DoNotIncludeSmartPaste);
</del><ins>+    writeToClipboard(smartReplaceOption == CanSmartReplace ? ShouldIncludeSmartPaste::Yes : ShouldIncludeSmartPaste::No);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Pasteboard::write(const PasteboardURL&amp; pasteboardURL)
</span><span class="lines">@@ -158,8 +170,7 @@
</span><span class="cx">     m_dataObject-&gt;clearAll();
</span><span class="cx">     m_dataObject-&gt;setURL(pasteboardURL.url, pasteboardURL.title);
</span><span class="cx"> 
</span><del>-    if (m_gtkClipboard)
-        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject);
</del><ins>+    writeToClipboard();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Pasteboard::write(const PasteboardImage&amp; pasteboardImage)
</span><span class="lines">@@ -174,8 +185,7 @@
</span><span class="cx">     if (pixbuf)
</span><span class="cx">         m_dataObject-&gt;setImage(pixbuf.get());
</span><span class="cx"> 
</span><del>-    if (m_gtkClipboard)
-        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject);
</del><ins>+    writeToClipboard();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Pasteboard::write(const PasteboardWebContent&amp; pasteboardContent)
</span><span class="lines">@@ -184,8 +194,7 @@
</span><span class="cx">     m_dataObject-&gt;setText(pasteboardContent.text);
</span><span class="cx">     m_dataObject-&gt;setMarkup(pasteboardContent.markup);
</span><span class="cx"> 
</span><del>-    if (m_gtkClipboard)
-        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject, pasteboardContent.canSmartCopyOrDelete ? PasteboardHelper::IncludeSmartPaste : PasteboardHelper::DoNotIncludeSmartPaste, pasteboardContent.callback.get());
</del><ins>+    writeToClipboard(pasteboardContent.canSmartCopyOrDelete ? ShouldIncludeSmartPaste::Yes : ShouldIncludeSmartPaste::No);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Pasteboard::writePasteboard(const Pasteboard&amp; sourcePasteboard)
</span><span class="lines">@@ -208,8 +217,7 @@
</span><span class="cx">             m_dataObject-&gt;setUnknownTypeData(it.key, it.value);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if (m_gtkClipboard)
-        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject);
</del><ins>+    writeToClipboard();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Pasteboard::clear()
</span><span class="lines">@@ -219,9 +227,7 @@
</span><span class="cx">     // attribute's list might still not be empty after calling clearData() (it would
</span><span class="cx">     // still contain the &quot;Files&quot; string if any files were included in the drag).&quot;
</span><span class="cx">     m_dataObject-&gt;clearAllExceptFilenames();
</span><del>-
-    if (m_gtkClipboard)
-        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject);
</del><ins>+    writeToClipboard();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Pasteboard::clear(const String&amp; type)
</span><span class="lines">@@ -245,13 +251,13 @@
</span><span class="cx">         break;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if (m_gtkClipboard)
-        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject);
</del><ins>+    writeToClipboard();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool Pasteboard::canSmartReplace()
</span><span class="cx"> {
</span><del>-    return m_gtkClipboard &amp;&amp; PasteboardHelper::singleton().clipboardContentSupportsSmartReplace(m_gtkClipboard);
</del><ins>+    readFromClipboard();
+    return m_dataObject-&gt;canSmartReplace();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(DRAG_SUPPORT)
</span><span class="lines">@@ -262,23 +268,19 @@
</span><span class="cx"> 
</span><span class="cx"> void Pasteboard::read(PasteboardPlainText&amp; text)
</span><span class="cx"> {
</span><del>-    if (m_gtkClipboard)
-        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard, *m_dataObject);
</del><ins>+    readFromClipboard();
</ins><span class="cx">     text.text = m_dataObject-&gt;text();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool Pasteboard::hasData()
</span><span class="cx"> {
</span><del>-    if (m_gtkClipboard)
-        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard, *m_dataObject);
-
</del><ins>+    readFromClipboard();
</ins><span class="cx">     return m_dataObject-&gt;hasText() || m_dataObject-&gt;hasMarkup() || m_dataObject-&gt;hasURIList() || m_dataObject-&gt;hasImage() || m_dataObject-&gt;hasUnknownTypeData();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> Vector&lt;String&gt; Pasteboard::types()
</span><span class="cx"> {
</span><del>-    if (m_gtkClipboard)
-        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard, *m_dataObject);
</del><ins>+    readFromClipboard();
</ins><span class="cx"> 
</span><span class="cx">     Vector&lt;String&gt; types;
</span><span class="cx">     if (m_dataObject-&gt;hasText()) {
</span><span class="lines">@@ -306,8 +308,7 @@
</span><span class="cx"> 
</span><span class="cx"> String Pasteboard::readString(const String&amp; type)
</span><span class="cx"> {
</span><del>-    if (m_gtkClipboard)
-        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard, *m_dataObject);
</del><ins>+    readFromClipboard();
</ins><span class="cx"> 
</span><span class="cx">     switch (dataObjectTypeFromHTMLClipboardType(type)) {
</span><span class="cx">     case ClipboardDataTypeURIList:
</span><span class="lines">@@ -329,9 +330,7 @@
</span><span class="cx"> 
</span><span class="cx"> Vector&lt;String&gt; Pasteboard::readFilenames()
</span><span class="cx"> {
</span><del>-    if (m_gtkClipboard)
-        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard, *m_dataObject);
-
</del><ins>+    readFromClipboard();
</ins><span class="cx">     return m_dataObject-&gt;filenames();
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgtkPasteboardHelpercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/gtk/PasteboardHelper.cpp (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/gtk/PasteboardHelper.cpp        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebCore/platform/gtk/PasteboardHelper.cpp        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -76,8 +76,6 @@
</span><span class="cx"> 
</span><span class="cx"> PasteboardHelper::~PasteboardHelper()
</span><span class="cx"> {
</span><del>-    for (auto* clipboard : m_gtkClipboards)
-        gtk_clipboard_store(clipboard);
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> GtkTargetList* PasteboardHelper::targetList() const
</span><span class="lines">@@ -115,6 +113,8 @@
</span><span class="cx">             gtk_selection_data_free(data);
</span><span class="cx">         }
</span><span class="cx">     }
</span><ins>+
+    dataObject.setCanSmartReplace(gtk_clipboard_wait_is_target_available(clipboard, smartPasteAtom));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void PasteboardHelper::fillSelectionData(GtkSelectionData* selectionData, guint info, const DataObjectGtk&amp; dataObject)
</span><span class="lines">@@ -169,7 +169,7 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-GRefPtr&lt;GtkTargetList&gt; PasteboardHelper::targetListForDataObject(const DataObjectGtk&amp; dataObject, SmartPasteInclusion shouldInludeSmartPaste)
</del><ins>+GRefPtr&lt;GtkTargetList&gt; PasteboardHelper::targetListForDataObject(const DataObjectGtk&amp; dataObject)
</ins><span class="cx"> {
</span><span class="cx">     GRefPtr&lt;GtkTargetList&gt; list = adoptGRef(gtk_target_list_new(nullptr, 0));
</span><span class="cx"> 
</span><span class="lines">@@ -190,7 +190,7 @@
</span><span class="cx">     if (dataObject.hasUnknownTypeData())
</span><span class="cx">         gtk_target_list_add(list.get(), unknownAtom, 0, TargetTypeUnknown);
</span><span class="cx"> 
</span><del>-    if (shouldInludeSmartPaste == IncludeSmartPaste)
</del><ins>+    if (dataObject.canSmartReplace())
</ins><span class="cx">         gtk_target_list_add(list.get(), smartPasteAtom, 0, TargetTypeSmartPaste);
</span><span class="cx"> 
</span><span class="cx">     return list;
</span><span class="lines">@@ -257,9 +257,9 @@
</span><span class="cx"> static DataObjectGtk* settingClipboardDataObject = 0;
</span><span class="cx"> 
</span><span class="cx"> struct ClipboardSetData {
</span><del>-    ClipboardSetData(DataObjectGtk* dataObject, GClosure* callback)
</del><ins>+    ClipboardSetData(DataObjectGtk* dataObject, std::function&lt;void()&gt;&amp;&amp; selectionClearedCallback)
</ins><span class="cx">         : dataObject(dataObject)
</span><del>-        , callback(callback)
</del><ins>+        , selectionClearedCallback(WTFMove(selectionClearedCallback))
</ins><span class="cx">     {
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -268,7 +268,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     RefPtr&lt;DataObjectGtk&gt; dataObject;
</span><del>-    GRefPtr&lt;GClosure&gt; callback;
</del><ins>+    std::function&lt;void()&gt; selectionClearedCallback;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> static void getClipboardContentsCallback(GtkClipboard*, GtkSelectionData *selectionData, guint info, gpointer userData)
</span><span class="lines">@@ -277,7 +277,7 @@
</span><span class="cx">     PasteboardHelper::singleton().fillSelectionData(selectionData, info, *data-&gt;dataObject);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void clearClipboardContentsCallback(GtkClipboard* clipboard, gpointer userData)
</del><ins>+static void clearClipboardContentsCallback(GtkClipboard*, gpointer userData)
</ins><span class="cx"> {
</span><span class="cx">     std::unique_ptr&lt;ClipboardSetData&gt; data(static_cast&lt;ClipboardSetData*&gt;(userData));
</span><span class="cx"> 
</span><span class="lines">@@ -285,18 +285,13 @@
</span><span class="cx">     if (data-&gt;dataObject.get() != settingClipboardDataObject)
</span><span class="cx">         data-&gt;dataObject-&gt;clearAll();
</span><span class="cx"> 
</span><del>-    if (!data-&gt;callback)
-        return;
-
-    GValue firstArgument = {0, {{0}}};
-    g_value_init(&amp;firstArgument, G_TYPE_POINTER);
-    g_value_set_pointer(&amp;firstArgument, clipboard);
-    g_closure_invoke(data-&gt;callback.get(), nullptr, 1, &amp;firstArgument, 0);
</del><ins>+    if (data-&gt;selectionClearedCallback)
+        data-&gt;selectionClearedCallback();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void PasteboardHelper::writeClipboardContents(GtkClipboard* clipboard, const DataObjectGtk&amp; dataObject, SmartPasteInclusion includeSmartPaste, GClosure* callback)
</del><ins>+void PasteboardHelper::writeClipboardContents(GtkClipboard* clipboard, const DataObjectGtk&amp; dataObject, std::function&lt;void()&gt;&amp;&amp; primarySelectionCleared)
</ins><span class="cx"> {
</span><del>-    GRefPtr&lt;GtkTargetList&gt; list = targetListForDataObject(dataObject, includeSmartPaste);
</del><ins>+    GRefPtr&lt;GtkTargetList&gt; list = targetListForDataObject(dataObject);
</ins><span class="cx"> 
</span><span class="cx">     int numberOfTargets;
</span><span class="cx">     GtkTargetEntry* table = gtk_target_table_new_from_list(list.get(), &amp;numberOfTargets);
</span><span class="lines">@@ -304,7 +299,7 @@
</span><span class="cx">     if (numberOfTargets &gt; 0 &amp;&amp; table) {
</span><span class="cx">         settingClipboardDataObject = const_cast&lt;DataObjectGtk*&gt;(&amp;dataObject);
</span><span class="cx"> 
</span><del>-        auto data = std::make_unique&lt;ClipboardSetData&gt;(settingClipboardDataObject, callback);
</del><ins>+        auto data = std::make_unique&lt;ClipboardSetData&gt;(settingClipboardDataObject, WTFMove(primarySelectionCleared));
</ins><span class="cx">         if (gtk_clipboard_set_with_data(clipboard, table, numberOfTargets, getClipboardContentsCallback, clearClipboardContentsCallback, data.get())) {
</span><span class="cx">             gtk_clipboard_set_can_store(clipboard, nullptr, 0);
</span><span class="cx">             // When gtk_clipboard_set_with_data() succeeds clearClipboardContentsCallback takes the ownership of data, so we leak it here.
</span><span class="lines">@@ -319,16 +314,5 @@
</span><span class="cx">         gtk_target_table_free(table, numberOfTargets);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool PasteboardHelper::clipboardContentSupportsSmartReplace(GtkClipboard* clipboard)
-{
-    return gtk_clipboard_wait_is_target_available(clipboard, smartPasteAtom);
</del><span class="cx"> }
</span><span class="cx"> 
</span><del>-void PasteboardHelper::registerClipboard(GtkClipboard* clipboard)
-{
-    ASSERT(clipboard);
-    m_gtkClipboards.add(clipboard);
-}
-
-}
-
</del></span></pre></div>
<a id="trunkSourceWebCoreplatformgtkPasteboardHelperh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/gtk/PasteboardHelper.h (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/gtk/PasteboardHelper.h        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebCore/platform/gtk/PasteboardHelper.h        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -26,7 +26,6 @@
</span><span class="cx"> #define PasteboardHelper_h
</span><span class="cx"> 
</span><span class="cx"> #include &quot;GRefPtrGtk.h&quot;
</span><del>-#include &lt;wtf/HashSet.h&gt;
</del><span class="cx"> #include &lt;wtf/Noncopyable.h&gt;
</span><span class="cx"> #include &lt;wtf/Vector.h&gt;
</span><span class="cx"> #include &lt;wtf/glib/GRefPtr.h&gt;
</span><span class="lines">@@ -43,24 +42,20 @@
</span><span class="cx">     enum SmartPasteInclusion { IncludeSmartPaste, DoNotIncludeSmartPaste };
</span><span class="cx"> 
</span><span class="cx">     GtkTargetList* targetList() const;
</span><del>-    GRefPtr&lt;GtkTargetList&gt; targetListForDataObject(const DataObjectGtk&amp;, SmartPasteInclusion = DoNotIncludeSmartPaste);
</del><ins>+    GRefPtr&lt;GtkTargetList&gt; targetListForDataObject(const DataObjectGtk&amp;);
</ins><span class="cx">     void fillSelectionData(GtkSelectionData*, guint, const DataObjectGtk&amp;);
</span><span class="cx">     void fillDataObjectFromDropData(GtkSelectionData*, guint, DataObjectGtk&amp;);
</span><span class="cx">     Vector&lt;GdkAtom&gt; dropAtomsForContext(GtkWidget*, GdkDragContext*);
</span><del>-    void writeClipboardContents(GtkClipboard*, const DataObjectGtk&amp;, SmartPasteInclusion = DoNotIncludeSmartPaste, GClosure* = 0);
</del><ins>+    void writeClipboardContents(GtkClipboard*, const DataObjectGtk&amp;, std::function&lt;void()&gt;&amp;&amp; primarySelectionCleared = nullptr);
</ins><span class="cx">     void getClipboardContents(GtkClipboard*, DataObjectGtk&amp;);
</span><span class="cx"> 
</span><span class="cx">     enum PasteboardTargetType { TargetTypeMarkup, TargetTypeText, TargetTypeImage, TargetTypeURIList, TargetTypeNetscapeURL, TargetTypeSmartPaste, TargetTypeUnknown };
</span><del>-    bool clipboardContentSupportsSmartReplace(GtkClipboard*);
</del><span class="cx"> 
</span><del>-    void registerClipboard(GtkClipboard*);
-
</del><span class="cx"> private:
</span><span class="cx">     PasteboardHelper();
</span><span class="cx">     ~PasteboardHelper();
</span><span class="cx"> 
</span><span class="cx">     GRefPtr&lt;GtkTargetList&gt; m_targetList;
</span><del>-    HashSet&lt;GtkClipboard*&gt; m_gtkClipboards;
</del><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgtkPlatformPasteboardGtkcpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/gtk/PlatformPasteboardGtk.cpp (0 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/gtk/PlatformPasteboardGtk.cpp                                (rev 0)
+++ trunk/Source/WebCore/platform/gtk/PlatformPasteboardGtk.cpp        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -0,0 +1,49 @@
</span><ins>+/*
+ *  Copyright (C) 2016 Red Hat Inc.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include &quot;config.h&quot;
+#include &quot;PlatformPasteboard.h&quot;
+
+#include &quot;Color.h&quot;
+#include &quot;DataObjectGtk.h&quot;
+#include &quot;PasteboardHelper.h&quot;
+#include &quot;SharedBuffer.h&quot;
+#include &quot;URL.h&quot;
+#include &lt;gtk/gtk.h&gt;
+
+namespace WebCore {
+
+PlatformPasteboard::PlatformPasteboard(const String&amp; pasteboardName)
+    : m_clipboard(gtk_clipboard_get(gdk_atom_intern(pasteboardName.utf8().data(), TRUE)))
+{
+    ASSERT(m_clipboard);
+}
+
+void PlatformPasteboard::writeToClipboard(const RefPtr&lt;DataObjectGtk&gt;&amp; dataObject, std::function&lt;void()&gt;&amp;&amp; primarySelectionCleared)
+{
+    PasteboardHelper::singleton().writeClipboardContents(m_clipboard, *dataObject, gtk_clipboard_get(GDK_SELECTION_PRIMARY) == m_clipboard ? WTFMove(primarySelectionCleared) : nullptr);
+}
+
+RefPtr&lt;DataObjectGtk&gt; PlatformPasteboard::readFromClipboard()
+{
+    RefPtr&lt;DataObjectGtk&gt; dataObject = DataObjectGtk::create();
+    PasteboardHelper::singleton().getClipboardContents(m_clipboard, *dataObject);
+    return dataObject;
+}
+
+}
</ins></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebKit2/ChangeLog        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -1,3 +1,68 @@
</span><ins>+2016-09-14  Carlos Garnacho  &lt;carlosg@gnome.org&gt;
+
+        [GTK][Wayland] Implement clipboard support
+        https://bugs.webkit.org/show_bug.cgi?id=146574
+
+        Reviewed by Carlos Garcia Campos.
+
+        Add the necessary plumbing for the GTK+ backend to use the
+        PlatformPasteboard in WebCore. All selection data is transmitted
+        at once through the serialization of PasteboardContentGtk/DataObjectGtk.
+
+        * PlatformGTK.cmake: Add PasteboardContentGtk.cpp and
+        WebPasteboardProxyGtk.cpp
+        * Shared/gtk/ArgumentCodersGtk.cpp:
+        (IPC::encode):
+        (IPC::decode): Renamed from encodeDataObject/decodeDataObject
+        and made public.
+        (IPC::ArgumentCoder&lt;DragData&gt;::encode):
+        (IPC::ArgumentCoder&lt;DragData&gt;::decode): Update DataObjectGtk
+        encode/decode callers. Encode the extra canSmartReplace field.
+        * Shared/gtk/ArgumentCodersGtk.h: Expose encode/decode methods for
+        DataObjectGtk.
+        * Shared/gtk/PasteboardContent.cpp: Added. Wraps a DataObjectGtk
+        so it can be serialized on WebProcess/UIProcess messaging.
+        (WebKit::PasteboardContent::PasteboardContent):
+        (WebKit::PasteboardContent::encode):
+        (WebKit::PasteboardContent::decode): Methods to encode/decode a
+        PasteboardContent.
+        * Shared/gtk/PasteboardContent.h: Added.
+        * UIProcess/WebFrameProxy.cpp:
+        (WebKit::WebFrameProxy::collapseSelection): Added plumbing to allow
+        collapsing the global selection from the UI process side.
+        * UIProcess/WebFrameProxy.h:
+        * UIProcess/WebPasteboardProxy.h:
+        * UIProcess/WebPasteboardProxy.messages.in: Added plumbing for the
+        GTK+ pasteboard proxy functions.
+        * UIProcess/gtk/WebPageProxyGtk.cpp:
+        (WebKit::WebPageProxy::editorStateChanged):
+        * UIProcess/gtk/WebPasteboardProxyGtk.cpp: Added.
+        (WebKit::WebPasteboardProxy::writeToClipboard):
+        (WebKit::WebPasteboardProxy::readFromClipboard): Implemented functions
+        hooking into the PlatformPasteboard. Per-selection (ie.
+        primary/clipboard) PlatformPasteboards are kept at this level, so those
+        are independently set and dealt with.
+        (WebKit::WebPasteboardProxy::setPrimarySelectionOwner):
+        (WebKit::WebPasteboardProxy::didDestroyFrame): Implemented functions
+        to manage the frame currently being currently interacted, so we can
+        signal back when the global selection has been replaced.
+        * WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
+        (WebKit::WebPlatformStrategies::writeToClipboard):
+        (WebKit::WebPlatformStrategies::readFromClipboard): Added methods to
+        send the WebProcess-&gt;UIProcess messages.
+        * WebProcess/WebCoreSupport/WebPlatformStrategies.h:
+        * WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:
+        (WebKit::WebEditorClient::updateGlobalSelection): Remove GClosure to
+        get notifications about changes in global selection ownership. This
+        is done through a WebPage message now, as the UI process manages the
+        clipboard.
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+        * WebProcess/WebPage/gtk/WebPageGtk.cpp:
+        (WebKit::WebPage::collapseSelectionInFrame): Added methods to send
+        the UIProcess-&gt;WebProcess notification that the global selection has
+        been replaced.
+
</ins><span class="cx"> 2016-09-13  Tim Horton  &lt;timothy_horton@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Provide a mechanism to specify the maximum size of WKThumbnailView snapshots
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformGTKcmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/PlatformGTK.cmake (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/PlatformGTK.cmake        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebKit2/PlatformGTK.cmake        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -71,6 +71,7 @@
</span><span class="cx">     Shared/gtk/NativeWebMouseEventGtk.cpp
</span><span class="cx">     Shared/gtk/NativeWebTouchEventGtk.cpp
</span><span class="cx">     Shared/gtk/NativeWebWheelEventGtk.cpp
</span><ins>+    Shared/gtk/PasteboardContent.cpp
</ins><span class="cx">     Shared/gtk/PrintInfoGtk.cpp
</span><span class="cx">     Shared/gtk/ProcessExecutablePathGtk.cpp
</span><span class="cx">     Shared/gtk/WebContextMenuItemGtk.cpp
</span><span class="lines">@@ -313,6 +314,7 @@
</span><span class="cx">     UIProcess/gtk/WebInspectorClientGtk.cpp
</span><span class="cx">     UIProcess/gtk/WebInspectorProxyGtk.cpp
</span><span class="cx">     UIProcess/gtk/WebPageProxyGtk.cpp
</span><ins>+    UIProcess/gtk/WebPasteboardProxyGtk.cpp
</ins><span class="cx">     UIProcess/gtk/WebPopupMenuProxyGtk.cpp
</span><span class="cx">     UIProcess/gtk/WebPreferencesGtk.cpp
</span><span class="cx">     UIProcess/gtk/WebProcessPoolGtk.cpp
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedgtkArgumentCodersGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.cpp (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.cpp        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.cpp        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -82,7 +82,7 @@
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void encodeDataObject(Encoder&amp; encoder, const DataObjectGtk* dataObject)
</del><ins>+void encode(Encoder&amp; encoder, const DataObjectGtk* dataObject)
</ins><span class="cx"> {
</span><span class="cx">     bool hasText = dataObject-&gt;hasText();
</span><span class="cx">     encoder &lt;&lt; hasText;
</span><span class="lines">@@ -113,9 +113,12 @@
</span><span class="cx">     encoder &lt;&lt; hasUnknownTypeData;
</span><span class="cx">     if (hasUnknownTypeData)
</span><span class="cx">         encoder &lt;&lt; dataObject-&gt;unknownTypes();
</span><ins>+
+    bool canSmartReplace = dataObject-&gt;canSmartReplace();
+    encoder &lt;&lt; canSmartReplace;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-static bool decodeDataObject(Decoder&amp; decoder, RefPtr&lt;DataObjectGtk&gt;&amp; dataObject)
</del><ins>+bool decode(Decoder&amp; decoder, RefPtr&lt;DataObjectGtk&gt;&amp; dataObject)
</ins><span class="cx"> {
</span><span class="cx">     RefPtr&lt;DataObjectGtk&gt; data = DataObjectGtk::create();
</span><span class="cx"> 
</span><span class="lines">@@ -182,6 +185,11 @@
</span><span class="cx">             data-&gt;setUnknownTypeData(it-&gt;key, it-&gt;value);
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    bool canSmartReplace;
+    if (!decoder.decode(canSmartReplace))
+        return false;
+    data-&gt;setCanSmartReplace(canSmartReplace);
+
</ins><span class="cx">     dataObject = data;
</span><span class="cx"> 
</span><span class="cx">     return true;
</span><span class="lines">@@ -198,7 +206,7 @@
</span><span class="cx">     DataObjectGtk* platformData = dragData.platformData();
</span><span class="cx">     encoder &lt;&lt; static_cast&lt;bool&gt;(platformData);
</span><span class="cx">     if (platformData)
</span><del>-        encodeDataObject(encoder, platformData);
</del><ins>+        IPC::encode(encoder, platformData);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool ArgumentCoder&lt;DragData&gt;::decode(Decoder&amp; decoder, DragData&amp; dragData)
</span><span class="lines">@@ -225,7 +233,7 @@
</span><span class="cx"> 
</span><span class="cx">     RefPtr&lt;DataObjectGtk&gt; platformData;
</span><span class="cx">     if (hasPlatformData) {
</span><del>-        if (!decodeDataObject(decoder, platformData))
</del><ins>+        if (!IPC::decode(decoder, platformData))
</ins><span class="cx">             return false;
</span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedgtkArgumentCodersGtkh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.h (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.h        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.h        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -52,6 +52,9 @@
</span><span class="cx"> void encode(Encoder&amp;, GtkPageSetup*);
</span><span class="cx"> bool decode(Decoder&amp;, GRefPtr&lt;GtkPageSetup&gt;&amp;);
</span><span class="cx"> 
</span><ins>+void encode(Encoder&amp;, const WebCore::DataObjectGtk*);
+bool decode(Decoder&amp;, RefPtr&lt;WebCore::DataObjectGtk&gt;&amp;);
+
</ins><span class="cx"> } // namespace IPC
</span><span class="cx"> 
</span><span class="cx"> #endif // ArgumentCodersGtk_h
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedgtkPasteboardContentcpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/Shared/gtk/PasteboardContent.cpp (0 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/gtk/PasteboardContent.cpp                                (rev 0)
+++ trunk/Source/WebKit2/Shared/gtk/PasteboardContent.cpp        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -0,0 +1,46 @@
</span><ins>+/*
+ *  Copyright (C) 2016 Red Hat Inc.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include &quot;config.h&quot;
+#include &quot;PasteboardContent.h&quot;
+
+#include &quot;ArgumentCodersGtk.h&quot;
+#include &quot;DataObjectGtk.h&quot;
+#include &quot;Decoder.h&quot;
+#include &quot;Encoder.h&quot;
+#include &lt;wtf/RetainPtr.h&gt;
+
+namespace WebKit {
+
+PasteboardContent::PasteboardContent(const RefPtr&lt;WebCore::DataObjectGtk&gt;&amp; data)
+    : dataObject(data)
+{
+    ASSERT(dataObject);
+}
+
+void PasteboardContent::encode(IPC::Encoder&amp; encoder) const
+{
+    IPC::encode(encoder, dataObject.get());
+}
+
+bool PasteboardContent::decode(IPC::Decoder&amp; decoder, PasteboardContent&amp; pasteboardContent)
+{
+    return IPC::decode(decoder, pasteboardContent.dataObject);
+}
+
+} // namespace WebKit
</ins></span></pre></div>
<a id="trunkSourceWebKit2SharedgtkPasteboardContenth"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/Shared/gtk/PasteboardContent.h (0 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/gtk/PasteboardContent.h                                (rev 0)
+++ trunk/Source/WebKit2/Shared/gtk/PasteboardContent.h        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -0,0 +1,43 @@
</span><ins>+/*
+ *  Copyright (C) 2016 Red Hat Inc.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef PasteboardContent_h
+#define PasteboardContent_h
+
+#include &quot;DataObjectGtk.h&quot;
+
+namespace IPC {
+class Decoder;
+class Encoder;
+}
+
+namespace WebKit {
+
+struct PasteboardContent {
+    PasteboardContent() = default;
+    explicit PasteboardContent(const RefPtr&lt;WebCore::DataObjectGtk&gt;&amp;);
+
+    RefPtr&lt;WebCore::DataObjectGtk&gt; dataObject;
+
+    void encode(IPC::Encoder&amp;) const;
+    static bool decode(IPC::Decoder&amp;, PasteboardContent&amp;);
+};
+
+} // namespace WebKit
+
+#endif // PasteboardContent_h
</ins></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebFrameProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebFrameProxy.cpp (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebFrameProxy.cpp        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebKit2/UIProcess/WebFrameProxy.cpp        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -31,6 +31,7 @@
</span><span class="cx"> #include &quot;WebFramePolicyListenerProxy.h&quot;
</span><span class="cx"> #include &quot;WebPageMessages.h&quot;
</span><span class="cx"> #include &quot;WebPageProxy.h&quot;
</span><ins>+#include &quot;WebPasteboardProxy.h&quot;
</ins><span class="cx"> #include &quot;WebProcessPool.h&quot;
</span><span class="cx"> #include &lt;WebCore/Image.h&gt;
</span><span class="cx"> #include &lt;WebCore/MIMETypeRegistry.h&gt;
</span><span class="lines">@@ -52,6 +53,9 @@
</span><span class="cx"> WebFrameProxy::~WebFrameProxy()
</span><span class="cx"> {
</span><span class="cx">     WebProcessPool::statistics().wkFrameCount--;
</span><ins>+#if PLATFORM(GTK)
+    WebPasteboardProxy::singleton().didDestroyFrame(this);
+#endif
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebFrameProxy::webProcessWillShutDown()
</span><span class="lines">@@ -254,4 +258,14 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if PLATFORM(GTK)
+void WebFrameProxy::collapseSelection()
+{
+    if (!m_page)
+        return;
+
+    m_page-&gt;process().send(Messages::WebPage::CollapseSelectionInFrame(m_frameID), m_page-&gt;pageID());
+}
+#endif
+
</ins><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebFrameProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebFrameProxy.h (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebFrameProxy.h        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebKit2/UIProcess/WebFrameProxy.h        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -124,6 +124,10 @@
</span><span class="cx">     bool didHandleContentFilterUnblockNavigation(const WebCore::ResourceRequest&amp;);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if PLATFORM(GTK)
+    void collapseSelection();
+#endif
+
</ins><span class="cx"> private:
</span><span class="cx">     WebFrameProxy(WebPageProxy* page, uint64_t frameID);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPasteboardProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPasteboardProxy.h (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPasteboardProxy.h        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebKit2/UIProcess/WebPasteboardProxy.h        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -40,8 +40,13 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><ins>+class WebFrameProxy;
</ins><span class="cx"> class WebProcessProxy;
</span><span class="cx"> 
</span><ins>+#if PLATFORM(GTK)
+class PasteboardContent;
+#endif
+
</ins><span class="cx"> class WebPasteboardProxy : public IPC::MessageReceiver {
</span><span class="cx">     WTF_MAKE_NONCOPYABLE(WebPasteboardProxy);
</span><span class="cx">     friend class LazyNeverDestroyed&lt;WebPasteboardProxy&gt;;
</span><span class="lines">@@ -50,6 +55,11 @@
</span><span class="cx"> 
</span><span class="cx">     void addWebProcessProxy(WebProcessProxy&amp;);
</span><span class="cx"> 
</span><ins>+#if PLATFORM(GTK)
+    void setPrimarySelectionOwner(WebFrameProxy*);
+    void didDestroyFrame(WebFrameProxy*);
+#endif
+
</ins><span class="cx"> private:
</span><span class="cx">     WebPasteboardProxy();
</span><span class="cx"> 
</span><span class="lines">@@ -81,6 +91,13 @@
</span><span class="cx">     void setPasteboardStringForType(const String&amp; pasteboardName, const String&amp; pasteboardType, const String&amp;, uint64_t&amp; newChangeCount);
</span><span class="cx">     void setPasteboardBufferForType(const String&amp; pasteboardName, const String&amp; pasteboardType, const SharedMemory::Handle&amp;, uint64_t size, uint64_t&amp; newChangeCount);
</span><span class="cx"> #endif
</span><ins>+#if PLATFORM(GTK)
+    void writeToClipboard(const String&amp; pasteboardName, const PasteboardContent&amp;);
+    void readFromClipboard(const String&amp; pasteboardName, PasteboardContent&amp;);
+
+    WebFrameProxy* m_primarySelectionOwner { nullptr };
+    WebFrameProxy* m_frameWritingToClipboard { nullptr };
+#endif // PLATFORM(GTK)
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPasteboardProxymessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPasteboardProxy.messages.in (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPasteboardProxy.messages.in        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebKit2/UIProcess/WebPasteboardProxy.messages.in        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -48,4 +48,9 @@
</span><span class="cx">     SetPasteboardStringForType(String pasteboardName, String pasteboardType, String string) -&gt; (uint64_t changeCount)
</span><span class="cx">     SetPasteboardBufferForType(String pasteboardName, String pasteboardType, WebKit::SharedMemory::Handle handle, uint64_t size) -&gt; (uint64_t changeCount)
</span><span class="cx"> #endif
</span><ins>+
+#if PLATFORM(GTK)
+    WriteToClipboard(String pasteboardName, struct WebKit::PasteboardContent pasteboardContent)
+    ReadFromClipboard(String pasteboardName) -&gt; (struct WebKit::PasteboardContent pasteboardContent)
+#endif
</ins><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessgtkWebPageProxyGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -31,6 +31,7 @@
</span><span class="cx"> #include &quot;PageClientImpl.h&quot;
</span><span class="cx"> #include &quot;WebKitWebViewBasePrivate.h&quot;
</span><span class="cx"> #include &quot;WebPageMessages.h&quot;
</span><ins>+#include &quot;WebPasteboardProxy.h&quot;
</ins><span class="cx"> #include &quot;WebProcessProxy.h&quot;
</span><span class="cx"> #include &quot;WebsiteDataStore.h&quot;
</span><span class="cx"> #include &lt;WebCore/UserAgentGtk.h&gt;
</span><span class="lines">@@ -79,6 +80,8 @@
</span><span class="cx">     
</span><span class="cx">     if (editorState.shouldIgnoreCompositionSelectionChange)
</span><span class="cx">         return;
</span><ins>+    if (m_editorState.selectionIsRange)
+        WebPasteboardProxy::singleton().setPrimarySelectionOwner(focusedFrame());
</ins><span class="cx">     m_pageClient.selectionDidChange();
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessgtkWebPasteboardProxyGtkcpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/UIProcess/gtk/WebPasteboardProxyGtk.cpp (0 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/gtk/WebPasteboardProxyGtk.cpp                                (rev 0)
+++ trunk/Source/WebKit2/UIProcess/gtk/WebPasteboardProxyGtk.cpp        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -0,0 +1,73 @@
</span><ins>+/*
+ * Copyright (C) 2016 Red Hat Inc.
+ *
+ * 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;WebPasteboardProxy.h&quot;
+
+#include &quot;PasteboardContent.h&quot;
+#include &quot;WebFrameProxy.h&quot;
+#include &lt;WebCore/PlatformPasteboard.h&gt;
+#include &lt;wtf/HashMap.h&gt;
+#include &lt;wtf/NeverDestroyed.h&gt;
+#include &lt;wtf/TemporaryChange.h&gt;
+#include &lt;wtf/text/StringHash.h&gt;
+
+using namespace WebCore;
+
+namespace WebKit {
+
+void WebPasteboardProxy::writeToClipboard(const String&amp; pasteboardName, const PasteboardContent&amp; pasteboardContent)
+{
+    TemporaryChange&lt;WebFrameProxy*&gt; frameWritingToClipboard(m_frameWritingToClipboard, m_primarySelectionOwner);
+    PlatformPasteboard(pasteboardName).writeToClipboard(pasteboardContent.dataObject, [this] {
+        if (m_frameWritingToClipboard == m_primarySelectionOwner)
+            return;
+        setPrimarySelectionOwner(nullptr);
+    });
+}
+
+void WebPasteboardProxy::readFromClipboard(const String&amp; pasteboardName, PasteboardContent&amp; pasteboardContent)
+{
+    pasteboardContent = PasteboardContent(PlatformPasteboard(pasteboardName).readFromClipboard().get());
+}
+
+void WebPasteboardProxy::setPrimarySelectionOwner(WebFrameProxy* frame)
+{
+    if (m_primarySelectionOwner == frame)
+        return;
+
+    if (m_primarySelectionOwner)
+        m_primarySelectionOwner-&gt;collapseSelection();
+
+    m_primarySelectionOwner = frame;
+}
+
+void WebPasteboardProxy::didDestroyFrame(WebFrameProxy* frame)
+{
+    if (frame == m_primarySelectionOwner)
+        m_primarySelectionOwner = nullptr;
+}
+
+} // namespace WebKit
</ins></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebCoreSupportWebPlatformStrategiescpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -69,6 +69,10 @@
</span><span class="cx"> #include &quot;StringUtilities.h&quot;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if PLATFORM(GTK)
+#include &quot;PasteboardContent.h&quot;
+#endif
+
</ins><span class="cx"> using namespace WebCore;
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="lines">@@ -339,4 +343,22 @@
</span><span class="cx"> 
</span><span class="cx"> #endif // PLATFORM(COCOA)
</span><span class="cx"> 
</span><ins>+#if PLATFORM(GTK)
+// PasteboardStrategy
+
+void WebPlatformStrategies::writeToClipboard(const String&amp; pasteboardName, const RefPtr&lt;WebCore::DataObjectGtk&gt;&amp; dataObject)
+{
+    PasteboardContent pasteboardContent = PasteboardContent(dataObject.get());
+    WebProcess::singleton().parentProcessConnection()-&gt;send(Messages::WebPasteboardProxy::WriteToClipboard(pasteboardName, pasteboardContent), 0);
+}
+
+RefPtr&lt;WebCore::DataObjectGtk&gt; WebPlatformStrategies::readFromClipboard(const String&amp; pasteboardName)
+{
+    PasteboardContent pasteboardContent;
+    WebProcess::singleton().parentProcessConnection()-&gt;sendSync(Messages::WebPasteboardProxy::ReadFromClipboard(pasteboardName), Messages::WebPasteboardProxy::ReadFromClipboard::Reply(pasteboardContent), 0);
+    return pasteboardContent.dataObject;
+}
+
+#endif // PLATFORM(GTK)
+
</ins><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebCoreSupportWebPlatformStrategiesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -86,7 +86,10 @@
</span><span class="cx">     long setPathnamesForType(const Vector&lt;String&gt;&amp;, const String&amp; pasteboardType, const String&amp; pasteboardName) override;
</span><span class="cx">     long setStringForType(const String&amp;, const String&amp; pasteboardType, const String&amp; pasteboardName) override;
</span><span class="cx"> #endif
</span><del>-
</del><ins>+#if PLATFORM(GTK)
+    void writeToClipboard(const String&amp; pasteboardName, const RefPtr&lt;WebCore::DataObjectGtk&gt;&amp;) override;
+    RefPtr&lt;WebCore::DataObjectGtk&gt; readFromClipboard(const String&amp; pasteboardName) override;
+#endif
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebCoreSupportgtkWebEditorClientGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -119,45 +119,6 @@
</span><span class="cx">         event-&gt;setDefaultHandled();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-class EditorClientFrameDestructionObserver : FrameDestructionObserver {
-public:
-    EditorClientFrameDestructionObserver(Frame* frame, GClosure* closure)
-        : FrameDestructionObserver(frame)
-        , m_closure(closure)
-    {
-        g_closure_add_finalize_notifier(m_closure, this, destroyOnClosureFinalization);
-    }
-
-    void frameDestroyed()
-    {
-        g_closure_invalidate(m_closure);
-        FrameDestructionObserver::frameDestroyed();
-    }
-private:
-    GClosure* m_closure;
-
-    static void destroyOnClosureFinalization(gpointer data, GClosure*)
-    {
-        // Calling delete void* will free the memory but won't invoke
-        // the destructor, something that is a must for us.
-        EditorClientFrameDestructionObserver* observer = static_cast&lt;EditorClientFrameDestructionObserver*&gt;(data);
-        delete observer;
-    }
-};
-
-static Frame* frameSettingClipboard;
-
-static void collapseSelection(GtkClipboard*, Frame* frame)
-{
-    if (frameSettingClipboard &amp;&amp; frameSettingClipboard == frame)
-        return;
-
-    // Collapse the selection without clearing it.
-    ASSERT(frame);
-    const VisibleSelection&amp; selection = frame-&gt;selection().selection();
-    frame-&gt;selection().setBase(selection.extent(), selection.affinity());
-}
-
</del><span class="cx"> void WebEditorClient::updateGlobalSelection(Frame* frame)
</span><span class="cx"> {
</span><span class="cx">     if (!frame-&gt;selection().isRange())
</span><span class="lines">@@ -166,21 +127,11 @@
</span><span class="cx">     if (!range)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    frameSettingClipboard = frame;
-    GRefPtr&lt;GClosure&gt; callback = adoptGRef(g_cclosure_new(G_CALLBACK(collapseSelection), frame, nullptr));
-    // This observer will be self-destroyed on closure finalization,
-    // that will happen either after closure execution or after
-    // closure invalidation.
-    new EditorClientFrameDestructionObserver(frame, callback.get());
-    g_closure_set_marshal(callback.get(), g_cclosure_marshal_VOID__VOID);
-
</del><span class="cx">     PasteboardWebContent pasteboardContent;
</span><span class="cx">     pasteboardContent.canSmartCopyOrDelete = false;
</span><span class="cx">     pasteboardContent.text = range-&gt;text();
</span><span class="cx">     pasteboardContent.markup = createMarkup(*range, nullptr, AnnotateForInterchange, false, ResolveNonLocalURLs);
</span><del>-    pasteboardContent.callback = callback;
</del><span class="cx">     Pasteboard::createForGlobalSelection()-&gt;write(pasteboardContent);
</span><del>-    frameSettingClipboard = nullptr;
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool WebEditorClient::shouldShowUnicodeMenu()
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -646,6 +646,8 @@
</span><span class="cx">     void setComposition(const String&amp; text, const Vector&lt;WebCore::CompositionUnderline&gt;&amp; underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeLength);
</span><span class="cx">     void confirmComposition(const String&amp; text, int64_t selectionStart, int64_t selectionLength);
</span><span class="cx">     void cancelComposition();
</span><ins>+
+    void collapseSelectionInFrame(uint64_t frameID);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM (GTK) &amp;&amp; HAVE(GTK_GESTURES)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPagemessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -340,6 +340,8 @@
</span><span class="cx">     SetComposition(String text, Vector&lt;WebCore::CompositionUnderline&gt; underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeEnd)
</span><span class="cx">     ConfirmComposition(String text, int64_t selectionStart, int64_t selectionLength)
</span><span class="cx">     CancelComposition()
</span><ins>+
+    CollapseSelectionInFrame(uint64_t frameID)
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM (GTK) &amp;&amp; HAVE(GTK_GESTURES)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPagegtkWebPageGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPageGtk.cpp (205908 => 205909)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPageGtk.cpp        2016-09-14 16:40:13 UTC (rev 205908)
+++ trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPageGtk.cpp        2016-09-14 16:45:48 UTC (rev 205909)
</span><span class="lines">@@ -31,8 +31,10 @@
</span><span class="cx"> #include &quot;EditorState.h&quot;
</span><span class="cx"> #include &quot;NotImplemented.h&quot;
</span><span class="cx"> #include &quot;WebEvent.h&quot;
</span><ins>+#include &quot;WebFrame.h&quot;
</ins><span class="cx"> #include &quot;WebPageAccessibilityObject.h&quot;
</span><span class="cx"> #include &quot;WebPageProxyMessages.h&quot;
</span><ins>+#include &quot;WebProcess.h&quot;
</ins><span class="cx"> #include &quot;WindowsKeyboardCodes.h&quot;
</span><span class="cx"> #include &lt;WebCore/BackForwardController.h&gt;
</span><span class="cx"> #include &lt;WebCore/EventHandler.h&gt;
</span><span class="lines">@@ -216,4 +218,15 @@
</span><span class="cx">     send(Messages::WebPageProxy::SetInputMethodState(enabled));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPage::collapseSelectionInFrame(uint64_t frameID)
+{
+    WebFrame* frame = WebProcess::singleton().webFrame(frameID);
+    if (!frame || !frame-&gt;coreFrame())
+        return;
+
+    // Collapse the selection without clearing it.
+    const VisibleSelection&amp; selection = frame-&gt;coreFrame()-&gt;selection().selection();
+    frame-&gt;coreFrame()-&gt;selection().setBase(selection.extent(), selection.affinity());
+}
+
</ins><span class="cx"> } // namespace WebKit
</span></span></pre>
</div>
</div>

</body>
</html>