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

Log Message

Merge r205860 - [GTK] Get rid of DataObjectGtk::forClipboard and cleanup pasteboard code
https://bugs.webkit.org/show_bug.cgi?id=161907

Reviewed by Michael Catanzaro.

Source/WebCore:

We don't really need to keep a DataObjectGtk for every clipboard, we could simply pass the DataObjectGtk to read
and write methods of PasteboardHelper.

* editing/gtk/EditorGtk.cpp:
(WebCore::createFragmentFromPasteboardData): Update for DataObjectGtk API changes.
* platform/Pasteboard.h:
* platform/gtk/DataObjectGtk.cpp: Remove forClipboard() static method.
* platform/gtk/DataObjectGtk.h: Ditto.
* platform/gtk/PasteboardGtk.cpp:
(WebCore::Pasteboard::Pasteboard): Always create a new DataObjectGtk.
(WebCore::Pasteboard::dataObject): Return a const reference instead of a pointer.
(WebCore::Pasteboard::writePlainText): Pass the DataObjectGtk to PasteboardHelper.
(WebCore::Pasteboard::write): Ditto.
(WebCore::Pasteboard::writePasteboard): Ditto.
(WebCore::Pasteboard::clear): Ditto.
(WebCore::Pasteboard::read): Ditto.
(WebCore::Pasteboard::hasData): Ditto.
(WebCore::Pasteboard::types): Ditto.
(WebCore::Pasteboard::readString): Ditto.
(WebCore::Pasteboard::readFilenames): Ditto.
* platform/gtk/PasteboardHelper.cpp:
(WebCore::PasteboardHelper::getClipboardContents): Update the given DataObjectGtk.
(WebCore::PasteboardHelper::fillSelectionData): Use a const reference to DataObjectGtk instead of a pointer.
(WebCore::PasteboardHelper::targetListForDataObject): Ditto.
(WebCore::PasteboardHelper::fillDataObjectFromDropData): Use a reference to DataObjectGtk instead of a pointer.
(WebCore::ClipboardSetData::ClipboardSetData): Helper struct to pass DataObjectGtk and callback to clipboard callbacks.
(WebCore::ClipboardSetData::~ClipboardSetData):
(WebCore::getClipboardContentsCallback): Get the DataObjectGtk from ClipboardSetData struct passed as user data.
(WebCore::clearClipboardContentsCallback): Get the DataObjectGtk and callback from ClipboardSetData struct
passed as user data.
(WebCore::PasteboardHelper::writeClipboardContents): Write the given DataObjectGtk.
* platform/gtk/PasteboardHelper.h:

Source/WebKit2:

Update to DataObjectGtk and PasteboardHelper API changes.

* UIProcess/gtk/DragAndDropHandler.cpp:
(WebKit::DragAndDropHandler::startDrag):
(WebKit::DragAndDropHandler::fillDragData):
(WebKit::DragAndDropHandler::dataObjectForDropData):
* WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp:
(WebKit::WebDragClient::startDrag):
* WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:
(WebKit::collapseSelection):
(WebKit::WebEditorClient::updateGlobalSelection): Remove wrong X11 guards, since that code is not X11 specific.

Modified Paths

Diff

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


