| Index: Source/modules/filesystem/LocalFileSystem.cpp
|
| diff --git a/Source/modules/filesystem/LocalFileSystem.cpp b/Source/modules/filesystem/LocalFileSystem.cpp
|
| index 98d046d5beecfa556938bcf35821c9b5f255a86a..deb05efb48881dafef35e7dc20ba3b5979ba5589 100644
|
| --- a/Source/modules/filesystem/LocalFileSystem.cpp
|
| +++ b/Source/modules/filesystem/LocalFileSystem.cpp
|
| @@ -41,8 +41,11 @@
|
| #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"
|
| +#include "wtf/Functional.h"
|
| +#include "wtf/RefCounted.h"
|
|
|
| namespace WebCore {
|
|
|
| @@ -55,6 +58,22 @@ void fileSystemNotAllowed(ExecutionContext*, PassOwnPtr<AsyncFileSystemCallbacks
|
|
|
| } // namespace
|
|
|
| +class CallbackWrapper : public RefCounted<CallbackWrapper> {
|
| +public:
|
| + CallbackWrapper(PassOwnPtr<AsyncFileSystemCallbacks> c)
|
| + : m_callbacks(c)
|
| + {
|
| + }
|
| + virtual ~CallbackWrapper() { }
|
| + PassOwnPtr<AsyncFileSystemCallbacks> release()
|
| + {
|
| + return m_callbacks.release();
|
| + }
|
| +
|
| +private:
|
| + OwnPtr<AsyncFileSystemCallbacks> m_callbacks;
|
| +};
|
| +
|
| PassOwnPtrWillBeRawPtr<LocalFileSystem> LocalFileSystem::create(PassOwnPtr<FileSystemClient> client)
|
| {
|
| return adoptPtrWillBeNoop(new LocalFileSystem(client));
|
| @@ -66,34 +85,80 @@ LocalFileSystem::~LocalFileSystem()
|
|
|
| void LocalFileSystem::resolveURL(ExecutionContext* context, const KURL& fileSystemURL, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
|
| {
|
| - if (!client() || !client()->allowFileSystem(context)) {
|
| - context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks));
|
| - return;
|
| - }
|
| - blink::Platform::current()->fileSystem()->resolveURL(fileSystemURL, callbacks);
|
| + RefPtr<CallbackWrapper> wrapper = adoptRef(new CallbackWrapper(callbacks));
|
| + requestFileSystemAccessInternal(context,
|
| + bind(&LocalFileSystem::resolveURLInternal, this, fileSystemURL, wrapper),
|
| + bind(&LocalFileSystem::fileSystemNotAllowedInternal, this, PassRefPtr<ExecutionContext>(context), wrapper));
|
| }
|
|
|
| void LocalFileSystem::requestFileSystem(ExecutionContext* context, FileSystemType type, long long size, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
|
| {
|
| - if (!client() || !client()->allowFileSystem(context)) {
|
| - context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks));
|
| - return;
|
| - }
|
| - KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString());
|
| - blink::Platform::current()->fileSystem()->openFileSystem(storagePartition, static_cast<blink::WebFileSystemType>(type), callbacks);
|
| + RefPtr<ExecutionContext> contextPtr(context);
|
| + RefPtr<CallbackWrapper> wrapper = adoptRef(new CallbackWrapper(callbacks));
|
| + requestFileSystemAccessInternal(context,
|
| + bind(&LocalFileSystem::fileSystemAllowedInternal, this, contextPtr, type, wrapper),
|
| + bind(&LocalFileSystem::fileSystemNotAllowedInternal, this, contextPtr, wrapper));
|
| }
|
|
|
| void LocalFileSystem::deleteFileSystem(ExecutionContext* context, FileSystemType type, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
|
| {
|
| + RefPtr<ExecutionContext> contextPtr(context);
|
| ASSERT(context);
|
| ASSERT_WITH_SECURITY_IMPLICATION(context->isDocument());
|
|
|
| - if (!client() || !client()->allowFileSystem(context)) {
|
| - context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks));
|
| + RefPtr<CallbackWrapper> wrapper = adoptRef(new CallbackWrapper(callbacks));
|
| + requestFileSystemAccessInternal(context,
|
| + bind(&LocalFileSystem::deleteFileSystemInternal, this, contextPtr, type, wrapper),
|
| + bind(&LocalFileSystem::fileSystemNotAllowedInternal, this, contextPtr, wrapper));
|
| +}
|
| +
|
| +void LocalFileSystem::requestFileSystemAccessInternal(ExecutionContext* context, const Closure& allowed, const Closure& denied)
|
| +{
|
| + if (!client()) {
|
| + denied();
|
| + return;
|
| + }
|
| + if (!context->isDocument()) {
|
| + if (!client()->requestFileSystemAccessSync(context)) {
|
| + denied();
|
| + return;
|
| + }
|
| + allowed();
|
| return;
|
| }
|
| + client()->requestFileSystemAccessAsync(context, PermissionCallbacks::create(allowed, denied));
|
| +}
|
| +
|
| +void LocalFileSystem::fileSystemNotAllowedInternal(
|
| + PassRefPtr<ExecutionContext> context,
|
| + PassRefPtr<CallbackWrapper> callbacks)
|
| +{
|
| + context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks->release()));
|
| +}
|
| +
|
| +void LocalFileSystem::fileSystemAllowedInternal(
|
| + PassRefPtr<ExecutionContext> context,
|
| + FileSystemType type,
|
| + PassRefPtr<CallbackWrapper> callbacks)
|
| +{
|
| + KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString());
|
| + blink::Platform::current()->fileSystem()->openFileSystem(storagePartition, static_cast<blink::WebFileSystemType>(type), callbacks->release());
|
| +}
|
| +
|
| +void LocalFileSystem::resolveURLInternal(
|
| + const KURL& fileSystemURL,
|
| + PassRefPtr<CallbackWrapper> callbacks)
|
| +{
|
| + blink::Platform::current()->fileSystem()->resolveURL(fileSystemURL, callbacks->release());
|
| +}
|
| +
|
| +void LocalFileSystem::deleteFileSystemInternal(
|
| + PassRefPtr<ExecutionContext> context,
|
| + FileSystemType type,
|
| + PassRefPtr<CallbackWrapper> 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->release());
|
| }
|
|
|
| LocalFileSystem::LocalFileSystem(PassOwnPtr<FileSystemClient> client)
|
|
|