This source file includes following definitions.
- create
- createIsolatedFileSystem
- m_numberOfPendingCallbacks
- root
- addPendingCallbacks
- removePendingCallbacks
- hasPendingActivity
- reportError
- create
- handleEvent
- createWriter
- create
- didCreateSnapshotFile
- m_successCallback
- createFile
#include "config.h"
#include "modules/filesystem/DOMFileSystem.h"
#include "core/fileapi/File.h"
#include "modules/filesystem/DOMFilePath.h"
#include "modules/filesystem/DirectoryEntry.h"
#include "modules/filesystem/ErrorCallback.h"
#include "modules/filesystem/FileCallback.h"
#include "modules/filesystem/FileEntry.h"
#include "modules/filesystem/FileSystemCallbacks.h"
#include "modules/filesystem/FileWriter.h"
#include "modules/filesystem/FileWriterBaseCallback.h"
#include "modules/filesystem/FileWriterCallback.h"
#include "modules/filesystem/MetadataCallback.h"
#include "platform/FileMetadata.h"
#include "platform/weborigin/DatabaseIdentifier.h"
#include "platform/weborigin/SecurityOrigin.h"
#include "public/platform/WebFileSystem.h"
#include "public/platform/WebFileSystemCallbacks.h"
#include "wtf/OwnPtr.h"
#include "wtf/text/StringBuilder.h"
#include "wtf/text/WTFString.h"
namespace WebCore {
PassRefPtrWillBeRawPtr<DOMFileSystem> DOMFileSystem::create(ExecutionContext* context, const String& name, FileSystemType type, const KURL& rootURL)
{
RefPtrWillBeRawPtr<DOMFileSystem> fileSystem(adoptRefWillBeRefCountedGarbageCollected(new DOMFileSystem(context, name, type, rootURL)));
fileSystem->suspendIfNeeded();
return fileSystem.release();
}
PassRefPtrWillBeRawPtr<DOMFileSystem> DOMFileSystem::createIsolatedFileSystem(ExecutionContext* context, const String& filesystemId)
{
if (filesystemId.isEmpty())
return nullptr;
StringBuilder filesystemName;
filesystemName.append(createDatabaseIdentifierFromSecurityOrigin(context->securityOrigin()));
filesystemName.append(":Isolated_");
filesystemName.append(filesystemId);
StringBuilder rootURL;
rootURL.append("filesystem:");
rootURL.append(context->securityOrigin()->toString());
rootURL.append("/");
rootURL.append(isolatedPathPrefix);
rootURL.append("/");
rootURL.append(filesystemId);
rootURL.append("/");
return DOMFileSystem::create(context, filesystemName.toString(), FileSystemTypeIsolated, KURL(ParsedURLString, rootURL.toString()));
}
DOMFileSystem::DOMFileSystem(ExecutionContext* context, const String& name, FileSystemType type, const KURL& rootURL)
: DOMFileSystemBase(context, name, type, rootURL)
, ActiveDOMObject(context)
, m_numberOfPendingCallbacks(0)
{
ScriptWrappable::init(this);
}
PassRefPtrWillBeRawPtr<DirectoryEntry> DOMFileSystem::root()
{
return DirectoryEntry::create(this, DOMFilePath::root);
}
void DOMFileSystem::addPendingCallbacks()
{
++m_numberOfPendingCallbacks;
}
void DOMFileSystem::removePendingCallbacks()
{
ASSERT(m_numberOfPendingCallbacks > 0);
--m_numberOfPendingCallbacks;
}
bool DOMFileSystem::hasPendingActivity() const
{
ASSERT(m_numberOfPendingCallbacks >= 0);
return m_numberOfPendingCallbacks;
}
void DOMFileSystem::reportError(PassOwnPtr<ErrorCallback> errorCallback, PassRefPtrWillBeRawPtr<FileError> fileError)
{
scheduleCallback(errorCallback, fileError);
}
namespace {
class ConvertToFileWriterCallback : public FileWriterBaseCallback {
public:
static PassOwnPtr<ConvertToFileWriterCallback> create(PassOwnPtr<FileWriterCallback> callback)
{
return adoptPtr(new ConvertToFileWriterCallback(callback));
}
void handleEvent(FileWriterBase* fileWriterBase)
{
m_callback->handleEvent(static_cast<FileWriter*>(fileWriterBase));
}
private:
ConvertToFileWriterCallback(PassOwnPtr<FileWriterCallback> callback)
: m_callback(callback)
{
}
OwnPtr<FileWriterCallback> m_callback;
};
}
void DOMFileSystem::createWriter(const FileEntry* fileEntry, PassOwnPtr<FileWriterCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback)
{
ASSERT(fileEntry);
RefPtrWillBeRawPtr<FileWriter> fileWriter = FileWriter::create(executionContext());
OwnPtr<FileWriterBaseCallback> conversionCallback = ConvertToFileWriterCallback::create(successCallback);
OwnPtr<AsyncFileSystemCallbacks> callbacks = FileWriterBaseCallbacks::create(fileWriter, conversionCallback.release(), errorCallback);
fileSystem()->createFileWriter(createFileSystemURL(fileEntry), fileWriter.get(), callbacks.release());
}
namespace {
class SnapshotFileCallback : public FileSystemCallbacksBase {
public:
static PassOwnPtr<AsyncFileSystemCallbacks> create(PassRefPtrWillBeRawPtr<DOMFileSystem> filesystem, const String& name, const KURL& url, PassOwnPtr<FileCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback)
{
return adoptPtr(static_cast<AsyncFileSystemCallbacks*>(new SnapshotFileCallback(filesystem, name, url, successCallback, errorCallback)));
}
virtual void didCreateSnapshotFile(const FileMetadata& metadata, PassRefPtr<BlobDataHandle> snapshot)
{
if (!m_successCallback)
return;
if (m_fileSystem->type() == FileSystemTypeTemporary || m_fileSystem->type() == FileSystemTypePersistent) {
m_successCallback->handleEvent(File::createWithName(metadata.platformPath, m_name).get());
} else if (!metadata.platformPath.isEmpty()) {
m_successCallback->handleEvent(File::createForFileSystemFile(m_name, metadata).get());
} else {
m_successCallback->handleEvent(File::createForFileSystemFile(m_url, metadata).get());
}
m_successCallback.release();
}
private:
SnapshotFileCallback(PassRefPtrWillBeRawPtr<DOMFileSystem> filesystem, const String& name, const KURL& url, PassOwnPtr<FileCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback)
: FileSystemCallbacksBase(errorCallback, filesystem.get())
, m_name(name)
, m_url(url)
, m_successCallback(successCallback)
{
}
String m_name;
KURL m_url;
OwnPtr<FileCallback> m_successCallback;
};
}
void DOMFileSystem::createFile(const FileEntry* fileEntry, PassOwnPtr<FileCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback)
{
KURL fileSystemURL = createFileSystemURL(fileEntry);
fileSystem()->createSnapshotFileAndReadMetadata(fileSystemURL, SnapshotFileCallback::create(this, fileEntry->name(), fileSystemURL, successCallback, errorCallback));
}
}