DOMWindowFileSystem.cpp [plain text]
#include "config.h"
#include "DOMWindowFileSystem.h"
#if ENABLE(FILE_SYSTEM)
#include "AsyncFileSystem.h"
#include "DOMFileSystem.h"
#include "DOMWindow.h"
#include "Document.h"
#include "EntryCallback.h"
#include "ErrorCallback.h"
#include "FileError.h"
#include "FileSystemCallback.h"
#include "FileSystemCallbacks.h"
#include "LocalFileSystem.h"
#include "SecurityOrigin.h"
namespace WebCore {
DOMWindowFileSystem::DOMWindowFileSystem()
{
}
DOMWindowFileSystem::~DOMWindowFileSystem()
{
}
void DOMWindowFileSystem::webkitRequestFileSystem(DOMWindow* window, int type, long long size, PassRefPtr<FileSystemCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
{
if (!window->isCurrentlyDisplayedInFrame())
return;
Document* document = window->document();
if (!document)
return;
if (!AsyncFileSystem::isAvailable() || !document->securityOrigin()->canAccessFileSystem()) {
DOMFileSystem::scheduleCallback(document, errorCallback, FileError::create(FileError::SECURITY_ERR));
return;
}
AsyncFileSystem::Type fileSystemType = static_cast<AsyncFileSystem::Type>(type);
if (!AsyncFileSystem::isValidType(fileSystemType)) {
DOMFileSystem::scheduleCallback(document, errorCallback, FileError::create(FileError::INVALID_MODIFICATION_ERR));
return;
}
LocalFileSystem::localFileSystem().requestFileSystem(document, fileSystemType, size, FileSystemCallbacks::create(successCallback, errorCallback, document), false);
}
void DOMWindowFileSystem::webkitResolveLocalFileSystemURL(DOMWindow* window, const String& url, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
{
if (!window->isCurrentlyDisplayedInFrame())
return;
Document* document = window->document();
if (!document)
return;
SecurityOrigin* securityOrigin = document->securityOrigin();
KURL completedURL = document->completeURL(url);
if (!AsyncFileSystem::isAvailable() || !securityOrigin->canAccessFileSystem() || !securityOrigin->canRequest(completedURL)) {
DOMFileSystem::scheduleCallback(document, errorCallback, FileError::create(FileError::SECURITY_ERR));
return;
}
AsyncFileSystem::Type type;
String filePath;
if (!completedURL.isValid() || !AsyncFileSystem::crackFileSystemURL(completedURL, type, filePath)) {
DOMFileSystem::scheduleCallback(document, errorCallback, FileError::create(FileError::ENCODING_ERR));
return;
}
LocalFileSystem::localFileSystem().readFileSystem(document, type, ResolveURICallbacks::create(successCallback, errorCallback, document, filePath));
}
COMPILE_ASSERT(static_cast<int>(DOMWindowFileSystem::TEMPORARY) == static_cast<int>(AsyncFileSystem::Temporary), enum_mismatch);
COMPILE_ASSERT(static_cast<int>(DOMWindowFileSystem::PERSISTENT) == static_cast<int>(AsyncFileSystem::Persistent), enum_mismatch);
}
#endif // ENABLE(FILE_SYSTEM)