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 16 matching lines...) Expand all Loading... |
27 #include "File.h" | 27 #include "File.h" |
28 | 28 |
29 #include "FileMetadata.h" | 29 #include "FileMetadata.h" |
30 #include "FileSystem.h" | 30 #include "FileSystem.h" |
31 #include "MIMETypeRegistry.h" | 31 #include "MIMETypeRegistry.h" |
32 #include <wtf/CurrentTime.h> | 32 #include <wtf/CurrentTime.h> |
33 #include <wtf/text/WTFString.h> | 33 #include <wtf/text/WTFString.h> |
34 | 34 |
35 namespace WebCore { | 35 namespace WebCore { |
36 | 36 |
37 static String getContentTypeFromFileName(const String& name) | 37 static String getContentTypeFromFileName(const String& name, File::ContentTypeLo
okupPolicy policy) |
38 { | 38 { |
39 String type; | 39 String type; |
40 int index = name.reverseFind('.'); | 40 int index = name.reverseFind('.'); |
41 if (index != -1) | 41 if (index != -1) { |
42 type = MIMETypeRegistry::getWellKnownMIMETypeForExtension(name.substring
(index + 1)); | 42 if (policy == File::WellKnownContentTypes) |
| 43 type = MIMETypeRegistry::getWellKnownMIMETypeForExtension(name.subst
ring(index + 1)); |
| 44 else { |
| 45 ASSERT(policy == File::AllContentTypes); |
| 46 type = MIMETypeRegistry::getMIMETypeForExtension(name.substring(inde
x + 1)); |
| 47 } |
| 48 } |
43 return type; | 49 return type; |
44 } | 50 } |
45 | 51 |
46 static PassOwnPtr<BlobData> createBlobDataForFileWithType(const String& path, co
nst String& contentType) | 52 static PassOwnPtr<BlobData> createBlobDataForFileWithType(const String& path, co
nst String& contentType) |
47 { | 53 { |
48 OwnPtr<BlobData> blobData = BlobData::create(); | 54 OwnPtr<BlobData> blobData = BlobData::create(); |
49 blobData->setContentType(contentType); | 55 blobData->setContentType(contentType); |
50 blobData->appendFile(path); | 56 blobData->appendFile(path); |
51 return blobData.release(); | 57 return blobData.release(); |
52 } | 58 } |
53 | 59 |
54 static PassOwnPtr<BlobData> createBlobDataForFile(const String& path) | 60 static PassOwnPtr<BlobData> createBlobDataForFile(const String& path, File::Cont
entTypeLookupPolicy policy) |
55 { | 61 { |
56 return createBlobDataForFileWithType(path, getContentTypeFromFileName(path))
; | 62 return createBlobDataForFileWithType(path, getContentTypeFromFileName(path,
policy)); |
57 } | 63 } |
58 | 64 |
59 static PassOwnPtr<BlobData> createBlobDataForFileWithName(const String& path, co
nst String& fileSystemName) | 65 static PassOwnPtr<BlobData> createBlobDataForFileWithName(const String& path, co
nst String& fileSystemName, File::ContentTypeLookupPolicy policy) |
60 { | 66 { |
61 return createBlobDataForFileWithType(path, getContentTypeFromFileName(fileSy
stemName)); | 67 return createBlobDataForFileWithType(path, getContentTypeFromFileName(fileSy
stemName, policy)); |
62 } | 68 } |
63 | 69 |
64 #if ENABLE(FILE_SYSTEM) | 70 #if ENABLE(FILE_SYSTEM) |
65 static PassOwnPtr<BlobData> createBlobDataForFileWithMetadata(const String& file
SystemName, const FileMetadata& metadata) | 71 static PassOwnPtr<BlobData> createBlobDataForFileWithMetadata(const String& file
SystemName, const FileMetadata& metadata) |
66 { | 72 { |
67 OwnPtr<BlobData> blobData = BlobData::create(); | 73 OwnPtr<BlobData> blobData = BlobData::create(); |
68 blobData->setContentType(getContentTypeFromFileName(fileSystemName)); | 74 blobData->setContentType(getContentTypeFromFileName(fileSystemName, File::We
llKnownContentTypes)); |
69 blobData->appendFile(metadata.platformPath, 0, metadata.length, metadata.mod
ificationTime); | 75 blobData->appendFile(metadata.platformPath, 0, metadata.length, metadata.mod
ificationTime); |
70 return blobData.release(); | 76 return blobData.release(); |
71 } | 77 } |
72 #endif | 78 #endif |
73 | 79 |
74 #if ENABLE(DIRECTORY_UPLOAD) | 80 #if ENABLE(DIRECTORY_UPLOAD) |
75 PassRefPtr<File> File::createWithRelativePath(const String& path, const String&
relativePath) | 81 PassRefPtr<File> File::createWithRelativePath(const String& path, const String&
relativePath) |
76 { | 82 { |
77 RefPtr<File> file = adoptRef(new File(path)); | 83 RefPtr<File> file = adoptRef(new File(path, AllContentTypes)); |
78 file->m_relativePath = relativePath; | 84 file->m_relativePath = relativePath; |
79 return file.release(); | 85 return file.release(); |
80 } | 86 } |
81 #endif | 87 #endif |
82 | 88 |
83 File::File(const String& path) | 89 File::File(const String& path, ContentTypeLookupPolicy policy) |
84 : Blob(createBlobDataForFile(path), -1) | 90 : Blob(createBlobDataForFile(path, policy), -1) |
85 , m_path(path) | 91 , m_path(path) |
86 , m_name(pathGetFileName(path)) | 92 , m_name(pathGetFileName(path)) |
87 #if ENABLE(FILE_SYSTEM) | 93 #if ENABLE(FILE_SYSTEM) |
88 , m_snapshotSize(-1) | 94 , m_snapshotSize(-1) |
89 , m_snapshotModificationTime(invalidFileTime()) | 95 , m_snapshotModificationTime(invalidFileTime()) |
90 #endif | 96 #endif |
91 { | 97 { |
92 } | 98 } |
93 | 99 |
94 File::File(const String& path, const KURL& url, const String& type) | 100 File::File(const String& path, const KURL& url, const String& type) |
95 : Blob(url, type, -1) | 101 : Blob(url, type, -1) |
96 , m_path(path) | 102 , m_path(path) |
97 #if ENABLE(FILE_SYSTEM) | 103 #if ENABLE(FILE_SYSTEM) |
98 , m_snapshotSize(-1) | 104 , m_snapshotSize(-1) |
99 , m_snapshotModificationTime(invalidFileTime()) | 105 , m_snapshotModificationTime(invalidFileTime()) |
100 #endif | 106 #endif |
101 { | 107 { |
102 m_name = pathGetFileName(path); | 108 m_name = pathGetFileName(path); |
103 // FIXME: File object serialization/deserialization does not include | 109 // FIXME: File object serialization/deserialization does not include |
104 // newer file object data members: m_name and m_relativePath. | 110 // newer file object data members: m_name and m_relativePath. |
105 // See SerializedScriptValue.cpp for js and v8. | 111 // See SerializedScriptValue.cpp for js and v8. |
106 } | 112 } |
107 | 113 |
108 File::File(const String& path, const String& name) | 114 File::File(const String& path, const String& name, ContentTypeLookupPolicy polic
y) |
109 : Blob(createBlobDataForFileWithName(path, name), -1) | 115 : Blob(createBlobDataForFileWithName(path, name, policy), -1) |
110 , m_path(path) | 116 , m_path(path) |
111 , m_name(name) | 117 , m_name(name) |
112 #if ENABLE(FILE_SYSTEM) | 118 #if ENABLE(FILE_SYSTEM) |
113 , m_snapshotSize(-1) | 119 , m_snapshotSize(-1) |
114 , m_snapshotModificationTime(invalidFileTime()) | 120 , m_snapshotModificationTime(invalidFileTime()) |
115 #endif | 121 #endif |
116 { | 122 { |
117 } | 123 } |
118 | 124 |
119 #if ENABLE(FILE_SYSTEM) | 125 #if ENABLE(FILE_SYSTEM) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 snapshotSize = 0; | 180 snapshotSize = 0; |
175 snapshotModificationTime = invalidFileTime(); | 181 snapshotModificationTime = invalidFileTime(); |
176 return; | 182 return; |
177 } | 183 } |
178 | 184 |
179 snapshotSize = metadata.length; | 185 snapshotSize = metadata.length; |
180 snapshotModificationTime = metadata.modificationTime; | 186 snapshotModificationTime = metadata.modificationTime; |
181 } | 187 } |
182 | 188 |
183 } // namespace WebCore | 189 } // namespace WebCore |
OLD | NEW |