QuickLookDocumentData.cpp [plain text]
#include "config.h"
#include "QuickLookDocumentData.h"
#if USE(QUICK_LOOK)
#include "ArgumentDecoder.h"
#include "ArgumentEncoder.h"
namespace WebKit {
void QuickLookDocumentData::append(CFDataRef data)
{
m_data.append(data);
}
CFDataRef QuickLookDocumentData::decodedData() const
{
ASSERT(m_data.size() <= 1);
if (m_data.isEmpty())
return nullptr;
return m_data[0].get();
}
void QuickLookDocumentData::clear()
{
m_data.clear();
}
void QuickLookDocumentData::encode(IPC::ArgumentEncoder& encoder) const
{
uint64_t size = 0;
for (const auto& data : m_data)
size += CFDataGetLength(data.get());
encoder << size;
for (const auto& data : m_data)
encoder.encodeFixedLengthData(CFDataGetBytePtr(data.get()), CFDataGetLength(data.get()), 1);
}
bool QuickLookDocumentData::decode(IPC::ArgumentDecoder& decoder, QuickLookDocumentData& documentData)
{
uint64_t size;
if (!decoder.decode(size))
return false;
if (!size)
return true;
uint8_t* const buffer = static_cast<uint8_t*>(CFAllocatorAllocate(kCFAllocatorDefault, size, 0));
ASSERT(buffer);
if (!decoder.decodeFixedLengthData(buffer, size, 1)) {
CFAllocatorDeallocate(kCFAllocatorDefault, buffer);
return false;
}
documentData.clear();
documentData.m_data.append(adoptCF(CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, buffer, size, kCFAllocatorDefault)));
return true;
}
}
#endif // USE(QUICK_LOOK)