Title: [187842] releases/WebKitGTK/webkit-2.8/Source
Revision
187842
Author
carlo...@webkit.org
Date
2015-08-04 04:29:25 -0700 (Tue, 04 Aug 2015)

Log Message

Merge r186954 - [GTK] Cleanup PasteboardHelper
https://bugs.webkit.org/show_bug.cgi?id=147035

Reviewed by Žan Doberšek.

Source/WebCore:

It's actually a singleton, but the API suggests you can create
your own or use the default one, but the default one should be the
only one. Rename PasteboardHelper::defaultPasteboardHelper() as
PasteboardHelper::singleton() and make it non-copyable and never
destroyed.

* platform/gtk/PasteboardGtk.cpp:
(WebCore::Pasteboard::writePlainText): Use PasteboardHelper::singleton().
(WebCore::Pasteboard::write): Ditto.
(WebCore::Pasteboard::writePasteboard): Ditto.
(WebCore::Pasteboard::clear): Ditto.
(WebCore::Pasteboard::canSmartReplace): 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::singleton): Renamed as singleton, also
use NeverDestroyed and return a reference instead of a pointer.
(WebCore::PasteboardHelper::PasteboardHelper): Do all
initializations here and remove the initialization static flag,
since this is a real singleton now. Also use
gdk_atom_intern_static_string() to initialize the atoms instead of
gdk_atom_intern().
(WebCore::PasteboardHelper::targetList):
(WebCore::PasteboardHelper::targetListForDataObject):
(WebCore::getClipboardContentsCallback):
* platform/gtk/PasteboardHelper.h:

Source/WebKit2:

Use PasteboardHelper::singleton() instead of
PasteboardHelper::defaultPasteboardHelper().

* UIProcess/API/gtk/WebKitWebViewBase.cpp:
(webkitWebViewBaseConstructed):
* UIProcess/gtk/DragAndDropHandler.cpp:
(WebKit::DragAndDropHandler::startDrag):
(WebKit::DragAndDropHandler::fillDragData):
(WebKit::DragAndDropHandler::dataObjectForDropData):
(WebKit::DragAndDropHandler::requestDragData):

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.8/Source/WebCore/ChangeLog (187841 => 187842)


--- releases/WebKitGTK/webkit-2.8/Source/WebCore/ChangeLog	2015-08-04 11:27:05 UTC (rev 187841)
+++ releases/WebKitGTK/webkit-2.8/Source/WebCore/ChangeLog	2015-08-04 11:29:25 UTC (rev 187842)
@@ -1,3 +1,40 @@
+2015-07-17  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] Cleanup PasteboardHelper
+        https://bugs.webkit.org/show_bug.cgi?id=147035
+
+        Reviewed by Žan Doberšek.
+
+        It's actually a singleton, but the API suggests you can create
+        your own or use the default one, but the default one should be the
+        only one. Rename PasteboardHelper::defaultPasteboardHelper() as
+        PasteboardHelper::singleton() and make it non-copyable and never
+        destroyed.
+
+        * platform/gtk/PasteboardGtk.cpp:
+        (WebCore::Pasteboard::writePlainText): Use PasteboardHelper::singleton().
+        (WebCore::Pasteboard::write): Ditto.
+        (WebCore::Pasteboard::writePasteboard): Ditto.
+        (WebCore::Pasteboard::clear): Ditto.
+        (WebCore::Pasteboard::canSmartReplace): 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::singleton): Renamed as singleton, also
+        use NeverDestroyed and return a reference instead of a pointer.
+        (WebCore::PasteboardHelper::PasteboardHelper): Do all
+        initializations here and remove the initialization static flag,
+        since this is a real singleton now. Also use
+        gdk_atom_intern_static_string() to initialize the atoms instead of
+        gdk_atom_intern().
+        (WebCore::PasteboardHelper::targetList):
+        (WebCore::PasteboardHelper::targetListForDataObject):
+        (WebCore::getClipboardContentsCallback):
+        * platform/gtk/PasteboardHelper.h:
+
 2015-07-16  Simon Fraser  <simon.fra...@apple.com>
 
         Fix disappearing position:fixed elements in fixed layout mode

Modified: releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/gtk/PasteboardGtk.cpp (187841 => 187842)


--- releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/gtk/PasteboardGtk.cpp	2015-08-04 11:27:05 UTC (rev 187841)
+++ releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/gtk/PasteboardGtk.cpp	2015-08-04 11:29:25 UTC (rev 187842)
@@ -147,7 +147,7 @@
     m_dataObject->setText(text);
 
     if (m_gtkClipboard)
-        PasteboardHelper::defaultPasteboardHelper()->writeClipboardContents(m_gtkClipboard, (smartReplaceOption == CanSmartReplace) ? PasteboardHelper::IncludeSmartPaste : PasteboardHelper::DoNotIncludeSmartPaste);
+        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, (smartReplaceOption == CanSmartReplace) ? PasteboardHelper::IncludeSmartPaste : PasteboardHelper::DoNotIncludeSmartPaste);
 }
 
 void Pasteboard::write(const PasteboardURL& pasteboardURL)
@@ -158,7 +158,7 @@
     m_dataObject->setURL(pasteboardURL.url, pasteboardURL.title);
 
     if (m_gtkClipboard)
-        PasteboardHelper::defaultPasteboardHelper()->writeClipboardContents(m_gtkClipboard);
+        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard);
 }
 
 void Pasteboard::write(const PasteboardImage& pasteboardImage)
@@ -174,7 +174,7 @@
         m_dataObject->setImage(pixbuf.get());
 
     if (m_gtkClipboard)
-        PasteboardHelper::defaultPasteboardHelper()->writeClipboardContents(m_gtkClipboard);
+        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard);
 }
 
 void Pasteboard::write(const PasteboardWebContent& pasteboardContent)
@@ -184,7 +184,7 @@
     m_dataObject->setMarkup(pasteboardContent.markup);
 
     if (m_gtkClipboard)
-        PasteboardHelper::defaultPasteboardHelper()->writeClipboardContents(m_gtkClipboard, pasteboardContent.canSmartCopyOrDelete ? PasteboardHelper::IncludeSmartPaste : PasteboardHelper::DoNotIncludeSmartPaste, pasteboardContent.callback.get());
+        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard, pasteboardContent.canSmartCopyOrDelete ? PasteboardHelper::IncludeSmartPaste : PasteboardHelper::DoNotIncludeSmartPaste, pasteboardContent.callback.get());
 }
 
 void Pasteboard::writePasteboard(const Pasteboard& sourcePasteboard)
@@ -210,7 +210,7 @@
     }
 
     if (m_gtkClipboard)
-        PasteboardHelper::defaultPasteboardHelper()->writeClipboardContents(m_gtkClipboard);
+        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard);
 }
 
 void Pasteboard::clear()
@@ -222,7 +222,7 @@
     m_dataObject->clearAllExceptFilenames();
 
     if (m_gtkClipboard)
-        PasteboardHelper::defaultPasteboardHelper()->writeClipboardContents(m_gtkClipboard);
+        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard);
 }
 
 void Pasteboard::clear(const String& type)
@@ -247,12 +247,12 @@
     }
 
     if (m_gtkClipboard)
-        PasteboardHelper::defaultPasteboardHelper()->writeClipboardContents(m_gtkClipboard);
+        PasteboardHelper::singleton().writeClipboardContents(m_gtkClipboard);
 }
 
 bool Pasteboard::canSmartReplace()
 {
-    return m_gtkClipboard && PasteboardHelper::defaultPasteboardHelper()->clipboardContentSupportsSmartReplace(m_gtkClipboard);
+    return m_gtkClipboard && PasteboardHelper::singleton().clipboardContentSupportsSmartReplace(m_gtkClipboard);
 }
 
 #if ENABLE(DRAG_SUPPORT)
@@ -264,14 +264,14 @@
 void Pasteboard::read(PasteboardPlainText& text)
 {
     if (m_gtkClipboard)
-        PasteboardHelper::defaultPasteboardHelper()->getClipboardContents(m_gtkClipboard);
+        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard);
     text.text = m_dataObject->text();
 }
 
 bool Pasteboard::hasData()
 {
     if (m_gtkClipboard)
-        PasteboardHelper::defaultPasteboardHelper()->getClipboardContents(m_gtkClipboard);
+        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard);
 
     return m_dataObject->hasText() || m_dataObject->hasMarkup() || m_dataObject->hasURIList() || m_dataObject->hasImage() || m_dataObject->hasUnknownTypeData();
 }
