| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "core/dom/CrossThreadTask.h" | 34 #include "core/dom/CrossThreadTask.h" |
| 35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
| 36 #include "core/dom/ExceptionCode.h" | 36 #include "core/dom/ExceptionCode.h" |
| 37 #include "core/dom/ExecutionContext.h" | 37 #include "core/dom/ExecutionContext.h" |
| 38 #include "core/fileapi/FileError.h" | 38 #include "core/fileapi/FileError.h" |
| 39 #include "core/inspector/InspectorController.h" | 39 #include "core/inspector/InspectorController.h" |
| 40 #include "core/workers/WorkerGlobalScope.h" | 40 #include "core/workers/WorkerGlobalScope.h" |
| 41 #include "modules/filesystem/FileSystemClient.h" | 41 #include "modules/filesystem/FileSystemClient.h" |
| 42 #include "modules/filesystem/InspectorFileSystemAgent.h" | 42 #include "modules/filesystem/InspectorFileSystemAgent.h" |
| 43 #include "platform/AsyncFileSystemCallbacks.h" | 43 #include "platform/AsyncFileSystemCallbacks.h" |
| 44 #include "platform/PermissionCallbacks.h" |
| 44 #include "public/platform/Platform.h" | 45 #include "public/platform/Platform.h" |
| 45 #include "public/platform/WebFileSystem.h" | 46 #include "public/platform/WebFileSystem.h" |
| 47 #include "wtf/Functional.h" |
| 48 #include "wtf/RefCounted.h" |
| 46 | 49 |
| 47 namespace WebCore { | 50 namespace WebCore { |
| 48 | 51 |
| 49 namespace { | 52 namespace { |
| 50 | 53 |
| 51 void fileSystemNotAllowed(ExecutionContext*, PassOwnPtr<AsyncFileSystemCallbacks
> callbacks) | 54 void fileSystemNotAllowed(ExecutionContext*, PassOwnPtr<AsyncFileSystemCallbacks
> callbacks) |
| 52 { | 55 { |
| 53 callbacks->didFail(FileError::ABORT_ERR); | 56 callbacks->didFail(FileError::ABORT_ERR); |
| 54 } | 57 } |
| 55 | 58 |
| 56 } // namespace | 59 } // namespace |
| 57 | 60 |
| 61 class CallbackWrapper : public RefCounted<CallbackWrapper> { |
| 62 public: |
| 63 CallbackWrapper(PassOwnPtr<AsyncFileSystemCallbacks> c) |
| 64 : m_callbacks(c) |
| 65 { |
| 66 } |
| 67 virtual ~CallbackWrapper() { } |
| 68 PassOwnPtr<AsyncFileSystemCallbacks> release() |
| 69 { |
| 70 return m_callbacks.release(); |
| 71 } |
| 72 |
| 73 private: |
| 74 OwnPtr<AsyncFileSystemCallbacks> m_callbacks; |
| 75 }; |
| 76 |
| 58 PassOwnPtrWillBeRawPtr<LocalFileSystem> LocalFileSystem::create(PassOwnPtr<FileS
ystemClient> client) | 77 PassOwnPtrWillBeRawPtr<LocalFileSystem> LocalFileSystem::create(PassOwnPtr<FileS
ystemClient> client) |
| 59 { | 78 { |
| 60 return adoptPtrWillBeNoop(new LocalFileSystem(client)); | 79 return adoptPtrWillBeNoop(new LocalFileSystem(client)); |
| 61 } | 80 } |
| 62 | 81 |
| 63 LocalFileSystem::~LocalFileSystem() | 82 LocalFileSystem::~LocalFileSystem() |
| 64 { | 83 { |
| 65 } | 84 } |
| 66 | 85 |
| 67 void LocalFileSystem::resolveURL(ExecutionContext* context, const KURL& fileSyst
emURL, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) | 86 void LocalFileSystem::resolveURL(ExecutionContext* context, const KURL& fileSyst
emURL, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) |
| 68 { | 87 { |
| 69 if (!client() || !client()->allowFileSystem(context)) { | 88 RefPtr<CallbackWrapper> wrapper = adoptRef(new CallbackWrapper(callbacks)); |
| 70 context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks)); | 89 requestFileSystemAccessInternal(context, |
| 71 return; | 90 bind(&LocalFileSystem::resolveURLInternal, this, fileSystemURL, wrapper)
, |
| 72 } | 91 bind(&LocalFileSystem::fileSystemNotAllowedInternal, this, PassRefPtr<Ex
ecutionContext>(context), wrapper)); |
| 73 blink::Platform::current()->fileSystem()->resolveURL(fileSystemURL, callback
s); | |
| 74 } | 92 } |
| 75 | 93 |
| 76 void LocalFileSystem::requestFileSystem(ExecutionContext* context, FileSystemTyp
e type, long long size, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) | 94 void LocalFileSystem::requestFileSystem(ExecutionContext* context, FileSystemTyp
e type, long long size, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) |
| 77 { | 95 { |
| 78 if (!client() || !client()->allowFileSystem(context)) { | 96 RefPtr<ExecutionContext> contextPtr(context); |
| 79 context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks)); | 97 RefPtr<CallbackWrapper> wrapper = adoptRef(new CallbackWrapper(callbacks)); |
| 80 return; | 98 requestFileSystemAccessInternal(context, |
| 81 } | 99 bind(&LocalFileSystem::fileSystemAllowedInternal, this, contextPtr, type
, wrapper), |
| 82 KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString()); | 100 bind(&LocalFileSystem::fileSystemNotAllowedInternal, this, contextPtr, w
rapper)); |
| 83 blink::Platform::current()->fileSystem()->openFileSystem(storagePartition, s
tatic_cast<blink::WebFileSystemType>(type), callbacks); | |
| 84 } | 101 } |
| 85 | 102 |
| 86 void LocalFileSystem::deleteFileSystem(ExecutionContext* context, FileSystemType
type, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) | 103 void LocalFileSystem::deleteFileSystem(ExecutionContext* context, FileSystemType
type, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) |
| 87 { | 104 { |
| 105 RefPtr<ExecutionContext> contextPtr(context); |
| 88 ASSERT(context); | 106 ASSERT(context); |
| 89 ASSERT_WITH_SECURITY_IMPLICATION(context->isDocument()); | 107 ASSERT_WITH_SECURITY_IMPLICATION(context->isDocument()); |
| 90 | 108 |
| 91 if (!client() || !client()->allowFileSystem(context)) { | 109 RefPtr<CallbackWrapper> wrapper = adoptRef(new CallbackWrapper(callbacks)); |
| 92 context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks)); | 110 requestFileSystemAccessInternal(context, |
| 111 bind(&LocalFileSystem::deleteFileSystemInternal, this, contextPtr, type,
wrapper), |
| 112 bind(&LocalFileSystem::fileSystemNotAllowedInternal, this, contextPtr, w
rapper)); |
| 113 } |
| 114 |
| 115 void LocalFileSystem::requestFileSystemAccessInternal(ExecutionContext* context,
const Closure& allowed, const Closure& denied) |
| 116 { |
| 117 if (!client()) { |
| 118 denied(); |
| 93 return; | 119 return; |
| 94 } | 120 } |
| 121 if (!context->isDocument()) { |
| 122 if (!client()->requestFileSystemAccessSync(context)) { |
| 123 denied(); |
| 124 return; |
| 125 } |
| 126 allowed(); |
| 127 return; |
| 128 } |
| 129 client()->requestFileSystemAccessAsync(context, PermissionCallbacks::create(
allowed, denied)); |
| 130 } |
| 131 |
| 132 void LocalFileSystem::fileSystemNotAllowedInternal( |
| 133 PassRefPtr<ExecutionContext> context, |
| 134 PassRefPtr<CallbackWrapper> callbacks) |
| 135 { |
| 136 context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks->relea
se())); |
| 137 } |
| 138 |
| 139 void LocalFileSystem::fileSystemAllowedInternal( |
| 140 PassRefPtr<ExecutionContext> context, |
| 141 FileSystemType type, |
| 142 PassRefPtr<CallbackWrapper> callbacks) |
| 143 { |
| 95 KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString()); | 144 KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString()); |
| 96 blink::Platform::current()->fileSystem()->deleteFileSystem(storagePartition,
static_cast<blink::WebFileSystemType>(type), callbacks); | 145 blink::Platform::current()->fileSystem()->openFileSystem(storagePartition, s
tatic_cast<blink::WebFileSystemType>(type), callbacks->release()); |
| 146 } |
| 147 |
| 148 void LocalFileSystem::resolveURLInternal( |
| 149 const KURL& fileSystemURL, |
| 150 PassRefPtr<CallbackWrapper> callbacks) |
| 151 { |
| 152 blink::Platform::current()->fileSystem()->resolveURL(fileSystemURL, callback
s->release()); |
| 153 } |
| 154 |
| 155 void LocalFileSystem::deleteFileSystemInternal( |
| 156 PassRefPtr<ExecutionContext> context, |
| 157 FileSystemType type, |
| 158 PassRefPtr<CallbackWrapper> callbacks) |
| 159 { |
| 160 KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString()); |
| 161 blink::Platform::current()->fileSystem()->deleteFileSystem(storagePartition,
static_cast<blink::WebFileSystemType>(type), callbacks->release()); |
| 97 } | 162 } |
| 98 | 163 |
| 99 LocalFileSystem::LocalFileSystem(PassOwnPtr<FileSystemClient> client) | 164 LocalFileSystem::LocalFileSystem(PassOwnPtr<FileSystemClient> client) |
| 100 : m_client(client) | 165 : m_client(client) |
| 101 { | 166 { |
| 102 } | 167 } |
| 103 | 168 |
| 104 const char* LocalFileSystem::supplementName() | 169 const char* LocalFileSystem::supplementName() |
| 105 { | 170 { |
| 106 return "LocalFileSystem"; | 171 return "LocalFileSystem"; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 120 page.provideSupplement(LocalFileSystem::supplementName(), LocalFileSystem::c
reate(client)); | 185 page.provideSupplement(LocalFileSystem::supplementName(), LocalFileSystem::c
reate(client)); |
| 121 page.inspectorController().registerModuleAgent(InspectorFileSystemAgent::cre
ate(&page)); | 186 page.inspectorController().registerModuleAgent(InspectorFileSystemAgent::cre
ate(&page)); |
| 122 } | 187 } |
| 123 | 188 |
| 124 void provideLocalFileSystemToWorker(WorkerClients* clients, PassOwnPtr<FileSyste
mClient> client) | 189 void provideLocalFileSystemToWorker(WorkerClients* clients, PassOwnPtr<FileSyste
mClient> client) |
| 125 { | 190 { |
| 126 clients->provideSupplement(LocalFileSystem::supplementName(), LocalFileSyste
m::create(client)); | 191 clients->provideSupplement(LocalFileSystem::supplementName(), LocalFileSyste
m::create(client)); |
| 127 } | 192 } |
| 128 | 193 |
| 129 } // namespace WebCore | 194 } // namespace WebCore |
| OLD | NEW |