PasteboardCustomData.h [plain text]
#pragma once
#include <wtf/Function.h>
#include <wtf/HashMap.h>
#include <wtf/Variant.h>
#include <wtf/Vector.h>
#include <wtf/persistence/PersistentCoders.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
class SharedBuffer;
class PasteboardCustomData {
public:
struct Entry {
WEBCORE_EXPORT Entry();
WEBCORE_EXPORT Entry(const Entry&);
WEBCORE_EXPORT Entry(Entry&&);
WEBCORE_EXPORT Entry& operator=(const Entry& otherData);
WEBCORE_EXPORT Entry& operator=(Entry&& otherData);
Entry(const String& type);
String type;
String customData;
Variant<String, Ref<SharedBuffer>> platformData;
};
WEBCORE_EXPORT PasteboardCustomData();
WEBCORE_EXPORT PasteboardCustomData(String&& origin, Vector<Entry>&&);
WEBCORE_EXPORT PasteboardCustomData(PasteboardCustomData&&);
WEBCORE_EXPORT PasteboardCustomData(const PasteboardCustomData&);
WEBCORE_EXPORT ~PasteboardCustomData();
const String& origin() const { return m_origin; }
void setOrigin(const String& origin) { m_origin = origin; }
WEBCORE_EXPORT Ref<SharedBuffer> createSharedBuffer() const;
WEBCORE_EXPORT static PasteboardCustomData fromSharedBuffer(const SharedBuffer&);
WEBCORE_EXPORT static PasteboardCustomData fromPersistenceDecoder(WTF::Persistence::Decoder&&);
String readString(const String& type) const;
RefPtr<SharedBuffer> readBuffer(const String& type) const;
String readStringInCustomData(const String& type) const;
void writeString(const String& type, const String& value);
void writeData(const String& type, Ref<SharedBuffer>&& data);
void writeStringInCustomData(const String& type, const String& value);
void clear();
void clear(const String& type);
#if PLATFORM(COCOA)
WEBCORE_EXPORT static const char* cocoaType();
#elif PLATFORM(GTK)
static const char* gtkType() { return "org.webkitgtk.WebKit.custom-pasteboard-data"; }
#endif
void forEachType(Function<void(const String&)>&&) const;
void forEachPlatformString(Function<void(const String& type, const String& data)>&&) const;
void forEachPlatformStringOrBuffer(Function<void(const String& type, const Variant<String, Ref<SharedBuffer>>& data)>&&) const;
void forEachCustomString(Function<void(const String& type, const String& data)>&&) const;
bool hasData() const;
bool hasSameOriginCustomData() const;
Vector<String> orderedTypes() const;
WEBCORE_EXPORT PasteboardCustomData& operator=(const PasteboardCustomData& otherData);
const Vector<Entry>& data() const { return m_data; }
private:
HashMap<String, String> sameOriginCustomStringData() const;
Entry& addOrMoveEntryToEnd(const String&);
String m_origin;
Vector<Entry> m_data;
};
}