--- releases/WebKitGTK/webkit-2.14/Source/WebCore/ChangeLog	2016-09-15 08:00:45 UTC (rev 205957)
+++ releases/WebKitGTK/webkit-2.14/Source/WebCore/ChangeLog	2016-09-15 08:02:20 UTC (rev 205958)
@@ -1,3 +1,43 @@
+2016-09-13  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] Get rid of DataObjectGtk::forClipboard and cleanup pasteboard code
+        https://bugs.webkit.org/show_bug.cgi?id=161907
+
+        Reviewed by Michael Catanzaro.
+
+        We don't really need to keep a DataObjectGtk for every clipboard, we could simply pass the DataObjectGtk to read
+        and write methods of PasteboardHelper.
+
+        * editing/gtk/EditorGtk.cpp:
+        (WebCore::createFragmentFromPasteboardData): Update for DataObjectGtk API changes.
+        * platform/Pasteboard.h:
+        * platform/gtk/DataObjectGtk.cpp: Remove forClipboard() static method.
+        * platform/gtk/DataObjectGtk.h: Ditto.
+        * platform/gtk/PasteboardGtk.cpp:
+        (WebCore::Pasteboard::Pasteboard): Always create a new DataObjectGtk.
+        (WebCore::Pasteboard::dataObject): Return a const reference instead of a pointer.
+        (WebCore::Pasteboard::writePlainText): Pass the DataObjectGtk to PasteboardHelper.
+        (WebCore::Pasteboard::write): Ditto.
+        (WebCore::Pasteboard::writePasteboard): Ditto.
+        (WebCore::Pasteboard::clear): Ditto.
+        (WebCore::Pasteboard::read): Ditto.
+        (WebCore::Pasteboard::hasData): Ditto.
+        (WebCore::Pasteboard::types): Ditto.
+        (WebCore::Pasteboard::readString): Ditto.
+        (WebCore::Pasteboard::readFilenames): Ditto.
+        * platform/gtk/PasteboardHelper.cpp:
+        (WebCore::PasteboardHelper::getClipboardContents): Update the given DataObjectGtk.
+        (WebCore::PasteboardHelper::fillSelectionData): Use a const reference to DataObjectGtk instead of a pointer.
+        (WebCore::PasteboardHelper::targetListForDataObject): Ditto.
+        (WebCore::PasteboardHelper::fillDataObjectFromDropData): Use a reference to DataObjectGtk instead of a pointer.
+        (WebCore::ClipboardSetData::ClipboardSetData): Helper struct to pass DataObjectGtk and callback to clipboard callbacks.
+        (WebCore::ClipboardSetData::~ClipboardSetData):
+        (WebCore::getClipboardContentsCallback): Get the DataObjectGtk from ClipboardSetData struct passed as user data.
+        (WebCore::clearClipboardContentsCallback): Get the DataObjectGtk and callback from ClipboardSetData struct
+        passed as user data.
+        (WebCore::PasteboardHelper::writeClipboardContents): Write the given DataObjectGtk.
+        * platform/gtk/PasteboardHelper.h:
+
 2016-09-12  Carlos Garcia Campos  <cgar...@igalia.com>
 
         [GTK] Scrollbar  too large

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


--- releases/WebKitGTK/webkit-2.14/Source/WebCore/editing/gtk/EditorGtk.cpp	2016-09-15 08:00:45 UTC (rev 205957)
+++ releases/WebKitGTK/webkit-2.14/Source/WebCore/editing/gtk/EditorGtk.cpp	2016-09-15 08:02:20 UTC (rev 205958)
@@ -53,16 +53,16 @@
     if (!pasteboard.hasData())
         return nullptr;
 
-    DataObjectGtk* dataObject = pasteboard.dataObject();
-    if (dataObject->hasMarkup() && frame.document())
-        return createFragmentFromMarkup(*frame.document(), dataObject->markup(), emptyString(), DisallowScriptingAndPluginContent);
+    const auto& dataObject = pasteboard.dataObject();
+    if (dataObject.hasMarkup() && frame.document())
+        return createFragmentFromMarkup(*frame.document(), dataObject.markup(), emptyString(), DisallowScriptingAndPluginContent);
 
     if (!allowPlainText)
         return nullptr;
 
-    if (dataObject->hasText()) {
+    if (dataObject.hasText()) {
         chosePlainText = true;
-        return createFragmentFromText(range, dataObject->text());
+        return createFragmentFromText(range, dataObject.text());
     }
 
     return nullptr;

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


--- releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/Pasteboard.h	2016-09-15 08:00:45 UTC (rev 205957)
+++ releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/Pasteboard.h	2016-09-15 08:02:20 UTC (rev 205958)
@@ -193,7 +193,7 @@
 #endif
 
 #if PLATFORM(GTK)
-    DataObjectGtk* dataObject() const;
+    const DataObjectGtk& dataObject() const;
     static std::unique_ptr<Pasteboard> createForGlobalSelection();
 #endif
 

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


--- releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/DataObjectGtk.cpp	2016-09-15 08:00:45 UTC (rev 205957)
+++ releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/DataObjectGtk.cpp	2016-09-15 08:02:20 UTC (rev 205958)
@@ -147,15 +147,4 @@
     m_filenames.clear();
 }
 
-DataObjectGtk* DataObjectGtk::forClipboard(GtkClipboard* clipboard)
-{
-    static HashMap<GtkClipboard*, RefPtr<DataObjectGtk> > objectMap;
-
-    auto addResult = objectMap.add(clipboard, nullptr);
-    if (addResult.isNewEntry)
-        addResult.iterator->value = DataObjectGtk::create();
-
-    return addResult.iterator->value.get();
 }
