#include "config.h"
#include "APIAttachment.h"
#include <WebCore/AttachmentTypes.h>
#include <WebCore/SharedBuffer.h>
#include <wtf/BlockPtr.h>
#include <wtf/text/WTFString.h>
namespace API {
Ref<Attachment> Attachment::create(const WTF::String& identifier, WebKit::WebPageProxy& webPage)
{
return adoptRef(*new Attachment(identifier, webPage));
}
Attachment::Attachment(const WTF::String& identifier, WebKit::WebPageProxy& webPage)
: m_identifier(identifier)
, m_webPage(webPage.createWeakPtr())
{
}
Attachment::~Attachment()
{
}
void Attachment::requestData(Function<void(RefPtr<WebCore::SharedBuffer>, WebKit::CallbackBase::Error)>&& callback)
{
if (m_webPage)
m_webPage->requestAttachmentData(m_identifier, WTFMove(callback));
else
callback(nullptr, WebKit::CallbackBase::Error::OwnerWasInvalidated);
}
void Attachment::setDisplayOptions(WebCore::AttachmentDisplayOptions options, Function<void(WebKit::CallbackBase::Error)>&& callback)
{
if (m_webPage)
m_webPage->setAttachmentDisplayOptions(m_identifier, options, WTFMove(callback));
else
callback(WebKit::CallbackBase::Error::OwnerWasInvalidated);
}
void Attachment::setDataAndContentType(WebCore::SharedBuffer& data, const WTF::String& newContentType, const WTF::String& newFilename, Function<void(WebKit::CallbackBase::Error)>&& callback)
{
auto optionalNewContentType = newContentType.isNull() ? std::nullopt : std::optional<WTF::String> { newContentType };
auto optionalNewFilename = newFilename.isNull() ? std::nullopt : std::optional<WTF::String> { newFilename };
if (m_webPage)
m_webPage->setAttachmentDataAndContentType(m_identifier, data, WTFMove(optionalNewContentType), WTFMove(optionalNewFilename), WTFMove(callback));
else
callback(WebKit::CallbackBase::Error::OwnerWasInvalidated);
}
}