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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 } | 105 } |
106 | 106 |
107 // static | 107 // static |
108 File* File::create( | 108 File* File::create( |
109 ExecutionContext* context, | 109 ExecutionContext* context, |
110 const HeapVector<ArrayBufferOrArrayBufferViewOrBlobOrUSVString>& fileBits, | 110 const HeapVector<ArrayBufferOrArrayBufferViewOrBlobOrUSVString>& fileBits, |
111 const String& fileName, | 111 const String& fileName, |
112 const FilePropertyBag& options, | 112 const FilePropertyBag& options, |
113 ExceptionState& exceptionState) { | 113 ExceptionState& exceptionState) { |
114 ASSERT(options.hasType()); | 114 ASSERT(options.hasType()); |
115 if (!options.type().containsOnlyASCII()) { | |
116 exceptionState.throwDOMException( | |
117 SyntaxError, "The 'type' property must consist of ASCII characters."); | |
118 return nullptr; | |
119 } | |
120 | 115 |
121 double lastModified; | 116 double lastModified; |
122 if (options.hasLastModified()) | 117 if (options.hasLastModified()) |
123 lastModified = static_cast<double>(options.lastModified()); | 118 lastModified = static_cast<double>(options.lastModified()); |
124 else | 119 else |
125 lastModified = currentTimeMS(); | 120 lastModified = currentTimeMS(); |
126 ASSERT(options.hasEndings()); | 121 ASSERT(options.hasEndings()); |
127 bool normalizeLineEndingsToNative = options.endings() == "native"; | 122 bool normalizeLineEndingsToNative = options.endings() == "native"; |
128 if (normalizeLineEndingsToNative) | 123 if (normalizeLineEndingsToNative) |
129 UseCounter::count(context, UseCounter::FileAPINativeLineEndings); | 124 UseCounter::count(context, UseCounter::FileAPINativeLineEndings); |
130 | 125 |
131 std::unique_ptr<BlobData> blobData = BlobData::create(); | 126 std::unique_ptr<BlobData> blobData = BlobData::create(); |
132 blobData->setContentType(options.type().lower()); | 127 blobData->setContentType(normalizeType(options.type())); |
133 populateBlobData(blobData.get(), fileBits, normalizeLineEndingsToNative); | 128 populateBlobData(blobData.get(), fileBits, normalizeLineEndingsToNative); |
134 | 129 |
135 long long fileSize = blobData->length(); | 130 long long fileSize = blobData->length(); |
136 return File::create(fileName, lastModified, | 131 return File::create(fileName, lastModified, |
137 BlobDataHandle::create(std::move(blobData), fileSize)); | 132 BlobDataHandle::create(std::move(blobData), fileSize)); |
138 } | 133 } |
139 | 134 |
140 File* File::createWithRelativePath(const String& path, | 135 File* File::createWithRelativePath(const String& path, |
141 const String& relativePath) { | 136 const String& relativePath) { |
142 File* file = new File(path, File::AllContentTypes, File::IsUserVisible); | 137 File* file = new File(path, File::AllContentTypes, File::IsUserVisible); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 | 303 |
309 // FIXME: This involves synchronous file operation. We need to figure out how | 304 // FIXME: This involves synchronous file operation. We need to figure out how |
310 // to make it asynchronous. | 305 // to make it asynchronous. |
311 long long size; | 306 long long size; |
312 double modificationTimeMS; | 307 double modificationTimeMS; |
313 captureSnapshot(size, modificationTimeMS); | 308 captureSnapshot(size, modificationTimeMS); |
314 clampSliceOffsets(size, start, end); | 309 clampSliceOffsets(size, start, end); |
315 | 310 |
316 long long length = end - start; | 311 long long length = end - start; |
317 std::unique_ptr<BlobData> blobData = BlobData::create(); | 312 std::unique_ptr<BlobData> blobData = BlobData::create(); |
318 blobData->setContentType(contentType); | 313 blobData->setContentType(normalizeType(contentType)); |
319 if (!m_fileSystemURL.isEmpty()) { | 314 if (!m_fileSystemURL.isEmpty()) { |
320 blobData->appendFileSystemURL(m_fileSystemURL, start, length, | 315 blobData->appendFileSystemURL(m_fileSystemURL, start, length, |
321 modificationTimeMS / msPerSecond); | 316 modificationTimeMS / msPerSecond); |
322 } else { | 317 } else { |
323 ASSERT(!m_path.isEmpty()); | 318 ASSERT(!m_path.isEmpty()); |
324 blobData->appendFile(m_path, start, length, | 319 blobData->appendFile(m_path, start, length, |
325 modificationTimeMS / msPerSecond); | 320 modificationTimeMS / msPerSecond); |
326 } | 321 } |
327 return Blob::create(BlobDataHandle::create(std::move(blobData), length)); | 322 return Blob::create(BlobDataHandle::create(std::move(blobData), length)); |
328 } | 323 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 if (m_fileSystemURL.isEmpty() != other.m_fileSystemURL.isEmpty()) | 393 if (m_fileSystemURL.isEmpty() != other.m_fileSystemURL.isEmpty()) |
399 return false; | 394 return false; |
400 | 395 |
401 if (!m_fileSystemURL.isEmpty()) | 396 if (!m_fileSystemURL.isEmpty()) |
402 return m_fileSystemURL == other.m_fileSystemURL; | 397 return m_fileSystemURL == other.m_fileSystemURL; |
403 | 398 |
404 return uuid() == other.uuid(); | 399 return uuid() == other.uuid(); |
405 } | 400 } |
406 | 401 |
407 } // namespace blink | 402 } // namespace blink |
OLD | NEW |