@@ -279,7 +279,7 @@
 Vector<String> Pasteboard::types()
 {
     if (m_gtkClipboard)
-        PasteboardHelper::defaultPasteboardHelper()->getClipboardContents(m_gtkClipboard);
+        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard);
 
     Vector<String> types;
     if (m_dataObject->hasText()) {
@@ -310,7 +310,7 @@
 String Pasteboard::readString(const String& type)
 {
     if (m_gtkClipboard)
-        PasteboardHelper::defaultPasteboardHelper()->getClipboardContents(m_gtkClipboard);
+        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard);
 
     switch (dataObjectTypeFromHTMLClipboardType(type)) {
     case ClipboardDataTypeURIList:
@@ -333,7 +333,7 @@
 Vector<String> Pasteboard::readFilenames()
 {
     if (m_gtkClipboard)
-        PasteboardHelper::defaultPasteboardHelper()->getClipboardContents(m_gtkClipboard);
+        PasteboardHelper::singleton().getClipboardContents(m_gtkClipboard);
 
     return m_dataObject->filenames();
 }

Modified: releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/gtk/PasteboardHelper.cpp (187841 => 187842)


--- releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/gtk/PasteboardHelper.cpp	2015-08-04 11:27:05 UTC (rev 187841)
+++ releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/gtk/PasteboardHelper.cpp	2015-08-04 11:29:25 UTC (rev 187842)
@@ -41,7 +41,7 @@
 static GdkAtom smartPasteAtom;
 static GdkAtom unknownAtom;
 
-static String gMarkupPrefix;
+static const String gMarkupPrefix = ASCIILiteral("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">");
 
 static void removeMarkupPrefix(String& markup)
 {
@@ -51,51 +51,33 @@
         markup.remove(0, gMarkupPrefix.length());
 }
 
-static void initGdkAtoms()
+PasteboardHelper& PasteboardHelper::singleton()
 {
-    static gboolean initialized = FALSE;
-
-    if (initialized)
-        return;
-
-    initialized = TRUE;
-
-    textPlainAtom = gdk_atom_intern("text/plain;charset=utf-8", FALSE);
-    markupAtom = gdk_atom_intern("text/html", FALSE);
-    netscapeURLAtom = gdk_atom_intern("_NETSCAPE_URL", FALSE);
-    uriListAtom = gdk_atom_intern("text/uri-list", FALSE);
-    smartPasteAtom = gdk_atom_intern("application/vnd.webkitgtk.smartpaste", FALSE);
-    unknownAtom = gdk_atom_intern("application/vnd.webkitgtk.unknown", FALSE);
-    gMarkupPrefix = "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">";
+    static NeverDestroyed<PasteboardHelper> helper;
+    return helper;
 }
 
-PasteboardHelper* PasteboardHelper::defaultPasteboardHelper()
-{
-    DEPRECATED_DEFINE_STATIC_LOCAL(PasteboardHelper, defaultHelper, ());
-    return &defaultHelper;
-}
-
 PasteboardHelper::PasteboardHelper()
-    : m_targetList(gtk_target_list_new(0, 0))
+    : m_targetList(adoptGRef(gtk_target_list_new(nullptr, 0)))
 {
-    initGdkAtoms();
+    textPlainAtom = gdk_atom_intern_static_string("text/plain;charset=utf-8");
+    markupAtom = gdk_atom_intern_static_string("text/html");
+    netscapeURLAtom = gdk_atom_intern_static_string("_NETSCAPE_URL");
+    uriListAtom = gdk_atom_intern_static_string("text/uri-list");
+    smartPasteAtom = gdk_atom_intern_static_string("application/vnd.webkitgtk.smartpaste");
+    unknownAtom = gdk_atom_intern_static_string("application/vnd.webkitgtk.unknown");
 
-    gtk_target_list_add_text_targets(m_targetList, PasteboardHelper::TargetTypeText);
-    gtk_target_list_add(m_targetList, markupAtom, 0, PasteboardHelper::TargetTypeMarkup);
-    gtk_target_list_add_uri_targets(m_targetList, PasteboardHelper::TargetTypeURIList);
-    gtk_target_list_add(m_targetList, netscapeURLAtom, 0, PasteboardHelper::TargetTypeNetscapeURL);
-    gtk_target_list_add_image_targets(m_targetList, PasteboardHelper::TargetTypeImage, TRUE);
-    gtk_target_list_add(m_targetList, unknownAtom, 0, PasteboardHelper::TargetTypeUnknown);
+    gtk_target_list_add_text_targets(m_targetList.get(), PasteboardHelper::TargetTypeText);
+    gtk_target_list_add(m_targetList.get(), markupAtom, 0, PasteboardHelper::TargetTypeMarkup);
+    gtk_target_list_add_uri_targets(m_targetList.get(), PasteboardHelper::TargetTypeURIList);
+    gtk_target_list_add(m_targetList.get(), netscapeURLAtom, 0, PasteboardHelper::TargetTypeNetscapeURL);
+    gtk_target_list_add_image_targets(m_targetList.get(), PasteboardHelper::TargetTypeImage, TRUE);
+    gtk_target_list_add(m_targetList.get(), unknownAtom, 0, PasteboardHelper::TargetTypeUnknown);
 }
 
-PasteboardHelper::~PasteboardHelper()
-{
-    gtk_target_list_unref(m_targetList);
-}
-
 GtkTargetList* PasteboardHelper::targetList() const
 {
-    return m_targetList;
+    return m_targetList.get();
 }
 
 static String selectionDataToUTF8String(GtkSelectionData* data)
@@ -189,7 +171,7 @@
 
 GtkTargetList* PasteboardHelper::targetListForDataObject(DataObjectGtk* dataObject, SmartPasteInclusion shouldInludeSmartPaste)
 {
-    GtkTargetList* list = gtk_target_list_new(0, 0);
+    GtkTargetList* list = gtk_target_list_new(nullptr, 0);
 
     if (dataObject->hasText())
         gtk_target_list_add_text_targets(list, TargetTypeText);
@@ -278,7 +260,7 @@
 {
     DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
     ASSERT(dataObject);
-    PasteboardHelper::defaultPasteboardHelper()->fillSelectionData(selectionData, info, dataObject);
+    PasteboardHelper::singleton().fillSelectionData(selectionData, info, dataObject);
 }
 
 static void clearClipboardContentsCallback(GtkClipboard* clipboard, gpointer data)

Modified: releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/gtk/PasteboardHelper.h (187841 => 187842)


--- releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/gtk/PasteboardHelper.h	2015-08-04 11:27:05 UTC (rev 187841)
+++ releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/gtk/PasteboardHelper.h	2015-08-04 11:29:25 UTC (rev 187842)
@@ -25,18 +25,19 @@
 #ifndef PasteboardHelper_h
 #define PasteboardHelper_h
 
-#include <glib-object.h>
+#include <wtf/NeverDestroyed.h>
+#include <wtf/Noncopyable.h>
 #include <wtf/Vector.h>
+#include <wtf/gobject/GRefPtr.h>
 
 namespace WebCore {
 
 class DataObjectGtk;
 
 class PasteboardHelper {
+    WTF_MAKE_NONCOPYABLE(PasteboardHelper);
 public:
-    PasteboardHelper();
-    virtual ~PasteboardHelper();
-    static PasteboardHelper* defaultPasteboardHelper();
+    static PasteboardHelper& singleton();
 
     enum SmartPasteInclusion { IncludeSmartPaste, DoNotIncludeSmartPaste };
 
@@ -52,7 +53,12 @@
     bool clipboardContentSupportsSmartReplace(GtkClipboard*);
 
 private:
-    GtkTargetList* m_targetList;
+    PasteboardHelper();
+    ~PasteboardHelper() = delete;
+
+    GRefPtr<GtkTargetList> m_targetList;
+
+    friend class WTF::NeverDestroyed<PasteboardHelper>;
 };
 
 }

Modified: releases/WebKitGTK/webkit-2.8/Source/WebKit2/ChangeLog (187841 => 187842)


--- releases/WebKitGTK/webkit-2.8/Source/WebKit2/ChangeLog	2015-08-04 11:27:05 UTC (rev 187841)
+++ releases/WebKitGTK/webkit-2.8/Source/WebKit2/ChangeLog	2015-08-04 11:29:25 UTC (rev 187842)
@@ -1,3 +1,21 @@
+2015-07-17  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] Cleanup PasteboardHelper
+        https://bugs.webkit.org/show_bug.cgi?id=147035
+
+        Reviewed by Žan Doberšek.
+
+        Use PasteboardHelper::singleton() instead of
+        PasteboardHelper::defaultPasteboardHelper().
+
+        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
+        (webkitWebViewBaseConstructed):
+        * UIProcess/gtk/DragAndDropHandler.cpp:
+        (WebKit::DragAndDropHandler::startDrag):
+        (WebKit::DragAndDropHandler::fillDragData):
+        (WebKit::DragAndDropHandler::dataObjectForDropData):
+        (WebKit::DragAndDropHandler::requestDragData):
+
 2015-07-13  Carlos Garcia Campos  <cgar...@igalia.com>
 
         [GTK] Contents not correctly laid out when the web view is not realized

Modified: releases/WebKitGTK/webkit-2.8/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp (187841 => 187842)


--- releases/WebKitGTK/webkit-2.8/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp	2015-08-04 11:27:05 UTC (rev 187841)
+++ releases/WebKitGTK/webkit-2.8/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp	2015-08-04 11:29:25 UTC (rev 187842)
@@ -507,7 +507,7 @@
     gtk_widget_set_can_focus(viewWidget, TRUE);
     gtk_drag_dest_set(viewWidget, static_cast<GtkDestDefaults>(0), nullptr, 0,
         static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_PRIVATE));
-    gtk_drag_dest_set_target_list(viewWidget, PasteboardHelper::defaultPasteboardHelper()->targetList());
+    gtk_drag_dest_set_target_list(viewWidget, PasteboardHelper::singleton().targetList());
 
     WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(object)->priv;
     priv->pageClient = PageClientImpl::create(viewWidget);

Modified: releases/WebKitGTK/webkit-2.8/Source/WebKit2/UIProcess/gtk/DragAndDropHandler.cpp (187841 => 187842)


--- releases/WebKitGTK/webkit-2.8/Source/WebKit2/UIProcess/gtk/DragAndDropHandler.cpp	2015-08-04 11:27:05 UTC (rev 187841)
+++ releases/WebKitGTK/webkit-2.8/Source/WebKit2/UIProcess/gtk/DragAndDropHandler.cpp	2015-08-04 11:29:25 UTC (rev 187842)
@@ -111,7 +111,7 @@
 void DragAndDropHandler::startDrag(const DragData& dragData, PassRefPtr<ShareableBitmap> dragImage)
 {
     RefPtr<DataObjectGtk> dataObject = adoptRef(dragData.platformData());
-    GRefPtr<GtkTargetList> targetList = adoptGRef(PasteboardHelper::defaultPasteboardHelper()->targetListForDataObject(dataObject.get()));
+    GRefPtr<GtkTargetList> targetList = adoptGRef(PasteboardHelper::singleton().targetListForDataObject(dataObject.get()));
     GUniquePtr<GdkEvent> currentEvent(gtk_get_current_event());
 
     GdkDragContext* context = gtk_drag_begin(m_page.viewWidget(), targetList.get(), dragOperationToGdkDragActions(dragData.draggingSourceOperationMask()),
@@ -130,7 +130,7 @@
 void DragAndDropHandler::fillDragData(GdkDragContext* context, GtkSelectionData* selectionData, unsigned info)
 {
     if (DataObjectGtk* dataObject = m_draggingDataObjects.get(context))
-        PasteboardHelper::defaultPasteboardHelper()->fillSelectionData(selectionData, info, dataObject);
+        PasteboardHelper::singleton().fillSelectionData(selectionData, info, dataObject);
 }
 
 void DragAndDropHandler::finishDrag(GdkDragContext* context)
@@ -153,7 +153,7 @@
         return nullptr;
 
     droppingContext->pendingDataRequests--;
-    PasteboardHelper::defaultPasteboardHelper()->fillDataObjectFromDropData(selectionData, info, droppingContext->dataObject.get());
+    PasteboardHelper::singleton().fillDataObjectFromDropData(selectionData, info, droppingContext->dataObject.get());
     if (droppingContext->pendingDataRequests)
         return nullptr;
 
@@ -185,7 +185,7 @@
     if (!droppingContext) {
         GtkWidget* widget = m_page.viewWidget();
         droppingContext = std::make_unique<DroppingContext>(context, position);
-        Vector<GdkAtom> acceptableTargets(PasteboardHelper::defaultPasteboardHelper()->dropAtomsForContext(widget, droppingContext->gdkContext));
+        Vector<GdkAtom> acceptableTargets(PasteboardHelper::singleton().dropAtomsForContext(widget, droppingContext->gdkContext));
         droppingContext->pendingDataRequests = acceptableTargets.size();
         for (auto& target : acceptableTargets)
             gtk_drag_get_data(widget, droppingContext->gdkContext, target, time);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to