[GTK] Clean up DataObjectGtk handling
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Sep 2016 06:17:13 +0000 (06:17 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Sep 2016 06:17:13 +0000 (06:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=162267

Reviewed by Michael Catanzaro.

Source/WebCore:

* platform/Pasteboard.h: Use Ref instead of RefPtr for DataObjectGtk member.
* platform/PasteboardStrategy.h: Pass a const reference to DataObjectGtk in write method and return a Ref from read.
* platform/PlatformPasteboard.h: Ditto.
* platform/gtk/DataObjectGtk.h:
(WebCore::DataObjectGtk::image): Use Image instead of GdkPixbuf.
(WebCore::DataObjectGtk::setImage):
* platform/gtk/PasteboardGtk.cpp:
(WebCore::Pasteboard::createForDragAndDrop): Use a reference instead of a pointer.
(WebCore::Pasteboard::Pasteboard): Receives a reference, so we can also remove the ASSERT.
(WebCore::Pasteboard::dataObject):
(WebCore::Pasteboard::writeToClipboard): Remove the ShouldIncludeSmartPaste parameter, callers should also update
canSmartPaste property of DataObjectGtk before calling this.
(WebCore::Pasteboard::writePlainText):
(WebCore::Pasteboard::write): Do not convert the image the GdkPixbuf, pass the image to the DataObjectGtk instead.
* platform/gtk/PasteboardHelper.cpp:
(WebCore::PasteboardHelper::fillSelectionData): Convert the DataObjectGtk image to GdkPixbuf right before
passing it to gtk_selection_data_set_pixbuf().
(WebCore::ClipboardSetData::ClipboardSetData): Use reference instead of pointer.
(WebCore::getClipboardContentsCallback):
(WebCore::clearClipboardContentsCallback): Never clear the saved DataObjectGtk, that was only needed when we had
a global DataObjectGtk associated to a GtkClipboard.
(WebCore::PasteboardHelper::writeClipboardContents): Use TemporaryChange to set the settingClipboardDataObject global.
* platform/gtk/PlatformPasteboardGtk.cpp:
(WebCore::PlatformPasteboard::writeToClipboard):
(WebCore::PlatformPasteboard::readFromClipboard):

Source/WebKit2:

In some cases the ownership of DataObjectGtk instances is not clear enough, and we have hacks to avoid memory
leaks because of that.

* Shared/gtk/ArgumentCodersGtk.cpp:
(IPC::encodeImage): Use Image instead of GdkPixbuf.
(IPC::decodeImage): Ditto.
(IPC::ArgumentCoder<DataObjectGtk>::encode):
(IPC::ArgumentCoder<DataObjectGtk>::decode):
(IPC::encode): Deleted.
(IPC::decode): Deleted.
(IPC::ArgumentCoder<DragData>::encode): Deleted.
(IPC::ArgumentCoder<DragData>::decode): Deleted.
* Shared/gtk/ArgumentCodersGtk.h:
* Shared/gtk/PasteboardContent.cpp:
(WebKit::PasteboardContent::PasteboardContent): Add empty constructor that creates a new DataObjectGtk, a
constructor that receives a const reference and another one that takes the ownership of the given DataObjectGtk.
(WebKit::PasteboardContent::encode):
(WebKit::PasteboardContent::decode):
* Shared/gtk/PasteboardContent.h: Use Ref instead of RefPtr for the DataObjectGtk member.
* UIProcess/API/gtk/PageClientImpl.cpp:
(WebKit::PageClientImpl::startDrag): Transfer the DataObjectGtk to the DragAndDropHandler, instead of using DragData.
* UIProcess/API/gtk/PageClientImpl.h:
* UIProcess/PageClient.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::performDragControllerAction): Instead of sending a DragData object to the web process,
send the DataObjectGtk and DragData members needed as parameters.
(WebKit::WebPageProxy::startDrag): Transfer the received DataObjectGtk to page client, instead of using
DragData. Also notify the web process that drag started.
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in: Update StartDrag message parameters.
* UIProcess/gtk/DragAndDropHandler.cpp:
(WebKit::DragAndDropHandler::DragAndDropHandler): Remove unneeded initialization.
(WebKit::DragAndDropHandler::startDrag): Take ownership of the given DataObjectGtk.
* UIProcess/gtk/DragAndDropHandler.h:
* UIProcess/gtk/WebPasteboardProxyGtk.cpp:
(WebKit::WebPasteboardProxy::writeToClipboard):
(WebKit::WebPasteboardProxy::readFromClipboard):
* WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
(WebKit::WebPlatformStrategies::writeToClipboard):
(WebKit::WebPlatformStrategies::readFromClipboard):
* WebProcess/WebCoreSupport/WebPlatformStrategies.h:
* WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp:
(WebKit::convertCairoSurfaceToShareableBitmap):
(WebKit::WebDragClient::startDrag): Do not create a DragData and pass the DataObjectGtk directly to the
message. Also notify the WebPage that drag is about to start.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::performDragControllerAction): Remove explicit DataObjectGtk derefs and simply create a
DragData using the DataObjectGtk pointer as platform data.
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in: Update PerformDragControllerAction message parameters.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@206197 268f45cc-cd09-0410-ab3c-d52691b4dbfc

28 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/Pasteboard.h
Source/WebCore/platform/PasteboardStrategy.h
Source/WebCore/platform/PlatformPasteboard.h
Source/WebCore/platform/gtk/DataObjectGtk.h
Source/WebCore/platform/gtk/PasteboardGtk.cpp
Source/WebCore/platform/gtk/PasteboardHelper.cpp
Source/WebCore/platform/gtk/PlatformPasteboardGtk.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/gtk/ArgumentCodersGtk.cpp
Source/WebKit2/Shared/gtk/ArgumentCodersGtk.h
Source/WebKit2/Shared/gtk/PasteboardContent.cpp
Source/WebKit2/Shared/gtk/PasteboardContent.h
Source/WebKit2/UIProcess/API/gtk/PageClientImpl.cpp
Source/WebKit2/UIProcess/API/gtk/PageClientImpl.h
Source/WebKit2/UIProcess/PageClient.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/WebPageProxy.messages.in
Source/WebKit2/UIProcess/gtk/DragAndDropHandler.cpp
Source/WebKit2/UIProcess/gtk/DragAndDropHandler.h
Source/WebKit2/UIProcess/gtk/WebPasteboardProxyGtk.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h
Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