-
-}

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


--- releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/DataObjectGtk.h	2016-09-15 08:00:45 UTC (rev 205957)
+++ releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/DataObjectGtk.h	2016-09-15 08:02:20 UTC (rev 205958)
@@ -66,8 +66,6 @@
     void clearText();
     void clearMarkup();
 
-    static DataObjectGtk* forClipboard(GtkClipboard*);
-
 private:
     String m_text;
     String m_markup;

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


--- releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/PasteboardGtk.cpp	2016-09-15 08:00:45 UTC (rev 205957)
+++ releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/PasteboardGtk.cpp	2016-09-15 08:02:20 UTC (rev 205958)
@@ -82,7 +82,7 @@
 }
 
 Pasteboard::Pasteboard(GtkClipboard* gtkClipboard)
-    : m_dataObject(DataObjectGtk::forClipboard(gtkClipboard))
+    : m_dataObject(DataObjectGtk::create())
     , m_gtkClipboard(gtkClipboard)
 {
     ASSERT(m_dataObject);
@@ -93,9 +93,9 @@
 {
 }
 
-DataObjectGtk* Pasteboard::dataObject() const
+const DataObjectGtk& Pasteboard::dataObject() const
 {
-    return m_dataObject.get();
+    return *m_dataObject;
 }
 
 static ClipboardDataType dataObjectTypeFromHTMLClipboardType(const String& rawType)
@@ -148,7 +148,7 @@
     m_dataObject->setText(text);
 
     if (m_gtkClipboard)
-        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, (smartReplaceOption == CanSmartReplace) ? PasteboardHelper::IncludeSmartPaste : PasteboardHelper::DoNotIncludeSmartPaste);
+        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject, (smartReplaceOption == CanSmartReplace) ? PasteboardHelper::IncludeSmartPaste : PasteboardHelper::DoNotIncludeSmartPaste);
 }
 
 void Pasteboard::write(const PasteboardURL& pasteboardURL)
@@ -159,7 +159,7 @@
     m_dataObject->setURL(pasteboardURL.url, pasteboardURL.title);
 
     if (m_gtkClipboard)
-        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard);
+        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject);
 }
 
 void Pasteboard::write(const PasteboardImage& pasteboardImage)
@@ -175,7 +175,7 @@
         m_dataObject->setImage(pixbuf.get());
 
     if (m_gtkClipboard)
-        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard);
+        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject);
 }
 
 void Pasteboard::write(const PasteboardWebContent& pasteboardContent)
@@ -185,31 +185,31 @@
     m_dataObject->setMarkup(pasteboardContent.markup);
 
     if (m_gtkClipboard)
-        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, pasteboardContent.canSmartCopyOrDelete ? PasteboardHelper::IncludeSmartPaste : PasteboardHelper::DoNotIncludeSmartPaste, pasteboardContent.callback.get());
+        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject, pasteboardContent.canSmartCopyOrDelete ? PasteboardHelper::IncludeSmartPaste : PasteboardHelper::DoNotIncludeSmartPaste, pasteboardContent.callback.get());
 }
 
 void Pasteboard::writePasteboard(const Pasteboard& sourcePasteboard)
 {
-    RefPtr<DataObjectGtk> sourceDataObject = sourcePasteboard.dataObject();
+    const auto& sourceDataObject = sourcePasteboard.dataObject();
     m_dataObject->clearAll();
 
-    if (sourceDataObject->hasText())
-        m_dataObject->setText(sourceDataObject->text());
-    if (sourceDataObject->hasMarkup())
-        m_dataObject->setMarkup(sourceDataObject->markup());
-    if (sourceDataObject->hasURL())
-        m_dataObject->setURL(sourceDataObject->url(), sourceDataObject->urlLabel());
-    if (sourceDataObject->hasURIList())
-        m_dataObject->setURIList(sourceDataObject->uriList());
-    if (sourceDataObject->hasImage())
-        m_dataObject->setImage(sourceDataObject->image());
-    if (sourceDataObject->hasUnknownTypeData()) {
-        for (auto& it : m_dataObject->unknownTypes())
+    if (sourceDataObject.hasText())
+        m_dataObject->setText(sourceDataObject.text());
+    if (sourceDataObject.hasMarkup())
+        m_dataObject->setMarkup(sourceDataObject.markup());
+    if (sourceDataObject.hasURL())
+        m_dataObject->setURL(sourceDataObject.url(), sourceDataObject.urlLabel());
+    if (sourceDataObject.hasURIList())
+        m_dataObject->setURIList(sourceDataObject.uriList());
+    if (sourceDataObject.hasImage())
+        m_dataObject->setImage(sourceDataObject.image());
+    if (sourceDataObject.hasUnknownTypeData()) {
+        for (auto& it : sourceDataObject.unknownTypes())
             m_dataObject->setUnknownTypeData(it.key, it.value);
     }
 
     if (m_gtkClipboard)
-        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard);
+        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject);
 }
 
 void Pasteboard::clear()
