Chromium Code Reviews| Index: Source/modules/filesystem/LocalFileSystem.cpp |
| diff --git a/Source/modules/filesystem/LocalFileSystem.cpp b/Source/modules/filesystem/LocalFileSystem.cpp |
| index 98d046d5beecfa556938bcf35821c9b5f255a86a..80408585089d4167a84a16861d2f86777fed1692 100644 |
| --- a/Source/modules/filesystem/LocalFileSystem.cpp |
| +++ b/Source/modules/filesystem/LocalFileSystem.cpp |
| @@ -41,6 +41,7 @@ |
| #include "modules/filesystem/FileSystemClient.h" |
| #include "modules/filesystem/InspectorFileSystemAgent.h" |
| #include "platform/AsyncFileSystemCallbacks.h" |
| +#include "platform/PermissionCallbacks.h" |
| #include "public/platform/Platform.h" |
| #include "public/platform/WebFileSystem.h" |
| @@ -66,34 +67,99 @@ LocalFileSystem::~LocalFileSystem() |
| void LocalFileSystem::resolveURL(ExecutionContext* context, const KURL& fileSystemURL, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) |
| { |
| - if (!client() || !client()->allowFileSystem(context)) { |
| - context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks)); |
| + RefPtr<ExecutionContext> contextPtr(context); |
| + RefPtr<RefCountedFileSystemCallbacks> refCountedCallbacks = adoptRef(new RefCountedFileSystemCallbacks(callbacks)); |
| + if (!client()) { |
| + fileSystemNotAllowedInternal(contextPtr, refCountedCallbacks); |
| return; |
| } |
| - blink::Platform::current()->fileSystem()->resolveURL(fileSystemURL, callbacks); |
| + ASSERT(contextPtr); |
| + if (!contextPtr->isDocument()) { |
| + if (!client()->requestFileSystemAccessSync(contextPtr.get())) { |
| + fileSystemNotAllowedInternal(contextPtr, refCountedCallbacks); |
| + return; |
| + } |
| + resolveURLInternal(fileSystemURL, refCountedCallbacks); |
| + return; |
| + } |
| + requestFileSystemAccesssAsyncInternal( |
| + contextPtr, |
| + bind(&LocalFileSystem::resolveURLInternal, this, fileSystemURL, refCountedCallbacks), |
| + bind(&LocalFileSystem::fileSystemNotAllowedInternal, this, contextPtr, refCountedCallbacks)); |
| } |
| void LocalFileSystem::requestFileSystem(ExecutionContext* context, FileSystemType type, long long size, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) |
| { |
| - if (!client() || !client()->allowFileSystem(context)) { |
| - context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks)); |
| + RefPtr<ExecutionContext> contextPtr(context); |
| + RefPtr<RefCountedFileSystemCallbacks> refCountedCallbacks = adoptRef(new RefCountedFileSystemCallbacks(callbacks)); |
| + if (!client()) { |
| + fileSystemNotAllowedInternal(contextPtr, refCountedCallbacks); |
| return; |
| } |
| - KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString()); |
| - blink::Platform::current()->fileSystem()->openFileSystem(storagePartition, static_cast<blink::WebFileSystemType>(type), callbacks); |
| + ASSERT(contextPtr); |
| + if (!contextPtr->isDocument()) { |
| + if (!client()->requestFileSystemAccessSync(contextPtr.get())) { |
| + fileSystemNotAllowedInternal(contextPtr, refCountedCallbacks); |
| + return; |
| + } |
| + fileSystemAllowedInternal(contextPtr, type, refCountedCallbacks); |
| + return; |
| + } |
| + requestFileSystemAccesssAsyncInternal( |
| + contextPtr, |
| + bind(&LocalFileSystem::fileSystemAllowedInternal, this, contextPtr, type, refCountedCallbacks), |
| + bind(&LocalFileSystem::fileSystemNotAllowedInternal, this, contextPtr, refCountedCallbacks)); |
| } |
| void LocalFileSystem::deleteFileSystem(ExecutionContext* context, FileSystemType type, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) |
| { |
| - ASSERT(context); |
| - ASSERT_WITH_SECURITY_IMPLICATION(context->isDocument()); |
| - |
| - if (!client() || !client()->allowFileSystem(context)) { |
| - context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks)); |
| + RefPtr<ExecutionContext> contextPtr(context); |
| + ASSERT(contextPtr); |
| + ASSERT_WITH_SECURITY_IMPLICATION(contextPtr->isDocument()); |
| + RefPtr<RefCountedFileSystemCallbacks> refCountedCallbacks = adoptRef(new RefCountedFileSystemCallbacks(callbacks)); |
| + if (!client()) { |
| + fileSystemNotAllowedInternal(contextPtr, refCountedCallbacks); |
| return; |
| } |
| + requestFileSystemAccesssAsyncInternal( |
| + contextPtr, |
| + bind(&LocalFileSystem::deleteFileSystemInternal, this, contextPtr, type, refCountedCallbacks), |
| + bind(&LocalFileSystem::fileSystemNotAllowedInternal, this, contextPtr, refCountedCallbacks)); |
| +} |
| + |
| +void LocalFileSystem::fileSystemNotAllowedInternal( |
| + PassRefPtr<ExecutionContext> context, |
| + PassRefPtr<RefCountedFileSystemCallbacks> callbacks) { |
| + context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks->callbacks)); |
| +} |
| + |
| +void LocalFileSystem::fileSystemAllowedInternal( |
| + PassRefPtr<ExecutionContext> context, |
| + FileSystemType type, |
| + PassRefPtr<RefCountedFileSystemCallbacks> callbacks) { |
| + KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString()); |
| + blink::Platform::current()->fileSystem()->openFileSystem(storagePartition, static_cast<blink::WebFileSystemType>(type), callbacks->callbacks); |
| +} |
| + |
| +void LocalFileSystem::resolveURLInternal( |
| + const KURL& fileSystemURL, |
| + PassRefPtr<RefCountedFileSystemCallbacks> callbacks) { |
|
kinuko
2014/05/22 10:37:42
Please break the line before '{' (here and below.
Xi Han
2014/05/22 14:21:41
Done.
|
| + blink::Platform::current()->fileSystem()->resolveURL(fileSystemURL, callbacks->callbacks); |
| +} |
| + |
| +void LocalFileSystem::deleteFileSystemInternal( |
| + PassRefPtr<ExecutionContext> context, |
| + FileSystemType type, |
| + PassRefPtr<RefCountedFileSystemCallbacks> callbacks) { |
| KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString()); |
| - blink::Platform::current()->fileSystem()->deleteFileSystem(storagePartition, static_cast<blink::WebFileSystemType>(type), callbacks); |
| + blink::Platform::current()->fileSystem()->deleteFileSystem(storagePartition, static_cast<blink::WebFileSystemType>(type), callbacks->callbacks); |
| +} |
| + |
| +void LocalFileSystem::requestFileSystemAccesssAsyncInternal( |
| + PassRefPtr<ExecutionContext> context, |
| + const Closure& allowedCallback, |
| + const Closure& deniedCallback) { |
| + client()->requestFileSystemAccessAsync(context.get(), PermissionCallbacks::create(allowedCallback, deniedCallback)); |
| } |
| LocalFileSystem::LocalFileSystem(PassOwnPtr<FileSystemClient> client) |