#include "config.h"
#include "Pasteboard.h"
#include "PasteboardStrategy.h"
#include "PlatformStrategies.h"
#include "Settings.h"
#include "SharedBuffer.h"
#include <wtf/text/StringHash.h>
namespace WebCore {
PasteboardImage::PasteboardImage() = default;
PasteboardImage::~PasteboardImage() = default;
bool Pasteboard::isSafeTypeForDOMToReadAndWrite(const String& type)
{
return type == "text/plain" || type == "text/html" || type == "text/uri-list";
}
bool Pasteboard::canExposeURLToDOMWhenPasteboardContainsFiles(const String& urlString)
{
URL url({ }, urlString);
return url.protocolIsInHTTPFamily() || url.protocolIsBlob() || url.protocolIsData();
}
#if !PLATFORM(COCOA)
Vector<String> Pasteboard::readAllStrings(const String& type)
{
auto result = readString(type);
if (result.isEmpty())
return { };
return { result };
}
#endif
Optional<Vector<PasteboardItemInfo>> Pasteboard::allPasteboardItemInfo() const
{
#if PLATFORM(COCOA)
if (auto* strategy = platformStrategies()->pasteboardStrategy())
return strategy->allPasteboardItemInfo(name(), m_changeCount);
#endif
return WTF::nullopt;
}
Optional<PasteboardItemInfo> Pasteboard::pasteboardItemInfo(size_t index) const
{
#if PLATFORM(COCOA)
if (auto* strategy = platformStrategies()->pasteboardStrategy())
return strategy->informationForItemAtIndex(index, name(), m_changeCount);
#else
UNUSED_PARAM(index);
#endif
return WTF::nullopt;
}
String Pasteboard::readString(size_t index, const String& type)
{
if (auto* strategy = platformStrategies()->pasteboardStrategy())
return strategy->readStringFromPasteboard(index, type, name());
return { };
}
RefPtr<WebCore::SharedBuffer> Pasteboard::readBuffer(size_t index, const String& type)
{
if (auto* strategy = platformStrategies()->pasteboardStrategy())
return strategy->readBufferFromPasteboard(index, type, name());
return nullptr;
}
URL Pasteboard::readURL(size_t index, String& title)
{
if (auto* strategy = platformStrategies()->pasteboardStrategy())
return strategy->readURLFromPasteboard(index, name(), title);
return { };
}
#if !PLATFORM(MAC)
bool Pasteboard::canWriteTrustworthyWebURLsPboardType()
{
return false;
}
#endif
};