index 406c3a6..933cc90 100644 (file)
@@ -1,3 +1,36 @@
+2016-09-20  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Clean up DataObjectGtk handling
+        https://bugs.webkit.org/show_bug.cgi?id=162267
+
+        Reviewed by Michael Catanzaro.
+
+        * platform/Pasteboard.h: Use Ref instead of RefPtr for DataObjectGtk member.
+        * platform/PasteboardStrategy.h: Pass a const reference to DataObjectGtk in write method and return a Ref from read.
+        * platform/PlatformPasteboard.h: Ditto.
+        * platform/gtk/DataObjectGtk.h:
+        (WebCore::DataObjectGtk::image): Use Image instead of GdkPixbuf.
+        (WebCore::DataObjectGtk::setImage):
+        * platform/gtk/PasteboardGtk.cpp:
+        (WebCore::Pasteboard::createForDragAndDrop): Use a reference instead of a pointer.
+        (WebCore::Pasteboard::Pasteboard): Receives a reference, so we can also remove the ASSERT.
+        (WebCore::Pasteboard::dataObject):
+        (WebCore::Pasteboard::writeToClipboard): Remove the ShouldIncludeSmartPaste parameter, callers should also update
+        canSmartPaste property of DataObjectGtk before calling this.
+        (WebCore::Pasteboard::writePlainText):
+        (WebCore::Pasteboard::write): Do not convert the image the GdkPixbuf, pass the image to the DataObjectGtk instead.
+        * platform/gtk/PasteboardHelper.cpp:
+        (WebCore::PasteboardHelper::fillSelectionData): Convert the DataObjectGtk image to GdkPixbuf right before
+        passing it to gtk_selection_data_set_pixbuf().
+        (WebCore::ClipboardSetData::ClipboardSetData): Use reference instead of pointer.
+        (WebCore::getClipboardContentsCallback):
+        (WebCore::clearClipboardContentsCallback): Never clear the saved DataObjectGtk, that was only needed when we had
+        a global DataObjectGtk associated to a GtkClipboard.
+        (WebCore::PasteboardHelper::writeClipboardContents): Use TemporaryChange to set the settingClipboardDataObject global.
+        * platform/gtk/PlatformPasteboardGtk.cpp:
+        (WebCore::PlatformPasteboard::writeToClipboard):
+        (WebCore::PlatformPasteboard::readFromClipboard):
+
 2016-09-20  Alex Christensen  <achristensen@webkit.org>
 
         Require WTFMove for String::adopt
index 59b498f..d23824e 100644 (file)
@@ -138,7 +138,7 @@ public:
 
 #if PLATFORM(GTK)
     explicit Pasteboard(const String& name);
-    explicit Pasteboard(RefPtr<DataObjectGtk>&&);
+    explicit Pasteboard(DataObjectGtk&);
 #endif
 
 #if PLATFORM(WIN)
@@ -220,10 +220,9 @@ private:
 #endif
 
 #if PLATFORM(GTK)
-    enum class ShouldIncludeSmartPaste { No, Yes };
-    void writeToClipboard(ShouldIncludeSmartPaste = ShouldIncludeSmartPaste::No);
+    void writeToClipboard();
     void readFromClipboard();
-    RefPtr<DataObjectGtk> m_dataObject;
+    Ref<DataObjectGtk> m_dataObject;
     String m_name;
 #endif
 
index 81716f5..608bf1d 100644 (file)
@@ -73,8 +73,8 @@ public:
     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;
+    virtual void writeToClipboard(const String& pasteboardName, const DataObjectGtk&) = 0;
+    virtual Ref<DataObjectGtk> readFromClipboard(const String& pasteboardName) = 0;
 #endif // PLATFORM(GTK)
 protected:
     virtual ~PasteboardStrategy()
index 695bc0e..dc72658 100644 (file)
@@ -86,8 +86,8 @@ public:
     WEBCORE_EXPORT int count();
 
 #if PLATFORM(GTK)
-    WEBCORE_EXPORT void writeToClipboard(const RefPtr<DataObjectGtk>&, std::function<void()>&& primarySelectionCleared);
-    WEBCORE_EXPORT RefPtr<DataObjectGtk> readFromClipboard();
+    WEBCORE_EXPORT void writeToClipboard(const DataObjectGtk&, std::function<void()>&& primarySelectionCleared);
+    WEBCORE_EXPORT Ref<DataObjectGtk> readFromClipboard();
 #endif
 
 private:
index e293b29..17e8d70 100644 (file)
 
 #pragma once
 
-#include "FileList.h"
+#include "Image.h"
 #include "URL.h"
 #include <wtf/HashMap.h>
 #include <wtf/RefCounted.h>
-#include <wtf/glib/GRefPtr.h>
 #include <wtf/text/StringHash.h>
 
 namespace WebCore {
@@ -37,8 +36,8 @@ public:
     const URL& url() const { return m_url; }
     const String& uriList() const { return m_uriList; }
     const Vector<String>& filenames() const { return m_filenames; }
-    GdkPixbuf* image() const { return m_image.get(); }
-    void setImage(GdkPixbuf* newImage) { m_image = newImage; }
+    Image* image() const { return m_image.get(); }
+    void setImage(Image* newImage) { m_image = newImage; }
     void setURL(const URL&, const String&);
     bool hasUnknownTypeData() const { return !m_unknownTypeData.isEmpty(); }
     bool hasText() const { return !m_text.isEmpty(); }
@@ -74,7 +73,7 @@ private:
     URL m_url;
     String m_uriList;
     Vector<String> m_filenames;
-    GRefPtr<GdkPixbuf> m_image;
+    RefPtr<Image> m_image;
     HashMap<String, String> m_unknownTypeData;
     bool m_canSmartReplace { false };
 };
index b702764..07d9cc0 100644 (file)
@@ -62,7 +62,8 @@ std::unique_ptr<Pasteboard> Pasteboard::createForDragAndDrop()
 
 std::unique_ptr<Pasteboard> Pasteboard::createForDragAndDrop(const DragData& dragData)
 {
-    return std::make_unique<Pasteboard>(dragData.platformData());
+    ASSERT(dragData.platformData());
+    return std::make_unique<Pasteboard>(*dragData.platformData());
 }
 #endif
 
@@ -75,10 +76,9 @@ PasteboardImage::~PasteboardImage()
 {
 }
 
-Pasteboard::Pasteboard(RefPtr<DataObjectGtk>&& dataObject)
-    : m_dataObject(WTFMove(dataObject))
+Pasteboard::Pasteboard(DataObjectGtk& dataObject)
+    : m_dataObject(dataObject)
 {
-    ASSERT(m_dataObject);
 }
 
 Pasteboard::Pasteboard(const String& name)
@@ -93,7 +93,7 @@ Pasteboard::~Pasteboard()
 
 const DataObjectGtk& Pasteboard::dataObject() const
 {
-    return *m_dataObject;
+    return m_dataObject.get();
 }
 
 static ClipboardDataType dataObjectTypeFromHTMLClipboardType(const String& rawType)
@@ -119,11 +119,11 @@ static ClipboardDataType dataObjectTypeFromHTMLClipboardType(const String& rawTy
     return ClipboardDataTypeUnknown;
 }
 
-void Pasteboard::writeToClipboard(ShouldIncludeSmartPaste shouldIncludeSmartPaste)
+void Pasteboard::writeToClipboard()
 {
     if (m_name.isNull())
         return;
-    m_dataObject->setCanSmartReplace(shouldIncludeSmartPaste == ShouldIncludeSmartPaste::Yes);
+
     platformStrategies()->pasteboardStrategy()->writeToClipboard(m_name, m_dataObject);
 }
 
