summaryrefslogtreecommitdiff
path: root/mozilla-1631061.patch
blob: acd1c5a88bae89a6e2f489505bc4741e10919732 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
changeset:   563258:ed4b271af277
tag:         tip
parent:      563255:2c9db4cd3d89
user:        stransky <stransky@redhat.com>
date:        Tue Dec 22 11:03:28 2020 +0100
files:       widget/gtk/nsClipboardWayland.cpp widget/gtk/nsClipboardWayland.h
description:
Bug 1631061 [Wayland] Remove fast track clipboard and always ask compositor for clipboard data, r?rmader

Differential Revision: https://phabricator.services.mozilla.com/D100317


diff --git a/widget/gtk/nsClipboardWayland.cpp b/widget/gtk/nsClipboardWayland.cpp
--- a/widget/gtk/nsClipboardWayland.cpp
+++ b/widget/gtk/nsClipboardWayland.cpp
@@ -749,7 +749,6 @@ nsRetrievalContextWayland::nsRetrievalCo
       mClipboardOffer(nullptr),
       mPrimaryOffer(nullptr),
       mDragContext(nullptr),
-      mClipboardRequestNumber(0),
       mClipboardData(nullptr),
       mClipboardDataLength(0) {
   wl_data_device* dataDevice = wl_data_device_manager_get_data_device(
@@ -807,42 +806,6 @@ GdkAtom* nsRetrievalContextWayland::GetT
   return nullptr;
 }
 
-struct FastTrackClipboard {
-  FastTrackClipboard(int aClipboardRequestNumber,
-                     nsRetrievalContextWayland* aRetrievalContex)
-      : mClipboardRequestNumber(aClipboardRequestNumber),
-        mRetrievalContex(aRetrievalContex) {}
-
-  int mClipboardRequestNumber;
-  nsRetrievalContextWayland* mRetrievalContex;
-};
-
-static void wayland_clipboard_contents_received(
-    GtkClipboard* clipboard, GtkSelectionData* selection_data, gpointer data) {
-  LOGCLIP(("wayland_clipboard_contents_received() callback\n"));
-  FastTrackClipboard* fastTrack = static_cast<FastTrackClipboard*>(data);
-  fastTrack->mRetrievalContex->TransferFastTrackClipboard(
-      fastTrack->mClipboardRequestNumber, selection_data);
-  delete fastTrack;
-}
-
-void nsRetrievalContextWayland::TransferFastTrackClipboard(
-    int aClipboardRequestNumber, GtkSelectionData* aSelectionData) {
-  if (mClipboardRequestNumber == aClipboardRequestNumber) {
-    int dataLength = gtk_selection_data_get_length(aSelectionData);
-    if (dataLength > 0) {
-      mClipboardDataLength = dataLength;
-      mClipboardData = reinterpret_cast<char*>(
-          g_malloc(sizeof(char) * (mClipboardDataLength + 1)));
-      memcpy(mClipboardData, gtk_selection_data_get_data(aSelectionData),
-             sizeof(char) * mClipboardDataLength);
-      mClipboardData[mClipboardDataLength] = '\0';
-    }
-  } else {
-    NS_WARNING("Received obsoleted clipboard data!");
-  }
-}
-
 const char* nsRetrievalContextWayland::GetClipboardData(
     const char* aMimeType, int32_t aWhichClipboard, uint32_t* aContentLength) {
   NS_ASSERTION(mClipboardData == nullptr && mClipboardDataLength == 0,
@@ -851,33 +814,20 @@ const char* nsRetrievalContextWayland::G
   LOGCLIP(("nsRetrievalContextWayland::GetClipboardData [%p] mime %s\n", this,
            aMimeType));
 
-  /* If actual clipboard data is owned by us we don't need to go
-   * through Wayland but we ask Gtk+ to directly call data
-   * getter callback nsClipboard::SelectionGetEvent().
-   * see gtk_selection_convert() at gtk+/gtkselection.c.
-   */
-  GdkAtom selection = GetSelectionAtom(aWhichClipboard);
-  if (gdk_selection_owner_get(selection)) {
-    LOGCLIP(("  Internal clipboard content\n"));
-    mClipboardRequestNumber++;
-    gtk_clipboard_request_contents(
-        gtk_clipboard_get(selection), gdk_atom_intern(aMimeType, FALSE),
-        wayland_clipboard_contents_received,
-        new FastTrackClipboard(mClipboardRequestNumber, this));
+  const auto& dataOffer =
+      (GetSelectionAtom(aWhichClipboard) == GDK_SELECTION_PRIMARY)
+          ? mPrimaryOffer
+          : mClipboardOffer;
+  if (!dataOffer) {
+    // Something went wrong. We're requested to provide clipboard data
+    // but we haven't got any from wayland.
+    NS_WARNING("Requested data without valid DataOffer!");
+    if (mClipboardData) {
+      ReleaseClipboardData(mClipboardData);
+    }
   } else {
-    LOGCLIP(("  Remote clipboard content\n"));
-    const auto& dataOffer =
-        (selection == GDK_SELECTION_PRIMARY) ? mPrimaryOffer : mClipboardOffer;
-    if (!dataOffer) {
-      // Something went wrong. We're requested to provide clipboard data
-      // but we haven't got any from wayland.
-      NS_WARNING("Requested data without valid DataOffer!");
-      mClipboardData = nullptr;
-      mClipboardDataLength = 0;
-    } else {
-      mClipboardData = dataOffer->GetData(mDisplay->GetDisplay(), aMimeType,
-                                          &mClipboardDataLength);
-    }
+    mClipboardData = dataOffer->GetData(mDisplay->GetDisplay(), aMimeType,
+                                        &mClipboardDataLength);
   }
 
   *aContentLength = mClipboardDataLength;
@@ -908,8 +858,10 @@ void nsRetrievalContextWayland::ReleaseC
 
   NS_ASSERTION(aClipboardData == mClipboardData,
                "Releasing unknown clipboard data!");
-  g_free((void*)aClipboardData);
 
-  mClipboardData = nullptr;
-  mClipboardDataLength = 0;
+  if (mClipboardData) {
+    g_free((void*)aClipboardData);
+    mClipboardData = nullptr;
+    mClipboardDataLength = 0;
+  }
 }
diff --git a/widget/gtk/nsClipboardWayland.h b/widget/gtk/nsClipboardWayland.h
--- a/widget/gtk/nsClipboardWayland.h
+++ b/widget/gtk/nsClipboardWayland.h
@@ -16,8 +16,6 @@
 #include "nsClipboard.h"
 #include "nsWaylandDisplay.h"
 
-struct FastTrackClipboard;
-
 class DataOffer {
  public:
   void AddMIMEType(const char* aMimeType);
@@ -134,9 +132,6 @@ class nsRetrievalContextWayland : public
 
   void ClearDragAndDropDataOffer();
 
-  void TransferFastTrackClipboard(int aClipboardRequestNumber,
-                                  GtkSelectionData* aSelectionData);
-
   virtual ~nsRetrievalContextWayland() override;
 
  private:
@@ -149,7 +144,6 @@ class nsRetrievalContextWayland : public
   mozilla::UniquePtr<DataOffer> mPrimaryOffer;
   RefPtr<nsWaylandDragContext> mDragContext;
 
-  int mClipboardRequestNumber;
   char* mClipboardData;
   uint32_t mClipboardDataLength;
 

bgstack15