| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "modules/filesystem/FileSystemCallbacks.h" | 32 #include "modules/filesystem/FileSystemCallbacks.h" |
| 33 | 33 |
| 34 #include "core/dom/ExecutionContext.h" | 34 #include "core/dom/ExecutionContext.h" |
| 35 #include "core/fileapi/File.h" |
| 35 #include "core/fileapi/FileError.h" | 36 #include "core/fileapi/FileError.h" |
| 36 #include "core/html/VoidCallback.h" | 37 #include "core/html/VoidCallback.h" |
| 37 #include "modules/filesystem/DOMFilePath.h" | 38 #include "modules/filesystem/DOMFilePath.h" |
| 38 #include "modules/filesystem/DOMFileSystem.h" | 39 #include "modules/filesystem/DOMFileSystem.h" |
| 39 #include "modules/filesystem/DOMFileSystemBase.h" | 40 #include "modules/filesystem/DOMFileSystemBase.h" |
| 40 #include "modules/filesystem/DirectoryEntry.h" | 41 #include "modules/filesystem/DirectoryEntry.h" |
| 41 #include "modules/filesystem/DirectoryReader.h" | 42 #include "modules/filesystem/DirectoryReader.h" |
| 42 #include "modules/filesystem/Entry.h" | 43 #include "modules/filesystem/Entry.h" |
| 43 #include "modules/filesystem/EntryCallback.h" | 44 #include "modules/filesystem/EntryCallback.h" |
| 44 #include "modules/filesystem/ErrorCallback.h" | 45 #include "modules/filesystem/ErrorCallback.h" |
| 46 #include "modules/filesystem/FileCallback.h" |
| 45 #include "modules/filesystem/FileEntry.h" | 47 #include "modules/filesystem/FileEntry.h" |
| 46 #include "modules/filesystem/FileSystemCallback.h" | 48 #include "modules/filesystem/FileSystemCallback.h" |
| 47 #include "modules/filesystem/FileWriterBase.h" | 49 #include "modules/filesystem/FileWriterBase.h" |
| 48 #include "modules/filesystem/FileWriterBaseCallback.h" | 50 #include "modules/filesystem/FileWriterBaseCallback.h" |
| 49 #include "modules/filesystem/Metadata.h" | 51 #include "modules/filesystem/Metadata.h" |
| 50 #include "modules/filesystem/MetadataCallback.h" | 52 #include "modules/filesystem/MetadataCallback.h" |
| 51 #include "platform/FileMetadata.h" | 53 #include "platform/FileMetadata.h" |
| 52 #include "public/platform/WebFileWriter.h" | 54 #include "public/platform/WebFileWriter.h" |
| 53 | 55 |
| 54 namespace WebCore { | 56 namespace WebCore { |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 , m_successCallback(successCallback) | 235 , m_successCallback(successCallback) |
| 234 { | 236 { |
| 235 } | 237 } |
| 236 | 238 |
| 237 void MetadataCallbacks::didReadMetadata(const FileMetadata& metadata) | 239 void MetadataCallbacks::didReadMetadata(const FileMetadata& metadata) |
| 238 { | 240 { |
| 239 if (m_successCallback) | 241 if (m_successCallback) |
| 240 handleEventOrScheduleCallback(m_successCallback.release(), Metadata::cre
ate(metadata)); | 242 handleEventOrScheduleCallback(m_successCallback.release(), Metadata::cre
ate(metadata)); |
| 241 } | 243 } |
| 242 | 244 |
| 243 // FileWriterBaseCallbacks -----------------------------------------------------
----- | 245 // FileWriterBaseCallbacks ---------------------------------------------------- |
| 244 | 246 |
| 245 PassOwnPtr<AsyncFileSystemCallbacks> FileWriterBaseCallbacks::create(PassRefPtrW
illBeRawPtr<FileWriterBase> fileWriter, PassOwnPtr<FileWriterBaseCallback> succe
ssCallback, PassOwnPtr<ErrorCallback> errorCallback, ExecutionContext* context) | 247 PassOwnPtr<AsyncFileSystemCallbacks> FileWriterBaseCallbacks::create(PassRefPtrW
illBeRawPtr<FileWriterBase> fileWriter, PassOwnPtr<FileWriterBaseCallback> succe
ssCallback, PassOwnPtr<ErrorCallback> errorCallback, ExecutionContext* context) |
| 246 { | 248 { |
| 247 return adoptPtr(new FileWriterBaseCallbacks(fileWriter, successCallback, err
orCallback, context)); | 249 return adoptPtr(new FileWriterBaseCallbacks(fileWriter, successCallback, err
orCallback, context)); |
| 248 } | 250 } |
| 249 | 251 |
| 250 FileWriterBaseCallbacks::FileWriterBaseCallbacks(PassRefPtrWillBeRawPtr<FileWrit
erBase> fileWriter, PassOwnPtr<FileWriterBaseCallback> successCallback, PassOwnP
tr<ErrorCallback> errorCallback, ExecutionContext* context) | 252 FileWriterBaseCallbacks::FileWriterBaseCallbacks(PassRefPtrWillBeRawPtr<FileWrit
erBase> fileWriter, PassOwnPtr<FileWriterBaseCallback> successCallback, PassOwnP
tr<ErrorCallback> errorCallback, ExecutionContext* context) |
| 251 : FileSystemCallbacksBase(errorCallback, nullptr, context) | 253 : FileSystemCallbacksBase(errorCallback, nullptr, context) |
| 252 , m_fileWriter(fileWriter.get()) | 254 , m_fileWriter(fileWriter.get()) |
| 253 , m_successCallback(successCallback) | 255 , m_successCallback(successCallback) |
| 254 { | 256 { |
| 255 } | 257 } |
| 256 | 258 |
| 257 void FileWriterBaseCallbacks::didCreateFileWriter(PassOwnPtr<blink::WebFileWrite
r> fileWriter, long long length) | 259 void FileWriterBaseCallbacks::didCreateFileWriter(PassOwnPtr<blink::WebFileWrite
r> fileWriter, long long length) |
| 258 { | 260 { |
| 259 m_fileWriter->initialize(fileWriter, length); | 261 m_fileWriter->initialize(fileWriter, length); |
| 260 if (m_successCallback) | 262 if (m_successCallback) |
| 261 handleEventOrScheduleCallback(m_successCallback.release(), m_fileWriter.
release()); | 263 handleEventOrScheduleCallback(m_successCallback.release(), m_fileWriter.
release()); |
| 262 } | 264 } |
| 263 | 265 |
| 266 // SnapshotFileCallback ------------------------------------------------------- |
| 267 |
| 268 PassOwnPtr<AsyncFileSystemCallbacks> SnapshotFileCallback::create(DOMFileSystemB
ase* filesystem, const String& name, const KURL& url, PassOwnPtr<FileCallback> s
uccessCallback, PassOwnPtr<ErrorCallback> errorCallback, ExecutionContext* conte
xt) |
| 269 { |
| 270 return adoptPtr(new SnapshotFileCallback(filesystem, name, url, successCallb
ack, errorCallback, context)); |
| 271 } |
| 272 |
| 273 SnapshotFileCallback::SnapshotFileCallback(DOMFileSystemBase* filesystem, const
String& name, const KURL& url, PassOwnPtr<FileCallback> successCallback, PassOwn
Ptr<ErrorCallback> errorCallback, ExecutionContext* context) |
| 274 : FileSystemCallbacksBase(errorCallback, filesystem, context) |
| 275 , m_name(name) |
| 276 , m_url(url) |
| 277 , m_successCallback(successCallback) |
| 278 { |
| 279 } |
| 280 |
| 281 void SnapshotFileCallback::didCreateSnapshotFile(const FileMetadata& metadata, P
assRefPtr<BlobDataHandle> snapshot) |
| 282 { |
| 283 if (!m_successCallback) |
| 284 return; |
| 285 |
| 286 // We can't directly use the snapshot blob data handle because the content t
ype on it hasn't been set. |
| 287 // The |snapshot| param is here to provide a a chain of custody thru thread
bridging that is held onto until |
| 288 // *after* we've coined a File with a new handle that has the correct type s
et on it. This allows the |
| 289 // blob storage system to track when a temp file can and can't be safely del
eted. |
| 290 |
| 291 // For regular filesystem types (temporary or persistent), we should not cac
he file metadata as it could change File semantics. |
| 292 // For other filesystem types (which could be platform-specific ones), there
's a chance that the files are on remote filesystem. If the port has returned me
tadata just pass it to File constructor (so we may cache the metadata). |
| 293 // FIXME: We should use the snapshot metadata for all files. |
| 294 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=17746 |
| 295 if (m_fileSystem->type() == FileSystemTypeTemporary || m_fileSystem->type()
== FileSystemTypePersistent) { |
| 296 handleEventOrScheduleCallback(m_successCallback.release(), File::createW
ithName(metadata.platformPath, m_name)); |
| 297 } else if (!metadata.platformPath.isEmpty()) { |
| 298 // If the platformPath in the returned metadata is given, we create a Fi
le object for the path. |
| 299 handleEventOrScheduleCallback(m_successCallback.release(), File::createF
orFileSystemFile(m_name, metadata)); |
| 300 } else { |
| 301 // Otherwise create a File from the FileSystem URL. |
| 302 handleEventOrScheduleCallback(m_successCallback.release(), File::createF
orFileSystemFile(m_url, metadata)); |
| 303 } |
| 304 } |
| 305 |
| 264 // VoidCallbacks -------------------------------------------------------------- | 306 // VoidCallbacks -------------------------------------------------------------- |
| 265 | 307 |
| 266 PassOwnPtr<AsyncFileSystemCallbacks> VoidCallbacks::create(PassOwnPtr<VoidCallba
ck> successCallback, PassOwnPtr<ErrorCallback> errorCallback, ExecutionContext*
context, DOMFileSystemBase* fileSystem) | 308 PassOwnPtr<AsyncFileSystemCallbacks> VoidCallbacks::create(PassOwnPtr<VoidCallba
ck> successCallback, PassOwnPtr<ErrorCallback> errorCallback, ExecutionContext*
context, DOMFileSystemBase* fileSystem) |
| 267 { | 309 { |
| 268 return adoptPtr(new VoidCallbacks(successCallback, errorCallback, context, f
ileSystem)); | 310 return adoptPtr(new VoidCallbacks(successCallback, errorCallback, context, f
ileSystem)); |
| 269 } | 311 } |
| 270 | 312 |
| 271 VoidCallbacks::VoidCallbacks(PassOwnPtr<VoidCallback> successCallback, PassOwnPt
r<ErrorCallback> errorCallback, ExecutionContext* context, DOMFileSystemBase* fi
leSystem) | 313 VoidCallbacks::VoidCallbacks(PassOwnPtr<VoidCallback> successCallback, PassOwnPt
r<ErrorCallback> errorCallback, ExecutionContext* context, DOMFileSystemBase* fi
leSystem) |
| 272 : FileSystemCallbacksBase(errorCallback, fileSystem, context) | 314 : FileSystemCallbacksBase(errorCallback, fileSystem, context) |
| 273 , m_successCallback(successCallback) | 315 , m_successCallback(successCallback) |
| 274 { | 316 { |
| 275 } | 317 } |
| 276 | 318 |
| 277 void VoidCallbacks::didSucceed() | 319 void VoidCallbacks::didSucceed() |
| 278 { | 320 { |
| 279 if (m_successCallback) | 321 if (m_successCallback) |
| 280 handleEventOrScheduleCallback(m_successCallback.release()); | 322 handleEventOrScheduleCallback(m_successCallback.release()); |
| 281 } | 323 } |
| 282 | 324 |
| 283 } // namespace | 325 } // namespace |
| OLD | NEW |