This source file includes following definitions.
- webkitRequestFileSystem
- webkitRequestFileSystemSync
- webkitResolveLocalFileSystemURL
- webkitResolveLocalFileSystemSyncURL
#include "config.h"
#include "modules/filesystem/WorkerGlobalScopeFileSystem.h"
#include "bindings/v8/ExceptionState.h"
#include "core/dom/ExceptionCode.h"
#include "core/fileapi/FileError.h"
#include "core/workers/WorkerGlobalScope.h"
#include "modules/filesystem/DOMFileSystemBase.h"
#include "modules/filesystem/DirectoryEntrySync.h"
#include "modules/filesystem/ErrorCallback.h"
#include "modules/filesystem/FileEntrySync.h"
#include "modules/filesystem/FileSystemCallback.h"
#include "modules/filesystem/FileSystemCallbacks.h"
#include "modules/filesystem/LocalFileSystem.h"
#include "modules/filesystem/SyncCallbackHelper.h"
#include "platform/FileSystemType.h"
#include "platform/weborigin/SecurityOrigin.h"
namespace WebCore {
void WorkerGlobalScopeFileSystem::webkitRequestFileSystem(WorkerGlobalScope& worker, int type, long long size, PassOwnPtr<FileSystemCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback)
{
ExecutionContext* secureContext = worker.executionContext();
if (!secureContext->securityOrigin()->canAccessFileSystem()) {
DOMFileSystem::scheduleCallback(&worker, errorCallback, FileError::create(FileError::SECURITY_ERR));
return;
}
FileSystemType fileSystemType = static_cast<FileSystemType>(type);
if (!DOMFileSystemBase::isValidType(fileSystemType)) {
DOMFileSystem::scheduleCallback(&worker, errorCallback, FileError::create(FileError::INVALID_MODIFICATION_ERR));
return;
}
LocalFileSystem::from(worker)->requestFileSystem(&worker, fileSystemType, size, FileSystemCallbacks::create(successCallback, errorCallback, &worker, fileSystemType));
}
PassRefPtrWillBeRawPtr<DOMFileSystemSync> WorkerGlobalScopeFileSystem::webkitRequestFileSystemSync(WorkerGlobalScope& worker, int type, long long size, ExceptionState& exceptionState)
{
ExecutionContext* secureContext = worker.executionContext();
if (!secureContext->securityOrigin()->canAccessFileSystem()) {
exceptionState.throwSecurityError(FileError::securityErrorMessage);
return nullptr;
}
FileSystemType fileSystemType = static_cast<FileSystemType>(type);
if (!DOMFileSystemBase::isValidType(fileSystemType)) {
exceptionState.throwDOMException(InvalidModificationError, "the type must be TEMPORARY or PERSISTENT.");
return nullptr;
}
RefPtr<FileSystemSyncCallbackHelper> helper = FileSystemSyncCallbackHelper::create();
OwnPtr<AsyncFileSystemCallbacks> callbacks = FileSystemCallbacks::create(helper->successCallback(), helper->errorCallback(), &worker, fileSystemType);
callbacks->setShouldBlockUntilCompletion(true);
LocalFileSystem::from(worker)->requestFileSystem(&worker, fileSystemType, size, callbacks.release());
return helper->getResult(exceptionState);
}
void WorkerGlobalScopeFileSystem::webkitResolveLocalFileSystemURL(WorkerGlobalScope& worker, const String& url, PassOwnPtr<EntryCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback)
{
KURL completedURL = worker.completeURL(url);
ExecutionContext* secureContext = worker.executionContext();
if (!secureContext->securityOrigin()->canAccessFileSystem() || !secureContext->securityOrigin()->canRequest(completedURL)) {
DOMFileSystem::scheduleCallback(&worker, errorCallback, FileError::create(FileError::SECURITY_ERR));
return;
}
if (!completedURL.isValid()) {
DOMFileSystem::scheduleCallback(&worker, errorCallback, FileError::create(FileError::ENCODING_ERR));
return;
}
LocalFileSystem::from(worker)->resolveURL(&worker, completedURL, ResolveURICallbacks::create(successCallback, errorCallback, &worker));
}
PassRefPtrWillBeRawPtr<EntrySync> WorkerGlobalScopeFileSystem::webkitResolveLocalFileSystemSyncURL(WorkerGlobalScope& worker, const String& url, ExceptionState& exceptionState)
{
KURL completedURL = worker.completeURL(url);
ExecutionContext* secureContext = worker.executionContext();
if (!secureContext->securityOrigin()->canAccessFileSystem() || !secureContext->securityOrigin()->canRequest(completedURL)) {
exceptionState.throwSecurityError(FileError::securityErrorMessage);
return nullptr;
}
if (!completedURL.isValid()) {
exceptionState.throwDOMException(EncodingError, "the URL '" + url + "' is invalid.");
return nullptr;
}
RefPtr<EntrySyncCallbackHelper> resolveURLHelper = EntrySyncCallbackHelper::create();
OwnPtr<AsyncFileSystemCallbacks> callbacks = ResolveURICallbacks::create(resolveURLHelper->successCallback(), resolveURLHelper->errorCallback(), &worker);
callbacks->setShouldBlockUntilCompletion(true);
LocalFileSystem::from(worker)->resolveURL(&worker, completedURL, callbacks.release());
RefPtrWillBeRawPtr<EntrySync> entry = resolveURLHelper->getResult(exceptionState);
if (!entry)
return nullptr;
return entry.release();
}
COMPILE_ASSERT(static_cast<int>(WorkerGlobalScopeFileSystem::TEMPORARY) == static_cast<int>(FileSystemTypeTemporary), enum_mismatch);
COMPILE_ASSERT(static_cast<int>(WorkerGlobalScopeFileSystem::PERSISTENT) == static_cast<int>(FileSystemTypePersistent), enum_mismatch);
}