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 13 matching lines...) Expand all Loading... | |
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/core/v8/ExceptionState.h" | 29 #include "bindings/core/v8/ExceptionState.h" |
30 #include "core/dom/ExceptionCode.h" | 30 #include "core/dom/ExceptionCode.h" |
31 #include "core/fileapi/FilePropertyBag.h" | 31 #include "core/fileapi/FilePropertyBag.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 "public/platform/Platform.h" | 35 #include "public/platform/Platform.h" |
35 #include "public/platform/WebFileUtilities.h" | 36 #include "public/platform/WebFileUtilities.h" |
36 #include "wtf/CurrentTime.h" | 37 #include "wtf/CurrentTime.h" |
37 #include "wtf/DateMath.h" | 38 #include "wtf/DateMath.h" |
38 | 39 |
39 namespace blink { | 40 namespace blink { |
40 | 41 |
41 static String getContentTypeFromFileName(const String& name, File::ContentTypeLo okupPolicy policy) | 42 static String getContentTypeFromFileName(const String& name, File::ContentTypeLo okupPolicy policy) |
42 { | 43 { |
43 String type; | 44 String type; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 if (!options.type().containsOnlyASCII()) { | 95 if (!options.type().containsOnlyASCII()) { |
95 exceptionState.throwDOMException(SyntaxError, "The 'type' property must consist of ASCII characters."); | 96 exceptionState.throwDOMException(SyntaxError, "The 'type' property must consist of ASCII characters."); |
96 return nullptr; | 97 return nullptr; |
97 } | 98 } |
98 | 99 |
99 double lastModified; | 100 double lastModified; |
100 if (options.hasLastModified()) | 101 if (options.hasLastModified()) |
101 lastModified = static_cast<double>(options.lastModified()); | 102 lastModified = static_cast<double>(options.lastModified()); |
102 else | 103 else |
103 lastModified = currentTimeMS(); | 104 lastModified = currentTimeMS(); |
104 | |
105 ASSERT(options.hasEndings()); | 105 ASSERT(options.hasEndings()); |
106 bool normalizeLineEndingsToNative = options.endings() == "native"; | 106 bool normalizeLineEndingsToNative = options.endings() == "native"; |
107 | 107 |
108 OwnPtr<BlobData> blobData = BlobData::create(); | 108 OwnPtr<BlobData> blobData = BlobData::create(); |
109 blobData->setContentType(options.type().lower()); | 109 blobData->setContentType(options.type().lower()); |
110 populateBlobData(blobData.get(), fileBits, normalizeLineEndingsToNative); | 110 populateBlobData(blobData.get(), fileBits, normalizeLineEndingsToNative); |
111 | 111 |
112 long long fileSize = blobData->length(); | 112 long long fileSize = blobData->length(); |
113 return File::create(fileName, lastModified, BlobDataHandle::create(blobData. release(), fileSize)); | 113 return File::create(fileName, lastModified, BlobDataHandle::create(blobData. release(), fileSize)); |
114 } | 114 } |
115 | 115 |
116 File* File::create(Vector<char>* encodedImage, const String& mimeType) | |
117 { | |
118 ASSERT(encodedImage); | |
119 | |
120 OwnPtr<BlobData> blobData = BlobData::create(); | |
121 blobData->setContentType(mimeType); | |
Justin Novosad
2015/08/13 21:03:40
your test should be checking that setting the mime
xlai (Olivia)
2015/08/20 19:46:44
Acknowledged. Planning to write one more layout te
| |
122 blobData->appendBytes(encodedImage->data(), encodedImage->size()); | |
123 long long blobSize = blobData->length(); | |
124 | |
125 // create blob as the type of file with two additional attributes -- name an d lastModificationTime | |
126 return File::create("", currentTimeMS(), BlobDataHandle::create(blobData.rel ease(), blobSize)); | |
127 } | |
128 | |
116 File* File::createWithRelativePath(const String& path, const String& relativePat h) | 129 File* File::createWithRelativePath(const String& path, const String& relativePat h) |
117 { | 130 { |
118 File* file = new File(path, File::AllContentTypes, File::IsUserVisible); | 131 File* file = new File(path, File::AllContentTypes, File::IsUserVisible); |
119 file->m_relativePath = relativePath; | 132 file->m_relativePath = relativePath; |
120 return file; | 133 return file; |
121 } | 134 } |
122 | 135 |
123 File::File(const String& path, ContentTypeLookupPolicy policy, UserVisibility us erVisibility) | 136 File::File(const String& path, ContentTypeLookupPolicy policy, UserVisibility us erVisibility) |
124 : Blob(BlobDataHandle::create(createBlobDataForFile(path, policy), -1)) | 137 : Blob(BlobDataHandle::create(createBlobDataForFile(path, policy), -1)) |
125 , m_hasBackingFile(true) | 138 , m_hasBackingFile(true) |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
355 if (m_fileSystemURL.isEmpty() != other.m_fileSystemURL.isEmpty()) | 368 if (m_fileSystemURL.isEmpty() != other.m_fileSystemURL.isEmpty()) |
356 return false; | 369 return false; |
357 | 370 |
358 if (!m_fileSystemURL.isEmpty()) | 371 if (!m_fileSystemURL.isEmpty()) |
359 return m_fileSystemURL == other.m_fileSystemURL; | 372 return m_fileSystemURL == other.m_fileSystemURL; |
360 | 373 |
361 return uuid() == other.uuid(); | 374 return uuid() == other.uuid(); |
362 } | 375 } |
363 | 376 |
364 } // namespace blink | 377 } // namespace blink |
OLD | NEW |