<!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>[173687] 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/173687">173687</a></dd>
<dt>Author</dt> <dd>carlosgc@webkit.org</dd>
<dt>Date</dt> <dd>2014-09-17 00:05:45 -0700 (Wed, 17 Sep 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[GTK] Fix layering violations in PasteboardGtk
https://bugs.webkit.org/show_bug.cgi?id=136802

Reviewed by Darin Adler.

Source/WebCore:

Refactor the Pasteboard code moving the WebCore parts to the Editor.

* PlatformGTK.cmake: Add new file to compilation.
* editing/Editor.cpp:
(WebCore::Editor::performCutOrCopy):
(WebCore::Editor::copyImage):
* editing/Editor.h:
* editing/gtk/EditorGtk.cpp: Added.
(WebCore::createFragmentFromPasteBoardData):
(WebCore::Editor::pasteWithPasteboard):
(WebCore::getImageAndURLForElement):
(WebCore::Editor::writeImageToPasteboard):
(WebCore::Editor::writeSelectionToPasteboard):
* page/DragController.cpp:
(WebCore::DragController::startDrag):
* page/gtk/DragControllerGtk.cpp:
(WebCore::DragController::declareAndWriteDragImage):
* platform/Pasteboard.h:
* platform/gtk/DataObjectGtk.cpp: Remove range member, the caller
should call setText() + setMarkup() intead.
(WebCore::DataObjectGtk::setText):
(WebCore::DataObjectGtk::setMarkup):
(WebCore::DataObjectGtk::clearText):
(WebCore::DataObjectGtk::clearMarkup):
(WebCore::DataObjectGtk::clearAllExceptFilenames):
* platform/gtk/DataObjectGtk.h:
(WebCore::DataObjectGtk::hasText):
(WebCore::DataObjectGtk::hasMarkup):
(WebCore::DataObjectGtk::clearImage):
(WebCore::DataObjectGtk::text):
(WebCore::DataObjectGtk::markup):
(WebCore::DataObjectGtk::setRange): Deleted.
* platform/gtk/GtkDragAndDropHelper.h:
* platform/gtk/PasteboardGtk.cpp:
(WebCore::PasteboardImage::PasteboardImage):
(WebCore::PasteboardImage::~PasteboardImage):
(WebCore::Pasteboard::write):
(WebCore::Pasteboard::writeSelection): Deleted.
(WebCore::getURLForImageElement): Deleted.
(WebCore::Pasteboard::writeImage): Deleted.
(WebCore::Pasteboard::documentFragment): Deleted.
* platform/gtk/PasteboardHelper.cpp:
(WebCore::displayFromFrame): Deleted.
(WebCore::PasteboardHelper::getPrimarySelectionClipboard): Deleted.
* platform/gtk/PasteboardHelper.h:

Source/WebKit2:

* WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:
(WebKit::WebEditorClient::updateGlobalSelection): Use new API to
update the global selection.</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="#trunkSourceWebCoreeditingEditorcpp">trunk/Source/WebCore/editing/Editor.cpp</a></li>
<li><a href="#trunkSourceWebCoreeditingEditorh">trunk/Source/WebCore/editing/Editor.h</a></li>
<li><a href="#trunkSourceWebCorepageDragControllercpp">trunk/Source/WebCore/page/DragController.cpp</a></li>
<li><a href="#trunkSourceWebCorepagegtkDragControllerGtkcpp">trunk/Source/WebCore/page/gtk/DragControllerGtk.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformPasteboardh">trunk/Source/WebCore/platform/Pasteboard.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="#trunkSourceWebCoreplatformgtkGtkDragAndDropHelperh">trunk/Source/WebCore/platform/gtk/GtkDragAndDropHelper.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="#trunkSourceWebKit2WebProcessWebCoreSupportgtkWebEditorClientGtkcpp">trunk/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li>trunk/Source/WebCore/editing/gtk/</li>
<li><a href="#trunkSourceWebCoreeditinggtkEditorGtkcpp">trunk/Source/WebCore/editing/gtk/EditorGtk.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (173686 => 173687)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-09-17 06:27:46 UTC (rev 173686)
+++ trunk/Source/WebCore/ChangeLog        2014-09-17 07:05:45 UTC (rev 173687)
</span><span class="lines">@@ -1,5 +1,58 @@
</span><span class="cx"> 2014-09-16  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><ins>+        [GTK] Fix layering violations in PasteboardGtk
+        https://bugs.webkit.org/show_bug.cgi?id=136802
+
+        Reviewed by Darin Adler.
+
+        Refactor the Pasteboard code moving the WebCore parts to the Editor.
+
+        * PlatformGTK.cmake: Add new file to compilation.
+        * editing/Editor.cpp:
+        (WebCore::Editor::performCutOrCopy):
+        (WebCore::Editor::copyImage):
+        * editing/Editor.h:
+        * editing/gtk/EditorGtk.cpp: Added.
+        (WebCore::createFragmentFromPasteBoardData):
+        (WebCore::Editor::pasteWithPasteboard):
+        (WebCore::getImageAndURLForElement):
+        (WebCore::Editor::writeImageToPasteboard):
+        (WebCore::Editor::writeSelectionToPasteboard):
+        * page/DragController.cpp:
+        (WebCore::DragController::startDrag):
+        * page/gtk/DragControllerGtk.cpp:
+        (WebCore::DragController::declareAndWriteDragImage):
+        * platform/Pasteboard.h:
+        * platform/gtk/DataObjectGtk.cpp: Remove range member, the caller
+        should call setText() + setMarkup() intead.
+        (WebCore::DataObjectGtk::setText):
+        (WebCore::DataObjectGtk::setMarkup):
+        (WebCore::DataObjectGtk::clearText):
+        (WebCore::DataObjectGtk::clearMarkup):
+        (WebCore::DataObjectGtk::clearAllExceptFilenames):
+        * platform/gtk/DataObjectGtk.h:
+        (WebCore::DataObjectGtk::hasText):
+        (WebCore::DataObjectGtk::hasMarkup):
+        (WebCore::DataObjectGtk::clearImage):
+        (WebCore::DataObjectGtk::text):
+        (WebCore::DataObjectGtk::markup):
+        (WebCore::DataObjectGtk::setRange): Deleted.
+        * platform/gtk/GtkDragAndDropHelper.h:
+        * platform/gtk/PasteboardGtk.cpp:
+        (WebCore::PasteboardImage::PasteboardImage):
+        (WebCore::PasteboardImage::~PasteboardImage):
+        (WebCore::Pasteboard::write):
+        (WebCore::Pasteboard::writeSelection): Deleted.
+        (WebCore::getURLForImageElement): Deleted.
+        (WebCore::Pasteboard::writeImage): Deleted.
+        (WebCore::Pasteboard::documentFragment): Deleted.
+        * platform/gtk/PasteboardHelper.cpp:
+        (WebCore::displayFromFrame): Deleted.
+        (WebCore::PasteboardHelper::getPrimarySelectionClipboard): Deleted.
+        * platform/gtk/PasteboardHelper.h:
+
+2014-09-16  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
+
</ins><span class="cx">         DragData should not depend on Clipboard, DocumentFragment, and Document
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=21358
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorePlatformGTKcmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/PlatformGTK.cmake (173686 => 173687)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/PlatformGTK.cmake        2014-09-17 06:27:46 UTC (rev 173686)
+++ trunk/Source/WebCore/PlatformGTK.cmake        2014-09-17 07:05:45 UTC (rev 173687)
</span><span class="lines">@@ -180,6 +180,7 @@
</span><span class="cx">     accessibility/atk/WebKitAccessibleWrapperAtk.cpp
</span><span class="cx"> 
</span><span class="cx">     editing/atk/FrameSelectionAtk.cpp
</span><ins>+    editing/gtk/EditorGtk.cpp
</ins><span class="cx"> 
</span><span class="cx">     page/gtk/DragControllerGtk.cpp
</span><span class="cx">     page/gtk/EventHandlerGtk.cpp
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingEditorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/Editor.cpp (173686 => 173687)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/Editor.cpp        2014-09-17 06:27:46 UTC (rev 173686)
+++ trunk/Source/WebCore/editing/Editor.cpp        2014-09-17 07:05:45 UTC (rev 173687)
</span><span class="lines">@@ -562,7 +562,7 @@
</span><span class="cx"> 
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-#if !PLATFORM(COCOA) &amp;&amp; !PLATFORM(EFL)
</del><ins>+#if !PLATFORM(COCOA) &amp;&amp; !PLATFORM(EFL) &amp;&amp; !PLATFORM(GTK)
</ins><span class="cx"> void Editor::pasteWithPasteboard(Pasteboard* pasteboard, bool allowPlainText, MailBlockquoteHandling mailBlockquoteHandling)
</span><span class="cx"> {
</span><span class="cx">     RefPtr&lt;Range&gt; range = selectedRange();
</span><span class="lines">@@ -1324,13 +1324,13 @@
</span><span class="cx">             imageElement = imageElementFromImageDocument(document());
</span><span class="cx"> 
</span><span class="cx">         if (imageElement) {
</span><del>-#if PLATFORM(COCOA) || PLATFORM(EFL)
</del><ins>+#if PLATFORM(COCOA) || PLATFORM(EFL) || PLATFORM(GTK)
</ins><span class="cx">             writeImageToPasteboard(*Pasteboard::createForCopyAndPaste(), *imageElement, document().url(), document().title());
</span><span class="cx"> #else
</span><span class="cx">             Pasteboard::createForCopyAndPaste()-&gt;writeImage(*imageElement, document().url(), document().title());
</span><span class="cx"> #endif
</span><span class="cx">         } else {
</span><del>-#if PLATFORM(COCOA) || PLATFORM(EFL)
</del><ins>+#if PLATFORM(COCOA) || PLATFORM(EFL) || PLATFORM(GTK)
</ins><span class="cx">             writeSelectionToPasteboard(*Pasteboard::createForCopyAndPaste());
</span><span class="cx"> #else
</span><span class="cx">             // FIXME: Convert all other platforms to match Mac and delete this.
</span><span class="lines">@@ -1436,7 +1436,7 @@
</span><span class="cx">     if (url.isEmpty())
</span><span class="cx">         url = result.absoluteImageURL();
</span><span class="cx"> 
</span><del>-#if PLATFORM(COCOA) || PLATFORM(EFL)
</del><ins>+#if PLATFORM(COCOA) || PLATFORM(EFL) || PLATFORM(GTK)
</ins><span class="cx">     writeImageToPasteboard(*Pasteboard::createForCopyAndPaste(), *element, url, result.altDisplayString());
</span><span class="cx"> #else
</span><span class="cx">     Pasteboard::createForCopyAndPaste()-&gt;writeImage(*element, url, result.altDisplayString());
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingEditorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/Editor.h (173686 => 173687)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/Editor.h        2014-09-17 06:27:46 UTC (rev 173686)
+++ trunk/Source/WebCore/editing/Editor.h        2014-09-17 07:05:45 UTC (rev 173687)
</span><span class="lines">@@ -443,7 +443,7 @@
</span><span class="cx"> #endif // !PLATFORM(IOS)
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-#if PLATFORM(COCOA) || PLATFORM(EFL)
</del><ins>+#if PLATFORM(COCOA) || PLATFORM(EFL) || PLATFORM(GTK)
</ins><span class="cx">     WEBCORE_EXPORT void writeSelectionToPasteboard(Pasteboard&amp;);
</span><span class="cx">     WEBCORE_EXPORT void writeImageToPasteboard(Pasteboard&amp;, Element&amp; imageElement, const URL&amp;, const String&amp; title);
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCoreeditinggtkEditorGtkcpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/editing/gtk/EditorGtk.cpp (0 => 173687)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/gtk/EditorGtk.cpp                                (rev 0)
+++ trunk/Source/WebCore/editing/gtk/EditorGtk.cpp        2014-09-17 07:05:45 UTC (rev 173687)
</span><span class="lines">@@ -0,0 +1,132 @@
</span><ins>+/*
+ * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * 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. ``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
+ * 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;Editor.h&quot;
+
+#include &quot;CachedImage.h&quot;
+#include &quot;DataObjectGtk.h&quot;
+#include &quot;DocumentFragment.h&quot;
+#include &quot;Frame.h&quot;
+#include &quot;HTMLImageElement.h&quot;
+#include &quot;HTMLInputElement.h&quot;
+#include &quot;HTMLNames.h&quot;
+#include &quot;HTMLParserIdioms.h&quot;
+#include &quot;Pasteboard.h&quot;
+#include &quot;RenderImage.h&quot;
+#include &quot;SVGElement.h&quot;
+#include &quot;XLinkNames.h&quot;
+#include &quot;markup.h&quot;
+
+namespace WebCore {
+
+static PassRefPtr&lt;DocumentFragment&gt; createFragmentFromPasteboardData(Pasteboard&amp; pasteboard, Frame&amp; frame, Range&amp; range, bool allowPlainText, bool&amp; chosePlainText)
+{
+    chosePlainText = false;
+
+    if (!pasteboard.hasData())
+        return nullptr;
+
+    RefPtr&lt;DataObjectGtk&gt; dataObject = pasteboard.dataObject();
+    if (dataObject-&gt;hasMarkup() &amp;&amp; frame.document()) {
+        if (RefPtr&lt;DocumentFragment&gt; fragment = createFragmentFromMarkup(*frame.document(), dataObject-&gt;markup(), emptyString(), DisallowScriptingAndPluginContent))
+            return fragment.release();
+    }
+
+    if (!allowPlainText)
+        return nullptr;
+
+    if (dataObject-&gt;hasText()) {
+        chosePlainText = true;
+        if (RefPtr&lt;DocumentFragment&gt; fragment = createFragmentFromText(range, dataObject-&gt;text()))
+            return fragment.release();
+    }
+
+    return nullptr;
+}
+
+void Editor::pasteWithPasteboard(Pasteboard* pasteboard, bool allowPlainText, MailBlockquoteHandling mailBlockquoteHandling)
+{
+    RefPtr&lt;Range&gt; range = selectedRange();
+    if (!range)
+        return;
+
+    bool chosePlainText;
+    RefPtr&lt;DocumentFragment&gt; fragment = createFragmentFromPasteboardData(*pasteboard, m_frame, *range, allowPlainText, chosePlainText);
+    if (fragment &amp;&amp; shouldInsertFragment(fragment, range, EditorInsertActionPasted))
+        pasteAsFragment(fragment, canSmartReplaceWithPasteboard(*pasteboard), chosePlainText, mailBlockquoteHandling);
+}
+
+static const AtomicString&amp; elementURL(Element&amp; element)
+{
+    if (isHTMLImageElement(element) || isHTMLInputElement(element))
+        return element.fastGetAttribute(HTMLNames::srcAttr);
+    if (isSVGImageElement(element))
+        return element.fastGetAttribute(XLinkNames::hrefAttr);
+    if (isHTMLEmbedElement(element) || isHTMLObjectElement(element))
+        return element.imageSourceURL();
+    return nullAtom;
+}
+
+static bool getImageForElement(Element&amp; element, RefPtr&lt;Image&gt;&amp; image)
+{
+    auto renderer = element.renderer();
+    if (!renderer || !renderer-&gt;isRenderImage())
+        return false;
+
+    CachedImage* cachedImage = toRenderImage(*renderer).cachedImage();
+    if (!cachedImage || cachedImage-&gt;errorOccurred())
+        return false;
+
+    image = cachedImage-&gt;imageForRenderer(renderer);
+    return image;
+}
+
+void Editor::writeImageToPasteboard(Pasteboard&amp; pasteboard, Element&amp; imageElement, const URL&amp;, const String&amp; title)
+{
+    PasteboardImage pasteboardImage;
+
+    if (!getImageForElement(imageElement, pasteboardImage.image))
+        return;
+    ASSERT(pasteboardImage.image);
+
+    pasteboardImage.url.url = imageElement.document().completeURL(stripLeadingAndTrailingHTMLSpaces(elementURL(imageElement)));
+    pasteboardImage.url.title = title;
+    pasteboardImage.url.markup = createMarkup(imageElement, IncludeNode, nullptr, ResolveAllURLs);
+    pasteboard.write(pasteboardImage);
+}
+
+void Editor::writeSelectionToPasteboard(Pasteboard&amp; pasteboard)
+{
+    PasteboardWebContent pasteboardContent;
+    pasteboardContent.canSmartCopyOrDelete = canSmartCopyOrDelete();
+    pasteboardContent.text = selectedTextForDataTransfer();
+    pasteboardContent.markup = createMarkup(*selectedRange(), nullptr, AnnotateForInterchange, false, ResolveNonLocalURLs);
+    pasteboardContent.callback = nullptr;
+    pasteboard.write(pasteboardContent);
+}
+
+} // namespace WebCore
</ins></span></pre></div>
<a id="trunkSourceWebCorepageDragControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/DragController.cpp (173686 => 173687)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/DragController.cpp        2014-09-17 06:27:46 UTC (rev 173686)
+++ trunk/Source/WebCore/page/DragController.cpp        2014-09-17 07:05:45 UTC (rev 173687)
</span><span class="lines">@@ -783,7 +783,7 @@
</span><span class="cx">             if (enclosingTextFormControl(src.selection().selection().start()))
</span><span class="cx">                 dataTransfer.pasteboard().writePlainText(src.editor().selectedTextForDataTransfer(), Pasteboard::CannotSmartReplace);
</span><span class="cx">             else {
</span><del>-#if PLATFORM(COCOA) || PLATFORM(EFL)
</del><ins>+#if PLATFORM(COCOA) || PLATFORM(EFL) || PLATFORM(GTK)
</ins><span class="cx">                 src.editor().writeSelectionToPasteboard(dataTransfer.pasteboard());
</span><span class="cx"> #else
</span><span class="cx">                 // FIXME: Convert all other platforms to match Mac and delete this.
</span></span></pre></div>
<a id="trunkSourceWebCorepagegtkDragControllerGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/gtk/DragControllerGtk.cpp (173686 => 173687)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/gtk/DragControllerGtk.cpp        2014-09-17 06:27:46 UTC (rev 173686)
+++ trunk/Source/WebCore/page/gtk/DragControllerGtk.cpp        2014-09-17 07:05:45 UTC (rev 173687)
</span><span class="lines">@@ -31,6 +31,7 @@
</span><span class="cx"> #include &quot;Document.h&quot;
</span><span class="cx"> #include &quot;DocumentFragment.h&quot;
</span><span class="cx"> #include &quot;DragData.h&quot;
</span><ins>+#include &quot;Editor.h&quot;
</ins><span class="cx"> #include &quot;Element.h&quot;
</span><span class="cx"> #include &quot;Frame.h&quot;
</span><span class="cx"> #include &quot;FrameView.h&quot;
</span><span class="lines">@@ -75,7 +76,9 @@
</span><span class="cx"> 
</span><span class="cx"> void DragController::declareAndWriteDragImage(DataTransfer&amp; dataTransfer, Element&amp; element, const URL&amp; url, const String&amp; label)
</span><span class="cx"> {
</span><del>-    dataTransfer.pasteboard().writeImage(element, url, label);
</del><ins>+    Frame* frame = element.document().frame();
+    ASSERT(frame);
+    frame-&gt;editor().writeImageToPasteboard(dataTransfer.pasteboard(), element, url, label);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> PassRefPtr&lt;DocumentFragment&gt; DragController::createFragmentFromDragData(DragData&amp; dragData, Frame&amp; frame, Range&amp;, bool /*allowPlainText*/, bool&amp; /*chosePlainText*/)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformPasteboardh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/Pasteboard.h (173686 => 173687)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/Pasteboard.h        2014-09-17 06:27:46 UTC (rev 173686)
+++ trunk/Source/WebCore/platform/Pasteboard.h        2014-09-17 07:05:45 UTC (rev 173687)
</span><span class="lines">@@ -34,6 +34,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(GTK)
</span><span class="cx"> typedef struct _GtkClipboard GtkClipboard;
</span><ins>+#include &lt;wtf/gobject/GRefPtr.h&gt;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="lines">@@ -78,6 +79,12 @@
</span><span class="cx">     Vector&lt;String&gt; clientTypes;
</span><span class="cx">     Vector&lt;RefPtr&lt;SharedBuffer&gt;&gt; clientData;
</span><span class="cx"> #endif
</span><ins>+#if PLATFORM(GTK)
+    bool canSmartCopyOrDelete;
+    String text;
+    String markup;
+    GRefPtr&lt;GClosure&gt; callback;
+#endif
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> struct PasteboardURL {
</span><span class="lines">@@ -86,14 +93,19 @@
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">     String userVisibleForm;
</span><span class="cx"> #endif
</span><ins>+#if PLATFORM(GTK)
+    String markup;
+#endif
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> struct PasteboardImage {
</span><span class="cx">     WEBCORE_EXPORT PasteboardImage();
</span><span class="cx">     WEBCORE_EXPORT ~PasteboardImage();
</span><span class="cx">     RefPtr&lt;Image&gt; image;
</span><ins>+#if !(PLATFORM(EFL) || PLATFORM(WIN))
+    PasteboardURL url;
+#endif
</ins><span class="cx"> #if !(PLATFORM(EFL) || PLATFORM(GTK) || PLATFORM(WIN))
</span><del>-    PasteboardURL url;
</del><span class="cx">     RefPtr&lt;SharedBuffer&gt; resourceData;
</span><span class="cx">     String resourceMIMEType;
</span><span class="cx"> #endif
</span><span class="lines">@@ -162,7 +174,7 @@
</span><span class="cx">     void setDragImage(DragImageRef, const IntPoint&amp; hotSpot);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-#if PLATFORM(GTK) || PLATFORM(WIN)
</del><ins>+#if PLATFORM(WIN)
</ins><span class="cx">     PassRefPtr&lt;DocumentFragment&gt; documentFragment(Frame&amp;, Range&amp;, bool allowPlainText, bool&amp; chosePlainText); // FIXME: Layering violation.
</span><span class="cx">     void writeImage(Element&amp;, const URL&amp;, const String&amp; title); // FIXME: Layering violation.
</span><span class="cx">     void writeSelection(Range&amp;, bool canSmartCopyOrDelete, Frame&amp;, ShouldSerializeSelectedTextForDataTransfer = DefaultSelectedTextType); // FIXME: Layering violation.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgtkDataObjectGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/gtk/DataObjectGtk.cpp (173686 => 173687)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/gtk/DataObjectGtk.cpp        2014-09-17 06:27:46 UTC (rev 173686)
+++ trunk/Source/WebCore/platform/gtk/DataObjectGtk.cpp        2014-09-17 07:05:45 UTC (rev 173687)
</span><span class="lines">@@ -19,9 +19,9 @@
</span><span class="cx"> #include &quot;config.h&quot;
</span><span class="cx"> #include &quot;DataObjectGtk.h&quot;
</span><span class="cx"> 
</span><del>-#include &quot;markup.h&quot;
</del><span class="cx"> #include &lt;gtk/gtk.h&gt;
</span><span class="cx"> #include &lt;wtf/gobject/GUniquePtr.h&gt;
</span><ins>+#include &lt;wtf/text/CString.h&gt;
</ins><span class="cx"> #include &lt;wtf/text/StringBuilder.h&gt;
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -33,23 +33,6 @@
</span><span class="cx">     str.replace(NonBreakingSpaceCharacter, SpaceCharacter);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-String DataObjectGtk::text() const
-{
-    if (m_range) {
-        String text = m_range-&gt;text();
-        replaceNonBreakingSpaceWithSpace(text);
-        return text;
-    }
-    return m_text;
-}
-
-String DataObjectGtk::markup() const
-{
-    if (m_range)
-        return createMarkup(*m_range, 0, AnnotateForInterchange, false, ResolveNonLocalURLs);
-    return m_markup;
-}
-
</del><span class="cx"> HashMap&lt;String, String&gt; DataObjectGtk::unknownTypes() const
</span><span class="cx"> {
</span><span class="cx">     return m_unknownTypeData;
</span><span class="lines">@@ -57,14 +40,12 @@
</span><span class="cx"> 
</span><span class="cx"> void DataObjectGtk::setText(const String&amp; newText)
</span><span class="cx"> {
</span><del>-    m_range = 0;
</del><span class="cx">     m_text = newText;
</span><span class="cx">     replaceNonBreakingSpaceWithSpace(m_text);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void DataObjectGtk::setMarkup(const String&amp; newMarkup)
</span><span class="cx"> {
</span><del>-    m_range = 0;
</del><span class="cx">     m_markup = newMarkup;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -131,14 +112,12 @@
</span><span class="cx"> 
</span><span class="cx"> void DataObjectGtk::clearText()
</span><span class="cx"> {
</span><del>-    m_range = 0;
-    m_text = &quot;&quot;;
</del><ins>+    m_text = emptyString();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void DataObjectGtk::clearMarkup()
</span><span class="cx"> {
</span><del>-    m_range = 0;
-    m_markup = &quot;&quot;;
</del><ins>+    m_markup = emptyString();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> String DataObjectGtk::urlLabel() const
</span><span class="lines">@@ -154,12 +133,11 @@
</span><span class="cx"> 
</span><span class="cx"> void DataObjectGtk::clearAllExceptFilenames()
</span><span class="cx"> {
</span><del>-    m_text = &quot;&quot;;
-    m_markup = &quot;&quot;;
-    m_uriList = &quot;&quot;;
</del><ins>+    m_text = emptyString();
+    m_markup = emptyString();
+    m_uriList = emptyString();
</ins><span class="cx">     m_url = URL();
</span><del>-    m_image = 0;
-    m_range = 0;
</del><ins>+    m_image = nullptr;
</ins><span class="cx">     m_unknownTypeData.clear();
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgtkDataObjectGtkh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/gtk/DataObjectGtk.h (173686 => 173687)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/gtk/DataObjectGtk.h        2014-09-17 06:27:46 UTC (rev 173686)
+++ trunk/Source/WebCore/platform/gtk/DataObjectGtk.h        2014-09-17 07:05:45 UTC (rev 173687)
</span><span class="lines">@@ -21,10 +21,8 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;FileList.h&quot;
</span><span class="cx"> #include &quot;URL.h&quot;
</span><del>-#include &quot;Range.h&quot;
</del><span class="cx"> #include &lt;wtf/RefCounted.h&gt;
</span><span class="cx"> #include &lt;wtf/gobject/GRefPtr.h&gt;
</span><del>-#include &lt;wtf/text/CString.h&gt;
</del><span class="cx"> #include &lt;wtf/text/StringHash.h&gt;
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -40,22 +38,21 @@
</span><span class="cx">     const String&amp; uriList() const { return m_uriList; }
</span><span class="cx">     const Vector&lt;String&gt;&amp; filenames() const { return m_filenames; }
</span><span class="cx">     GdkPixbuf* image() const { return m_image.get(); }
</span><del>-    void setRange(PassRefPtr&lt;Range&gt; newRange) { m_range = newRange; }
</del><span class="cx">     void setImage(GdkPixbuf* newImage) { m_image = newImage; }
</span><span class="cx">     void setURL(const URL&amp;, const String&amp;);
</span><span class="cx">     bool hasUnknownTypeData() const { return !m_unknownTypeData.isEmpty(); }
</span><del>-    bool hasText() const { return m_range || !m_text.isEmpty(); }
-    bool hasMarkup() const { return m_range || !m_markup.isEmpty(); }
</del><ins>+    bool hasText() const { return !m_text.isEmpty(); }
+    bool hasMarkup() const { return !m_markup.isEmpty(); }
</ins><span class="cx">     bool hasURIList() const { return !m_uriList.isEmpty(); }
</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><span class="cx">     void clearURIList() { m_uriList = &quot;&quot;; }
</span><span class="cx">     void clearURL() { m_url = URL(); }
</span><del>-    void clearImage() { m_image = 0; }
</del><ins>+    void clearImage() { m_image = nullptr; }
</ins><span class="cx"> 
</span><del>-    String text() const;
-    String markup() const;
</del><ins>+    String text() const { return m_text; }
+    String markup() const { return m_markup; }
</ins><span class="cx">     String unknownTypeData(const String&amp; type) const { return m_unknownTypeData.get(type); }
</span><span class="cx">     HashMap&lt;String, String&gt; unknownTypes() const;
</span><span class="cx">     void setText(const String&amp;);
</span><span class="lines">@@ -78,7 +75,6 @@
</span><span class="cx">     String m_uriList;
</span><span class="cx">     Vector&lt;String&gt; m_filenames;
</span><span class="cx">     GRefPtr&lt;GdkPixbuf&gt; m_image;
</span><del>-    RefPtr&lt;Range&gt; m_range;
</del><span class="cx">     HashMap&lt;String, String&gt; m_unknownTypeData;
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgtkGtkDragAndDropHelperh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/gtk/GtkDragAndDropHelper.h (173686 => 173687)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/gtk/GtkDragAndDropHelper.h        2014-09-17 06:27:46 UTC (rev 173686)
+++ trunk/Source/WebCore/platform/gtk/GtkDragAndDropHelper.h        2014-09-17 07:05:45 UTC (rev 173687)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> 
</span><span class="cx"> struct DroppingContext;
</span><span class="cx"> class DragData;
</span><ins>+class IntPoint;
</ins><span class="cx"> 
</span><span class="cx"> typedef void (*DragExitedCallback)(GtkWidget*, DragData&amp;, bool dropHappened);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgtkPasteboardGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp (173686 => 173687)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp        2014-09-17 06:27:46 UTC (rev 173686)
+++ trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp        2014-09-17 07:05:45 UTC (rev 173687)
</span><span class="lines">@@ -20,27 +20,14 @@
</span><span class="cx"> #include &quot;config.h&quot;
</span><span class="cx"> #include &quot;Pasteboard.h&quot;
</span><span class="cx"> 
</span><del>-#include &quot;CachedImage.h&quot;
</del><span class="cx"> #include &quot;DataObjectGtk.h&quot;
</span><del>-#include &quot;DocumentFragment.h&quot;
</del><span class="cx"> #include &quot;DragData.h&quot;
</span><del>-#include &quot;Editor.h&quot;
-#include &quot;Frame.h&quot;
-#include &quot;HTMLImageElement.h&quot;
-#include &quot;HTMLInputElement.h&quot;
-#include &quot;HTMLNames.h&quot;
-#include &quot;HTMLParserIdioms.h&quot;
</del><span class="cx"> #include &quot;Image.h&quot;
</span><span class="cx"> #include &quot;URL.h&quot;
</span><span class="cx"> #include &quot;PasteboardHelper.h&quot;
</span><del>-#include &quot;RenderImage.h&quot;
-#include &quot;SVGElement.h&quot;
-#include &quot;SVGNames.h&quot;
-#include &quot;XLinkNames.h&quot;
-#include &quot;markup.h&quot;
</del><span class="cx"> #include &lt;gtk/gtk.h&gt;
</span><ins>+#include &lt;wtf/PassOwnPtr.h&gt;
</ins><span class="cx"> 
</span><del>-
</del><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> enum ClipboardDataType {
</span><span class="lines">@@ -89,6 +76,15 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+// Making this non-inline so that WebKit 2's decoding doesn't have to include Image.h.
+PasteboardImage::PasteboardImage()
+{
+}
+
+PasteboardImage::~PasteboardImage()
+{
+}
+
</ins><span class="cx"> Pasteboard::Pasteboard(PassRefPtr&lt;DataObjectGtk&gt; dataObject)
</span><span class="cx">     : m_dataObject(dataObject)
</span><span class="cx">     , m_gtkClipboard(0)
</span><span class="lines">@@ -156,16 +152,6 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void Pasteboard::writeSelection(Range&amp; selectedRange, bool canSmartCopyOrDelete, Frame&amp; frame, ShouldSerializeSelectedTextForDataTransfer shouldSerializeSelectedTextForDataTransfer)
-{
-    m_dataObject-&gt;clearAll();
-    m_dataObject-&gt;setText(shouldSerializeSelectedTextForDataTransfer == IncludeImageAltTextForDataTransfer ? frame.editor().selectedTextForDataTransfer() : frame.editor().selectedText());
-    m_dataObject-&gt;setMarkup(createMarkup(selectedRange, 0, AnnotateForInterchange, false, ResolveNonLocalURLs));
-
-    if (m_gtkClipboard)
-        PasteboardHelper::defaultPasteboardHelper()-&gt;writeClipboardContents(m_gtkClipboard, canSmartCopyOrDelete ? PasteboardHelper::IncludeSmartPaste : PasteboardHelper::DoNotIncludeSmartPaste);
-}
-
</del><span class="cx"> void Pasteboard::writePlainText(const String&amp; text, SmartReplaceOption smartReplaceOption)
</span><span class="cx"> {
</span><span class="cx">     m_dataObject-&gt;clearAll();
</span><span class="lines">@@ -186,46 +172,30 @@
</span><span class="cx">         PasteboardHelper::defaultPasteboardHelper()-&gt;writeClipboardContents(m_gtkClipboard);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static URL getURLForImageElement(Element&amp; element)
</del><ins>+void Pasteboard::write(const PasteboardImage&amp; pasteboardImage)
</ins><span class="cx"> {
</span><del>-    // FIXME: Later this code should be shared with Chromium somehow. Chances are all platforms want it.
-    AtomicString urlString;
-    if (isHTMLImageElement(element) || isHTMLInputElement(element))
-        urlString = element.getAttribute(HTMLNames::srcAttr);
-    else if (element.hasTagName(SVGNames::imageTag))
-        urlString = element.getAttribute(XLinkNames::hrefAttr);
-    else if (element.hasTagName(HTMLNames::embedTag) || isHTMLObjectElement(element))
-        urlString = element.imageSourceURL();
</del><ins>+    m_dataObject-&gt;clearAll();
+    if (!pasteboardImage.url.url.isEmpty()) {
+        m_dataObject-&gt;setURL(pasteboardImage.url.url, pasteboardImage.url.title);
+        m_dataObject-&gt;setMarkup(pasteboardImage.url.markup);
+    }
</ins><span class="cx"> 
</span><del>-    return urlString.isEmpty() ? URL() : element.document().completeURL(stripLeadingAndTrailingHTMLSpaces(urlString));
</del><ins>+    GRefPtr&lt;GdkPixbuf&gt; pixbuf = adoptGRef(pasteboardImage.image-&gt;getGdkPixbuf());
+    if (pixbuf)
+        m_dataObject-&gt;setImage(pixbuf.get());
+
+    if (m_gtkClipboard)
+        PasteboardHelper::defaultPasteboardHelper()-&gt;writeClipboardContents(m_gtkClipboard);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void Pasteboard::writeImage(Element&amp; element, const URL&amp;, const String&amp; title)
</del><ins>+void Pasteboard::write(const PasteboardWebContent&amp; pasteboardContent)
</ins><span class="cx"> {
</span><del>-    if (!(element.renderer() &amp;&amp; element.renderer()-&gt;isRenderImage()))
-        return;
-
-    RenderImage* renderer = toRenderImage(element.renderer());
-    CachedImage* cachedImage = renderer-&gt;cachedImage();
-    if (!cachedImage || cachedImage-&gt;errorOccurred())
-        return;
-    Image* image = cachedImage-&gt;imageForRenderer(renderer);
-    ASSERT(image);
-
</del><span class="cx">     m_dataObject-&gt;clearAll();
</span><ins>+    m_dataObject-&gt;setText(pasteboardContent.text);
+    m_dataObject-&gt;setMarkup(pasteboardContent.markup);
</ins><span class="cx"> 
</span><del>-    URL url = getURLForImageElement(element);
-    if (!url.isEmpty()) {
-        m_dataObject-&gt;setURL(url, title);
-
-        m_dataObject-&gt;setMarkup(createMarkup(element, IncludeNode, 0, ResolveAllURLs));
-    }
-
-    GRefPtr&lt;GdkPixbuf&gt; pixbuf = adoptGRef(image-&gt;getGdkPixbuf());
-    m_dataObject-&gt;setImage(pixbuf.get());
-
</del><span class="cx">     if (m_gtkClipboard)
</span><del>-        PasteboardHelper::defaultPasteboardHelper()-&gt;writeClipboardContents(m_gtkClipboard);
</del><ins>+        PasteboardHelper::defaultPasteboardHelper()-&gt;writeClipboardContents(m_gtkClipboard, pasteboardContent.canSmartCopyOrDelete ? PasteboardHelper::IncludeSmartPaste : PasteboardHelper::DoNotIncludeSmartPaste, pasteboardContent.callback.get());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Pasteboard::writePasteboard(const Pasteboard&amp; sourcePasteboard)
</span><span class="lines">@@ -302,34 +272,6 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-PassRefPtr&lt;DocumentFragment&gt; Pasteboard::documentFragment(Frame&amp; frame, Range&amp; context, bool allowPlainText, bool&amp; chosePlainText)
-{
-    if (m_gtkClipboard)
-        PasteboardHelper::defaultPasteboardHelper()-&gt;getClipboardContents(m_gtkClipboard);
-
-    chosePlainText = false;
-
-    if (m_dataObject-&gt;hasMarkup()) {
-        if (frame.document()) {
-            RefPtr&lt;DocumentFragment&gt; fragment = createFragmentFromMarkup(*frame.document(), m_dataObject-&gt;markup(), emptyString(), DisallowScriptingAndPluginContent);
-            if (fragment)
-                return fragment.release();
-        }
-    }
-
-    if (!allowPlainText)
-        return 0;
-
-    if (m_dataObject-&gt;hasText()) {
-        chosePlainText = true;
-        RefPtr&lt;DocumentFragment&gt; fragment = createFragmentFromText(context, m_dataObject-&gt;text());
-        if (fragment)
-            return fragment.release();
-    }
-
-    return 0;
-}
-
</del><span class="cx"> void Pasteboard::read(PasteboardPlainText&amp; text)
</span><span class="cx"> {
</span><span class="cx">     if (m_gtkClipboard)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgtkPasteboardHelpercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/gtk/PasteboardHelper.cpp (173686 => 173687)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/gtk/PasteboardHelper.cpp        2014-09-17 06:27:46 UTC (rev 173686)
+++ trunk/Source/WebCore/platform/gtk/PasteboardHelper.cpp        2014-09-17 07:05:45 UTC (rev 173687)
</span><span class="lines">@@ -23,16 +23,14 @@
</span><span class="cx"> #include &quot;config.h&quot;
</span><span class="cx"> #include &quot;PasteboardHelper.h&quot;
</span><span class="cx"> 
</span><del>-#include &quot;Chrome.h&quot;
</del><span class="cx"> #include &quot;DataObjectGtk.h&quot;
</span><del>-#include &quot;Frame.h&quot;
</del><span class="cx"> #include &quot;GRefPtrGtk.h&quot;
</span><span class="cx"> #include &quot;GtkVersioning.h&quot;
</span><del>-#include &quot;Page.h&quot;
</del><span class="cx"> #include &quot;Pasteboard.h&quot;
</span><span class="cx"> #include &quot;TextResourceDecoder.h&quot;
</span><span class="cx"> #include &lt;gtk/gtk.h&gt;
</span><span class="cx"> #include &lt;wtf/gobject/GUniquePtr.h&gt;
</span><ins>+#include &lt;wtf/text/CString.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="lines">@@ -95,20 +93,6 @@
</span><span class="cx">     gtk_target_list_unref(m_targetList);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static inline GdkDisplay* displayFromFrame(Frame* frame)
-{
-    ASSERT(frame);
-    Page* page = frame-&gt;page();
-    ASSERT(page);
-    PlatformPageClient client = page-&gt;chrome().platformPageClient();
-    return client ? gtk_widget_get_display(client) : gdk_display_get_default();
-}
-
-GtkClipboard* PasteboardHelper::getPrimarySelectionClipboard(Frame* frame) const
-{
-    return gtk_clipboard_get_for_display(displayFromFrame(frame), GDK_SELECTION_PRIMARY);
-}
-
</del><span class="cx"> GtkTargetList* PasteboardHelper::targetList() const
</span><span class="cx"> {
</span><span class="cx">     return m_targetList;
</span><span class="lines">@@ -309,12 +293,11 @@
</span><span class="cx">     if (!data)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    GClosure* callback = static_cast&lt;GClosure*&gt;(data);
</del><ins>+    GRefPtr&lt;GClosure&gt; callback = adoptGRef(static_cast&lt;GClosure*&gt;(data));
</ins><span class="cx">     GValue firstArgument = {0, {{0}}};
</span><span class="cx">     g_value_init(&amp;firstArgument, G_TYPE_POINTER);
</span><span class="cx">     g_value_set_pointer(&amp;firstArgument, clipboard);
</span><del>-    g_closure_invoke(callback, 0, 1, &amp;firstArgument, 0);
-    g_closure_unref(callback);
</del><ins>+    g_closure_invoke(callback.get(), nullptr, 1, &amp;firstArgument, 0);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void PasteboardHelper::writeClipboardContents(GtkClipboard* clipboard, SmartPasteInclusion includeSmartPaste, GClosure* callback)
</span><span class="lines">@@ -328,11 +311,14 @@
</span><span class="cx">     if (numberOfTargets &gt; 0 &amp;&amp; table) {
</span><span class="cx">         settingClipboardDataObject = dataObject;
</span><span class="cx"> 
</span><del>-        gtk_clipboard_set_with_data(clipboard, table, numberOfTargets,
-            getClipboardContentsCallback, clearClipboardContentsCallback, callback);
-        gtk_clipboard_set_can_store(clipboard, 0, 0);
</del><ins>+        if (gtk_clipboard_set_with_data(clipboard, table, numberOfTargets, getClipboardContentsCallback, clearClipboardContentsCallback, g_closure_ref(callback)))
+            gtk_clipboard_set_can_store(clipboard, nullptr, 0);
+        else {
+            // When gtk_clipboard_set_with_data fails the callbacks are ignored, so we need to release the reference we were passing to clearClipboardContentsCallback.
+            g_closure_unref(callback);
+        }
</ins><span class="cx"> 
</span><del>-        settingClipboardDataObject = 0;
</del><ins>+        settingClipboardDataObject = nullptr;
</ins><span class="cx"> 
</span><span class="cx">     } else
</span><span class="cx">         gtk_clipboard_clear(clipboard);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgtkPasteboardHelperh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/gtk/PasteboardHelper.h (173686 => 173687)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/gtk/PasteboardHelper.h        2014-09-17 06:27:46 UTC (rev 173686)
+++ trunk/Source/WebCore/platform/gtk/PasteboardHelper.h        2014-09-17 07:05:45 UTC (rev 173687)
</span><span class="lines">@@ -25,8 +25,8 @@
</span><span class="cx"> #ifndef PasteboardHelper_h
</span><span class="cx"> #define PasteboardHelper_h
</span><span class="cx"> 
</span><del>-#include &quot;Frame.h&quot;
</del><span class="cx"> #include &lt;glib-object.h&gt;
</span><ins>+#include &lt;wtf/Vector.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="lines">@@ -40,7 +40,6 @@
</span><span class="cx"> 
</span><span class="cx">     enum SmartPasteInclusion { IncludeSmartPaste, DoNotIncludeSmartPaste };
</span><span class="cx"> 
</span><del>-    GtkClipboard* getPrimarySelectionClipboard(Frame*) const;
</del><span class="cx">     GtkTargetList* targetList() const;
</span><span class="cx">     GtkTargetList* targetListForDataObject(DataObjectGtk*, SmartPasteInclusion = DoNotIncludeSmartPaste);
</span><span class="cx">     void fillSelectionData(GtkSelectionData*, guint, DataObjectGtk*);
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (173686 => 173687)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-09-17 06:27:46 UTC (rev 173686)
+++ trunk/Source/WebKit2/ChangeLog        2014-09-17 07:05:45 UTC (rev 173687)
</span><span class="lines">@@ -1,5 +1,16 @@
</span><span class="cx"> 2014-09-16  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><ins>+        [GTK] Fix layering violations in PasteboardGtk
+        https://bugs.webkit.org/show_bug.cgi?id=136802
+
+        Reviewed by Darin Adler.
+
+        * WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:
+        (WebKit::WebEditorClient::updateGlobalSelection): Use new API to
+        update the global selection.
+
+2014-09-16  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
+
</ins><span class="cx">         DragData should not depend on Clipboard, DocumentFragment, and Document
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=21358
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebCoreSupportgtkWebEditorClientGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp (173686 => 173687)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp        2014-09-17 06:27:46 UTC (rev 173686)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp        2014-09-17 07:05:45 UTC (rev 173687)
</span><span class="lines">@@ -20,17 +20,19 @@
</span><span class="cx"> #include &quot;config.h&quot;
</span><span class="cx"> #include &quot;WebEditorClient.h&quot;
</span><span class="cx"> 
</span><del>-#include &quot;Frame.h&quot;
-#include &quot;FrameDestructionObserver.h&quot;
</del><span class="cx"> #include &quot;PlatformKeyboardEvent.h&quot;
</span><span class="cx"> #include &quot;WebPage.h&quot;
</span><span class="cx"> #include &quot;WebPageProxyMessages.h&quot;
</span><span class="cx"> #include &quot;WebProcess.h&quot;
</span><span class="cx"> #include &lt;WebCore/DataObjectGtk.h&gt;
</span><span class="cx"> #include &lt;WebCore/Document.h&gt;
</span><ins>+#include &lt;WebCore/Frame.h&gt;
+#include &lt;WebCore/FrameDestructionObserver.h&gt;
</ins><span class="cx"> #include &lt;WebCore/KeyboardEvent.h&gt;
</span><del>-#include &lt;WebCore/PasteboardHelper.h&gt;
</del><ins>+#include &lt;WebCore/Pasteboard.h&gt;
</ins><span class="cx"> #include &lt;WebCore/WindowsKeyboardCodes.h&gt;
</span><ins>+#include &lt;WebCore/markup.h&gt;
+#include &lt;wtf/gobject/GRefPtr.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> using namespace WebCore;
</span><span class="cx"> 
</span><span class="lines">@@ -175,24 +177,25 @@
</span><span class="cx"> void WebEditorClient::updateGlobalSelection(Frame* frame)
</span><span class="cx"> {
</span><span class="cx"> #if PLATFORM(X11)
</span><del>-    GtkClipboard* clipboard = PasteboardHelper::defaultPasteboardHelper()-&gt;getPrimarySelectionClipboard(frame);
-    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
-
</del><span class="cx">     if (!frame-&gt;selection().isRange())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    dataObject-&gt;clearAll();
-    dataObject-&gt;setRange(frame-&gt;selection().toNormalizedRange());
-
</del><span class="cx">     frameSettingClipboard = frame;
</span><del>-    GClosure* callback = g_cclosure_new(G_CALLBACK(collapseSelection), frame, 0);
</del><ins>+    GRefPtr&lt;GClosure&gt; callback = adoptGRef(g_cclosure_new(G_CALLBACK(collapseSelection), frame, nullptr));
</ins><span class="cx">     // This observer will be self-destroyed on closure finalization,
</span><span class="cx">     // that will happen either after closure execution or after
</span><span class="cx">     // closure invalidation.
</span><del>-    new EditorClientFrameDestructionObserver(frame, callback);
-    g_closure_set_marshal(callback, g_cclosure_marshal_VOID__VOID);
-    PasteboardHelper::defaultPasteboardHelper()-&gt;writeClipboardContents(clipboard, PasteboardHelper::DoNotIncludeSmartPaste, callback);
-    frameSettingClipboard = 0;
</del><ins>+    new EditorClientFrameDestructionObserver(frame, callback.get());
+    g_closure_set_marshal(callback.get(), g_cclosure_marshal_VOID__VOID);
+
+    RefPtr&lt;Range&gt; range = frame-&gt;selection().toNormalizedRange();
+    PasteboardWebContent pasteboardContent;
+    pasteboardContent.canSmartCopyOrDelete = false;
+    pasteboardContent.text = range-&gt;text();
+    pasteboardContent.markup = createMarkup(*range, nullptr, AnnotateForInterchange, false, ResolveNonLocalURLs);
+    pasteboardContent.callback = callback;
+    Pasteboard::createForGlobalSelection()-&gt;write(pasteboardContent);
+    frameSettingClipboard = nullptr;
</ins><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>