| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 return type; | 54 return type; |
| 55 } | 55 } |
| 56 | 56 |
| 57 static PassOwnPtr<BlobData> createBlobDataForFileWithType(const String& path, co
nst String& contentType) | 57 static PassOwnPtr<BlobData> createBlobDataForFileWithType(const String& path, co
nst String& contentType) |
| 58 { | 58 { |
| 59 OwnPtr<BlobData> blobData = BlobData::create(); | 59 OwnPtr<BlobData> blobData = BlobData::create(); |
| 60 blobData->setContentType(contentType); | 60 blobData->setContentType(contentType); |
| 61 blobData->appendFile(path); | 61 blobData->appendFile(path); |
| 62 return blobData.release(); | 62 return blobData; |
| 63 } | 63 } |
| 64 | 64 |
| 65 static PassOwnPtr<BlobData> createBlobDataForFile(const String& path, File::Cont
entTypeLookupPolicy policy) | 65 static PassOwnPtr<BlobData> createBlobDataForFile(const String& path, File::Cont
entTypeLookupPolicy policy) |
| 66 { | 66 { |
| 67 return createBlobDataForFileWithType(path, getContentTypeFromFileName(path,
policy)); | 67 return createBlobDataForFileWithType(path, getContentTypeFromFileName(path,
policy)); |
| 68 } | 68 } |
| 69 | 69 |
| 70 static PassOwnPtr<BlobData> createBlobDataForFileWithName(const String& path, co
nst String& fileSystemName, File::ContentTypeLookupPolicy policy) | 70 static PassOwnPtr<BlobData> createBlobDataForFileWithName(const String& path, co
nst String& fileSystemName, File::ContentTypeLookupPolicy policy) |
| 71 { | 71 { |
| 72 return createBlobDataForFileWithType(path, getContentTypeFromFileName(fileSy
stemName, policy)); | 72 return createBlobDataForFileWithType(path, getContentTypeFromFileName(fileSy
stemName, policy)); |
| 73 } | 73 } |
| 74 | 74 |
| 75 static PassOwnPtr<BlobData> createBlobDataForFileWithMetadata(const String& file
SystemName, const FileMetadata& metadata) | 75 static PassOwnPtr<BlobData> createBlobDataForFileWithMetadata(const String& file
SystemName, const FileMetadata& metadata) |
| 76 { | 76 { |
| 77 OwnPtr<BlobData> blobData = BlobData::create(); | 77 OwnPtr<BlobData> blobData = BlobData::create(); |
| 78 blobData->setContentType(getContentTypeFromFileName(fileSystemName, File::We
llKnownContentTypes)); | 78 blobData->setContentType(getContentTypeFromFileName(fileSystemName, File::We
llKnownContentTypes)); |
| 79 blobData->appendFile(metadata.platformPath, 0, metadata.length, metadata.mod
ificationTime / msPerSecond); | 79 blobData->appendFile(metadata.platformPath, 0, metadata.length, metadata.mod
ificationTime / msPerSecond); |
| 80 return blobData.release(); | 80 return blobData; |
| 81 } | 81 } |
| 82 | 82 |
| 83 static PassOwnPtr<BlobData> createBlobDataForFileSystemURL(const KURL& fileSyste
mURL, const FileMetadata& metadata) | 83 static PassOwnPtr<BlobData> createBlobDataForFileSystemURL(const KURL& fileSyste
mURL, const FileMetadata& metadata) |
| 84 { | 84 { |
| 85 OwnPtr<BlobData> blobData = BlobData::create(); | 85 OwnPtr<BlobData> blobData = BlobData::create(); |
| 86 blobData->setContentType(getContentTypeFromFileName(fileSystemURL.path(), Fi
le::WellKnownContentTypes)); | 86 blobData->setContentType(getContentTypeFromFileName(fileSystemURL.path(), Fi
le::WellKnownContentTypes)); |
| 87 blobData->appendFileSystemURL(fileSystemURL, 0, metadata.length, metadata.mo
dificationTime / msPerSecond); | 87 blobData->appendFileSystemURL(fileSystemURL, 0, metadata.length, metadata.mo
dificationTime / msPerSecond); |
| 88 return blobData.release(); | 88 return blobData; |
| 89 } | 89 } |
| 90 | 90 |
| 91 // static | 91 // static |
| 92 File* File::create(ExecutionContext* context, const HeapVector<ArrayBufferOrArra
yBufferViewOrBlobOrUSVString>& fileBits, const String& fileName, const FilePrope
rtyBag& options, ExceptionState& exceptionState) | 92 File* File::create(ExecutionContext* context, const HeapVector<ArrayBufferOrArra
yBufferViewOrBlobOrUSVString>& fileBits, const String& fileName, const FilePrope
rtyBag& options, ExceptionState& exceptionState) |
| 93 { | 93 { |
| 94 ASSERT(options.hasType()); | 94 ASSERT(options.hasType()); |
| 95 if (!options.type().containsOnlyASCII()) { | 95 if (!options.type().containsOnlyASCII()) { |
| 96 exceptionState.throwDOMException(SyntaxError, "The 'type' property must
consist of ASCII characters."); | 96 exceptionState.throwDOMException(SyntaxError, "The 'type' property must
consist of ASCII characters."); |
| 97 return nullptr; | 97 return nullptr; |
| 98 } | 98 } |
| 99 | 99 |
| 100 double lastModified; | 100 double lastModified; |
| 101 if (options.hasLastModified()) | 101 if (options.hasLastModified()) |
| 102 lastModified = static_cast<double>(options.lastModified()); | 102 lastModified = static_cast<double>(options.lastModified()); |
| 103 else | 103 else |
| 104 lastModified = currentTimeMS(); | 104 lastModified = currentTimeMS(); |
| 105 ASSERT(options.hasEndings()); | 105 ASSERT(options.hasEndings()); |
| 106 bool normalizeLineEndingsToNative = options.endings() == "native"; | 106 bool normalizeLineEndingsToNative = options.endings() == "native"; |
| 107 if (normalizeLineEndingsToNative) | 107 if (normalizeLineEndingsToNative) |
| 108 UseCounter::count(context, UseCounter::FileAPINativeLineEndings); | 108 UseCounter::count(context, UseCounter::FileAPINativeLineEndings); |
| 109 | 109 |
| 110 OwnPtr<BlobData> blobData = BlobData::create(); | 110 OwnPtr<BlobData> blobData = BlobData::create(); |
| 111 blobData->setContentType(options.type().lower()); | 111 blobData->setContentType(options.type().lower()); |
| 112 populateBlobData(blobData.get(), fileBits, normalizeLineEndingsToNative); | 112 populateBlobData(blobData.get(), fileBits, normalizeLineEndingsToNative); |
| 113 | 113 |
| 114 long long fileSize = blobData->length(); | 114 long long fileSize = blobData->length(); |
| 115 return File::create(fileName, lastModified, BlobDataHandle::create(blobData.
release(), fileSize)); | 115 return File::create(fileName, lastModified, BlobDataHandle::create(std::move
(blobData), fileSize)); |
| 116 } | 116 } |
| 117 | 117 |
| 118 File* File::createWithRelativePath(const String& path, const String& relativePat
h) | 118 File* File::createWithRelativePath(const String& path, const String& relativePat
h) |
| 119 { | 119 { |
| 120 File* file = new File(path, File::AllContentTypes, File::IsUserVisible); | 120 File* file = new File(path, File::AllContentTypes, File::IsUserVisible); |
| 121 file->m_relativePath = relativePath; | 121 file->m_relativePath = relativePath; |
| 122 return file; | 122 return file; |
| 123 } | 123 } |
| 124 | 124 |
| 125 File::File(const String& path, ContentTypeLookupPolicy policy, UserVisibility us
erVisibility) | 125 File::File(const String& path, ContentTypeLookupPolicy policy, UserVisibility us
erVisibility) |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 278 |
| 279 long long length = end - start; | 279 long long length = end - start; |
| 280 OwnPtr<BlobData> blobData = BlobData::create(); | 280 OwnPtr<BlobData> blobData = BlobData::create(); |
| 281 blobData->setContentType(contentType); | 281 blobData->setContentType(contentType); |
| 282 if (!m_fileSystemURL.isEmpty()) { | 282 if (!m_fileSystemURL.isEmpty()) { |
| 283 blobData->appendFileSystemURL(m_fileSystemURL, start, length, modificati
onTimeMS / msPerSecond); | 283 blobData->appendFileSystemURL(m_fileSystemURL, start, length, modificati
onTimeMS / msPerSecond); |
| 284 } else { | 284 } else { |
| 285 ASSERT(!m_path.isEmpty()); | 285 ASSERT(!m_path.isEmpty()); |
| 286 blobData->appendFile(m_path, start, length, modificationTimeMS / msPerSe
cond); | 286 blobData->appendFile(m_path, start, length, modificationTimeMS / msPerSe
cond); |
| 287 } | 287 } |
| 288 return Blob::create(BlobDataHandle::create(blobData.release(), length)); | 288 return Blob::create(BlobDataHandle::create(std::move(blobData), length)); |
| 289 } | 289 } |
| 290 | 290 |
| 291 void File::captureSnapshot(long long& snapshotSize, double& snapshotModification
TimeMS) const | 291 void File::captureSnapshot(long long& snapshotSize, double& snapshotModification
TimeMS) const |
| 292 { | 292 { |
| 293 if (hasValidSnapshotMetadata()) { | 293 if (hasValidSnapshotMetadata()) { |
| 294 snapshotSize = m_snapshotSize; | 294 snapshotSize = m_snapshotSize; |
| 295 snapshotModificationTimeMS = m_snapshotModificationTimeMS; | 295 snapshotModificationTimeMS = m_snapshotModificationTimeMS; |
| 296 return; | 296 return; |
| 297 } | 297 } |
| 298 | 298 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 if (m_fileSystemURL.isEmpty() != other.m_fileSystemURL.isEmpty()) | 357 if (m_fileSystemURL.isEmpty() != other.m_fileSystemURL.isEmpty()) |
| 358 return false; | 358 return false; |
| 359 | 359 |
| 360 if (!m_fileSystemURL.isEmpty()) | 360 if (!m_fileSystemURL.isEmpty()) |
| 361 return m_fileSystemURL == other.m_fileSystemURL; | 361 return m_fileSystemURL == other.m_fileSystemURL; |
| 362 | 362 |
| 363 return uuid() == other.uuid(); | 363 return uuid() == other.uuid(); |
| 364 } | 364 } |
| 365 | 365 |
| 366 } // namespace blink | 366 } // namespace blink |
| OLD | NEW |