#include "modules/filesystem/DOMFileSystemBase.h"
#include "core/dom/ExecutionContext.h"
+#include "core/fileapi/File.h"
#include "core/fileapi/FileError.h"
#include "core/html/VoidCallback.h"
#include "modules/filesystem/DOMFilePath.h"
#include "wtf/OwnPtr.h"
#include "wtf/text/StringBuilder.h"
-namespace WebCore {
+namespace blink {
const char DOMFileSystemBase::persistentPathPrefix[] = "persistent";
const char DOMFileSystemBase::temporaryPathPrefix[] = "temporary";
{
}
-blink::WebFileSystem* DOMFileSystemBase::fileSystem() const
+WebFileSystem* DOMFileSystemBase::fileSystem() const
{
- return blink::Platform::current()->fileSystem();
+ Platform* platform = Platform::current();
+ if (!platform)
+ return nullptr;
+ return platform->fileSystem();
}
SecurityOrigin* DOMFileSystemBase::securityOrigin() const
if (type() == FileSystemTypeExternal) {
// For external filesystem originString could be different from what we have in m_filesystemRootURL.
StringBuilder result;
- result.append("filesystem:");
+ result.appendLiteral("filesystem:");
result.append(securityOrigin()->toString());
- result.append("/");
+ result.append('/');
result.append(externalPathPrefix);
result.append(m_filesystemRootURL.path());
// Remove the extra leading slash.
return false;
}
-void DOMFileSystemBase::getMetadata(const EntryBase* entry, PassOwnPtr<MetadataCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback, SynchronousType synchronousType)
+PassRefPtrWillBeRawPtr<File> DOMFileSystemBase::createFile(const FileMetadata& metadata, const KURL& fileSystemURL, FileSystemType type, const String name)
{
- OwnPtr<AsyncFileSystemCallbacks> callbacks(MetadataCallbacks::create(successCallback, errorCallback, this));
+ // For regular filesystem types (temporary or persistent), we should not cache file metadata as it could change File semantics.
+ // 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 metadata just pass it to File constructor (so we may cache the metadata).
+ // FIXME: We should use the snapshot metadata for all files.
+ // https://www.w3.org/Bugs/Public/show_bug.cgi?id=17746
+ if (type == FileSystemTypeTemporary || type == FileSystemTypePersistent)
+ return File::createForFileSystemFile(metadata.platformPath, name);
+
+ if (!metadata.platformPath.isEmpty()) {
+ // If the platformPath in the returned metadata is given, we create a File object for the path.
+ File::UserVisibility userVisibility = (type == FileSystemTypeExternal) ? File::IsUserVisible : File::IsNotUserVisible;
+ return File::createForFileSystemFile(name, metadata, userVisibility);
+ }
+
+ return File::createForFileSystemFile(fileSystemURL, metadata);
+}
+
+void DOMFileSystemBase::getMetadata(const EntryBase* entry, MetadataCallback* successCallback, ErrorCallback* errorCallback, SynchronousType synchronousType)
+{
+ if (!fileSystem()) {
+ reportError(errorCallback, FileError::create(FileError::ABORT_ERR));
+ return;
+ }
+
+ OwnPtr<AsyncFileSystemCallbacks> callbacks(MetadataCallbacks::create(successCallback, errorCallback, m_context, this));
callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);
fileSystem()->readMetadata(createFileSystemURL(entry), callbacks.release());
}
return true;
}
-void DOMFileSystemBase::move(const EntryBase* source, EntryBase* parent, const String& newName, PassOwnPtr<EntryCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback, SynchronousType synchronousType)
+void DOMFileSystemBase::move(const EntryBase* source, EntryBase* parent, const String& newName, EntryCallback* successCallback, ErrorCallback* errorCallback, SynchronousType synchronousType)
{
+ if (!fileSystem()) {
+ reportError(errorCallback, FileError::create(FileError::ABORT_ERR));
+ return;
+ }
+
String destinationPath;
if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName, destinationPath)) {
reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICATION_ERR));
return;
}
- OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCallback, errorCallback, parent->filesystem(), destinationPath, source->isDirectory()));
+ OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCallback, errorCallback, m_context, parent->filesystem(), destinationPath, source->isDirectory()));
callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);
fileSystem()->move(createFileSystemURL(source), parent->filesystem()->createFileSystemURL(destinationPath), callbacks.release());
}
-void DOMFileSystemBase::copy(const EntryBase* source, EntryBase* parent, const String& newName, PassOwnPtr<EntryCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback, SynchronousType synchronousType)
+void DOMFileSystemBase::copy(const EntryBase* source, EntryBase* parent, const String& newName, EntryCallback* successCallback, ErrorCallback* errorCallback, SynchronousType synchronousType)
{
+ if (!fileSystem()) {
+ reportError(errorCallback, FileError::create(FileError::ABORT_ERR));
+ return;
+ }
+
String destinationPath;
if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName, destinationPath)) {
reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICATION_ERR));
return;
}
- OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCallback, errorCallback, parent->filesystem(), destinationPath, source->isDirectory()));
+ OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCallback, errorCallback, m_context, parent->filesystem(), destinationPath, source->isDirectory()));
callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);
fileSystem()->copy(createFileSystemURL(source), parent->filesystem()->createFileSystemURL(destinationPath), callbacks.release());
}
-void DOMFileSystemBase::remove(const EntryBase* entry, PassOwnPtr<VoidCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback, SynchronousType synchronousType)
+void DOMFileSystemBase::remove(const EntryBase* entry, VoidCallback* successCallback, ErrorCallback* errorCallback, SynchronousType synchronousType)
{
+ if (!fileSystem()) {
+ reportError(errorCallback, FileError::create(FileError::ABORT_ERR));
+ return;
+ }
+
ASSERT(entry);
// We don't allow calling remove() on the root directory.
if (entry->fullPath() == String(DOMFilePath::root)) {
return;
}
- OwnPtr<AsyncFileSystemCallbacks> callbacks(VoidCallbacks::create(successCallback, errorCallback, this));
+ OwnPtr<AsyncFileSystemCallbacks> callbacks(VoidCallbacks::create(successCallback, errorCallback, m_context, this));
callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);
fileSystem()->remove(createFileSystemURL(entry), callbacks.release());
}
-void DOMFileSystemBase::removeRecursively(const EntryBase* entry, PassOwnPtr<VoidCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback, SynchronousType synchronousType)
+void DOMFileSystemBase::removeRecursively(const EntryBase* entry, VoidCallback* successCallback, ErrorCallback* errorCallback, SynchronousType synchronousType)
{
+ if (!fileSystem()) {
+ reportError(errorCallback, FileError::create(FileError::ABORT_ERR));
+ return;
+ }
+
ASSERT(entry && entry->isDirectory());
// We don't allow calling remove() on the root directory.
if (entry->fullPath() == String(DOMFilePath::root)) {
return;
}
- OwnPtr<AsyncFileSystemCallbacks> callbacks(VoidCallbacks::create(successCallback, errorCallback, this));
+ OwnPtr<AsyncFileSystemCallbacks> callbacks(VoidCallbacks::create(successCallback, errorCallback, m_context, this));
callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);
fileSystem()->removeRecursively(createFileSystemURL(entry), callbacks.release());
}
-void DOMFileSystemBase::getParent(const EntryBase* entry, PassOwnPtr<EntryCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback)
+void DOMFileSystemBase::getParent(const EntryBase* entry, EntryCallback* successCallback, ErrorCallback* errorCallback)
{
+ if (!fileSystem()) {
+ reportError(errorCallback, FileError::create(FileError::ABORT_ERR));
+ return;
+ }
+
ASSERT(entry);
String path = DOMFilePath::getDirectory(entry->fullPath());
- fileSystem()->directoryExists(createFileSystemURL(path), EntryCallbacks::create(successCallback, errorCallback, this, path, true));
+
+ fileSystem()->directoryExists(createFileSystemURL(path), EntryCallbacks::create(successCallback, errorCallback, m_context, this, path, true));
}
-void DOMFileSystemBase::getFile(const EntryBase* entry, const String& path, const FileSystemFlags& flags, PassOwnPtr<EntryCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback, SynchronousType synchronousType)
+void DOMFileSystemBase::getFile(const EntryBase* entry, const String& path, const FileSystemFlags& flags, EntryCallback* successCallback, ErrorCallback* errorCallback, SynchronousType synchronousType)
{
+ if (!fileSystem()) {
+ reportError(errorCallback, FileError::create(FileError::ABORT_ERR));
+ return;
+ }
+
String absolutePath;
if (!pathToAbsolutePath(m_type, entry, path, absolutePath)) {
reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICATION_ERR));
return;
}
- OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCallback, errorCallback, this, absolutePath, false));
+ OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCallback, errorCallback, m_context, this, absolutePath, false));
callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);
if (flags.create)
fileSystem()->fileExists(createFileSystemURL(absolutePath), callbacks.release());
}
-void DOMFileSystemBase::getDirectory(const EntryBase* entry, const String& path, const FileSystemFlags& flags, PassOwnPtr<EntryCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback, SynchronousType synchronousType)
+void DOMFileSystemBase::getDirectory(const EntryBase* entry, const String& path, const FileSystemFlags& flags, EntryCallback* successCallback, ErrorCallback* errorCallback, SynchronousType synchronousType)
{
+ if (!fileSystem()) {
+ reportError(errorCallback, FileError::create(FileError::ABORT_ERR));
+ return;
+ }
+
String absolutePath;
if (!pathToAbsolutePath(m_type, entry, path, absolutePath)) {
reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICATION_ERR));
return;
}
- OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCallback, errorCallback, this, absolutePath, true));
+ OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCallback, errorCallback, m_context, this, absolutePath, true));
callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);
if (flags.create)
fileSystem()->directoryExists(createFileSystemURL(absolutePath), callbacks.release());
}
-int DOMFileSystemBase::readDirectory(PassRefPtrWillBeRawPtr<DirectoryReaderBase> reader, const String& path, PassOwnPtr<EntriesCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback, SynchronousType synchronousType)
+int DOMFileSystemBase::readDirectory(DirectoryReaderBase* reader, const String& path, EntriesCallback* successCallback, ErrorCallback* errorCallback, SynchronousType synchronousType)
{
+ if (!fileSystem()) {
+ reportError(errorCallback, FileError::create(FileError::ABORT_ERR));
+ return 0;
+ }
+
ASSERT(DOMFilePath::isAbsolute(path));
- OwnPtr<AsyncFileSystemCallbacks> callbacks(EntriesCallbacks::create(successCallback, errorCallback, reader, path));
+ OwnPtr<AsyncFileSystemCallbacks> callbacks(EntriesCallbacks::create(successCallback, errorCallback, m_context, reader, path));
callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);
return fileSystem()->readDirectory(createFileSystemURL(path), callbacks.release());
bool DOMFileSystemBase::waitForAdditionalResult(int callbacksId)
{
+ if (!fileSystem())
+ return false;
return fileSystem()->waitForAdditionalResult(callbacksId);
}
-} // namespace WebCore
+} // namespace blink