| 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 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "core/dom/ExceptionCode.h" | 29 #include "core/dom/ExceptionCode.h" |
| 30 #include "core/fileapi/FilePropertyBag.h" | 30 #include "core/fileapi/FilePropertyBag.h" |
| 31 #include "core/frame/UseCounter.h" | 31 #include "core/frame/UseCounter.h" |
| 32 #include "platform/FileMetadata.h" | 32 #include "platform/FileMetadata.h" |
| 33 #include "platform/MIMETypeRegistry.h" | 33 #include "platform/MIMETypeRegistry.h" |
| 34 #include "platform/blob/BlobData.h" | 34 #include "platform/blob/BlobData.h" |
| 35 #include "public/platform/Platform.h" | 35 #include "public/platform/Platform.h" |
| 36 #include "public/platform/WebFileUtilities.h" | 36 #include "public/platform/WebFileUtilities.h" |
| 37 #include "wtf/CurrentTime.h" | 37 #include "wtf/CurrentTime.h" |
| 38 #include "wtf/DateMath.h" | 38 #include "wtf/DateMath.h" |
| 39 #include <memory> |
| 39 | 40 |
| 40 namespace blink { | 41 namespace blink { |
| 41 | 42 |
| 42 static String getContentTypeFromFileName(const String& name, File::ContentTypeLo
okupPolicy policy) | 43 static String getContentTypeFromFileName(const String& name, File::ContentTypeLo
okupPolicy policy) |
| 43 { | 44 { |
| 44 String type; | 45 String type; |
| 45 int index = name.reverseFind('.'); | 46 int index = name.reverseFind('.'); |
| 46 if (index != -1) { | 47 if (index != -1) { |
| 47 if (policy == File::WellKnownContentTypes) { | 48 if (policy == File::WellKnownContentTypes) { |
| 48 type = MIMETypeRegistry::getWellKnownMIMETypeForExtension(name.subst
ring(index + 1)); | 49 type = MIMETypeRegistry::getWellKnownMIMETypeForExtension(name.subst
ring(index + 1)); |
| 49 } else { | 50 } else { |
| 50 ASSERT(policy == File::AllContentTypes); | 51 ASSERT(policy == File::AllContentTypes); |
| 51 type = MIMETypeRegistry::getMIMETypeForExtension(name.substring(inde
x + 1)); | 52 type = MIMETypeRegistry::getMIMETypeForExtension(name.substring(inde
x + 1)); |
| 52 } | 53 } |
| 53 } | 54 } |
| 54 return type; | 55 return type; |
| 55 } | 56 } |
| 56 | 57 |
| 57 static PassOwnPtr<BlobData> createBlobDataForFileWithType(const String& path, co
nst String& contentType) | 58 static std::unique_ptr<BlobData> createBlobDataForFileWithType(const String& pat
h, const String& contentType) |
| 58 { | 59 { |
| 59 OwnPtr<BlobData> blobData = BlobData::create(); | 60 std::unique_ptr<BlobData> blobData = BlobData::create(); |
| 60 blobData->setContentType(contentType); | 61 blobData->setContentType(contentType); |
| 61 blobData->appendFile(path); | 62 blobData->appendFile(path); |
| 62 return blobData; | 63 return blobData; |
| 63 } | 64 } |
| 64 | 65 |
| 65 static PassOwnPtr<BlobData> createBlobDataForFile(const String& path, File::Cont
entTypeLookupPolicy policy) | 66 static std::unique_ptr<BlobData> createBlobDataForFile(const String& path, File:
:ContentTypeLookupPolicy policy) |
| 66 { | 67 { |
| 67 return createBlobDataForFileWithType(path, getContentTypeFromFileName(path,
policy)); | 68 return createBlobDataForFileWithType(path, getContentTypeFromFileName(path,
policy)); |
| 68 } | 69 } |
| 69 | 70 |
| 70 static PassOwnPtr<BlobData> createBlobDataForFileWithName(const String& path, co
nst String& fileSystemName, File::ContentTypeLookupPolicy policy) | 71 static std::unique_ptr<BlobData> createBlobDataForFileWithName(const String& pat
h, const String& fileSystemName, File::ContentTypeLookupPolicy policy) |
| 71 { | 72 { |
| 72 return createBlobDataForFileWithType(path, getContentTypeFromFileName(fileSy
stemName, policy)); | 73 return createBlobDataForFileWithType(path, getContentTypeFromFileName(fileSy
stemName, policy)); |
| 73 } | 74 } |
| 74 | 75 |
| 75 static PassOwnPtr<BlobData> createBlobDataForFileWithMetadata(const String& file
SystemName, const FileMetadata& metadata) | 76 static std::unique_ptr<BlobData> createBlobDataForFileWithMetadata(const String&
fileSystemName, const FileMetadata& metadata) |
| 76 { | 77 { |
| 77 OwnPtr<BlobData> blobData = BlobData::create(); | 78 std::unique_ptr<BlobData> blobData = BlobData::create(); |
| 78 blobData->setContentType(getContentTypeFromFileName(fileSystemName, File::We
llKnownContentTypes)); | 79 blobData->setContentType(getContentTypeFromFileName(fileSystemName, File::We
llKnownContentTypes)); |
| 79 blobData->appendFile(metadata.platformPath, 0, metadata.length, metadata.mod
ificationTime / msPerSecond); | 80 blobData->appendFile(metadata.platformPath, 0, metadata.length, metadata.mod
ificationTime / msPerSecond); |
| 80 return blobData; | 81 return blobData; |
| 81 } | 82 } |
| 82 | 83 |
| 83 static PassOwnPtr<BlobData> createBlobDataForFileSystemURL(const KURL& fileSyste
mURL, const FileMetadata& metadata) | 84 static std::unique_ptr<BlobData> createBlobDataForFileSystemURL(const KURL& file
SystemURL, const FileMetadata& metadata) |
| 84 { | 85 { |
| 85 OwnPtr<BlobData> blobData = BlobData::create(); | 86 std::unique_ptr<BlobData> blobData = BlobData::create(); |
| 86 blobData->setContentType(getContentTypeFromFileName(fileSystemURL.path(), Fi
le::WellKnownContentTypes)); | 87 blobData->setContentType(getContentTypeFromFileName(fileSystemURL.path(), Fi
le::WellKnownContentTypes)); |
| 87 blobData->appendFileSystemURL(fileSystemURL, 0, metadata.length, metadata.mo
dificationTime / msPerSecond); | 88 blobData->appendFileSystemURL(fileSystemURL, 0, metadata.length, metadata.mo
dificationTime / msPerSecond); |
| 88 return blobData; | 89 return blobData; |
| 89 } | 90 } |
| 90 | 91 |
| 91 // static | 92 // static |
| 92 File* File::create(ExecutionContext* context, const HeapVector<ArrayBufferOrArra
yBufferViewOrBlobOrUSVString>& fileBits, const String& fileName, const FilePrope
rtyBag& options, ExceptionState& exceptionState) | 93 File* File::create(ExecutionContext* context, const HeapVector<ArrayBufferOrArra
yBufferViewOrBlobOrUSVString>& fileBits, const String& fileName, const FilePrope
rtyBag& options, ExceptionState& exceptionState) |
| 93 { | 94 { |
| 94 ASSERT(options.hasType()); | 95 ASSERT(options.hasType()); |
| 95 if (!options.type().containsOnlyASCII()) { | 96 if (!options.type().containsOnlyASCII()) { |
| 96 exceptionState.throwDOMException(SyntaxError, "The 'type' property must
consist of ASCII characters."); | 97 exceptionState.throwDOMException(SyntaxError, "The 'type' property must
consist of ASCII characters."); |
| 97 return nullptr; | 98 return nullptr; |
| 98 } | 99 } |
| 99 | 100 |
| 100 double lastModified; | 101 double lastModified; |
| 101 if (options.hasLastModified()) | 102 if (options.hasLastModified()) |
| 102 lastModified = static_cast<double>(options.lastModified()); | 103 lastModified = static_cast<double>(options.lastModified()); |
| 103 else | 104 else |
| 104 lastModified = currentTimeMS(); | 105 lastModified = currentTimeMS(); |
| 105 ASSERT(options.hasEndings()); | 106 ASSERT(options.hasEndings()); |
| 106 bool normalizeLineEndingsToNative = options.endings() == "native"; | 107 bool normalizeLineEndingsToNative = options.endings() == "native"; |
| 107 if (normalizeLineEndingsToNative) | 108 if (normalizeLineEndingsToNative) |
| 108 UseCounter::count(context, UseCounter::FileAPINativeLineEndings); | 109 UseCounter::count(context, UseCounter::FileAPINativeLineEndings); |
| 109 | 110 |
| 110 OwnPtr<BlobData> blobData = BlobData::create(); | 111 std::unique_ptr<BlobData> blobData = BlobData::create(); |
| 111 blobData->setContentType(options.type().lower()); | 112 blobData->setContentType(options.type().lower()); |
| 112 populateBlobData(blobData.get(), fileBits, normalizeLineEndingsToNative); | 113 populateBlobData(blobData.get(), fileBits, normalizeLineEndingsToNative); |
| 113 | 114 |
| 114 long long fileSize = blobData->length(); | 115 long long fileSize = blobData->length(); |
| 115 return File::create(fileName, lastModified, BlobDataHandle::create(std::move
(blobData), fileSize)); | 116 return File::create(fileName, lastModified, BlobDataHandle::create(std::move
(blobData), fileSize)); |
| 116 } | 117 } |
| 117 | 118 |
| 118 File* File::createWithRelativePath(const String& path, const String& relativePat
h) | 119 File* File::createWithRelativePath(const String& path, const String& relativePat
h) |
| 119 { | 120 { |
| 120 File* file = new File(path, File::AllContentTypes, File::IsUserVisible); | 121 File* file = new File(path, File::AllContentTypes, File::IsUserVisible); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 if (!m_hasBackingFile) | 271 if (!m_hasBackingFile) |
| 271 return Blob::slice(start, end, contentType, exceptionState); | 272 return Blob::slice(start, end, contentType, exceptionState); |
| 272 | 273 |
| 273 // FIXME: This involves synchronous file operation. We need to figure out ho
w to make it asynchronous. | 274 // FIXME: This involves synchronous file operation. We need to figure out ho
w to make it asynchronous. |
| 274 long long size; | 275 long long size; |
| 275 double modificationTimeMS; | 276 double modificationTimeMS; |
| 276 captureSnapshot(size, modificationTimeMS); | 277 captureSnapshot(size, modificationTimeMS); |
| 277 clampSliceOffsets(size, start, end); | 278 clampSliceOffsets(size, start, end); |
| 278 | 279 |
| 279 long long length = end - start; | 280 long long length = end - start; |
| 280 OwnPtr<BlobData> blobData = BlobData::create(); | 281 std::unique_ptr<BlobData> blobData = BlobData::create(); |
| 281 blobData->setContentType(contentType); | 282 blobData->setContentType(contentType); |
| 282 if (!m_fileSystemURL.isEmpty()) { | 283 if (!m_fileSystemURL.isEmpty()) { |
| 283 blobData->appendFileSystemURL(m_fileSystemURL, start, length, modificati
onTimeMS / msPerSecond); | 284 blobData->appendFileSystemURL(m_fileSystemURL, start, length, modificati
onTimeMS / msPerSecond); |
| 284 } else { | 285 } else { |
| 285 ASSERT(!m_path.isEmpty()); | 286 ASSERT(!m_path.isEmpty()); |
| 286 blobData->appendFile(m_path, start, length, modificationTimeMS / msPerSe
cond); | 287 blobData->appendFile(m_path, start, length, modificationTimeMS / msPerSe
cond); |
| 287 } | 288 } |
| 288 return Blob::create(BlobDataHandle::create(std::move(blobData), length)); | 289 return Blob::create(BlobDataHandle::create(std::move(blobData), length)); |
| 289 } | 290 } |
| 290 | 291 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 if (m_fileSystemURL.isEmpty() != other.m_fileSystemURL.isEmpty()) | 358 if (m_fileSystemURL.isEmpty() != other.m_fileSystemURL.isEmpty()) |
| 358 return false; | 359 return false; |
| 359 | 360 |
| 360 if (!m_fileSystemURL.isEmpty()) | 361 if (!m_fileSystemURL.isEmpty()) |
| 361 return m_fileSystemURL == other.m_fileSystemURL; | 362 return m_fileSystemURL == other.m_fileSystemURL; |
| 362 | 363 |
| 363 return uuid() == other.uuid(); | 364 return uuid() == other.uuid(); |
| 364 } | 365 } |
| 365 | 366 |
| 366 } // namespace blink | 367 } // namespace blink |
| OLD | NEW |