@@ -221,7 +221,7 @@
     m_dataObject->clearAllExceptFilenames();
 
     if (m_gtkClipboard)
-        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard);
+        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject);
 }
 
 void Pasteboard::clear(const String& type)
@@ -246,7 +246,7 @@
     }
 
     if (m_gtkClipboard)
-        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard);
+        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, *m_dataObject);
 }
 
 bool Pasteboard::canSmartReplace()
@@ -263,7 +263,7 @@
 void Pasteboard::read(PasteboardPlainText& text)
 {
     if (m_gtkClipboard)
-        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard);
+        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard, *m_dataObject);
     text.text = m_dataObject->text();
 }
 
@@ -270,7 +270,7 @@
 bool Pasteboard::hasData()
 {
     if (m_gtkClipboard)
-        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard);
+        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard, *m_dataObject);
 
     return m_dataObject->hasText() || m_dataObject->hasMarkup() || m_dataObject->hasURIList() || m_dataObject->hasImage() || m_dataObject->hasUnknownTypeData();
 }
@@ -278,7 +278,7 @@
 Vector<String> Pasteboard::types()
 {
     if (m_gtkClipboard)
-        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard);
+        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard, *m_dataObject);
 
     Vector<String> types;
     if (m_dataObject->hasText()) {
@@ -307,7 +307,7 @@
 String Pasteboard::readString(const String& type)
 {
     if (m_gtkClipboard)
-        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard);
+        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard, *m_dataObject);
 
     switch (dataObjectTypeFromHTMLClipboardType(type)) {
     case ClipboardDataTypeURIList:
@@ -330,7 +330,7 @@
 Vector<String> Pasteboard::readFilenames()
 {
     if (m_gtkClipboard)
-        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard);
+        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard, *m_dataObject);
 
     return m_dataObject->filenames();
 }

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


--- releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/PasteboardHelper.cpp	2016-09-15 08:00:45 UTC (rev 205957)
+++ releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/gtk/PasteboardHelper.cpp	2016-09-15 08:02:20 UTC (rev 205958)
@@ -24,7 +24,6 @@
 #include "PasteboardHelper.h"
 
 #include "DataObjectGtk.h"
-#include "GRefPtrGtk.h"
 #include "GtkVersioning.h"
 #include "Pasteboard.h"
 #include "TextResourceDecoder.h"
@@ -93,15 +92,12 @@
     return String::fromUTF8(markupString.get());
 }
 
-void PasteboardHelper::getClipboardContents(GtkClipboard* clipboard)
+void PasteboardHelper::getClipboardContents(GtkClipboard* clipboard, DataObjectGtk& dataObject)
 {
-    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
-    ASSERT(dataObject);
-
     if (gtk_clipboard_wait_is_text_available(clipboard)) {
         GUniquePtr<gchar> textData(gtk_clipboard_wait_for_text(clipboard));
         if (textData)
-            dataObject->setText(String::fromUTF8(textData.get()));
+            dataObject.setText(String::fromUTF8(textData.get()));
     }
 
     if (gtk_clipboard_wait_is_target_available(clipboard, markupAtom)) {
@@ -108,7 +104,7 @@
         if (GtkSelectionData* data = "" markupAtom)) {
             String markup(selectionDataToUTF8String(data));
             removeMarkupPrefix(markup);
-            dataObject->setMarkup(markup);
+            dataObject.setMarkup(markup);
             gtk_selection_data_free(data);
         }
     }
