Title: [205959] releases/WebKitGTK/webkit-2.14/Source
Revision
205959
Author
carlo...@webkit.org
Date
2016-09-15 01:11:31 -0700 (Thu, 15 Sep 2016)

Log Message

Merge r205909 - [GTK][Wayland] Implement clipboard support
https://bugs.webkit.org/show_bug.cgi?id=146574

Patch by Carlos Garnacho <carl...@gnome.org> 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 "smart
paste" 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 "smart paste" 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<DragData>::encode):
(IPC::ArgumentCoder<DragData>::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->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->WebProcess notification that the global selection has
been replaced.

Modified Paths

Added Paths

Diff

Modified: releases/WebKitGTK/webkit-2.14/Source/WebCore/ChangeLog (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebCore/ChangeLog	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebCore/ChangeLog	2016-09-15 08:11:31 UTC (rev 205959)
@@ -1,3 +1,73 @@
+2016-09-14  Carlos Garnacho <carl...@gnome.org>
+
+        [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 "smart
+        paste" 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 "smart paste" 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.
+
 2016-09-13  Carlos Garcia Campos  <cgar...@igalia.com>
 
         [GTK] Get rid of DataObjectGtk::forClipboard and cleanup pasteboard code

Modified: releases/WebKitGTK/webkit-2.14/Source/WebCore/PlatformGTK.cmake (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebCore/PlatformGTK.cmake	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebCore/PlatformGTK.cmake	2016-09-15 08:11:31 UTC (rev 205959)
@@ -221,6 +221,7 @@
     platform/gtk/PasteboardHelper.cpp
     platform/gtk/PlatformKeyboardEventGtk.cpp
     platform/gtk/PlatformMouseEventGtk.cpp
+    platform/gtk/PlatformPasteboardGtk.cpp
     platform/gtk/PlatformScreenGtk.cpp
     platform/gtk/PlatformWheelEventGtk.cpp
     platform/gtk/RenderThemeGadget.cpp

Modified: releases/WebKitGTK/webkit-2.14/Source/WebCore/editing/gtk/EditorGtk.cpp (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebCore/editing/gtk/EditorGtk.cpp	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebCore/editing/gtk/EditorGtk.cpp	2016-09-15 08:11:31 UTC (rev 205959)
@@ -125,7 +125,6 @@
     pasteboardContent.canSmartCopyOrDelete = canSmartCopyOrDelete();
     pasteboardContent.text = selectedTextForDataTransfer();
     pasteboardContent.markup = createMarkup(*selectedRange(), nullptr, AnnotateForInterchange, false, ResolveNonLocalURLs);
-    pasteboardContent.callback = nullptr;
     pasteboard.write(pasteboardContent);
 }
 

Modified: releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/Pasteboard.h (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/Pasteboard.h	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/Pasteboard.h	2016-09-15 08:11:31 UTC (rev 205959)
@@ -32,11 +32,6 @@
 #include <wtf/Vector.h>
 #include <wtf/text/WTFString.h>
 
-#if PLATFORM(GTK)
-typedef struct _GtkClipboard GtkClipboard;
-#include <wtf/glib/GRefPtr.h>
-#endif
-
 #if PLATFORM(IOS)
 OBJC_CLASS NSArray;
 OBJC_CLASS NSString;
@@ -83,7 +78,6 @@
     bool canSmartCopyOrDelete;
     String text;
     String markup;
-    GRefPtr<GClosure> callback;
 #endif
 };
 
@@ -143,8 +137,8 @@
     ~Pasteboard();
 
 #if PLATFORM(GTK)
+    explicit Pasteboard(const String& name);
     explicit Pasteboard(RefPtr<DataObjectGtk>&&);
-    explicit Pasteboard(GtkClipboard*);
 #endif
 
 #if PLATFORM(WIN)
@@ -226,8 +220,11 @@
 #endif
 
 #if PLATFORM(GTK)
+    enum class ShouldIncludeSmartPaste { No, Yes };
+    void writeToClipboard(ShouldIncludeSmartPaste = ShouldIncludeSmartPaste::No);
+    void readFromClipboard();
     RefPtr<DataObjectGtk> m_dataObject;
-    GtkClipboard* m_gtkClipboard;
+    String m_name;
 #endif
 
 #if PLATFORM(IOS)

Modified: releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/PasteboardStrategy.h (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/PasteboardStrategy.h	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/PasteboardStrategy.h	2016-09-15 08:11:31 UTC (rev 205959)
@@ -38,6 +38,10 @@
 struct PasteboardImage;
 struct PasteboardWebContent;
 
+#if PLATFORM(GTK)
+class DataObjectGtk;
+#endif
+
 class PasteboardStrategy {
 public:
 #if PLATFORM(IOS)
@@ -68,6 +72,10 @@
     virtual long setPathnamesForType(const Vector<String>&, const String& pasteboardType, const String& pasteboardName) = 0;
     virtual long setStringForType(const String&, const String& pasteboardType, const String& pasteboardName) = 0;
 #endif
+#if PLATFORM(GTK)
+    virtual void writeToClipboard(const String& pasteboardName, const RefPtr<DataObjectGtk>&) = 0;
+    virtual RefPtr<DataObjectGtk> readFromClipboard(const String& pasteboardName) = 0;
+#endif // PLATFORM(GTK)
 protected:
     virtual ~PasteboardStrategy()
     {

Modified: releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/PlatformPasteboard.h (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/PlatformPasteboard.h	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/PlatformPasteboard.h	2016-09-15 08:11:31 UTC (rev 205959)
@@ -47,6 +47,10 @@
 struct PasteboardImage;
 struct PasteboardWebContent;
 
+#if PLATFORM(GTK)
+class DataObjectGtk;
+#endif
+
 class PlatformPasteboard {
 public:
     // FIXME: probably we don't need a constructor that takes a pasteboard name for iOS.
@@ -81,6 +85,11 @@
     WEBCORE_EXPORT URL readURL(int index, const String& pasteboardType);
     WEBCORE_EXPORT int count();
 
+#if PLATFORM(GTK)
+    WEBCORE_EXPORT void writeToClipboard(const RefPtr<DataObjectGtk>&, std::function<void()>&& primarySelectionCleared);
+    WEBCORE_EXPORT RefPtr<DataObjectGtk> readFromClipboard();
+#endif
+
 private:
 #if PLATFORM(MAC)
     RetainPtr<NSPasteboard> m_pasteboard;
@@ -88,6 +97,9 @@
 #if PLATFORM(IOS)
     RetainPtr<UIPasteboard> m_pasteboard;
 #endif
+#if PLATFORM(GTK)
+    GtkClipboard* m_clipboard;
+#endif
 };
 
 }

Modified: releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/DataObjectGtk.cpp (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/DataObjectGtk.cpp	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/DataObjectGtk.cpp	2016-09-15 08:11:31 UTC (rev 205959)
@@ -139,6 +139,7 @@
     m_url = URL();
     m_image = nullptr;
     m_unknownTypeData.clear();
+    m_canSmartReplace = false;
 }
 
 void DataObjectGtk::clearAll()

Modified: releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/DataObjectGtk.h (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/DataObjectGtk.h	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/DataObjectGtk.h	2016-09-15 08:11:31 UTC (rev 205959)
@@ -47,6 +47,7 @@
     bool hasURL() const { return !m_url.isEmpty() && m_url.isValid(); }
     bool hasFilenames() const { return !m_filenames.isEmpty(); }
     bool hasImage() const { return m_image; }
+    bool canSmartReplace() const { return m_canSmartReplace; }
     void clearURIList() { m_uriList = emptyString(); }
     void clearURL() { m_url = URL(); }
     void clearImage() { m_image = nullptr; }
@@ -59,6 +60,7 @@
     void setMarkup(const String&);
     void setUnknownTypeData(const String& type, const String& data) { m_unknownTypeData.set(type, data); }
     void setURIList(const String&);
+    void setCanSmartReplace(bool canSmartReplace) { m_canSmartReplace = canSmartReplace; }
     String urlLabel() const;
 
     void clearAllExceptFilenames();
@@ -74,6 +76,7 @@
     Vector<String> m_filenames;
     GRefPtr<GdkPixbuf> m_image;
     HashMap<String, String> m_unknownTypeData;
+    bool m_canSmartReplace { false };
 };
 
 }

Modified: releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/PasteboardGtk.cpp (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/PasteboardGtk.cpp	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/PasteboardGtk.cpp	2016-09-15 08:11:31 UTC (rev 205959)
@@ -23,9 +23,10 @@
 #include "DataObjectGtk.h"
 #include "DragData.h"
 #include "Image.h"
+#include "PasteboardStrategy.h"
+#include "PlatformStrategies.h"
 #include "URL.h"
-#include "PasteboardHelper.h"
-#include <gtk/gtk.h>
+#include <wtf/NeverDestroyed.h>
 
 namespace WebCore {
 
@@ -40,12 +41,12 @@
 
 std::unique_ptr<Pasteboard> Pasteboard::createForCopyAndPaste()
 {
-    return std::make_unique<Pasteboard>(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
+    return std::make_unique<Pasteboard>("CLIPBOARD");
 }
 
 std::unique_ptr<Pasteboard> Pasteboard::createForGlobalSelection()
 {
-    return std::make_unique<Pasteboard>(gtk_clipboard_get(GDK_SELECTION_PRIMARY));
+    return std::make_unique<Pasteboard>("PRIMARY");
 }
 
 std::unique_ptr<Pasteboard> Pasteboard::createPrivate()
@@ -76,17 +77,14 @@
 
 Pasteboard::Pasteboard(RefPtr<DataObjectGtk>&& dataObject)
     : m_dataObject(WTFMove(dataObject))
-    , m_gtkClipboard(nullptr)
 {
     ASSERT(m_dataObject);
 }
 
-Pasteboard::Pasteboard(GtkClipboard* gtkClipboard)
+Pasteboard::Pasteboard(const String& name)
     : m_dataObject(DataObjectGtk::create())
-    , m_gtkClipboard(gtkClipboard)
+    , m_name(name)
 {
-    ASSERT(m_dataObject);
-    PasteboardHelper::singleton().registerClipboard(gtkClipboard);
 }
 
 Pasteboard::~Pasteboard()
@@ -121,6 +119,21 @@
     return ClipboardDataTypeUnknown;
 }
 
+void Pasteboard::writeToClipboard(ShouldIncludeSmartPaste shouldIncludeSmartPaste)
+{
+    if (m_name.isNull())
+        return;
+    m_dataObject->setCanSmartReplace(shouldIncludeSmartPaste == ShouldIncludeSmartPaste::Yes);
+    platformStrategies()->pasteboardStrategy()->writeToClipboard(m_name, m_dataObject);
+}
+
+void Pasteboard::readFromClipboard()
+{
+    if (m_name.isNull())
+        return;
+    m_dataObject = platformStrategies()->pasteboardStrategy()->readFromClipboard(m_name);
+}
+
 void Pasteboard::writeString(const String& type, const String& data)
 {
     switch (dataObjectTypeFromHTMLClipboardType(type)) {
@@ -147,8 +160,7 @@
     m_dataObject->clearAll();
     m_dataObject->setText(text);
 
-    if (m_gtkClipboard)
-        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject, (smartReplaceOption == CanSmartReplace) ? PasteboardHelper::IncludeSmartPaste : PasteboardHelper::DoNotIncludeSmartPaste);
+    writeToClipboard(smartReplaceOption == CanSmartReplace ? ShouldIncludeSmartPaste::Yes : ShouldIncludeSmartPaste::No);
 }
 
 void Pasteboard::write(const PasteboardURL& pasteboardURL)
@@ -158,8 +170,7 @@
     m_dataObject->clearAll();
     m_dataObject->setURL(pasteboardURL.url, pasteboardURL.title);
 
-    if (m_gtkClipboard)
-        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject);
+    writeToClipboard();
 }
 
 void Pasteboard::write(const PasteboardImage& pasteboardImage)
@@ -174,8 +185,7 @@
     if (pixbuf)
         m_dataObject->setImage(pixbuf.get());
 
-    if (m_gtkClipboard)
-        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject);
+    writeToClipboard();
 }
 
 void Pasteboard::write(const PasteboardWebContent& pasteboardContent)
@@ -184,8 +194,7 @@
     m_dataObject->setText(pasteboardContent.text);
     m_dataObject->setMarkup(pasteboardContent.markup);
 
-    if (m_gtkClipboard)
-        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject, pasteboardContent.canSmartCopyOrDelete ? PasteboardHelper::IncludeSmartPaste : PasteboardHelper::DoNotIncludeSmartPaste, pasteboardContent.callback.get());
+    writeToClipboard(pasteboardContent.canSmartCopyOrDelete ? ShouldIncludeSmartPaste::Yes : ShouldIncludeSmartPaste::No);
 }
 
 void Pasteboard::writePasteboard(const Pasteboard& sourcePasteboard)
@@ -208,8 +217,7 @@
             m_dataObject->setUnknownTypeData(it.key, it.value);
     }
 
-    if (m_gtkClipboard)
-        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject);
+    writeToClipboard();
 }
 
 void Pasteboard::clear()
