OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
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 | |
13 * distribution. | |
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. | |
17 * | |
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. | |
29 */ | |
30 | |
31 #include "config.h" | |
32 #include "WebDragData.h" | |
33 | |
34 #include "ChromiumDataObject.h" | |
35 #include "WebData.h" | |
36 #include "WebString.h" | |
37 #include "WebURL.h" | |
38 #include "WebVector.h" | |
39 | |
40 #include <wtf/PassRefPtr.h> | |
41 | |
42 using namespace WebCore; | |
43 | |
44 namespace WebKit { | |
45 | |
46 class WebDragDataPrivate : public ChromiumDataObject { | |
47 }; | |
48 | |
49 void WebDragData::initialize() | |
50 { | |
51 assign(static_cast<WebDragDataPrivate*>(ChromiumDataObject::create().releaseRef())); | |
52 } | |
53 | |
54 void WebDragData::reset() | |
55 { | |
56 assign(0); | |
57 } | |
58 | |
59 void WebDragData::assign(const WebDragData& other) | |
60 { | |
61 WebDragDataPrivate* p = const_cast<WebDragDataPrivate*>(other.m_private); | |
62 if (p) | |
63 p->ref(); | |
64 assign(p); | |
65 } | |
66 | |
67 WebURL WebDragData::url() const | |
68 { | |
69 ASSERT(!isNull()); | |
70 return m_private->url; | |
71 } | |
72 | |
73 void WebDragData::setURL(const WebURL& url) | |
74 { | |
75 ensureMutable(); | |
76 m_private->url = url; | |
77 } | |
78 | |
79 WebString WebDragData::urlTitle() const | |
80 { | |
81 ASSERT(!isNull()); | |
82 return m_private->urlTitle; | |
83 } | |
84 | |
85 void WebDragData::setURLTitle(const WebString& urlTitle) | |
86 { | |
87 ensureMutable(); | |
88 m_private->urlTitle = urlTitle; | |
89 } | |
90 | |
91 WebString WebDragData::fileExtension() const | |
92 { | |
93 ASSERT(!isNull()); | |
94 return m_private->fileExtension; | |
95 } | |
96 | |
97 void WebDragData::setFileExtension(const WebString& fileExtension) | |
98 { | |
99 ensureMutable(); | |
100 m_private->fileExtension = fileExtension; | |
101 } | |
102 | |
103 bool WebDragData::hasFileNames() const | |
104 { | |
105 ASSERT(!isNull()); | |
106 return !m_private->filenames.isEmpty(); | |
107 } | |
108 | |
109 void WebDragData::fileNames(WebVector<WebString>& fileNames) const | |
110 { | |
111 ASSERT(!isNull()); | |
112 fileNames = m_private->filenames; | |
113 } | |
114 | |
115 void WebDragData::setFileNames(const WebVector<WebString>& fileNames) | |
116 { | |
117 ensureMutable(); | |
118 m_private->filenames.clear(); | |
119 m_private->filenames.append(fileNames.data(), fileNames.size()); | |
120 } | |
121 | |
122 void WebDragData::appendToFileNames(const WebString& fileName) | |
123 { | |
124 ensureMutable(); | |
125 m_private->filenames.append(fileName); | |
126 } | |
127 | |
128 WebString WebDragData::plainText() const | |
129 { | |
130 ASSERT(!isNull()); | |
131 return m_private->plainText; | |
132 } | |
133 | |
134 void WebDragData::setPlainText(const WebString& plainText) | |
135 { | |
136 ensureMutable(); | |
137 m_private->plainText = plainText; | |
138 } | |
139 | |
140 WebString WebDragData::htmlText() const | |
141 { | |
142 ASSERT(!isNull()); | |
143 return m_private->textHtml; | |
144 } | |
145 | |
146 void WebDragData::setHTMLText(const WebString& htmlText) | |
147 { | |
148 ensureMutable(); | |
149 m_private->textHtml = htmlText; | |
150 } | |
151 | |
152 WebURL WebDragData::htmlBaseURL() const | |
153 { | |
154 ASSERT(!isNull()); | |
155 return m_private->htmlBaseUrl; | |
156 } | |
157 | |
158 void WebDragData::setHTMLBaseURL(const WebURL& htmlBaseURL) | |
159 { | |
160 ensureMutable(); | |
161 m_private->htmlBaseUrl = htmlBaseURL; | |
162 } | |
163 | |
164 WebString WebDragData::fileContentFileName() const | |
165 { | |
166 ASSERT(!isNull()); | |
167 return m_private->fileContentFilename; | |
168 } | |
169 | |
170 void WebDragData::setFileContentFileName(const WebString& fileName) | |
171 { | |
172 ensureMutable(); | |
173 m_private->fileContentFilename = fileName; | |
174 } | |
175 | |
176 WebData WebDragData::fileContent() const | |
177 { | |
178 ASSERT(!isNull()); | |
179 return WebData(m_private->fileContent); | |
180 } | |
181 | |
182 void WebDragData::setFileContent(const WebData& fileContent) | |
183 { | |
184 ensureMutable(); | |
185 m_private->fileContent = fileContent; | |
186 } | |
187 | |
188 WebDragData::WebDragData(const WTF::PassRefPtr<WebCore::ChromiumDataObject>& data) | |
189 : m_private(static_cast<WebDragDataPrivate*>(data.releaseRef())) | |
190 { | |
191 } | |
192 | |
193 WebDragData& WebDragData::operator=(const WTF::PassRefPtr<WebCore::ChromiumDataObject>& data) | |
194 { | |
195 assign(static_cast<WebDragDataPrivate*>(data.releaseRef())); | |
196 return *this; | |
197 } | |
198 | |
199 WebDragData::operator WTF::PassRefPtr<WebCore::ChromiumDataObject>() const | |
200 { | |
201 return PassRefPtr<ChromiumDataObject>(const_cast<WebDragDataPrivate*>(m_private)); | |
202 } | |
203 | |
204 void WebDragData::assign(WebDragDataPrivate* p) | |
205 { | |
206 // p is already ref'd for us by the caller | |
207 if (m_private) | |
208 m_private->deref(); | |
209 m_private = p; | |
210 } | |
211 | |
212 void WebDragData::ensureMutable() | |
213 { | |
214 ASSERT(!isNull()); | |
215 if (!m_private->hasOneRef()) | |
216 assign(static_cast<WebDragDataPrivate*>(m_private->copy().releaseRef())); | |
217 } | |
218 | |
219 } // namespace WebKit | |
OLD | NEW |