@@ -115,36 +111,36 @@
 
     if (gtk_clipboard_wait_is_target_available(clipboard, uriListAtom)) {
         if (GtkSelectionData* data = "" uriListAtom)) {
-            dataObject->setURIList(selectionDataToUTF8String(data));
+            dataObject.setURIList(selectionDataToUTF8String(data));
             gtk_selection_data_free(data);
         }
     }
 }
 
-void PasteboardHelper::fillSelectionData(GtkSelectionData* selectionData, guint info, DataObjectGtk* dataObject)
+void PasteboardHelper::fillSelectionData(GtkSelectionData* selectionData, guint info, const DataObjectGtk& dataObject)
 {
     if (info == TargetTypeText)
-        gtk_selection_data_set_text(selectionData, dataObject->text().utf8().data(), -1);
+        gtk_selection_data_set_text(selectionData, dataObject.text().utf8().data(), -1);
 
     else if (info == TargetTypeMarkup) {
         // Some Linux applications refuse to accept pasted markup unless it is
         // prefixed by a content-type meta tag.
-        CString markup = String(gMarkupPrefix + dataObject->markup()).utf8();
+        CString markup = String(gMarkupPrefix + dataObject.markup()).utf8();
         gtk_selection_data_set(selectionData, markupAtom, 8,
             reinterpret_cast<const guchar*>(markup.data()), markup.length());
 
     } else if (info == TargetTypeURIList) {
-        CString uriList = dataObject->uriList().utf8();
+        CString uriList = dataObject.uriList().utf8();
         gtk_selection_data_set(selectionData, uriListAtom, 8,
             reinterpret_cast<const guchar*>(uriList.data()), uriList.length());
 
-    } else if (info == TargetTypeNetscapeURL && dataObject->hasURL()) {
-        String url(dataObject->url());
+    } else if (info == TargetTypeNetscapeURL && dataObject.hasURL()) {
+        String url(dataObject.url());
         String result(url);
         result.append("\n");
 
-        if (dataObject->hasText())
-            result.append(dataObject->text());
+        if (dataObject.hasText())
+            result.append(dataObject.text());
         else
             result.append(url);
 
@@ -153,7 +149,7 @@
             reinterpret_cast<const guchar*>(resultData.get()), strlen(resultData.get()));
 
     } else if (info == TargetTypeImage)
-        gtk_selection_data_set_pixbuf(selectionData, dataObject->image());
+        gtk_selection_data_set_pixbuf(selectionData, dataObject.image());
 
     else if (info == TargetTypeSmartPaste)
         gtk_selection_data_set_text(selectionData, "", -1);
@@ -162,7 +158,7 @@
         GVariantBuilder builder;
         g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
 
-        for (auto& it : dataObject->unknownTypes()) {
+        for (auto& it : dataObject.unknownTypes()) {
             GUniquePtr<gchar> dictItem(g_strdup_printf("{'%s', '%s'}", it.key.utf8().data(), it.value.utf8().data()));
             g_variant_builder_add_parsed(&builder, dictItem.get());
         }
@@ -173,34 +169,34 @@
     }
 }
 