@@ -219,9 +227,7 @@
     // attribute's list might still not be empty after calling clearData() (it would
     // still contain the "Files" string if any files were included in the drag)."
     m_dataObject->clearAllExceptFilenames();
-
-    if (m_gtkClipboard)
-        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject);
+    writeToClipboard();
 }
 
 void Pasteboard::clear(const String& type)
@@ -245,13 +251,13 @@
         break;
     }
 
-    if (m_gtkClipboard)
-        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject);
+    writeToClipboard();
 }
 
 bool Pasteboard::canSmartReplace()
 {
-    return m_gtkClipboard && PasteboardHelper::singleton().clipboardContentSupportsSmartReplace(m_gtkClipboard);
+    readFromClipboard();
+    return m_dataObject->canSmartReplace();
 }
 
 #if ENABLE(DRAG_SUPPORT)
@@ -262,23 +268,19 @@
 
 void Pasteboard::read(PasteboardPlainText& text)
 {
-    if (m_gtkClipboard)
-        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard, *m_dataObject);
+    readFromClipboard();
     text.text = m_dataObject->text();
 }
 
 bool Pasteboard::hasData()
 {
-    if (m_gtkClipboard)
-        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard, *m_dataObject);
-
+    readFromClipboard();
     return m_dataObject->hasText() || m_dataObject->hasMarkup() || m_dataObject->hasURIList() || m_dataObject->hasImage() || m_dataObject->hasUnknownTypeData();
 }
 
 Vector<String> Pasteboard::types()
 {
-    if (m_gtkClipboard)
-        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard, *m_dataObject);
+    readFromClipboard();
 
     Vector<String> types;
     if (m_dataObject->hasText()) {
@@ -306,8 +308,7 @@
 
 String Pasteboard::readString(const String& type)
 {
-    if (m_gtkClipboard)
-        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard, *m_dataObject);
+    readFromClipboard();
 
     switch (dataObjectTypeFromHTMLClipboardType(type)) {
     case ClipboardDataTypeURIList:
@@ -329,9 +330,7 @@
 
 Vector<String> Pasteboard::readFilenames()
 {
-    if (m_gtkClipboard)
-        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard, *m_dataObject);
-
+    readFromClipboard();
     return m_dataObject->filenames();
 }
 

Modified: releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/PasteboardHelper.cpp (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/PasteboardHelper.cpp	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/PasteboardHelper.cpp	2016-09-15 08:11:31 UTC (rev 205959)
@@ -76,8 +76,6 @@
 
 PasteboardHelper::~PasteboardHelper()
 {
-    for (auto* clipboard : m_gtkClipboards)
-        gtk_clipboard_store(clipboard);
 }
 
 GtkTargetList* PasteboardHelper::targetList() const
@@ -115,6 +113,8 @@
             gtk_selection_data_free(data);
         }
     }