@@ -159,8 +159,9 @@ void Pasteboard::writePlainText(const String& text, SmartReplaceOption smartRepl
 {
     m_dataObject->clearAll();
     m_dataObject->setText(text);
+    m_dataObject->setCanSmartReplace(smartReplaceOption == CanSmartReplace);
 
-    writeToClipboard(smartReplaceOption == CanSmartReplace ? ShouldIncludeSmartPaste::Yes : ShouldIncludeSmartPaste::No);
+    writeToClipboard();
 }
 
 void Pasteboard::write(const PasteboardURL& pasteboardURL)
@@ -180,10 +181,7 @@ void Pasteboard::write(const PasteboardImage& pasteboardImage)
         m_dataObject->setURL(pasteboardImage.url.url, pasteboardImage.url.title);
         m_dataObject->setMarkup(pasteboardImage.url.markup);
     }
-
-    GRefPtr<GdkPixbuf> pixbuf = adoptGRef(pasteboardImage.image->getGdkPixbuf());
-    if (pixbuf)
-        m_dataObject->setImage(pixbuf.get());
+    m_dataObject->setImage(pasteboardImage.image.get());
 
     writeToClipboard();
 }
@@ -193,8 +191,9 @@ void Pasteboard::write(const PasteboardWebContent& pasteboardContent)
     m_dataObject->clearAll();
     m_dataObject->setText(pasteboardContent.text);
     m_dataObject->setMarkup(pasteboardContent.markup);
+    m_dataObject->setCanSmartReplace(pasteboardContent.canSmartCopyOrDelete);
 
-    writeToClipboard(pasteboardContent.canSmartCopyOrDelete ? ShouldIncludeSmartPaste::Yes : ShouldIncludeSmartPaste::No);
+    writeToClipboard();
 }
 
 void Pasteboard::writePasteboard(const Pasteboard& sourcePasteboard)
index a89cf1b..e67efbd 100644 (file)
@@ -25,9 +25,8 @@
 
 #include "DataObjectGtk.h"
 #include "GtkVersioning.h"
-#include "Pasteboard.h"
-#include "TextResourceDecoder.h"
 #include <gtk/gtk.h>
+#include <wtf/TemporaryChange.h>
 #include <wtf/glib/GUniquePtr.h>
 #include <wtf/text/CString.h>
 