-GtkTargetList* PasteboardHelper::targetListForDataObject(DataObjectGtk* dataObject, SmartPasteInclusion shouldInludeSmartPaste)
+GRefPtr<GtkTargetList> PasteboardHelper::targetListForDataObject(const DataObjectGtk& dataObject, SmartPasteInclusion shouldInludeSmartPaste)
 {
-    GtkTargetList* list = gtk_target_list_new(nullptr, 0);
+    GRefPtr<GtkTargetList> list = adoptGRef(gtk_target_list_new(nullptr, 0));
 
-    if (dataObject->hasText())
-        gtk_target_list_add_text_targets(list, TargetTypeText);
+    if (dataObject.hasText())
+        gtk_target_list_add_text_targets(list.get(), TargetTypeText);
 
-    if (dataObject->hasMarkup())
-        gtk_target_list_add(list, markupAtom, 0, TargetTypeMarkup);
+    if (dataObject.hasMarkup())
+        gtk_target_list_add(list.get(), markupAtom, 0, TargetTypeMarkup);
 
-    if (dataObject->hasURIList()) {
-        gtk_target_list_add_uri_targets(list, TargetTypeURIList);
-        gtk_target_list_add(list, netscapeURLAtom, 0, TargetTypeNetscapeURL);
+    if (dataObject.hasURIList()) {
+        gtk_target_list_add_uri_targets(list.get(), TargetTypeURIList);
+        gtk_target_list_add(list.get(), netscapeURLAtom, 0, TargetTypeNetscapeURL);
     }
 
-    if (dataObject->hasImage())
-        gtk_target_list_add_image_targets(list, TargetTypeImage, TRUE);
+    if (dataObject.hasImage())
+        gtk_target_list_add_image_targets(list.get(), TargetTypeImage, TRUE);
 
-    if (dataObject->hasUnknownTypeData())
-        gtk_target_list_add(list, unknownAtom, 0, TargetTypeUnknown);
+    if (dataObject.hasUnknownTypeData())
+        gtk_target_list_add(list.get(), unknownAtom, 0, TargetTypeUnknown);
 
     if (shouldInludeSmartPaste == IncludeSmartPaste)
-        gtk_target_list_add(list, smartPasteAtom, 0, TargetTypeSmartPaste);
+        gtk_target_list_add(list.get(), smartPasteAtom, 0, TargetTypeSmartPaste);
 
     return list;
 }
 
-void PasteboardHelper::fillDataObjectFromDropData(GtkSelectionData* data, guint /* info */, DataObjectGtk* dataObject)
+void PasteboardHelper::fillDataObjectFromDropData(GtkSelectionData* data, guint /* info */, DataObjectGtk& dataObject)
 {
     if (!gtk_selection_data_get_data(data))
         return;
@@ -207,13 +203,13 @@
 
     GdkAtom target = gtk_selection_data_get_target(data);
     if (target == textPlainAtom)
-        dataObject->setText(selectionDataToUTF8String(data));
+        dataObject.setText(selectionDataToUTF8String(data));
     else if (target == markupAtom) {
         String markup(selectionDataToUTF8String(data));
         removeMarkupPrefix(markup);
-        dataObject->setMarkup(markup);
+        dataObject.setMarkup(markup);
     } else if (target == uriListAtom) {
-        dataObject->setURIList(selectionDataToUTF8String(data));
+        dataObject.setURIList(selectionDataToUTF8String(data));
     } else if (target == netscapeURLAtom) {
         String urlWithLabel(selectionDataToUTF8String(data));
         Vector<String> pieces;
@@ -221,10 +217,10 @@
 
         // Give preference to text/uri-list here, as it can hold more
         // than one URI but still take  the label if there is one.
-        if (!dataObject->hasURIList())
-            dataObject->setURIList(pieces[0]);
+        if (!dataObject.hasURIList())
+            dataObject.setURIList(pieces[0]);
         if (pieces.size() > 1)
-            dataObject->setText(pieces[1]);
+            dataObject.setText(pieces[1]);
     } else if (target == unknownAtom) {
         GRefPtr<GVariant> variant = g_variant_new_parsed(reinterpret_cast<const char*>(gtk_selection_data_get_data(data)));
 
@@ -234,7 +230,7 @@
 
         g_variant_iter_init(&iter, variant.get());
         while (g_variant_iter_next(&iter, "{ss}", &key.outPtr(), &value.outPtr()))
-            dataObject->setUnknownTypeData(key.get(), value.get());
+            dataObject.setUnknownTypeData(key.get(), value.get());
     }
 }
 
@@ -260,59 +256,67 @@
 
 static DataObjectGtk* settingClipboardDataObject = 0;
 
-static void getClipboardContentsCallback(GtkClipboard* clipboard, GtkSelectionData *selectionData, guint info, gpointer)
+struct ClipboardSetData {
+    ClipboardSetData(DataObjectGtk* dataObject, GClosure* callback)
+        : dataObject(dataObject)
+        , callback(callback)
+    {
+    }
+
+    ~ClipboardSetData()
+    {
+    }
+
+    RefPtr<DataObjectGtk> dataObject;
+    GRefPtr<GClosure> callback;
+};
+
+static void getClipboardContentsCallback(GtkClipboard*, GtkSelectionData *selectionData, guint info, gpointer userData)
 {
-    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
-    ASSERT(dataObject);
-    PasteboardHelper::singleton().fillSelectionData(selectionData, info, dataObject);
+    auto* data = ""
+    PasteboardHelper::singleton().fillSelectionData(selectionData, info, *data->dataObject);
 }
 
-static void clearClipboardContentsCallback(GtkClipboard* clipboard, gpointer data)
+static void clearClipboardContentsCallback(GtkClipboard* clipboard, gpointer userData)
 {
-    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
-    ASSERT(dataObject);
+    std::unique_ptr<ClipboardSetData> data(static_cast<ClipboardSetData*>(userData));
 
     // Only clear the DataObject for this clipboard if we are not currently setting it.
-    if (dataObject != settingClipboardDataObject)
-        dataObject->clearAll();
+    if (data->dataObject.get() != settingClipboardDataObject)
+        data->dataObject->clearAll();
 
-    if (!data)
+    if (!data->callback)
         return;
 
-    GRefPtr<GClosure> callback = adoptGRef(static_cast<GClosure*>(data));
     GValue firstArgument = {0, {{0}}};
     g_value_init(&firstArgument, G_TYPE_POINTER);
     g_value_set_pointer(&firstArgument, clipboard);
-    g_closure_invoke(callback.get(), nullptr, 1, &firstArgument, 0);
+    g_closure_invoke(data->callback.get(), nullptr, 1, &firstArgument, 0);
 }
 
-void PasteboardHelper::writeClipboardContents(GtkClipboard* clipboard, SmartPasteInclusion includeSmartPaste, GClosure* callback)
+void PasteboardHelper::writeClipboardContents(GtkClipboard* clipboard, const DataObjectGtk& dataObject, SmartPasteInclusion includeSmartPaste, GClosure* callback)
 {
-    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
-    GtkTargetList* list = targetListForDataObject(dataObject, includeSmartPaste);
+    GRefPtr<GtkTargetList> list = targetListForDataObject(dataObject, includeSmartPaste);
 
     int numberOfTargets;
-    GtkTargetEntry* table = gtk_target_table_new_from_list(list, &numberOfTargets);
+    GtkTargetEntry* table = gtk_target_table_new_from_list(list.get(), &numberOfTargets);
 
     if (numberOfTargets > 0 && table) {
-        settingClipboardDataObject = dataObject;
+        settingClipboardDataObject = const_cast<DataObjectGtk*>(&dataObject);
 
-        if (gtk_clipboard_set_with_data(clipboard, table, numberOfTargets, getClipboardContentsCallback, clearClipboardContentsCallback, callback ? g_closure_ref(callback) : nullptr))
+        auto data = "" callback);
+        if (gtk_clipboard_set_with_data(clipboard, table, numberOfTargets, getClipboardContentsCallback, clearClipboardContentsCallback, data.get())) {
             gtk_clipboard_set_can_store(clipboard, nullptr, 0);
-        else {
-            // When gtk_clipboard_set_with_data fails the callbacks are ignored, so we need to release the reference we were passing to clearClipboardContentsCallback.
-            if (callback)
-                g_closure_unref(callback);
+            // 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);
 
     if (table)
         gtk_target_table_free(table, numberOfTargets);
-    gtk_target_list_unref(list);
 }
 
 bool PasteboardHelper::clipboardContentSupportsSmartReplace(GtkClipboard* clipboard)

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


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

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


--- releases/WebKitGTK/webkit-2.14/Source/WebKit2/ChangeLog	2016-09-15 08:00:45 UTC (rev 205957)
+++ releases/WebKitGTK/webkit-2.14/Source/WebKit2/ChangeLog	2016-09-15 08:02:20 UTC (rev 205958)
@@ -1,3 +1,22 @@
+2016-09-13  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] Get rid of DataObjectGtk::forClipboard and cleanup pasteboard code
+        https://bugs.webkit.org/show_bug.cgi?id=161907
+
+        Reviewed by Michael Catanzaro.
+
+        Update to DataObjectGtk and PasteboardHelper API changes.
+
+        * UIProcess/gtk/DragAndDropHandler.cpp:
+        (WebKit::DragAndDropHandler::startDrag):
+        (WebKit::DragAndDropHandler::fillDragData):
+        (WebKit::DragAndDropHandler::dataObjectForDropData):
+        * WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp:
+        (WebKit::WebDragClient::startDrag):
+        * WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:
+        (WebKit::collapseSelection):
+        (WebKit::WebEditorClient::updateGlobalSelection): Remove wrong X11 guards, since that code is not X11 specific.
+
 2016-09-09  Carlos Garcia Campos  <cgar...@igalia.com>
 
         Unreviewed. Update OptionsGTK.cmake and NEWS for 2.13.91 release.

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


--- releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/gtk/DragAndDropHandler.cpp	2016-09-15 08:00:45 UTC (rev 205957)
+++ releases/WebKitGTK/webkit-2.14/Source/WebKit2/UIProcess/gtk/DragAndDropHandler.cpp	2016-09-15 08:02:20 UTC (rev 205958)
@@ -115,10 +115,10 @@
 {
 #if GTK_CHECK_VERSION(3, 16, 0)
     m_draggingDataObject = adoptRef(dragData.platformData());
-    GRefPtr<GtkTargetList> targetList = adoptGRef(PasteboardHelper::singleton().targetListForDataObject(m_draggingDataObject.get()));
+    GRefPtr<GtkTargetList> targetList = PasteboardHelper::singleton().targetListForDataObject(*m_draggingDataObject);
 #else
     RefPtr<DataObjectGtk> dataObject = adoptRef(dragData.platformData());
-    GRefPtr<GtkTargetList> targetList = adoptGRef(PasteboardHelper::singleton().targetListForDataObject(dataObject.get()));
+    GRefPtr<GtkTargetList> targetList = PasteboardHelper::singleton().targetListForDataObject(*dataObject);
 #endif
 
     GUniquePtr<GdkEvent> currentEvent(gtk_get_current_event());
@@ -156,10 +156,10 @@
         return;
 
     ASSERT(m_draggingDataObject);
-    PasteboardHelper::singleton().fillSelectionData(selectionData, info, m_draggingDataObject.get());
+    PasteboardHelper::singleton().fillSelectionData(selectionData, info, *m_draggingDataObject);
 #else
     if (DataObjectGtk* dataObject = m_draggingDataObjects.get(context))
-        PasteboardHelper::singleton().fillSelectionData(selectionData, info, dataObject);
+        PasteboardHelper::singleton().fillSelectionData(selectionData, info, *dataObject);
 #endif
 }
 
@@ -196,7 +196,7 @@
         return nullptr;
 
     droppingContext->pendingDataRequests--;
-    PasteboardHelper::singleton().fillDataObjectFromDropData(selectionData, info, droppingContext->dataObject.get());
+    PasteboardHelper::singleton().fillDataObjectFromDropData(selectionData, info, *droppingContext->dataObject);
     if (droppingContext->pendingDataRequests)
         return nullptr;
 

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


--- releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp	2016-09-15 08:00:45 UTC (rev 205957)
+++ releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebDragClientGtk.cpp	2016-09-15 08:02:20 UTC (rev 205958)
@@ -65,8 +65,8 @@
     if (bitmap && !bitmap->createHandle(handle))
         return;
 
-    RefPtr<DataObjectGtk> dataObject = dataTransfer.pasteboard().dataObject();
-    DragData dragData(dataObject.get(), clientPosition, globalPosition, dataTransfer.sourceOperation());
+    const auto& dataObject = dataTransfer.pasteboard().dataObject();
+    DragData dragData(const_cast<DataObjectGtk*>(&dataObject), clientPosition, globalPosition, dataTransfer.sourceOperation());
     m_page->send(Messages::WebPageProxy::StartDrag(dragData, handle));
 }
 

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


--- releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp	2016-09-15 08:00:45 UTC (rev 205957)
+++ releases/WebKitGTK/webkit-2.14/Source/WebKit2/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp	2016-09-15 08:02:20 UTC (rev 205958)
@@ -119,7 +119,6 @@
         event->setDefaultHandled();
 }
 
-#if PLATFORM(X11)
 class EditorClientFrameDestructionObserver : FrameDestructionObserver {
 public:
     EditorClientFrameDestructionObserver(Frame* frame, GClosure* closure)
@@ -158,11 +157,9 @@
     const VisibleSelection& selection = frame->selection().selection();
     frame->selection().setBase(selection.extent(), selection.affinity());
 }
-#endif
 
 void WebEditorClient::updateGlobalSelection(Frame* frame)
 {
-#if PLATFORM(X11)
     if (!frame->selection().isRange())
         return;
     RefPtr<Range> range = frame->selection().toNormalizedRange();
@@ -184,7 +181,6 @@
     pasteboardContent.callback = callback;
     Pasteboard::createForGlobalSelection()->write(pasteboardContent);
     frameSettingClipboard = nullptr;
-#endif
 }
 
 bool WebEditorClient::shouldShowUnicodeMenu()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to