gecko-dev/widget/gtk/nsClipboardX11.h
Martin Stransky 2a63de4110 Bug 1424661 - refactor ncClipboard::GetData(), allocate all memory by moz_xmalloc() and release by free(), r=jhorak
Refactor ncClipboard::GetData() for better readability, add nsClipboard::SetTransferableData()
to send clipboard data to nsITransferable.

According to Gtk people [1] we can't mix free()/g_free() and malloc()/g_malloc() calls.
Existing nsClipboard code mixes that on some places which can lead to issued on glib built
with specific flags (ENABLE_MEM_PROFILE or ENABLE_MEM_CHECK).

[1] https://mail.gnome.org/archives/gtk-list/2000-July/msg00002.html

MozReview-Commit-ID: GvkUGSttVGO

--HG--
extra : rebase_source : 99801e1dc97e24a8d68fe7f3585562bb541c6628
2017-12-11 11:59:57 +01:00

64 lines
1.8 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:expandtab:shiftwidth=4:tabstop=4:
*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef __nsClipboardX11_h_
#define __nsClipboardX11_h_
#include "nsIClipboard.h"
#include <gtk/gtk.h>
class nsRetrievalContextX11 : public nsRetrievalContext
{
public:
enum State { INITIAL, COMPLETED, TIMED_OUT };
virtual const char* WaitForClipboardContext(const char* aMimeType,
int32_t aWhichClipboard, uint32_t* aContentLength) override;
virtual GdkAtom* GetTargets(int32_t aWhichClipboard,
int* aTargetNums) override;
// Call this when data has been retrieved.
void Complete(GtkSelectionData* aData, int aDataRequestNumber);
nsRetrievalContextX11();
virtual ~nsRetrievalContextX11() override;
private:
GtkSelectionData* WaitForContents(GtkClipboard *clipboard,
const char *aMimeType);
/**
* Spins X event loop until timing out or being completed. Returns
* null if we time out, otherwise returns the completed data (passing
* ownership to caller).
*/
void *Wait();
State mState;
void* mData;
int mClipboardRequestNumber;
};
class ClipboardRequestHandler
{
public:
ClipboardRequestHandler(nsRetrievalContextX11 *aContext, int aDataRequestNumber)
: mContext(aContext)
, mDataRequestNumber(aDataRequestNumber)
{}
void Complete(GtkSelectionData* aData)
{
mContext->Complete(aData, mDataRequestNumber);
}
private:
nsRetrievalContextX11 *mContext;
int mDataRequestNumber;
};
#endif /* __nsClipboardX11_h_ */