Bug 1447925 - Use GetClipboardText() to get text data at nsClipboard::GetData(), r?jhorak draft
authorMartin Stransky <stransky@redhat.com>
Tue, 03 Apr 2018 10:30:37 +0200
changeset 776587 b3ec4b510e734b6eebcac5716232270603c41200
parent 776586 09b0bc959fe68ae9d0cf34188c2ab4a2b0186ea1
push id104908
push userstransky@redhat.com
push dateTue, 03 Apr 2018 10:28:48 +0000
reviewersjhorak
bugs1447925
milestone61.0a1
Bug 1447925 - Use GetClipboardText() to get text data at nsClipboard::GetData(), r?jhorak MozReview-Commit-ID: 3JnLLyk0BOF
widget/gtk/nsClipboard.cpp
widget/gtk/nsClipboard.h
--- a/widget/gtk/nsClipboard.cpp
+++ b/widget/gtk/nsClipboard.cpp
@@ -296,30 +296,27 @@ nsClipboard::GetData(nsITransferable *aT
 
             mContext->ReleaseClipboardData(clipboardData);
             return NS_OK;
         }
 
         // Special case text/unicode since we can convert any
         // string into text/unicode
         if (flavorStr.EqualsLiteral(kUnicodeMime)) {
-            uint32_t    clipboardDataLength;
             const char* clipboardData =
-                mContext->GetClipboardData(GTK_DEFAULT_MIME_TEXT,
-                                           aWhichClipboard,
-                                           &clipboardDataLength);
+                mContext->GetClipboardText(aWhichClipboard);
             if (!clipboardData) {
                 // If the type was text/unicode and we couldn't get
                 // text off the clipboard, run the next loop
                 // iteration.
                 continue;
             }
 
             // Convert utf-8 into our unicode format.
-            NS_ConvertUTF8toUTF16 ucs2string(clipboardData, clipboardDataLength);
+            NS_ConvertUTF8toUTF16 ucs2string(clipboardData);
             const char* unicodeData = (const char *)ToNewUnicode(ucs2string);
             uint32_t unicodeDataLength = ucs2string.Length() * 2;
             SetTransferableData(aTransferable, flavorStr,
                                 unicodeData, unicodeDataLength);
             free((void *)unicodeData);
 
             mContext->ReleaseClipboardData(clipboardData);
             return NS_OK;
--- a/widget/gtk/nsClipboard.h
+++ b/widget/gtk/nsClipboard.h
@@ -8,27 +8,28 @@
 #ifndef __nsClipboard_h_
 #define __nsClipboard_h_
 
 #include "nsIClipboard.h"
 #include "nsIObserver.h"
 #include "nsIBinaryOutputStream.h"
 #include <gtk/gtk.h>
 
-// Default Gtk MIME for text
-#define GTK_DEFAULT_MIME_TEXT "UTF8_STRING"
-
 class nsRetrievalContext {
 public:
+    // Get actual clipboard content (GetClipboardData/GetClipboardText)
+    // which has to be released by ReleaseClipboardData().
     virtual const char* GetClipboardData(const char* aMimeType,
                                          int32_t aWhichClipboard,
                                          uint32_t* aContentLength) = 0;
     virtual const char* GetClipboardText(int32_t aWhichClipboard) = 0;
     virtual void ReleaseClipboardData(const char* aClipboardData) = 0;
 
+    // Get data mime types which can be obtained from clipboard.
+    // The returned array has to be released by g_free().
     virtual GdkAtom* GetTargets(int32_t aWhichClipboard,
                                 int* aTargetNum) = 0;
 
     nsRetrievalContext() {};
     virtual ~nsRetrievalContext() {};
 
 protected:
     // Idle timeout for receiving selection and property notify events (microsec)