+
+    dataObject.setCanSmartReplace(gtk_clipboard_wait_is_target_available(clipboard, smartPasteAtom));
 }
 
 void PasteboardHelper::fillSelectionData(GtkSelectionData* selectionData, guint info, const DataObjectGtk& dataObject)
@@ -169,7 +169,7 @@
     }
 }
 
-GRefPtr<GtkTargetList> PasteboardHelper::targetListForDataObject(const DataObjectGtk& dataObject, SmartPasteInclusion shouldInludeSmartPaste)
+GRefPtr<GtkTargetList> PasteboardHelper::targetListForDataObject(const DataObjectGtk& dataObject)
 {
     GRefPtr<GtkTargetList> list = adoptGRef(gtk_target_list_new(nullptr, 0));
 
@@ -190,7 +190,7 @@
     if (dataObject.hasUnknownTypeData())
         gtk_target_list_add(list.get(), unknownAtom, 0, TargetTypeUnknown);
 
-    if (shouldInludeSmartPaste == IncludeSmartPaste)
+    if (dataObject.canSmartReplace())
         gtk_target_list_add(list.get(), smartPasteAtom, 0, TargetTypeSmartPaste);
 
     return list;
@@ -257,9 +257,9 @@
 static DataObjectGtk* settingClipboardDataObject = 0;
 
 struct ClipboardSetData {
-    ClipboardSetData(DataObjectGtk* dataObject, GClosure* callback)
+    ClipboardSetData(DataObjectGtk* dataObject, std::function<void()>&& selectionClearedCallback)
         : dataObject(dataObject)
-        , callback(callback)
+        , selectionClearedCallback(WTFMove(selectionClearedCallback))
     {
     }
 
@@ -268,7 +268,7 @@
     }
 
     RefPtr<DataObjectGtk> dataObject;
-    GRefPtr<GClosure> callback;
+    std::function<void()> selectionClearedCallback;
 };
 
 static void getClipboardContentsCallback(GtkClipboard*, GtkSelectionData *selectionData, guint info, gpointer userData)
