#include "config.h"
#include "WebDragData.h"
#include "ChromiumDataObject.h"
#include "ChromiumDataObjectLegacy.h"
#include "ClipboardMimeTypes.h"
#include "WebData.h"
#include "WebString.h"
#include "WebURL.h"
#include "WebVector.h"
#include <wtf/PassRefPtr.h>
using namespace WebCore;
namespace WebKit {
class WebDragDataPrivate : public ChromiumDataObject {
};
void WebDragData::initialize()
{
assign(static_cast<WebDragDataPrivate*>(ChromiumDataObject::create(Clipboard::DragAndDrop).releaseRef()));
}
void WebDragData::reset()
{
assign(0);
}
void WebDragData::assign(const WebDragData& other)
{
WebDragDataPrivate* p = const_cast<WebDragDataPrivate*>(other.m_private);
if (p)
p->ref();
assign(p);
}
WebString WebDragData::url() const
{
ASSERT(!isNull());
bool ignoredSuccess;
return m_private->getData(mimeTypeURL, ignoredSuccess);
}
void WebDragData::setURL(const WebURL& url)
{
ensureMutable();
m_private->setData(mimeTypeURL, KURL(url).string());
}
WebString WebDragData::urlTitle() const
{
ASSERT(!isNull());
return m_private->urlTitle();
}
void WebDragData::setURLTitle(const WebString& urlTitle)
{
ensureMutable();
m_private->setUrlTitle(urlTitle);
}
WebString WebDragData::downloadMetadata() const
{
ASSERT(!isNull());
bool ignoredSuccess;
return m_private->getData(mimeTypeDownloadURL, ignoredSuccess);
}
void WebDragData::setDownloadMetadata(const WebString& downloadMetadata)
{
ensureMutable();
m_private->setData(mimeTypeDownloadURL, downloadMetadata);
}
WebString WebDragData::fileExtension() const
{
ASSERT(!isNull());
return m_private->fileExtension();
}
void WebDragData::setFileExtension(const WebString& fileExtension)
{
ensureMutable();
m_private->setFileExtension(fileExtension);
}
bool WebDragData::containsFilenames() const
{
ASSERT(!isNull());
return m_private->containsFilenames();
}
void WebDragData::filenames(WebVector<WebString>& filenames) const
{
ASSERT(!isNull());
filenames = m_private->filenames();
}
void WebDragData::setFilenames(const WebVector<WebString>& filenames)
{
ensureMutable();
Vector<String> filenamesCopy;
filenamesCopy.append(filenames.data(), filenames.size());
m_private->setFilenames(filenamesCopy);
}
void WebDragData::appendToFilenames(const WebString& filename)
{
ensureMutable();
Vector<String> filenames = m_private->filenames();
filenames.append(filename);
m_private->setFilenames(filenames);
}
WebString WebDragData::plainText() const
{
ASSERT(!isNull());
bool ignoredSuccess;
return m_private->getData(mimeTypeTextPlain, ignoredSuccess);
}
void WebDragData::setPlainText(const WebString& plainText)
{
ensureMutable();
m_private->setData(mimeTypeTextPlain, plainText);
}
WebString WebDragData::htmlText() const
{
ASSERT(!isNull());
bool ignoredSuccess;
return m_private->getData(mimeTypeTextHTML, ignoredSuccess);
}
void WebDragData::setHTMLText(const WebString& htmlText)
{
ensureMutable();
m_private->setData(mimeTypeTextHTML, htmlText);
}
WebURL WebDragData::htmlBaseURL() const
{
ASSERT(!isNull());
return m_private->htmlBaseUrl();
}
void WebDragData::setHTMLBaseURL(const WebURL& htmlBaseURL)
{
ensureMutable();
m_private->setHtmlBaseUrl(htmlBaseURL);
}
WebString WebDragData::fileContentFilename() const
{
ASSERT(!isNull());
return m_private->fileContentFilename();
}
void WebDragData::setFileContentFilename(const WebString& filename)
{
ensureMutable();
m_private->setFileContentFilename(filename);
}
WebData WebDragData::fileContent() const
{
ASSERT(!isNull());
return WebData(m_private->fileContent());
}
void WebDragData::setFileContent(const WebData& fileContent)
{
ensureMutable();
m_private->setFileContent(fileContent);
}
WebDragData::WebDragData(const WTF::PassRefPtr<WebCore::ChromiumDataObject>& data)
: m_private(static_cast<WebDragDataPrivate*>(data.releaseRef()))
{
}
WebDragData& WebDragData::operator=(const WTF::PassRefPtr<WebCore::ChromiumDataObject>& data)
{
assign(static_cast<WebDragDataPrivate*>(data.releaseRef()));
return *this;
}
WebDragData::operator WTF::PassRefPtr<WebCore::ChromiumDataObject>() const
{
return PassRefPtr<ChromiumDataObject>(const_cast<WebDragDataPrivate*>(m_private));
}
void WebDragData::assign(WebDragDataPrivate* p)
{
if (m_private)
m_private->deref();
m_private = p;
}
void WebDragData::ensureMutable()
{
ASSERT(!isNull());
ASSERT(m_private->hasOneRef());
}
}