2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "WebDragData.h"
34 #include "ChromiumDataObject.h"
35 #include "ClipboardMimeTypes.h"
37 #include "WebString.h"
39 #include "WebVector.h"
41 #include <wtf/PassRefPtr.h>
43 using namespace WebCore;
47 class WebDragDataPrivate : public ChromiumDataObject {
50 void WebDragData::initialize()
52 assign(static_cast<WebDragDataPrivate*>(ChromiumDataObject::create().leakRef()));
55 void WebDragData::reset()
60 void WebDragData::assign(const WebDragData& other)
62 WebDragDataPrivate* p = const_cast<WebDragDataPrivate*>(other.m_private);
68 WebString WebDragData::url() const
72 return m_private->getData(mimeTypeURL, ignoredSuccess);
75 void WebDragData::setURL(const WebURL& url)
78 m_private->setData(mimeTypeURL, KURL(url).string());
81 WebString WebDragData::urlTitle() const
84 return m_private->urlTitle();
87 void WebDragData::setURLTitle(const WebString& urlTitle)
90 m_private->setUrlTitle(urlTitle);
93 WebString WebDragData::downloadMetadata() const
97 return m_private->getData(mimeTypeDownloadURL, ignoredSuccess);
100 void WebDragData::setDownloadMetadata(const WebString& downloadMetadata)
103 m_private->setData(mimeTypeDownloadURL, downloadMetadata);
106 WebString WebDragData::fileExtension() const
109 return m_private->fileExtension();
112 void WebDragData::setFileExtension(const WebString& fileExtension)
115 m_private->setFileExtension(fileExtension);
118 bool WebDragData::containsFilenames() const
121 return m_private->containsFilenames();
124 void WebDragData::filenames(WebVector<WebString>& filenames) const
127 filenames = m_private->filenames();
130 void WebDragData::setFilenames(const WebVector<WebString>& filenames)
133 Vector<String> filenamesCopy;
134 filenamesCopy.append(filenames.data(), filenames.size());
135 m_private->setFilenames(filenamesCopy);
138 void WebDragData::appendToFilenames(const WebString& filename)
141 Vector<String> filenames = m_private->filenames();
142 filenames.append(filename);
143 m_private->setFilenames(filenames);
146 WebString WebDragData::plainText() const
150 return m_private->getData(mimeTypeTextPlain, ignoredSuccess);
153 void WebDragData::setPlainText(const WebString& plainText)
156 m_private->setData(mimeTypeTextPlain, plainText);
159 WebString WebDragData::htmlText() const
163 return m_private->getData(mimeTypeTextHTML, ignoredSuccess);
166 void WebDragData::setHTMLText(const WebString& htmlText)
169 m_private->setData(mimeTypeTextHTML, htmlText);
172 WebURL WebDragData::htmlBaseURL() const
175 return m_private->htmlBaseUrl();
178 void WebDragData::setHTMLBaseURL(const WebURL& htmlBaseURL)
181 m_private->setHtmlBaseUrl(htmlBaseURL);
184 WebString WebDragData::fileContentFilename() const
187 return m_private->fileContentFilename();
190 void WebDragData::setFileContentFilename(const WebString& filename)
193 m_private->setFileContentFilename(filename);
196 WebData WebDragData::fileContent() const
199 return WebData(m_private->fileContent());
202 void WebDragData::setFileContent(const WebData& fileContent)
205 m_private->setFileContent(fileContent);
208 WebDragData::WebDragData(const WTF::PassRefPtr<WebCore::ChromiumDataObject>& data)
209 : m_private(static_cast<WebDragDataPrivate*>(data.leakRef()))
213 WebDragData& WebDragData::operator=(const WTF::PassRefPtr<WebCore::ChromiumDataObject>& data)
215 assign(static_cast<WebDragDataPrivate*>(data.leakRef()));
219 WebDragData::operator WTF::PassRefPtr<WebCore::ChromiumDataObject>() const
221 return PassRefPtr<ChromiumDataObject>(const_cast<WebDragDataPrivate*>(m_private));
224 void WebDragData::assign(WebDragDataPrivate* p)
226 ASSERT(!p || p->storageMode() == ChromiumDataObject::Buffered);
227 // p is already ref'd for us by the caller
233 void WebDragData::ensureMutable()
236 ASSERT(m_private->hasOneRef());
239 } // namespace WebKit