@@ -277,7 +277,7 @@
     PasteboardHelper::singleton().fillSelectionData(selectionData, info, *data->dataObject);
 }
 
-static void clearClipboardContentsCallback(GtkClipboard* clipboard, gpointer userData)
+static void clearClipboardContentsCallback(GtkClipboard*, gpointer userData)
 {
     std::unique_ptr<ClipboardSetData> data(static_cast<ClipboardSetData*>(userData));
 
@@ -285,18 +285,13 @@
     if (data->dataObject.get() != settingClipboardDataObject)
         data->dataObject->clearAll();
 
-    if (!data->callback)
-        return;
-
-    GValue firstArgument = {0, {{0}}};
-    g_value_init(&firstArgument, G_TYPE_POINTER);
-    g_value_set_pointer(&firstArgument, clipboard);
-    g_closure_invoke(data->callback.get(), nullptr, 1, &firstArgument, 0);
+    if (data->selectionClearedCallback)
+        data->selectionClearedCallback();
 }
 
-void PasteboardHelper::writeClipboardContents(GtkClipboard* clipboard, const DataObjectGtk& dataObject, SmartPasteInclusion includeSmartPaste, GClosure* callback)
+void PasteboardHelper::writeClipboardContents(GtkClipboard* clipboard, const DataObjectGtk& dataObject, std::function<void()>&& primarySelectionCleared)
 {
-    GRefPtr<GtkTargetList> list = targetListForDataObject(dataObject, includeSmartPaste);
+    GRefPtr<GtkTargetList> list = targetListForDataObject(dataObject);
 
     int numberOfTargets;
     GtkTargetEntry* table = gtk_target_table_new_from_list(list.get(), &numberOfTargets);
@@ -304,7 +299,7 @@
     if (numberOfTargets > 0 && table) {
         settingClipboardDataObject = const_cast<DataObjectGtk*>(&dataObject);
 
-        auto data = "" callback);
+        auto data = "" WTFMove(primarySelectionCleared));
         if (gtk_clipboard_set_with_data(clipboard, table, numberOfTargets, getClipboardContentsCallback, clearClipboardContentsCallback, data.get())) {
             gtk_clipboard_set_can_store(clipboard, nullptr, 0);
             // When gtk_clipboard_set_with_data() succeeds clearClipboardContentsCallback takes the ownership of data, so we leak it here.
@@ -319,16 +314,5 @@
         gtk_target_table_free(table, numberOfTargets);
 }
 
-bool PasteboardHelper::clipboardContentSupportsSmartReplace(GtkClipboard* clipboard)
-{
-    return gtk_clipboard_wait_is_target_available(clipboard, smartPasteAtom);
 }
 
-void PasteboardHelper::registerClipboard(GtkClipboard* clipboard)
-{
-    ASSERT(clipboard);
-    m_gtkClipboards.add(clipboard);
-}
-
-}
-

Modified: releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/PasteboardHelper.h (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/PasteboardHelper.h	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/PasteboardHelper.h	2016-09-15 08:11:31 UTC (rev 205959)
@@ -26,7 +26,6 @@
 #define PasteboardHelper_h
 
 #include "GRefPtrGtk.h"
-#include <wtf/HashSet.h>
 #include <wtf/Noncopyable.h>
 #include <wtf/Vector.h>
 #include <wtf/glib/GRefPtr.h>
@@ -43,24 +42,20 @@
     enum SmartPasteInclusion { IncludeSmartPaste, DoNotIncludeSmartPaste };
 
     GtkTargetList* targetList() const;
-    GRefPtr<GtkTargetList> targetListForDataObject(const DataObjectGtk&, SmartPasteInclusion = DoNotIncludeSmartPaste);
+    GRefPtr<GtkTargetList> targetListForDataObject(const DataObjectGtk&);
     void fillSelectionData(GtkSelectionData*, guint, const DataObjectGtk&);
     void fillDataObjectFromDropData(GtkSelectionData*, guint, DataObjectGtk&);
     Vector<GdkAtom> dropAtomsForContext(GtkWidget*, GdkDragContext*);
-    void writeClipboardContents(GtkClipboard*, const DataObjectGtk&, SmartPasteInclusion = DoNotIncludeSmartPaste, GClosure* = 0);
+    void writeClipboardContents(GtkClipboard*, const DataObjectGtk&, std::function<void()>&& primarySelectionCleared = nullptr);
     void getClipboardContents(GtkClipboard*, DataObjectGtk&);
 
     enum PasteboardTargetType { TargetTypeMarkup, TargetTypeText, TargetTypeImage, TargetTypeURIList, TargetTypeNetscapeURL, TargetTypeSmartPaste, TargetTypeUnknown };
-    bool clipboardContentSupportsSmartReplace(GtkClipboard*);
 
-    void registerClipboard(GtkClipboard*);
-
 private:
     PasteboardHelper();
     ~PasteboardHelper();
 
     GRefPtr<GtkTargetList> m_targetList;
-    HashSet<GtkClipboard*> m_gtkClipboards;
 };
 
 }

