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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 67 |
68 static PassOwnPtr<BlobData> createBlobDataForFileWithName(const String& path, co
nst String& fileSystemName, File::ContentTypeLookupPolicy policy) | 68 static PassOwnPtr<BlobData> createBlobDataForFileWithName(const String& path, co
nst String& fileSystemName, File::ContentTypeLookupPolicy policy) |
69 { | 69 { |
70 return createBlobDataForFileWithType(path, getContentTypeFromFileName(fileSy
stemName, policy)); | 70 return createBlobDataForFileWithType(path, getContentTypeFromFileName(fileSy
stemName, policy)); |
71 } | 71 } |
72 | 72 |
73 static PassOwnPtr<BlobData> createBlobDataForFileWithMetadata(const String& file
SystemName, const FileMetadata& metadata) | 73 static PassOwnPtr<BlobData> createBlobDataForFileWithMetadata(const String& file
SystemName, const FileMetadata& metadata) |
74 { | 74 { |
75 OwnPtr<BlobData> blobData = BlobData::create(); | 75 OwnPtr<BlobData> blobData = BlobData::create(); |
76 blobData->setContentType(getContentTypeFromFileName(fileSystemName, File::We
llKnownContentTypes)); | 76 blobData->setContentType(getContentTypeFromFileName(fileSystemName, File::We
llKnownContentTypes)); |
77 blobData->appendFile(metadata.platformPath, 0, metadata.length, metadata.mod
ificationTimeMS / msPerSecond); | 77 blobData->appendFile(metadata.platformPath, 0, metadata.length, metadata.mod
ificationTime); |
78 return blobData.release(); | 78 return blobData.release(); |
79 } | 79 } |
80 | 80 |
81 static PassOwnPtr<BlobData> createBlobDataForFileSystemURL(const KURL& fileSyste
mURL, const FileMetadata& metadata) | 81 static PassOwnPtr<BlobData> createBlobDataForFileSystemURL(const KURL& fileSyste
mURL, const FileMetadata& metadata) |
82 { | 82 { |
83 OwnPtr<BlobData> blobData = BlobData::create(); | 83 OwnPtr<BlobData> blobData = BlobData::create(); |
84 blobData->setContentType(getContentTypeFromFileName(fileSystemURL.path(), Fi
le::WellKnownContentTypes)); | 84 blobData->setContentType(getContentTypeFromFileName(fileSystemURL.path(), Fi
le::WellKnownContentTypes)); |
85 blobData->appendFileSystemURL(fileSystemURL, 0, metadata.length, metadata.mo
dificationTimeMS / msPerSecond); | 85 blobData->appendFileSystemURL(fileSystemURL, 0, metadata.length, metadata.mo
dificationTime); |
86 return blobData.release(); | 86 return blobData.release(); |
87 } | 87 } |
88 | 88 |
89 File* File::createWithRelativePath(const String& path, const String& relativePat
h) | 89 File* File::createWithRelativePath(const String& path, const String& relativePat
h) |
90 { | 90 { |
91 File* file = new File(path, File::AllContentTypes, File::IsUserVisible); | 91 File* file = new File(path, File::AllContentTypes, File::IsUserVisible); |
92 file->m_relativePath = relativePath; | 92 file->m_relativePath = relativePath; |
93 return file; | 93 return file; |
94 } | 94 } |
95 | 95 |
96 File::File(const String& path, ContentTypeLookupPolicy policy, UserVisibility us
erVisibility) | 96 File::File(const String& path, ContentTypeLookupPolicy policy, UserVisibility us
erVisibility) |
97 : Blob(BlobDataHandle::create(createBlobDataForFile(path, policy), -1)) | 97 : Blob(BlobDataHandle::create(createBlobDataForFile(path, policy), -1)) |
98 , m_hasBackingFile(true) | 98 , m_hasBackingFile(true) |
99 , m_userVisibility(userVisibility) | 99 , m_userVisibility(userVisibility) |
100 , m_path(path) | 100 , m_path(path) |
101 , m_name(Platform::current()->fileUtilities()->baseName(path)) | 101 , m_name(Platform::current()->fileUtilities()->baseName(path)) |
102 , m_snapshotSize(-1) | 102 , m_snapshotSize(-1) |
103 , m_snapshotModificationTimeMS(invalidFileTime()) | 103 , m_snapshotModificationTime(invalidFileTime()) |
104 { | 104 { |
105 } | 105 } |
106 | 106 |
107 File::File(const String& path, const String& name, ContentTypeLookupPolicy polic
y, UserVisibility userVisibility) | 107 File::File(const String& path, const String& name, ContentTypeLookupPolicy polic
y, UserVisibility userVisibility) |
108 : Blob(BlobDataHandle::create(createBlobDataForFileWithName(path, name, poli
cy), -1)) | 108 : Blob(BlobDataHandle::create(createBlobDataForFileWithName(path, name, poli
cy), -1)) |
109 , m_hasBackingFile(true) | 109 , m_hasBackingFile(true) |
110 , m_userVisibility(userVisibility) | 110 , m_userVisibility(userVisibility) |
111 , m_path(path) | 111 , m_path(path) |
112 , m_name(name) | 112 , m_name(name) |
113 , m_snapshotSize(-1) | 113 , m_snapshotSize(-1) |
114 , m_snapshotModificationTimeMS(invalidFileTime()) | 114 , m_snapshotModificationTime(invalidFileTime()) |
115 { | 115 { |
116 } | 116 } |
117 | 117 |
118 File::File(const String& path, const String& name, const String& relativePath, U
serVisibility userVisibility, bool hasSnaphotData, uint64_t size, double lastMod
ified, PassRefPtr<BlobDataHandle> blobDataHandle) | 118 File::File(const String& path, const String& name, const String& relativePath, U
serVisibility userVisibility, bool hasSnaphotData, uint64_t size, double lastMod
ified, PassRefPtr<BlobDataHandle> blobDataHandle) |
119 : Blob(blobDataHandle) | 119 : Blob(blobDataHandle) |
120 , m_hasBackingFile(!path.isEmpty() || !relativePath.isEmpty()) | 120 , m_hasBackingFile(!path.isEmpty() || !relativePath.isEmpty()) |
121 , m_userVisibility(userVisibility) | 121 , m_userVisibility(userVisibility) |
122 , m_path(path) | 122 , m_path(path) |
123 , m_name(name) | 123 , m_name(name) |
124 , m_snapshotSize(hasSnaphotData ? static_cast<long long>(size) : -1) | 124 , m_snapshotSize(hasSnaphotData ? static_cast<long long>(size) : -1) |
125 , m_snapshotModificationTimeMS(hasSnaphotData ? lastModified : invalidFileTi
me()) | 125 , m_snapshotModificationTime(hasSnaphotData ? lastModified : invalidFileTime
()) |
126 , m_relativePath(relativePath) | 126 , m_relativePath(relativePath) |
127 { | 127 { |
128 } | 128 } |
129 | 129 |
130 File::File(const String& name, double modificationTimeMS, PassRefPtr<BlobDataHan
dle> blobDataHandle) | 130 File::File(const String& name, double modificationTime, PassRefPtr<BlobDataHandl
e> blobDataHandle) |
131 : Blob(blobDataHandle) | 131 : Blob(blobDataHandle) |
132 , m_hasBackingFile(false) | 132 , m_hasBackingFile(false) |
133 , m_userVisibility(File::IsNotUserVisible) | 133 , m_userVisibility(File::IsNotUserVisible) |
134 , m_name(name) | 134 , m_name(name) |
135 , m_snapshotSize(Blob::size()) | 135 , m_snapshotSize(Blob::size()) |
136 , m_snapshotModificationTimeMS(modificationTimeMS) | 136 , m_snapshotModificationTime(modificationTime) |
137 { | 137 { |
138 } | 138 } |
139 | 139 |
140 File::File(const String& name, const FileMetadata& metadata, UserVisibility user
Visibility) | 140 File::File(const String& name, const FileMetadata& metadata, UserVisibility user
Visibility) |
141 : Blob(BlobDataHandle::create(createBlobDataForFileWithMetadata(name, metada
ta), metadata.length)) | 141 : Blob(BlobDataHandle::create(createBlobDataForFileWithMetadata(name, metada
ta), metadata.length)) |
142 , m_hasBackingFile(true) | 142 , m_hasBackingFile(true) |
143 , m_userVisibility(userVisibility) | 143 , m_userVisibility(userVisibility) |
144 , m_path(metadata.platformPath) | 144 , m_path(metadata.platformPath) |
145 , m_name(name) | 145 , m_name(name) |
146 , m_snapshotSize(metadata.length) | 146 , m_snapshotSize(metadata.length) |
147 , m_snapshotModificationTimeMS(metadata.modificationTimeMS) | 147 , m_snapshotModificationTime(metadata.modificationTime) |
148 { | 148 { |
149 } | 149 } |
150 | 150 |
151 File::File(const KURL& fileSystemURL, const FileMetadata& metadata, UserVisibili
ty userVisibility) | 151 File::File(const KURL& fileSystemURL, const FileMetadata& metadata, UserVisibili
ty userVisibility) |
152 : Blob(BlobDataHandle::create(createBlobDataForFileSystemURL(fileSystemURL,
metadata), metadata.length)) | 152 : Blob(BlobDataHandle::create(createBlobDataForFileSystemURL(fileSystemURL,
metadata), metadata.length)) |
153 , m_hasBackingFile(false) | 153 , m_hasBackingFile(false) |
154 , m_userVisibility(userVisibility) | 154 , m_userVisibility(userVisibility) |
155 , m_name(decodeURLEscapeSequences(fileSystemURL.lastPathComponent())) | 155 , m_name(decodeURLEscapeSequences(fileSystemURL.lastPathComponent())) |
156 , m_fileSystemURL(fileSystemURL) | 156 , m_fileSystemURL(fileSystemURL) |
157 , m_snapshotSize(metadata.length) | 157 , m_snapshotSize(metadata.length) |
158 , m_snapshotModificationTimeMS(metadata.modificationTimeMS) | 158 , m_snapshotModificationTime(metadata.modificationTime) |
159 { | 159 { |
160 } | 160 } |
161 | 161 |
162 File::File(const File& other) | 162 File::File(const File& other) |
163 : Blob(other.blobDataHandle()) | 163 : Blob(other.blobDataHandle()) |
164 , m_hasBackingFile(other.m_hasBackingFile) | 164 , m_hasBackingFile(other.m_hasBackingFile) |
165 , m_userVisibility(other.m_userVisibility) | 165 , m_userVisibility(other.m_userVisibility) |
166 , m_path(other.m_path) | 166 , m_path(other.m_path) |
167 , m_name(other.m_name) | 167 , m_name(other.m_name) |
168 , m_fileSystemURL(other.m_fileSystemURL) | 168 , m_fileSystemURL(other.m_fileSystemURL) |
169 , m_snapshotSize(other.m_snapshotSize) | 169 , m_snapshotSize(other.m_snapshotSize) |
170 , m_snapshotModificationTimeMS(other.m_snapshotModificationTimeMS) | 170 , m_snapshotModificationTime(other.m_snapshotModificationTime) |
171 , m_relativePath(other.m_relativePath) | 171 , m_relativePath(other.m_relativePath) |
172 { | 172 { |
173 } | 173 } |
174 | 174 |
175 File* File::clone(const String& name) const | 175 File* File::clone(const String& name) const |
176 { | 176 { |
177 File* file = new File(*this); | 177 File* file = new File(*this); |
178 if (!name.isNull()) | 178 if (!name.isNull()) |
179 file->m_name = name; | 179 file->m_name = name; |
180 return file; | 180 return file; |
181 } | 181 } |
182 | 182 |
183 double File::lastModifiedMS() const | 183 double File::lastModifiedMS() const |
184 { | 184 { |
185 if (hasValidSnapshotMetadata() && isValidFileTime(m_snapshotModificationTime
MS)) | 185 if (hasValidSnapshotMetadata() && isValidFileTime(m_snapshotModificationTime
)) |
186 return m_snapshotModificationTimeMS; | 186 return m_snapshotModificationTime * msPerSecond; |
187 | 187 |
188 time_t modificationTimeMS; | 188 time_t modificationTime; |
189 if (hasBackingFile() && getFileModificationTime(m_path, modificationTimeMS)
&& isValidFileTime(modificationTimeMS)) | 189 if (hasBackingFile() && getFileModificationTime(m_path, modificationTime) &&
isValidFileTime(modificationTime)) |
190 return modificationTimeMS; | 190 return modificationTime * msPerSecond; |
191 | 191 |
192 return currentTimeMS(); | 192 return currentTime() * msPerSecond; |
193 } | 193 } |
194 | 194 |
195 long long File::lastModified() const | 195 long long File::lastModified() const |
196 { | 196 { |
197 double modifiedDate = lastModifiedMS(); | 197 double modifiedDate = lastModifiedMS(); |
198 | 198 |
199 // The getter should return the current time when the last modification time
isn't known. | 199 // The getter should return the current time when the last modification time
isn't known. |
200 if (!isValidFileTime(modifiedDate)) | 200 if (!isValidFileTime(modifiedDate)) |
201 modifiedDate = currentTimeMS(); | 201 modifiedDate = currentTimeMS(); |
202 | 202 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 if (hasBeenClosed()) { | 236 if (hasBeenClosed()) { |
237 exceptionState.throwDOMException(InvalidStateError, "File has been close
d."); | 237 exceptionState.throwDOMException(InvalidStateError, "File has been close
d."); |
238 return nullptr; | 238 return nullptr; |
239 } | 239 } |
240 | 240 |
241 if (!m_hasBackingFile) | 241 if (!m_hasBackingFile) |
242 return Blob::slice(start, end, contentType, exceptionState); | 242 return Blob::slice(start, end, contentType, exceptionState); |
243 | 243 |
244 // FIXME: This involves synchronous file operation. We need to figure out ho
w to make it asynchronous. | 244 // FIXME: This involves synchronous file operation. We need to figure out ho
w to make it asynchronous. |
245 long long size; | 245 long long size; |
246 double modificationTimeMS; | 246 double modificationTime; |
247 captureSnapshot(size, modificationTimeMS); | 247 captureSnapshot(size, modificationTime); |
248 clampSliceOffsets(size, start, end); | 248 clampSliceOffsets(size, start, end); |
249 | 249 |
250 long long length = end - start; | 250 long long length = end - start; |
251 OwnPtr<BlobData> blobData = BlobData::create(); | 251 OwnPtr<BlobData> blobData = BlobData::create(); |
252 blobData->setContentType(contentType); | 252 blobData->setContentType(contentType); |
253 if (!m_fileSystemURL.isEmpty()) { | 253 if (!m_fileSystemURL.isEmpty()) { |
254 blobData->appendFileSystemURL(m_fileSystemURL, start, length, modificati
onTimeMS / msPerSecond); | 254 blobData->appendFileSystemURL(m_fileSystemURL, start, length, modificati
onTime); |
255 } else { | 255 } else { |
256 ASSERT(!m_path.isEmpty()); | 256 ASSERT(!m_path.isEmpty()); |
257 blobData->appendFile(m_path, start, length, modificationTimeMS / msPerSe
cond); | 257 blobData->appendFile(m_path, start, length, modificationTime); |
258 } | 258 } |
259 return Blob::create(BlobDataHandle::create(blobData.release(), length)); | 259 return Blob::create(BlobDataHandle::create(blobData.release(), length)); |
260 } | 260 } |
261 | 261 |
262 void File::captureSnapshot(long long& snapshotSize, double& snapshotModification
TimeMS) const | 262 void File::captureSnapshot(long long& snapshotSize, double& snapshotModification
Time) const |
263 { | 263 { |
264 if (hasValidSnapshotMetadata()) { | 264 if (hasValidSnapshotMetadata()) { |
265 snapshotSize = m_snapshotSize; | 265 snapshotSize = m_snapshotSize; |
266 snapshotModificationTimeMS = m_snapshotModificationTimeMS; | 266 snapshotModificationTime = m_snapshotModificationTime; |
267 return; | 267 return; |
268 } | 268 } |
269 | 269 |
270 // Obtains a snapshot of the file by capturing its current size and modifica
tion time. This is used when we slice a file for the first time. | 270 // Obtains a snapshot of the file by capturing its current size and modifica
tion time. This is used when we slice a file for the first time. |
271 // If we fail to retrieve the size or modification time, probably due to tha
t the file has been deleted, 0 size is returned. | 271 // If we fail to retrieve the size or modification time, probably due to tha
t the file has been deleted, 0 size is returned. |
272 FileMetadata metadata; | 272 FileMetadata metadata; |
273 if (!hasBackingFile() || !getFileMetadata(m_path, metadata)) { | 273 if (!hasBackingFile() || !getFileMetadata(m_path, metadata)) { |
274 snapshotSize = 0; | 274 snapshotSize = 0; |
275 snapshotModificationTimeMS = invalidFileTime(); | 275 snapshotModificationTime = invalidFileTime(); |
276 return; | 276 return; |
277 } | 277 } |
278 | 278 |
279 snapshotSize = metadata.length; | 279 snapshotSize = metadata.length; |
280 snapshotModificationTimeMS = metadata.modificationTimeMS; | 280 snapshotModificationTime = metadata.modificationTime; |
281 } | 281 } |
282 | 282 |
283 void File::close(ExecutionContext* executionContext, ExceptionState& exceptionSt
ate) | 283 void File::close(ExecutionContext* executionContext, ExceptionState& exceptionSt
ate) |
284 { | 284 { |
285 if (hasBeenClosed()) { | 285 if (hasBeenClosed()) { |
286 exceptionState.throwDOMException(InvalidStateError, "Blob has been close
d."); | 286 exceptionState.throwDOMException(InvalidStateError, "Blob has been close
d."); |
287 return; | 287 return; |
288 } | 288 } |
289 | 289 |
290 // Reset the File to its closed representation, an empty | 290 // Reset the File to its closed representation, an empty |
291 // Blob. The name isn't cleared, as it should still be | 291 // Blob. The name isn't cleared, as it should still be |
292 // available. | 292 // available. |
293 m_hasBackingFile = false; | 293 m_hasBackingFile = false; |
294 m_path = String(); | 294 m_path = String(); |
295 m_fileSystemURL = KURL(); | 295 m_fileSystemURL = KURL(); |
296 invalidateSnapshotMetadata(); | 296 invalidateSnapshotMetadata(); |
297 m_relativePath = String(); | 297 m_relativePath = String(); |
298 Blob::close(executionContext, exceptionState); | 298 Blob::close(executionContext, exceptionState); |
299 } | 299 } |
300 | 300 |
301 void File::appendTo(BlobData& blobData) const | 301 void File::appendTo(BlobData& blobData) const |
302 { | 302 { |
303 if (!m_hasBackingFile) { | 303 if (!m_hasBackingFile) { |
304 Blob::appendTo(blobData); | 304 Blob::appendTo(blobData); |
305 return; | 305 return; |
306 } | 306 } |
307 | 307 |
308 // FIXME: This involves synchronous file operation. We need to figure out ho
w to make it asynchronous. | 308 // FIXME: This involves synchronous file operation. We need to figure out ho
w to make it asynchronous. |
309 long long size; | 309 long long size; |
310 double modificationTimeMS; | 310 double modificationTime; |
311 captureSnapshot(size, modificationTimeMS); | 311 captureSnapshot(size, modificationTime); |
312 if (!m_fileSystemURL.isEmpty()) { | 312 if (!m_fileSystemURL.isEmpty()) { |
313 blobData.appendFileSystemURL(m_fileSystemURL, 0, size, modificationTimeM
S / msPerSecond); | 313 blobData.appendFileSystemURL(m_fileSystemURL, 0, size, modificationTime)
; |
314 return; | 314 return; |
315 } | 315 } |
316 ASSERT(!m_path.isEmpty()); | 316 ASSERT(!m_path.isEmpty()); |
317 blobData.appendFile(m_path, 0, size, modificationTimeMS / msPerSecond); | 317 blobData.appendFile(m_path, 0, size, modificationTime); |
318 } | 318 } |
319 | 319 |
320 bool File::hasSameSource(const File& other) const | 320 bool File::hasSameSource(const File& other) const |
321 { | 321 { |
322 if (m_hasBackingFile != other.m_hasBackingFile) | 322 if (m_hasBackingFile != other.m_hasBackingFile) |
323 return false; | 323 return false; |
324 | 324 |
325 if (m_hasBackingFile) | 325 if (m_hasBackingFile) |
326 return m_path == other.m_path; | 326 return m_path == other.m_path; |
327 | 327 |
328 if (m_fileSystemURL.isEmpty() != other.m_fileSystemURL.isEmpty()) | 328 if (m_fileSystemURL.isEmpty() != other.m_fileSystemURL.isEmpty()) |
329 return false; | 329 return false; |
330 | 330 |
331 if (!m_fileSystemURL.isEmpty()) | 331 if (!m_fileSystemURL.isEmpty()) |
332 return m_fileSystemURL == other.m_fileSystemURL; | 332 return m_fileSystemURL == other.m_fileSystemURL; |
333 | 333 |
334 return uuid() == other.uuid(); | 334 return uuid() == other.uuid(); |
335 } | 335 } |
336 | 336 |
337 } // namespace blink | 337 } // namespace blink |
OLD | NEW |