OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include "core/fileapi/File.h" | 27 #include "core/fileapi/File.h" |
28 | 28 |
| 29 #include "bindings/v8/ExceptionState.h" |
| 30 #include "core/dom/ExceptionCode.h" |
29 #include "platform/FileMetadata.h" | 31 #include "platform/FileMetadata.h" |
30 #include "platform/MIMETypeRegistry.h" | 32 #include "platform/MIMETypeRegistry.h" |
31 #include "public/platform/Platform.h" | 33 #include "public/platform/Platform.h" |
32 #include "public/platform/WebFileUtilities.h" | 34 #include "public/platform/WebFileUtilities.h" |
33 #include "wtf/CurrentTime.h" | 35 #include "wtf/CurrentTime.h" |
34 #include "wtf/DateMath.h" | 36 #include "wtf/DateMath.h" |
35 | 37 |
36 namespace WebCore { | 38 namespace WebCore { |
37 | 39 |
38 static String getContentTypeFromFileName(const String& name, File::ContentTypeLo
okupPolicy policy) | 40 static String getContentTypeFromFileName(const String& name, File::ContentTypeLo
okupPolicy policy) |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 return m_snapshotSize; | 176 return m_snapshotSize; |
175 | 177 |
176 // FIXME: JavaScript cannot represent sizes as large as unsigned long long,
we need to | 178 // FIXME: JavaScript cannot represent sizes as large as unsigned long long,
we need to |
177 // come up with an exception to throw if file size is not representable. | 179 // come up with an exception to throw if file size is not representable. |
178 long long size; | 180 long long size; |
179 if (!hasBackingFile() || !getFileSize(m_path, size)) | 181 if (!hasBackingFile() || !getFileSize(m_path, size)) |
180 return 0; | 182 return 0; |
181 return static_cast<unsigned long long>(size); | 183 return static_cast<unsigned long long>(size); |
182 } | 184 } |
183 | 185 |
184 PassRefPtrWillBeRawPtr<Blob> File::slice(long long start, long long end, const S
tring& contentType) const | 186 PassRefPtrWillBeRawPtr<Blob> File::slice(long long start, long long end, const S
tring& contentType, ExceptionState& exceptionState) const |
185 { | 187 { |
| 188 if (hasBeenClosed()) { |
| 189 exceptionState.throwDOMException(InvalidStateError, "File has been close
d."); |
| 190 return nullptr; |
| 191 } |
| 192 |
186 if (!m_hasBackingFile) | 193 if (!m_hasBackingFile) |
187 return Blob::slice(start, end, contentType); | 194 return Blob::slice(start, end, contentType, exceptionState); |
188 | 195 |
189 // FIXME: This involves synchronous file operation. We need to figure out ho
w to make it asynchronous. | 196 // FIXME: This involves synchronous file operation. We need to figure out ho
w to make it asynchronous. |
190 long long size; | 197 long long size; |
191 double modificationTime; | 198 double modificationTime; |
192 captureSnapshot(size, modificationTime); | 199 captureSnapshot(size, modificationTime); |
193 clampSliceOffsets(size, start, end); | 200 clampSliceOffsets(size, start, end); |
194 | 201 |
195 long long length = end - start; | 202 long long length = end - start; |
196 OwnPtr<BlobData> blobData = BlobData::create(); | 203 OwnPtr<BlobData> blobData = BlobData::create(); |
197 blobData->setContentType(contentType); | 204 blobData->setContentType(contentType); |
(...skipping 20 matching lines...) Expand all Loading... |
218 if (!hasBackingFile() || !getFileMetadata(m_path, metadata)) { | 225 if (!hasBackingFile() || !getFileMetadata(m_path, metadata)) { |
219 snapshotSize = 0; | 226 snapshotSize = 0; |
220 snapshotModificationTime = invalidFileTime(); | 227 snapshotModificationTime = invalidFileTime(); |
221 return; | 228 return; |
222 } | 229 } |
223 | 230 |
224 snapshotSize = metadata.length; | 231 snapshotSize = metadata.length; |
225 snapshotModificationTime = metadata.modificationTime; | 232 snapshotModificationTime = metadata.modificationTime; |
226 } | 233 } |
227 | 234 |
228 void File::close(ExecutionContext* executionContext) | 235 void File::close(ExecutionContext* executionContext, ExceptionState& exceptionSt
ate) |
229 { | 236 { |
230 if (!hasBeenClosed()) { | 237 if (hasBeenClosed()) { |
231 // Reset the File to its closed representation, an empty | 238 exceptionState.throwDOMException(InvalidStateError, "Blob has been close
d."); |
232 // Blob. The name isn't cleared, as it should still be | 239 return; |
233 // available. | |
234 m_hasBackingFile = false; | |
235 m_path = String(); | |
236 m_fileSystemURL = KURL(); | |
237 invalidateSnapshotMetadata(); | |
238 m_relativePath = String(); | |
239 Blob::close(executionContext); | |
240 } | 240 } |
| 241 |
| 242 // Reset the File to its closed representation, an empty |
| 243 // Blob. The name isn't cleared, as it should still be |
| 244 // available. |
| 245 m_hasBackingFile = false; |
| 246 m_path = String(); |
| 247 m_fileSystemURL = KURL(); |
| 248 invalidateSnapshotMetadata(); |
| 249 m_relativePath = String(); |
| 250 Blob::close(executionContext, exceptionState); |
241 } | 251 } |
242 | 252 |
243 void File::appendTo(BlobData& blobData) const | 253 void File::appendTo(BlobData& blobData) const |
244 { | 254 { |
245 if (!m_hasBackingFile) { | 255 if (!m_hasBackingFile) { |
246 Blob::appendTo(blobData); | 256 Blob::appendTo(blobData); |
247 return; | 257 return; |
248 } | 258 } |
249 | 259 |
250 // FIXME: This involves synchronous file operation. We need to figure out ho
w to make it asynchronous. | 260 // FIXME: This involves synchronous file operation. We need to figure out ho
w to make it asynchronous. |
251 long long size; | 261 long long size; |
252 double modificationTime; | 262 double modificationTime; |
253 captureSnapshot(size, modificationTime); | 263 captureSnapshot(size, modificationTime); |
254 if (!m_fileSystemURL.isEmpty()) { | 264 if (!m_fileSystemURL.isEmpty()) { |
255 blobData.appendFileSystemURL(m_fileSystemURL, 0, size, modificationTime)
; | 265 blobData.appendFileSystemURL(m_fileSystemURL, 0, size, modificationTime)
; |
256 return; | 266 return; |
257 } | 267 } |
258 ASSERT(!m_path.isEmpty()); | 268 ASSERT(!m_path.isEmpty()); |
259 blobData.appendFile(m_path, 0, size, modificationTime); | 269 blobData.appendFile(m_path, 0, size, modificationTime); |
260 } | 270 } |
261 | 271 |
262 } // namespace WebCore | 272 } // namespace WebCore |
OLD | NEW |