Backed out changeset e8c18967320c (bug 1631061) for causing Bug 1683989

This commit is contained in:
Narcis Beleuzu 2020-12-23 12:50:06 +02:00
Родитель d387ee0067
Коммит f2b3650083
2 изменённых файлов: 72 добавлений и 18 удалений

Просмотреть файл

@ -749,6 +749,7 @@ nsRetrievalContextWayland::nsRetrievalContextWayland(void)
mClipboardOffer(nullptr), mClipboardOffer(nullptr),
mPrimaryOffer(nullptr), mPrimaryOffer(nullptr),
mDragContext(nullptr), mDragContext(nullptr),
mClipboardRequestNumber(0),
mClipboardData(nullptr), mClipboardData(nullptr),
mClipboardDataLength(0) { mClipboardDataLength(0) {
wl_data_device* dataDevice = wl_data_device_manager_get_data_device( wl_data_device* dataDevice = wl_data_device_manager_get_data_device(
@ -806,6 +807,42 @@ GdkAtom* nsRetrievalContextWayland::GetTargets(int32_t aWhichClipboard,
return nullptr; 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* nsRetrievalContextWayland::GetClipboardData(
const char* aMimeType, int32_t aWhichClipboard, uint32_t* aContentLength) { const char* aMimeType, int32_t aWhichClipboard, uint32_t* aContentLength) {
NS_ASSERTION(mClipboardData == nullptr && mClipboardDataLength == 0, NS_ASSERTION(mClipboardData == nullptr && mClipboardDataLength == 0,
@ -814,20 +851,33 @@ const char* nsRetrievalContextWayland::GetClipboardData(
LOGCLIP(("nsRetrievalContextWayland::GetClipboardData [%p] mime %s\n", this, LOGCLIP(("nsRetrievalContextWayland::GetClipboardData [%p] mime %s\n", this,
aMimeType)); aMimeType));
const auto& dataOffer = /* If actual clipboard data is owned by us we don't need to go
(GetSelectionAtom(aWhichClipboard) == GDK_SELECTION_PRIMARY) * through Wayland but we ask Gtk+ to directly call data
? mPrimaryOffer * getter callback nsClipboard::SelectionGetEvent().
: mClipboardOffer; * see gtk_selection_convert() at gtk+/gtkselection.c.
if (!dataOffer) { */
// Something went wrong. We're requested to provide clipboard data GdkAtom selection = GetSelectionAtom(aWhichClipboard);
// but we haven't got any from wayland. if (gdk_selection_owner_get(selection)) {
NS_WARNING("Requested data without valid DataOffer!"); LOGCLIP((" Internal clipboard content\n"));
if (mClipboardData) { mClipboardRequestNumber++;
ReleaseClipboardData(mClipboardData); gtk_clipboard_request_contents(
} gtk_clipboard_get(selection), gdk_atom_intern(aMimeType, FALSE),
wayland_clipboard_contents_received,
new FastTrackClipboard(mClipboardRequestNumber, this));
} else { } else {
mClipboardData = dataOffer->GetData(mDisplay->GetDisplay(), aMimeType, LOGCLIP((" Remote clipboard content\n"));
&mClipboardDataLength); 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);
}
} }
*aContentLength = mClipboardDataLength; *aContentLength = mClipboardDataLength;
@ -858,10 +908,8 @@ void nsRetrievalContextWayland::ReleaseClipboardData(
NS_ASSERTION(aClipboardData == mClipboardData, NS_ASSERTION(aClipboardData == mClipboardData,
"Releasing unknown clipboard data!"); "Releasing unknown clipboard data!");
g_free((void*)aClipboardData);
if (mClipboardData) { mClipboardData = nullptr;
g_free((void*)aClipboardData); mClipboardDataLength = 0;
mClipboardData = nullptr;
mClipboardDataLength = 0;
}
} }

Просмотреть файл

@ -16,6 +16,8 @@
#include "nsClipboard.h" #include "nsClipboard.h"
#include "nsWaylandDisplay.h" #include "nsWaylandDisplay.h"
struct FastTrackClipboard;
class DataOffer { class DataOffer {
public: public:
void AddMIMEType(const char* aMimeType); void AddMIMEType(const char* aMimeType);
@ -132,6 +134,9 @@ class nsRetrievalContextWayland : public nsRetrievalContext {
void ClearDragAndDropDataOffer(); void ClearDragAndDropDataOffer();
void TransferFastTrackClipboard(int aClipboardRequestNumber,
GtkSelectionData* aSelectionData);
virtual ~nsRetrievalContextWayland() override; virtual ~nsRetrievalContextWayland() override;
private: private:
@ -144,6 +149,7 @@ class nsRetrievalContextWayland : public nsRetrievalContext {
mozilla::UniquePtr<DataOffer> mPrimaryOffer; mozilla::UniquePtr<DataOffer> mPrimaryOffer;
RefPtr<nsWaylandDragContext> mDragContext; RefPtr<nsWaylandDragContext> mDragContext;
int mClipboardRequestNumber;
char* mClipboardData; char* mClipboardData;
uint32_t mClipboardDataLength; uint32_t mClipboardDataLength;