@@ -148,10 +147,11 @@ void PasteboardHelper::fillSelectionData(GtkSelectionData* selectionData, guint
         gtk_selection_data_set(selectionData, netscapeURLAtom, 8,
             reinterpret_cast<const guchar*>(resultData.get()), strlen(resultData.get()));
 
-    } else if (info == TargetTypeImage)
-        gtk_selection_data_set_pixbuf(selectionData, dataObject.image());
+    } else if (info == TargetTypeImage && dataObject.hasImage()) {
+        GRefPtr<GdkPixbuf> pixbuf = adoptGRef(dataObject.image()->getGdkPixbuf());
+        gtk_selection_data_set_pixbuf(selectionData, pixbuf.get());
 
-    else if (info == TargetTypeSmartPaste)
+    else if (info == TargetTypeSmartPaste)
         gtk_selection_data_set_text(selectionData, "", -1);
 
     else if (info == TargetTypeUnknown) {
@@ -257,7 +257,7 @@ Vector<GdkAtom> PasteboardHelper::dropAtomsForContext(GtkWidget* widget, GdkDrag
 static DataObjectGtk* settingClipboardDataObject = 0;
 
 struct ClipboardSetData {
-    ClipboardSetData(DataObjectGtk* dataObject, std::function<void()>&& selectionClearedCallback)
+    ClipboardSetData(DataObjectGtk& dataObject, std::function<void()>&& selectionClearedCallback)
         : dataObject(dataObject)
         , selectionClearedCallback(WTFMove(selectionClearedCallback))
     {
@@ -267,24 +267,19 @@ struct ClipboardSetData {
     {
     }
 
-    RefPtr<DataObjectGtk> dataObject;
+    Ref<DataObjectGtk> dataObject;
     std::function<void()> selectionClearedCallback;
 };
 
 static void getClipboardContentsCallback(GtkClipboard*, GtkSelectionData *selectionData, guint info, gpointer userData)
 {
     auto* data = static_cast<ClipboardSetData*>(userData);
-    PasteboardHelper::singleton().fillSelectionData(selectionData, info, *data->dataObject);
+    PasteboardHelper::singleton().fillSelectionData(selectionData, info, data->dataObject);
 }
 
 static void clearClipboardContentsCallback(GtkClipboard*, gpointer userData)
 {
     std::unique_ptr<ClipboardSetData> data(static_cast<ClipboardSetData*>(userData));
-
-    // Only clear the DataObject for this clipboard if we are not currently setting it.
-    if (data->dataObject.get() != settingClipboardDataObject)
-        data->dataObject->clearAll();
-
     if (data->selectionClearedCallback)
         data->selectionClearedCallback();
 }
@@ -297,16 +292,13 @@ void PasteboardHelper::writeClipboardContents(GtkClipboard* clipboard, const Dat
     GtkTargetEntry* table = gtk_target_table_new_from_list(list.get(), &numberOfTargets);
 
     if (numberOfTargets > 0 && table) {
-        settingClipboardDataObject = const_cast<DataObjectGtk*>(&dataObject);
-
-        auto data = std::make_unique<ClipboardSetData>(settingClipboardDataObject, WTFMove(primarySelectionCleared));
+        TemporaryChange<DataObjectGtk*> change(settingClipboardDataObject, const_cast<DataObjectGtk*>(&dataObject));
+        auto data = std::make_unique<ClipboardSetData>(*settingClipboardDataObject, 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.
             data.release();
         }
-
-        settingClipboardDataObject = nullptr;
     } else
         gtk_clipboard_clear(clipboard);
 
index b7cbead..149096c 100644 (file)
@@ -34,15 +34,15 @@ PlatformPasteboard::PlatformPasteboard(const String& pasteboardName)
     ASSERT(m_clipboard);
 }
 
-void PlatformPasteboard::writeToClipboard(const RefPtr<DataObjectGtk>& dataObject, std::function<void()>&& primarySelectionCleared)
+void PlatformPasteboard::writeToClipboard(const DataObjectGtk& dataObject, std::function<void()>&& primarySelectionCleared)
 {
-    PasteboardHelper::singleton().writeClipboardContents(m_clipboard, *dataObject, gtk_clipboard_get(GDK_SELECTION_PRIMARY) == m_clipboard ? WTFMove(primarySelectionCleared) : nullptr);
+    PasteboardHelper::singleton().writeClipboardContents(m_clipboard, dataObject, gtk_clipboard_get(GDK_SELECTION_PRIMARY) == m_clipboard ? WTFMove(primarySelectionCleared) : nullptr);
 }
 
-RefPtr<DataObjectGtk> PlatformPasteboard::readFromClipboard()
+Ref<DataObjectGtk> PlatformPasteboard::readFromClipboard()
 {
-    RefPtr<DataObjectGtk> dataObject = DataObjectGtk::create();
-    PasteboardHelper::singleton().getClipboardContents(m_clipboard, *dataObject);
+    Ref<DataObjectGtk> dataObject(DataObjectGtk::create());
+    PasteboardHelper::singleton().getClipboardContents(m_clipboard, dataObject.get());
     return dataObject;
 }
 
index 1189ecd..8ef1719 100644 (file)
@@ -1,3 +1,61 @@
+2016-09-20  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Clean up DataObjectGtk handling
+        https://bugs.webkit.org/show_bug.cgi?id=162267
+
+        Reviewed by Michael Catanzaro.
+
+        In some cases the ownership of DataObjectGtk instances is not clear enough, and we have hacks to avoid memory
+        leaks because of that.
+
+        * Shared/gtk/ArgumentCodersGtk.cpp:
+        (IPC::encodeImage): Use Image instead of GdkPixbuf.
+        (IPC::decodeImage): Ditto.
+        (IPC::ArgumentCoder<DataObjectGtk>::encode):
+        (IPC::ArgumentCoder<DataObjectGtk>::decode):
+        (IPC::encode): Deleted.
+        (IPC::decode): Deleted.
+        (IPC::ArgumentCoder<DragData>::encode): Deleted.
+        (IPC::ArgumentCoder<DragData>::decode): Deleted.
+        * Shared/gtk/ArgumentCodersGtk.h:
+        * Shared/gtk/PasteboardContent.cpp:
+        (WebKit::PasteboardContent::PasteboardContent): Add empty constructor that creates a new DataObjectGtk, a
+        constructor that receives a const reference and another one that takes the ownership of the given DataObjectGtk.
+        (WebKit::PasteboardContent::encode):
+        (WebKit::PasteboardContent::decode):
+        * Shared/gtk/PasteboardContent.h: Use Ref instead of RefPtr for the DataObjectGtk member.
+        * UIProcess/API/gtk/PageClientImpl.cpp:
+        (WebKit::PageClientImpl::startDrag): Transfer the DataObjectGtk to the DragAndDropHandler, instead of using DragData.
+        * UIProcess/API/gtk/PageClientImpl.h:
+        * UIProcess/PageClient.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::performDragControllerAction): Instead of sending a DragData object to the web process,
+        send the DataObjectGtk and DragData members needed as parameters.
+        (WebKit::WebPageProxy::startDrag): Transfer the received DataObjectGtk to page client, instead of using
+        DragData. Also notify the web process that drag started.
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in: Update StartDrag message parameters.
+        * UIProcess/gtk/DragAndDropHandler.cpp:
+        (WebKit::DragAndDropHandler::DragAndDropHandler): Remove unneeded initialization.
+        (WebKit::DragAndDropHandler::startDrag): Take ownership of the given DataObjectGtk.
+        * UIProcess/gtk/DragAndDropHandler.h:
+        * UIProcess/gtk/WebPasteboardProxyGtk.cpp:
+        (WebKit::WebPasteboardProxy::writeToClipboard):
+        (WebKit::WebPasteboardProxy::readFromClipboard):
+        * WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
+        (WebKit::WebPlatformStrategies::writeToClipboard):
+        (WebKit::WebPlatformStrategies::readFromClipboard):
+        * WebProcess/WebCoreSupport/WebPlatformStrategies.h:
+        * WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp:
+        (WebKit::convertCairoSurfaceToShareableBitmap):
+        (WebKit::WebDragClient::startDrag): Do not create a DragData and pass the DataObjectGtk directly to the
+        message. Also notify the WebPage that drag is about to start.
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::performDragControllerAction): Remove explicit DataObjectGtk derefs and simply create a
+        DragData using the DataObjectGtk pointer as platform data.
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in: Update PerformDragControllerAction message parameters.
+
 2016-09-20  Hunseop Jeong  <hs85.jeong@samsung.com>
 
         [EFL] ewk_context_menu_item_select test have been failed
index c6d2358..e686bb3 100644 (file)
 #include "ShareableBitmap.h"
 #include "WebCoreArgumentCoders.h"
 #include <WebCore/DataObjectGtk.h>
-#include <WebCore/DragData.h>
 #include <WebCore/GraphicsContext.h>
-#include <WebCore/GtkVersioning.h>
-#include <WebCore/PlatformContextCairo.h>
+#include <WebCore/Image.h>
+#include <gtk/gtk.h>
 #include <wtf/glib/GUniquePtr.h>
 
 using namespace WebCore;
@@ -41,15 +40,10 @@ using namespace WebKit;
 
 namespace IPC {
 
-static void encodeImage(Encoder& encoder, const GdkPixbuf* pixbuf)
+static void encodeImage(Encoder& encoder, Image& image)
 {
-    IntSize imageSize(gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf));
-    RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(imageSize, ShareableBitmap::SupportsAlpha);
-    auto graphicsContext = bitmap->createGraphicsContext();
-
-    cairo_t* cr = graphicsContext->platformContext()->cr();
-    gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
-    cairo_paint(cr);
+    RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(IntSize(image.size()), ShareableBitmap::SupportsAlpha);
+    bitmap->createGraphicsContext()->drawImage(image, IntPoint());
 
     ShareableBitmap::Handle handle;
     bitmap->createHandle(handle);
@@ -57,7 +51,7 @@ static void encodeImage(Encoder& encoder, const GdkPixbuf* pixbuf)
     encoder << handle;
 }
 
-static bool decodeImage(Decoder& decoder, GRefPtr<GdkPixbuf>& pixbuf)
+static bool decodeImage(Decoder& decoder, RefPtr<Image>& image)
 {
     ShareableBitmap::Handle handle;
     if (!decoder.decode(handle))
@@ -66,61 +60,51 @@ static bool decodeImage(Decoder& decoder, GRefPtr<GdkPixbuf>& pixbuf)
     RefPtr<ShareableBitmap> bitmap = ShareableBitmap::create(handle);
     if (!bitmap)
         return false;
-
-    RefPtr<Image> image = bitmap->createImage();
+    image = bitmap->createImage();
     if (!image)
         return false;
-
-    RefPtr<cairo_surface_t> surface = image->nativeImageForCurrentFrame();
-    if (!surface)
-        return false;
-
-    pixbuf = adoptGRef(gdk_pixbuf_get_from_surface(surface.get(), 0, 0, cairo_image_surface_get_width(surface.get()), cairo_image_surface_get_height(surface.get())));
-    if (!pixbuf)
-        return false;
-
     return true;
 }
 
-void encode(Encoder& encoder, const DataObjectGtk* dataObject)
+void ArgumentCoder<DataObjectGtk>::encode(Encoder& encoder, const DataObjectGtk& dataObject)
 {
-    bool hasText = dataObject->hasText();
+    bool hasText = dataObject.hasText();
     encoder << hasText;
     if (hasText)
-        encoder << dataObject->text();
+        encoder << dataObject.text();
 
-    bool hasMarkup = dataObject->hasMarkup();
+    bool hasMarkup = dataObject.hasMarkup();
     encoder << hasMarkup;
     if (hasMarkup)
-        encoder << dataObject->markup();
+        encoder << dataObject.markup();
 
-    bool hasURL = dataObject->hasURL();
+    bool hasURL = dataObject.hasURL();
     encoder << hasURL;
     if (hasURL)
-        encoder << dataObject->url().string();
+        encoder << dataObject.url().string();
 
-    bool hasURIList = dataObject->hasURIList();
+    bool hasURIList = dataObject.hasURIList();
     encoder << hasURIList;
     if (hasURIList)
-        encoder << dataObject->uriList();
+        encoder << dataObject.uriList();
 
-    bool hasImage = dataObject->hasImage();
+    bool hasImage = dataObject.hasImage();
     encoder << hasImage;
     if (hasImage)
-        encodeImage(encoder, dataObject->image());
+        encodeImage(encoder, *dataObject.image());
 
-    bool hasUnknownTypeData = dataObject->hasUnknownTypeData();
+    bool hasUnknownTypeData = dataObject.hasUnknownTypeData();
     encoder << hasUnknownTypeData;
     if (hasUnknownTypeData)
-        encoder << dataObject->unknownTypes();
+        encoder << dataObject.unknownTypes();
 
-    bool canSmartReplace = dataObject->canSmartReplace();
+    bool canSmartReplace = dataObject.canSmartReplace();
     encoder << canSmartReplace;
 }
 
-bool decode(Decoder& decoder, RefPtr<DataObjectGtk>& dataObject)
+bool ArgumentCoder<DataObjectGtk>::decode(Decoder& decoder, DataObjectGtk& dataObject)
 {
-    RefPtr<DataObjectGtk> data = DataObjectGtk::create();
+    dataObject.clearAll();
 
     bool hasText;
     if (!decoder.decode(hasText))
@@ -129,7 +113,7 @@ bool decode(Decoder& decoder, RefPtr<DataObjectGtk>& dataObject)
         String text;
         if (!decoder.decode(text))
             return false;
-        data->setText(text);
+        dataObject.setText(text);
     }
 
     bool hasMarkup;
@@ -139,7 +123,7 @@ bool decode(Decoder& decoder, RefPtr<DataObjectGtk>& dataObject)
         String markup;
         if (!decoder.decode(markup))
             return false;
-        data->setMarkup(markup);
+        dataObject.setMarkup(markup);
     }
 
     bool hasURL;
@@ -149,7 +133,7 @@ bool decode(Decoder& decoder, RefPtr<DataObjectGtk>& dataObject)
         String url;
         if (!decoder.decode(url))
             return false;
-        data->setURL(URL(URL(), url), String());
+        dataObject.setURL(URL(URL(), url), String());
     }
 
     bool hasURIList;
@@ -159,17 +143,17 @@ bool decode(Decoder& decoder, RefPtr<DataObjectGtk>& dataObject)
         String uriList;
         if (!decoder.decode(uriList))
             return false;
-        data->setURIList(uriList);
+        dataObject.setURIList(uriList);
     }
 
     bool hasImage;
     if (!decoder.decode(hasImage))
         return false;
     if (hasImage) {
-        GRefPtr<GdkPixbuf> image;
+        RefPtr<Image> image;
         if (!decodeImage(decoder, image))
             return false;
-        data->setImage(image.get());
+        dataObject.setImage(image.get());
     }
 
     bool hasUnknownTypeData;