Added: releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/PlatformPasteboardGtk.cpp (0 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/PlatformPasteboardGtk.cpp	                        (rev 0)
+++ releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/PlatformPasteboardGtk.cpp	2016-09-15 08:11:31 UTC (rev 205959)
@@ -0,0 +1,49 @@
+/*
+ *  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 "config.h"
+#include "PlatformPasteboard.h"
+
+#include "Color.h"
+#include "DataObjectGtk.h"
+#include "PasteboardHelper.h"
+#include "SharedBuffer.h"
+#include "URL.h"
+#include <gtk/gtk.h>
+
+namespace WebCore {
+
+PlatformPasteboard::PlatformPasteboard(const String& pasteboardName)
+    : m_clipboard(gtk_clipboard_get(gdk_atom_intern(pasteboardName.utf8().data(), TRUE)))
+{
+    ASSERT(m_clipboard);
+}
+
+void PlatformPasteboard::writeToClipboard(const RefPtr<DataObjectGtk>& dataObject, std::function<void()>&& primarySelectionCleared)
+{
+    PasteboardHelper::singleton().writeClipboardContents(m_clipboard, *dataObject, gtk_clipboard_get(GDK_SELECTION_PRIMARY) == m_clipboard ? WTFMove(primarySelectionCleared) : nullptr);
+}
+
+RefPtr<DataObjectGtk> PlatformPasteboard::readFromClipboard()
+{
+    RefPtr<DataObjectGtk> dataObject = DataObjectGtk::create();
+    PasteboardHelper::singleton().getClipboardContents(m_clipboard, *dataObject);
+    return dataObject;
+}
+
+}

Modified: releases/WebKitGTK/webkit-2.14/Source/WebKit2/ChangeLog (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebKit2/ChangeLog	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebKit2/ChangeLog	2016-09-15 08:11:31 UTC (rev 205959)
@@ -1,3 +1,68 @@
+2016-09-14  Carlos Garnacho  <carl...@gnome.org>
+
+        [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<DragData>::encode):
+        (IPC::ArgumentCoder<DragData>::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->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->WebProcess notification that the global selection has
+        been replaced.
+
 2016-09-13  Carlos Garcia Campos  <cgar...@igalia.com>
 
         [GTK] Get rid of DataObjectGtk::forClipboard and cleanup pasteboard code

Modified: releases/WebKitGTK/webkit-2.14/Source/WebKit2/PlatformGTK.cmake (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebKit2/PlatformGTK.cmake	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebKit2/PlatformGTK.cmake	2016-09-15 08:11:31 UTC (rev 205959)
@@ -70,6 +70,7 @@
     Shared/gtk/NativeWebMouseEventGtk.cpp
     Shared/gtk/NativeWebTouchEventGtk.cpp
     Shared/gtk/NativeWebWheelEventGtk.cpp
+    Shared/gtk/PasteboardContent.cpp
     Shared/gtk/PrintInfoGtk.cpp
     Shared/gtk/ProcessExecutablePathGtk.cpp
     Shared/gtk/WebContextMenuItemGtk.cpp
@@ -311,6 +312,7 @@
     UIProcess/gtk/WebInspectorClientGtk.cpp
     UIProcess/gtk/WebInspectorProxyGtk.cpp
     UIProcess/gtk/WebPageProxyGtk.cpp
+    UIProcess/gtk/WebPasteboardProxyGtk.cpp
     UIProcess/gtk/WebPopupMenuProxyGtk.cpp
     UIProcess/gtk/WebPreferencesGtk.cpp
     UIProcess/gtk/WebProcessPoolGtk.cpp

Modified: releases/WebKitGTK/webkit-2.14/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.cpp (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.cpp	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.cpp	2016-09-15 08:11:31 UTC (rev 205959)
@@ -82,7 +82,7 @@
     return true;
 }
 
-static void encodeDataObject(Encoder& encoder, const DataObjectGtk* dataObject)
+void encode(Encoder& encoder, const DataObjectGtk* dataObject)
 {
     bool hasText = dataObject->hasText();
     encoder << hasText;
@@ -113,9 +113,12 @@
     encoder << hasUnknownTypeData;
     if (hasUnknownTypeData)
         encoder << dataObject->unknownTypes();
+
+    bool canSmartReplace = dataObject->canSmartReplace();
+    encoder << canSmartReplace;
 }
 
-static bool decodeDataObject(Decoder& decoder, RefPtr<DataObjectGtk>& dataObject)
+bool decode(Decoder& decoder, RefPtr<DataObjectGtk>& dataObject)
 {
     RefPtr<DataObjectGtk> data = ""
 
@@ -182,6 +185,11 @@
             data->setUnknownTypeData(it->key, it->value);
     }
 
+    bool canSmartReplace;
+    if (!decoder.decode(canSmartReplace))
+        return false;
+    data->setCanSmartReplace(canSmartReplace);
+
     dataObject = data;
 
     return true;
@@ -198,7 +206,7 @@
     DataObjectGtk* platformData = dragData.platformData();
     encoder << static_cast<bool>(platformData);
     if (platformData)
-        encodeDataObject(encoder, platformData);
+        IPC::encode(encoder, platformData);
 }
 
 bool ArgumentCoder<DragData>::decode(Decoder& decoder, DragData& dragData)
@@ -225,7 +233,7 @@
 
     RefPtr<DataObjectGtk> platformData;
     if (hasPlatformData) {
-        if (!decodeDataObject(decoder, platformData))
+        if (!IPC::decode(decoder, platformData))
             return false;
     }
 

Modified: releases/WebKitGTK/webkit-2.14/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.h (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.h	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebKit2/Shared/gtk/ArgumentCodersGtk.h	2016-09-15 08:11:31 UTC (rev 205959)
@@ -52,6 +52,9 @@
 void encode(Encoder&, GtkPageSetup*);
 bool decode(Decoder&, GRefPtr<GtkPageSetup>&);
 
+void encode(Encoder&, const WebCore::DataObjectGtk*);
+bool decode(Decoder&, RefPtr<WebCore::DataObjectGtk>&);
+
 } // namespace IPC
 
 #endif // ArgumentCodersGtk_h

Added: releases/WebKitGTK/webkit-2.14/Source/WebKit2/Shared/gtk/PasteboardContent.cpp (0 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebKit2/Shared/gtk/PasteboardContent.cpp	                        (rev 0)
+++ releases/WebKitGTK/webkit-2.14/Source/WebKit2/Shared/gtk/PasteboardContent.cpp	2016-09-15 08:11:31 UTC (rev 205959)
@@ -0,0 +1,46 @@
+/*
+ *  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 "config.h"
+#include "PasteboardContent.h"
+
+#include "ArgumentCodersGtk.h"
+#include "DataObjectGtk.h"
+#include "Decoder.h"
+#include "Encoder.h"
+#include <wtf/RetainPtr.h>
+
+namespace WebKit {
+
+PasteboardContent::PasteboardContent(const RefPtr<WebCore::DataObjectGtk>& data)
+    : dataObject(data)
+{
+    ASSERT(dataObject);
+}
+
+void PasteboardContent::encode(IPC::Encoder& encoder) const
+{
+    IPC::encode(encoder, dataObject.get());
+}
+
+bool PasteboardContent::decode(IPC::Decoder& decoder, PasteboardContent& pasteboardContent)
+{
+    return IPC::decode(decoder, pasteboardContent.dataObject);
+}
+
+} // namespace WebKit

Added: releases/WebKitGTK/webkit-2.14/Source/WebKit2/Shared/gtk/PasteboardContent.h (0 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebKit2/Shared/gtk/PasteboardContent.h	                        (rev 0)
+++ releases/WebKitGTK/webkit-2.14/Source/WebKit2/Shared/gtk/PasteboardContent.h	2016-09-15 08:11:31 UTC (rev 205959)
@@ -0,0 +1,43 @@
+/*
+ *  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 "DataObjectGtk.h"
+
+namespace IPC {
+class Decoder;
+class Encoder;
+}
+
+namespace WebKit {
+
+struct PasteboardContent {
+    PasteboardContent() = default;
+    explicit PasteboardContent(const RefPtr<WebCore::DataObjectGtk>&);
+
+    RefPtr<WebCore::DataObjectGtk> dataObject;
+
+    void encode(IPC::Encoder&) const;
+    static bool decode(IPC::Decoder&, PasteboardContent&);
+};
+
+} // namespace WebKit
+
+#endif // PasteboardContent_h

Modified: releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/WebFrameProxy.cpp (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/WebFrameProxy.cpp	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/WebFrameProxy.cpp	2016-09-15 08:11:31 UTC (rev 205959)
@@ -31,6 +31,7 @@
 #include "WebFramePolicyListenerProxy.h"
 #include "WebPageMessages.h"
 #include "WebPageProxy.h"
+#include "WebPasteboardProxy.h"
 #include "WebProcessPool.h"
 #include <WebCore/DOMImplementation.h>
 #include <WebCore/Image.h>
@@ -53,6 +54,9 @@
 WebFrameProxy::~WebFrameProxy()
 {
     WebProcessPool::statistics().wkFrameCount--;
+#if PLATFORM(GTK)
+    WebPasteboardProxy::singleton().didDestroyFrame(this);
+#endif
 }
 
 void WebFrameProxy::webProcessWillShutDown()
@@ -257,4 +261,14 @@
 }
 #endif
 
+#if PLATFORM(GTK)
+void WebFrameProxy::collapseSelection()
+{
+    if (!m_page)
+        return;
+
+    m_page->process().send(Messages::WebPage::CollapseSelectionInFrame(m_frameID), m_page->pageID());
+}
+#endif
+
 } // namespace WebKit

Modified: releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/WebFrameProxy.h (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/WebFrameProxy.h	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/WebFrameProxy.h	2016-09-15 08:11:31 UTC (rev 205959)
@@ -124,6 +124,10 @@
     bool didHandleContentFilterUnblockNavigation(const WebCore::ResourceRequest&);
 #endif
 
+#if PLATFORM(GTK)
+    void collapseSelection();
+#endif
+
 private:
     WebFrameProxy(WebPageProxy* page, uint64_t frameID);
 

Modified: releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/WebPasteboardProxy.h (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/WebPasteboardProxy.h	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/WebPasteboardProxy.h	2016-09-15 08:11:31 UTC (rev 205959)
@@ -40,8 +40,13 @@
 
 namespace WebKit {
 
+class WebFrameProxy;
 class WebProcessProxy;
 
+#if PLATFORM(GTK)
+class PasteboardContent;
+#endif
+
 class WebPasteboardProxy : public IPC::MessageReceiver {
     WTF_MAKE_NONCOPYABLE(WebPasteboardProxy);
     friend class LazyNeverDestroyed<WebPasteboardProxy>;
@@ -50,6 +55,11 @@
 
     void addWebProcessProxy(WebProcessProxy&);
 
+#if PLATFORM(GTK)
+    void setPrimarySelectionOwner(WebFrameProxy*);
+    void didDestroyFrame(WebFrameProxy*);
+#endif
+
 private:
     WebPasteboardProxy();
 
@@ -81,6 +91,13 @@
     void setPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, const String&, uint64_t& newChangeCount);
     void setPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, const SharedMemory::Handle&, uint64_t size, uint64_t& newChangeCount);
 #endif
+#if PLATFORM(GTK)
+    void writeToClipboard(const String& pasteboardName, const PasteboardContent&);
+    void readFromClipboard(const String& pasteboardName, PasteboardContent&);
+
+    WebFrameProxy* m_primarySelectionOwner { nullptr };
+    WebFrameProxy* m_frameWritingToClipboard { nullptr };
+#endif // PLATFORM(GTK)
 };
 
 } // namespace WebKit

Modified: releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/WebPasteboardProxy.messages.in (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/WebPasteboardProxy.messages.in	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/WebPasteboardProxy.messages.in	2016-09-15 08:11:31 UTC (rev 205959)
@@ -48,4 +48,9 @@
     SetPasteboardStringForType(String pasteboardName, String pasteboardType, String string) -> (uint64_t changeCount)
     SetPasteboardBufferForType(String pasteboardName, String pasteboardType, WebKit::SharedMemory::Handle handle, uint64_t size) -> (uint64_t changeCount)
 #endif
+
+#if PLATFORM(GTK)
+    WriteToClipboard(String pasteboardName, struct WebKit::PasteboardContent pasteboardContent)
+    ReadFromClipboard(String pasteboardName) -> (struct WebKit::PasteboardContent pasteboardContent)
+#endif
 }

Modified: releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp	2016-09-15 08:11:31 UTC (rev 205959)
@@ -31,6 +31,7 @@
 #include "PageClientImpl.h"
 #include "WebKitWebViewBasePrivate.h"
 #include "WebPageMessages.h"
+#include "WebPasteboardProxy.h"
 #include "WebProcessProxy.h"
 #include "WebsiteDataStore.h"
 #include <WebCore/UserAgentGtk.h>
@@ -79,6 +80,8 @@
     
     if (editorState.shouldIgnoreCompositionSelectionChange)
         return;
+    if (m_editorState.selectionIsRange)
+        WebPasteboardProxy::singleton().setPrimarySelectionOwner(focusedFrame());
     m_pageClient.selectionDidChange();
 }
 

Added: releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/gtk/WebPasteboardProxyGtk.cpp (0 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/gtk/WebPasteboardProxyGtk.cpp	                        (rev 0)
+++ releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/gtk/WebPasteboardProxyGtk.cpp	2016-09-15 08:11:31 UTC (rev 205959)
@@ -0,0 +1,73 @@
+/*
+ * 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 "config.h"
+#include "WebPasteboardProxy.h"
+
+#include "PasteboardContent.h"
+#include "WebFrameProxy.h"
+#include <WebCore/PlatformPasteboard.h>
+#include <wtf/HashMap.h>
+#include <wtf/NeverDestroyed.h>
+#include <wtf/TemporaryChange.h>
+#include <wtf/text/StringHash.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+void WebPasteboardProxy::writeToClipboard(const String& pasteboardName, const PasteboardContent& pasteboardContent)
+{
+    TemporaryChange<WebFrameProxy*> frameWritingToClipboard(m_frameWritingToClipboard, m_primarySelectionOwner);
+    PlatformPasteboard(pasteboardName).writeToClipboard(pasteboardContent.dataObject, [this] {
+        if (m_frameWritingToClipboard == m_primarySelectionOwner)
+            return;
+        setPrimarySelectionOwner(nullptr);
+    });
+}
+
+void WebPasteboardProxy::readFromClipboard(const String& pasteboardName, PasteboardContent& pasteboardContent)
+{
+    pasteboardContent = PasteboardContent(PlatformPasteboard(pasteboardName).readFromClipboard().get());
+}
+
+void WebPasteboardProxy::setPrimarySelectionOwner(WebFrameProxy* frame)
+{
+    if (m_primarySelectionOwner == frame)
+        return;
+
+    if (m_primarySelectionOwner)
+        m_primarySelectionOwner->collapseSelection();
+
+    m_primarySelectionOwner = frame;
+}
+
+void WebPasteboardProxy::didDestroyFrame(WebFrameProxy* frame)
+{
+    if (frame == m_primarySelectionOwner)
+        m_primarySelectionOwner = nullptr;
+}
+
+} // namespace WebKit

Modified: releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp	2016-09-15 08:11:31 UTC (rev 205959)
@@ -69,6 +69,10 @@
 #include "StringUtilities.h"
 #endif
 
+#if PLATFORM(GTK)
+#include "PasteboardContent.h"
+#endif
+
 using namespace WebCore;
 
 namespace WebKit {
@@ -339,4 +343,22 @@
 
 #endif // PLATFORM(COCOA)
 
+#if PLATFORM(GTK)
+// PasteboardStrategy
+
+void WebPlatformStrategies::writeToClipboard(const String& pasteboardName, const RefPtr<WebCore::DataObjectGtk>& dataObject)
+{
+    PasteboardContent pasteboardContent = PasteboardContent(dataObject.get());
+    WebProcess::singleton().parentProcessConnection()->send(Messages::WebPasteboardProxy::WriteToClipboard(pasteboardName, pasteboardContent), 0);
+}
+
+RefPtr<WebCore::DataObjectGtk> WebPlatformStrategies::readFromClipboard(const String& pasteboardName)
+{
+    PasteboardContent pasteboardContent;
+    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::ReadFromClipboard(pasteboardName), Messages::WebPasteboardProxy::ReadFromClipboard::Reply(pasteboardContent), 0);
+    return pasteboardContent.dataObject;
+}
+
+#endif // PLATFORM(GTK)
+
 } // namespace WebKit

Modified: releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h	2016-09-15 08:11:31 UTC (rev 205959)
@@ -86,7 +86,10 @@
     long setPathnamesForType(const Vector<String>&, const String& pasteboardType, const String& pasteboardName) override;
     long setStringForType(const String&, const String& pasteboardType, const String& pasteboardName) override;
 #endif
-
+#if PLATFORM(GTK)
+    void writeToClipboard(const String& pasteboardName, const RefPtr<WebCore::DataObjectGtk>&) override;
+    RefPtr<WebCore::DataObjectGtk> readFromClipboard(const String& pasteboardName) override;
+#endif
 };
 
 } // namespace WebKit

Modified: releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp	2016-09-15 08:11:31 UTC (rev 205959)
@@ -119,45 +119,6 @@
         event->setDefaultHandled();
 }
 
-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<EditorClientFrameDestructionObserver*>(data);
-        delete observer;
-    }
-};
-
-static Frame* frameSettingClipboard;
-
-static void collapseSelection(GtkClipboard*, Frame* frame)
-{
-    if (frameSettingClipboard && frameSettingClipboard == frame)
-        return;
-
-    // Collapse the selection without clearing it.
-    ASSERT(frame);
-    const VisibleSelection& selection = frame->selection().selection();
-    frame->selection().setBase(selection.extent(), selection.affinity());
-}
-
 void WebEditorClient::updateGlobalSelection(Frame* frame)
 {
     if (!frame->selection().isRange())
@@ -166,21 +127,11 @@
     if (!range)
         return;
 
-    frameSettingClipboard = frame;
-    GRefPtr<GClosure> 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);
-
     PasteboardWebContent pasteboardContent;
     pasteboardContent.canSmartCopyOrDelete = false;
     pasteboardContent.text = range->text();
     pasteboardContent.markup = createMarkup(*range, nullptr, AnnotateForInterchange, false, ResolveNonLocalURLs);
-    pasteboardContent.callback = callback;
     Pasteboard::createForGlobalSelection()->write(pasteboardContent);
-    frameSettingClipboard = nullptr;
 }
 
 bool WebEditorClient::shouldShowUnicodeMenu()

Modified: releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebPage/WebPage.h (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebPage/WebPage.h	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebPage/WebPage.h	2016-09-15 08:11:31 UTC (rev 205959)
@@ -643,6 +643,8 @@
     void setComposition(const String& text, const Vector<WebCore::CompositionUnderline>& underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeLength);
     void confirmComposition(const String& text, int64_t selectionStart, int64_t selectionLength);
     void cancelComposition();
+
+    void collapseSelectionInFrame(uint64_t frameID);
 #endif
 
 #if PLATFORM (GTK) && HAVE(GTK_GESTURES)

Modified: releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2016-09-15 08:11:31 UTC (rev 205959)
@@ -340,6 +340,8 @@
     SetComposition(String text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeEnd)
     ConfirmComposition(String text, int64_t selectionStart, int64_t selectionLength)
     CancelComposition()
+
+    CollapseSelectionInFrame(uint64_t frameID)
 #endif
 
 #if PLATFORM (GTK) && HAVE(GTK_GESTURES)

Modified: releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebPage/gtk/WebPageGtk.cpp (205958 => 205959)


--- releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebPage/gtk/WebPageGtk.cpp	2016-09-15 08:02:20 UTC (rev 205958)
+++ releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebPage/gtk/WebPageGtk.cpp	2016-09-15 08:11:31 UTC (rev 205959)
@@ -31,8 +31,10 @@
 #include "EditorState.h"
 #include "NotImplemented.h"
 #include "WebEvent.h"
+#include "WebFrame.h"
 #include "WebPageAccessibilityObject.h"
 #include "WebPageProxyMessages.h"
+#include "WebProcess.h"
 #include "WindowsKeyboardCodes.h"
 #include <WebCore/BackForwardController.h>
 #include <WebCore/EventHandler.h>
@@ -216,4 +218,15 @@
     send(Messages::WebPageProxy::SetInputMethodState(enabled));
 }
 
+void WebPage::collapseSelectionInFrame(uint64_t frameID)
+{
+    WebFrame* frame = WebProcess::singleton().webFrame(frameID);
+    if (!frame || !frame->coreFrame())
+        return;
+
+    // Collapse the selection without clearing it.
+    const VisibleSelection& selection = frame->coreFrame()->selection().selection();
+    frame->coreFrame()->selection().setBase(selection.extent(), selection.affinity());
+}
+
 } // namespace WebKit
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to