@@ -182,67 +166,16 @@ bool decode(Decoder& decoder, RefPtr<DataObjectGtk>& dataObject)
 
         auto end = unknownTypes.end();
         for (auto it = unknownTypes.begin(); it != end; ++it)
-            data->setUnknownTypeData(it->key, it->value);
+            dataObject.setUnknownTypeData(it->key, it->value);
     }
 
     bool canSmartReplace;
     if (!decoder.decode(canSmartReplace))
         return false;
-    data->setCanSmartReplace(canSmartReplace);
-
-    dataObject = data;
-
-    return true;
-}
-
-#if ENABLE(DRAG_SUPPORT)
-void ArgumentCoder<DragData>::encode(Encoder& encoder, const DragData& dragData)
-{
-    encoder << dragData.clientPosition();
-    encoder << dragData.globalPosition();
-    encoder << static_cast<uint64_t>(dragData.draggingSourceOperationMask());
-    encoder << static_cast<uint64_t>(dragData.flags());
-
-    DataObjectGtk* platformData = dragData.platformData();
-    encoder << static_cast<bool>(platformData);
-    if (platformData)
-        IPC::encode(encoder, platformData);
-}
-
-bool ArgumentCoder<DragData>::decode(Decoder& decoder, DragData& dragData)
-{
-    IntPoint clientPosition;
-    if (!decoder.decode(clientPosition))
-        return false;
-
-    IntPoint globalPosition;
-    if (!decoder.decode(globalPosition))
-        return false;
-
-    uint64_t sourceOperationMask;
-    if (!decoder.decode(sourceOperationMask))
-        return false;
-
-    uint64_t flags;
-    if (!decoder.decode(flags))
-        return false;
-
-    bool hasPlatformData;
-    if (!decoder.decode(hasPlatformData))
-        return false;
-
-    RefPtr<DataObjectGtk> platformData;
-    if (hasPlatformData) {
-        if (!IPC::decode(decoder, platformData))
-            return false;
-    }
-
-    dragData = DragData(platformData.leakRef(), clientPosition, globalPosition, static_cast<DragOperation>(sourceOperationMask),
-                        static_cast<DragApplicationFlags>(flags));
+    dataObject.setCanSmartReplace(canSmartReplace);
 
     return true;
 }
-#endif // ENABLE(DRAG_SUPPORT)
 
 static void encodeGKeyFile(Encoder& encoder, GKeyFile* keyFile)
 {
index 169c669..8ea94ac 100644 (file)
@@ -34,26 +34,20 @@ typedef struct _GtkPageSetup GtkPageSetup;
 
 namespace WebCore {
 class DataObjectGtk;
-class DragData;
 }
 
 namespace IPC {
 
-#if ENABLE(DRAG_SUPPORT)
-template<> struct ArgumentCoder<WebCore::DragData> {
-    static void encode(Encoder&, const WebCore::DragData&);
-    static bool decode(Decoder&, WebCore::DragData&);
-};
-#endif
-
 void encode(Encoder&, GtkPrintSettings*);
 bool decode(Decoder&, GRefPtr<GtkPrintSettings>&);
 
 void encode(Encoder&, GtkPageSetup*);
 bool decode(Decoder&, GRefPtr<GtkPageSetup>&);
 
-void encode(Encoder&, const WebCore::DataObjectGtk*);
-bool decode(Decoder&, RefPtr<WebCore::DataObjectGtk>&);
+template<> struct ArgumentCoder<WebCore::DataObjectGtk> {
+    static void encode(Encoder&, const WebCore::DataObjectGtk&);
+    static bool decode(Decoder&, WebCore::DataObjectGtk&);
+};
 
 } // namespace IPC
 
index b89ee56..3105c24 100644 (file)
 
 namespace WebKit {
 
-PasteboardContent::PasteboardContent(const RefPtr<WebCore::DataObjectGtk>& data)
-    : dataObject(data)
+PasteboardContent::PasteboardContent()
+    : dataObject(WebCore::DataObjectGtk::create())
+{
+}
+
+PasteboardContent::PasteboardContent(const WebCore::DataObjectGtk& data)
+    : dataObject(const_cast<WebCore::DataObjectGtk&>(data))
+{
+}
+
+PasteboardContent::PasteboardContent(Ref<WebCore::DataObjectGtk>&& data)
+    : dataObject(WTFMove(data))
 {
-    ASSERT(dataObject);
 }
 
 void PasteboardContent::encode(IPC::Encoder& encoder) const
 {
-    IPC::encode(encoder, dataObject.get());
+    encoder << dataObject.get();
 }
 
 bool PasteboardContent::decode(IPC::Decoder& decoder, PasteboardContent& pasteboardContent)
 {
-    return IPC::decode(decoder, pasteboardContent.dataObject);
+    return decoder.decode(pasteboardContent.dataObject.get());
 }
 
 } // namespace WebKit
index 098d17f..98d9255 100644 (file)
@@ -29,10 +29,11 @@ class Encoder;
 namespace WebKit {
 
 struct PasteboardContent {
-    PasteboardContent() = default;
-    explicit PasteboardContent(const RefPtr<WebCore::DataObjectGtk>&);
+    PasteboardContent();
+    explicit PasteboardContent(const WebCore::DataObjectGtk&);
+    explicit PasteboardContent(Ref<WebCore::DataObjectGtk>&&);
 
-    RefPtr<WebCore::DataObjectGtk> dataObject;
+    Ref<WebCore::DataObjectGtk> dataObject;
 
     void encode(IPC::Encoder&) const;
     static bool decode(IPC::Decoder&, PasteboardContent&);
index 8d258f6..b649db8 100644 (file)
@@ -254,10 +254,10 @@ void PageClientImpl::didChangeContentSize(const IntSize& size)
 }
 
 #if ENABLE(DRAG_SUPPORT)
-void PageClientImpl::startDrag(const WebCore::DragData& dragData, PassRefPtr<ShareableBitmap> dragImage)
+void PageClientImpl::startDrag(Ref<DataObjectGtk>&& selection, DragOperation dragOperation, RefPtr<ShareableBitmap>&& dragImage)
 {
     WebKitWebViewBase* webView = WEBKIT_WEB_VIEW_BASE(m_viewWidget);
-    webkitWebViewBaseDragAndDropHandler(webView).startDrag(dragData, dragImage);
+    webkitWebViewBaseDragAndDropHandler(webView).startDrag(WTFMove(selection), dragOperation, WTFMove(dragImage));
 
     // A drag starting should prevent a double-click from happening. This might
     // happen if a drag is followed very quickly by another click (like in the WTR).
index fe84fb2..cc1809f 100644 (file)
@@ -86,7 +86,7 @@ private:
 #endif
     void selectionDidChange() override;
 #if ENABLE(DRAG_SUPPORT)
-    void startDrag(const WebCore::DragData&, PassRefPtr<ShareableBitmap> dragImage) override;
+    void startDrag(Ref<WebCore::DataObjectGtk>&&, WebCore::DragOperation, RefPtr<ShareableBitmap>&& dragImage) override;
 #endif
 
     void enterAcceleratedCompositingMode(const LayerTreeContext&) override;
index 1b24db2..b176636 100644 (file)
@@ -157,7 +157,7 @@ public:
     virtual void didChangeContentSize(const WebCore::IntSize&) = 0;
 
 #if PLATFORM(GTK) && ENABLE(DRAG_SUPPORT)
-    virtual void startDrag(const WebCore::DragData&, PassRefPtr<ShareableBitmap> dragImage) = 0;
+    virtual void startDrag(Ref<WebCore::DataObjectGtk>&&, WebCore::DragOperation, RefPtr<ShareableBitmap>&& dragImage) = 0;
 #endif
 
     virtual void setCursor(const WebCore::Cursor&) = 0;
index 9da20cc..9a6ce45 100644 (file)
 #include <WebCore/TextIndicatorWindow.h>
 #endif
 
+#if PLATFORM(GTK)
+#include "PasteboardContent.h"
+#endif
+
 #if USE(CAIRO)
 #include <WebCore/CairoUtilities.h>
 #endif
@@ -1768,7 +1772,10 @@ void WebPageProxy::performDragControllerAction(DragControllerAction action, Drag
     String url = dragData.asURL();
     if (!url.isEmpty())
         m_process->assumeReadAccessToBaseURL(url);
-    m_process->send(Messages::WebPage::PerformDragControllerAction(action, dragData), m_pageID);
+
+    ASSERT(dragData.platformData());
+    PasteboardContent selection(*dragData.platformData());
+    m_process->send(Messages::WebPage::PerformDragControllerAction(action, dragData.clientPosition(), dragData.globalPosition(), dragData.draggingSourceOperationMask(), selection, dragData.flags()), m_pageID);
 #else
     m_process->send(Messages::WebPage::PerformDragControllerAction(action, dragData.clientPosition(), dragData.globalPosition(), dragData.draggingSourceOperationMask(), dragStorageName, dragData.flags(), sandboxExtensionHandle, sandboxExtensionsForUpload), m_pageID);
 #endif
@@ -1784,16 +1791,12 @@ void WebPageProxy::didPerformDragControllerAction(uint64_t dragOperation, bool m
 }
 
 #if PLATFORM(GTK)
-void WebPageProxy::startDrag(const DragData& dragData, const ShareableBitmap::Handle& dragImageHandle)
+void WebPageProxy::startDrag(PasteboardContent&& selection, uint64_t dragOperation, const ShareableBitmap::Handle& dragImageHandle)
 {
-    RefPtr<ShareableBitmap> dragImage = 0;
-    if (!dragImageHandle.isNull()) {
-        dragImage = ShareableBitmap::create(dragImageHandle);
-        if (!dragImage)
-            return;
-    }
+    RefPtr<ShareableBitmap> dragImage = !dragImageHandle.isNull() ? ShareableBitmap::create(dragImageHandle) : nullptr;
+    m_pageClient.startDrag(WTFMove(selection.dataObject), static_cast<WebCore::DragOperation>(dragOperation), WTFMove(dragImage));
 
-    m_pageClient.startDrag(dragData, dragImage.release());
+    m_process->send(Messages::WebPage::DidStartDrag(), m_pageID);
 }
 #endif
 
index 8612f7c..9a80cd4 100644 (file)
@@ -809,7 +809,7 @@ public:
 #endif
 #endif
 #if PLATFORM(GTK)
-    void startDrag(const WebCore::DragData&, const ShareableBitmap::Handle& dragImage);
+    void startDrag(PasteboardContent&&, uint64_t dragOperation, const ShareableBitmap::Handle& dragImage);
 #endif
 #endif
 
index 944b6f1..ae79a8d 100644 (file)
@@ -308,7 +308,7 @@ messages -> WebPageProxy {
 #endif
 #endif
 #if PLATFORM(GTK) && ENABLE(DRAG_SUPPORT)
-    StartDrag(WebCore::DragData dragData, WebKit::ShareableBitmap::Handle dragImage)
+    StartDrag(struct WebKit::PasteboardContent selection, uint64_t dragOperation, WebKit::ShareableBitmap::Handle dragImage)
 #endif
 
 #if PLATFORM(COCOA)
index 16dba7f..6f29ef8 100644 (file)
@@ -44,9 +44,6 @@ namespace WebKit {
 
 DragAndDropHandler::DragAndDropHandler(WebPageProxy& page)
     : m_page(page)
-#if GTK_CHECK_VERSION(3, 16, 0)
-    , m_dragContext(nullptr)
-#endif
 {
 }
 
@@ -111,18 +108,18 @@ static inline DragOperation gdkDragActionToDragOperation(GdkDragAction gdkAction
     return static_cast<DragOperation>(action);
 }
 
-void DragAndDropHandler::startDrag(const DragData& dragData, PassRefPtr<ShareableBitmap> dragImage)
+void DragAndDropHandler::startDrag(Ref<DataObjectGtk>&& selection, DragOperation dragOperation, RefPtr<ShareableBitmap>&& dragImage)
 {
 #if GTK_CHECK_VERSION(3, 16, 0)
-    m_draggingDataObject = adoptRef(dragData.platformData());
+    m_draggingDataObject = WTFMove(selection);
     GRefPtr<GtkTargetList> targetList = PasteboardHelper::singleton().targetListForDataObject(*m_draggingDataObject);
 #else
-    RefPtr<DataObjectGtk> dataObject = adoptRef(dragData.platformData());
+    RefPtr<DataObjectGtk> dataObject = WTFMove(selection);
     GRefPtr<GtkTargetList> targetList = PasteboardHelper::singleton().targetListForDataObject(*dataObject);
 #endif
 
     GUniquePtr<GdkEvent> currentEvent(gtk_get_current_event());
-    GdkDragContext* context = gtk_drag_begin(m_page.viewWidget(), targetList.get(), dragOperationToGdkDragActions(dragData.draggingSourceOperationMask()),
+    GdkDragContext* context = gtk_drag_begin(m_page.viewWidget(), targetList.get(), dragOperationToGdkDragActions(dragOperation),
         GDK_BUTTON_PRIMARY, currentEvent.get());
 
 #if GTK_CHECK_VERSION(3, 16, 0)
@@ -135,7 +132,7 @@ void DragAndDropHandler::startDrag(const DragData& dragData, PassRefPtr<Shareabl
 #else
     // We don't have gtk_drag_cancel() in GTK+ < 3.16, so we use the old code.
     // See https://bugs.webkit.org/show_bug.cgi?id=138468
-    m_draggingDataObjects.set(context, dataObject.get());
+    m_draggingDataObjects.set(context, WTFMove(dataObject));
 #endif
 
     if (dragImage) {
index 5020b9c..672d1c4 100644 (file)
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef DragAndDropHandler_h
-#define DragAndDropHandler_h
+#pragma once
 
 #if ENABLE(DRAG_SUPPORT)
 
 #include <WebCore/DataObjectGtk.h>
+#include <WebCore/DragActions.h>
 #include <WebCore/IntPoint.h>
 #include <gtk/gtk.h>
 #include <wtf/HashMap.h>
 #include <wtf/Noncopyable.h>
+#include <wtf/glib/GRefPtr.h>
 
 typedef struct _GdkDragContext GdkDragContext;
 typedef struct _GtkSelectionData GtkSelectionData;
@@ -51,7 +52,7 @@ class DragAndDropHandler {
 public:
     DragAndDropHandler(WebPageProxy&);
 
-    void startDrag(const WebCore::DragData&, PassRefPtr<ShareableBitmap> dragImage);
+    void startDrag(Ref<WebCore::DataObjectGtk>&&, WebCore::DragOperation, RefPtr<ShareableBitmap>&& dragImage);
     void fillDragData(GdkDragContext*, GtkSelectionData*, unsigned info);
     void finishDrag(GdkDragContext*);
 
@@ -90,5 +91,3 @@ private:
 } // namespace WebKit
 
 #endif // ENABLE(DRAG_SUPPORT)
-
-#endif // DragAndDropHandler_h
index 15f90d3..e25a4a0 100644 (file)
@@ -41,7 +41,7 @@ namespace WebKit {
 void WebPasteboardProxy::writeToClipboard(const String& pasteboardName, const PasteboardContent& pasteboardContent)
 {
     TemporaryChange<WebFrameProxy*> frameWritingToClipboard(m_frameWritingToClipboard, m_primarySelectionOwner);
-    PlatformPasteboard(pasteboardName).writeToClipboard(pasteboardContent.dataObject, [this] {
+    PlatformPasteboard(pasteboardName).writeToClipboard(pasteboardContent.dataObject.get(), [this] {
         if (m_frameWritingToClipboard == m_primarySelectionOwner)
             return;
         setPrimarySelectionOwner(nullptr);
@@ -50,7 +50,7 @@ void WebPasteboardProxy::writeToClipboard(const String& pasteboardName, const Pa
 
 void WebPasteboardProxy::readFromClipboard(const String& pasteboardName, PasteboardContent& pasteboardContent)
 {
-    pasteboardContent = PasteboardContent(PlatformPasteboard(pasteboardName).readFromClipboard().get());
+    pasteboardContent = PasteboardContent(PlatformPasteboard(pasteboardName).readFromClipboard());
 }
 
 void WebPasteboardProxy::setPrimarySelectionOwner(WebFrameProxy* frame)
index 9280a96..e04dcd5 100644 (file)
@@ -346,17 +346,17 @@ long WebPlatformStrategies::changeCount()
 #if PLATFORM(GTK)
 // PasteboardStrategy
 
-void WebPlatformStrategies::writeToClipboard(const String& pasteboardName, const RefPtr<WebCore::DataObjectGtk>& dataObject)
+void WebPlatformStrategies::writeToClipboard(const String& pasteboardName, const DataObjectGtk& dataObject)
 {
-    PasteboardContent pasteboardContent = PasteboardContent(dataObject.get());
+    PasteboardContent pasteboardContent(dataObject);
     WebProcess::singleton().parentProcessConnection()->send(Messages::WebPasteboardProxy::WriteToClipboard(pasteboardName, pasteboardContent), 0);
 }
 
-RefPtr<WebCore::DataObjectGtk> WebPlatformStrategies::readFromClipboard(const String& pasteboardName)
+Ref<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;
+    return WTFMove(pasteboardContent.dataObject);
 }
 
 #endif // PLATFORM(GTK)
index f3e5d81..167c66d 100644 (file)
@@ -87,8 +87,8 @@ private:
     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;
+    void writeToClipboard(const String& pasteboardName, const WebCore::DataObjectGtk&) override;
+    Ref<WebCore::DataObjectGtk> readFromClipboard(const String& pasteboardName) override;
 #endif
 };
 
index 5dab0a2..20d1952 100644 (file)
@@ -29,6 +29,7 @@
 #if ENABLE(DRAG_SUPPORT)
 
 #include "ArgumentCodersGtk.h"
+#include "PasteboardContent.h"
 #include "ShareableBitmap.h"
 #include "WebPage.h"
 #include "WebPageProxyMessages.h"
@@ -43,17 +44,17 @@ using namespace WebCore;
 
 namespace WebKit {
 
-static PassRefPtr<ShareableBitmap> convertCairoSurfaceToShareableBitmap(cairo_surface_t* surface)
+static RefPtr<ShareableBitmap> convertCairoSurfaceToShareableBitmap(cairo_surface_t* surface)
 {
     if (!surface)
-        return 0;
+        return nullptr;
 
     IntSize imageSize(cairo_image_surface_get_width(surface), cairo_image_surface_get_height(surface));
     RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(imageSize, ShareableBitmap::SupportsAlpha);
     auto graphicsContext = bitmap->createGraphicsContext();
 
     graphicsContext->platformContext()->drawSurfaceToContext(surface, IntRect(IntPoint(), imageSize), IntRect(IntPoint(), imageSize), *graphicsContext);
-    return bitmap.release();
+    return bitmap;
 }
 
 void WebDragClient::startDrag(DragImageRef dragImage, const IntPoint& clientPosition, const IntPoint& globalPosition, DataTransfer& dataTransfer, Frame&, bool)
@@ -65,9 +66,10 @@ void WebDragClient::startDrag(DragImageRef dragImage, const IntPoint& clientPosi
     if (bitmap && !bitmap->createHandle(handle))
         return;
 
-    const auto& dataObject = dataTransfer.pasteboard().dataObject();
-    DragData dragData(const_cast<DataObjectGtk*>(&dataObject), clientPosition, globalPosition, dataTransfer.sourceOperation());
-    m_page->send(Messages::WebPageProxy::StartDrag(dragData, handle));
+    m_page->willStartDrag();
+
+    PasteboardContent selection(dataTransfer.pasteboard().dataObject());
+    m_page->send(Messages::WebPageProxy::StartDrag(selection, dataTransfer.sourceOperation(), handle));
 }
 
 }; // namespace WebKit.
index ecb996e..b0b22d7 100644 (file)
 #endif
 
 #if PLATFORM(GTK)
-#include <gtk/gtk.h>
-#include "DataObjectGtk.h"
+#include "PasteboardContent.h"
 #include "WebPrintOperationGtk.h"
+#include <WebCore/DataObjectGtk.h>
+#include <gtk/gtk.h>
 #endif
 
 #if PLATFORM(IOS)
@@ -3396,15 +3397,14 @@ bool WebPage::handleEditingKeyboardEvent(KeyboardEvent* evt)
 #if ENABLE(DRAG_SUPPORT)
 
 #if PLATFORM(GTK)
-void WebPage::performDragControllerAction(uint64_t action, WebCore::DragData dragData)
+void WebPage::performDragControllerAction(uint64_t action, const IntPoint& clientPosition, const IntPoint& globalPosition, uint64_t draggingSourceOperationMask, PasteboardContent&& selection, uint32_t flags)
 {
     if (!m_page) {
         send(Messages::WebPageProxy::DidPerformDragControllerAction(DragOperationNone, false, 0));
-        DataObjectGtk* data = const_cast<DataObjectGtk*>(dragData.platformData());
-        data->deref();
         return;
     }
 
+    DragData dragData(selection.dataObject.ptr(), clientPosition, globalPosition, static_cast<DragOperation>(draggingSourceOperationMask), static_cast<DragApplicationFlags>(flags));
     switch (action) {
     case DragControllerActionEntered: {
         DragOperation resolvedDragOperation = m_page->dragController().dragEntered(dragData);
@@ -3428,11 +3428,7 @@ void WebPage::performDragControllerAction(uint64_t action, WebCore::DragData dra
     default:
         ASSERT_NOT_REACHED();
     }
-    // DragData does not delete its platformData so we need to do that here.
-    DataObjectGtk* data = const_cast<DataObjectGtk*>(dragData.platformData());
-    data->deref();
 }
-
 #else
 void WebPage::performDragControllerAction(uint64_t action, WebCore::IntPoint clientPosition, WebCore::IntPoint globalPosition, uint64_t draggingSourceOperationMask, const String& dragStorageName, uint32_t flags, const SandboxExtension::Handle& sandboxExtensionHandle, const SandboxExtension::HandleArray& sandboxExtensionsHandleArray)
 {
index a4651ac..afd3363 100644 (file)
@@ -204,6 +204,10 @@ struct WebPreferencesStore;
 class RemoteLayerTreeTransaction;
 #endif
 
+#if PLATFORM(GTK)
+struct PasteboardContent;
+#endif
+
 #if ENABLE(TOUCH_EVENTS)
 class WebTouchEvent;
 #endif
@@ -729,7 +733,7 @@ public:
 
 #if ENABLE(DRAG_SUPPORT)
 #if PLATFORM(GTK)
-    void performDragControllerAction(uint64_t action, WebCore::DragData);
+    void performDragControllerAction(uint64_t action, const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition, uint64_t draggingSourceOperationMask, PasteboardContent&&, uint32_t flags);
 #else
     void performDragControllerAction(uint64_t action, WebCore::IntPoint clientPosition, WebCore::IntPoint globalPosition, uint64_t draggingSourceOperationMask, const WTF::String& dragStorageName, uint32_t flags, const SandboxExtension::Handle&, const SandboxExtension::HandleArray&);
 #endif
index 0d22887..51167ae 100644 (file)
@@ -236,7 +236,7 @@ messages -> WebPage LegacyReceiver {
 
     # Drag and drop.
 #if PLATFORM(GTK) && ENABLE(DRAG_SUPPORT)
-    PerformDragControllerAction(uint64_t action, WebCore::DragData dragData)
+    PerformDragControllerAction(uint64_t action, WebCore::IntPoint clientPosition, WebCore::IntPoint globalPosition, uint64_t draggingSourceOperationMask, struct WebKit::PasteboardContent selection, uint32_t flags)
 #endif
 #if !PLATFORM(GTK) && ENABLE(DRAG_SUPPORT)
     PerformDragControllerAction(uint64_t action, WebCore::IntPoint clientPosition, WebCore::IntPoint globalPosition, uint64_t draggingSourceOperationMask, String dragStorageName, uint32_t flags, WebKit::SandboxExtension::Handle sandboxExtensionHandle, WebKit::SandboxExtension::HandleArray sandboxExtensionsForUpload)