| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 * Copyright (C) 2009, 2011 Google Inc. All Rights Reserved. | 3 * Copyright (C) 2009, 2011 Google Inc. All Rights Reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| 11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
| 12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
| 13 * | 13 * |
| 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 * | 25 * |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #include "config.h" | 28 #include "config.h" |
| 29 #include "modules/filesystem/WorkerContextFileSystem.h" | 29 #include "modules/filesystem/WorkerGlobalScopeFileSystem.h" |
| 30 | 30 |
| 31 #include "core/fileapi/FileError.h" | 31 #include "core/fileapi/FileError.h" |
| 32 #include "core/fileapi/FileException.h" | 32 #include "core/fileapi/FileException.h" |
| 33 #include "core/platform/AsyncFileSystem.h" | 33 #include "core/platform/AsyncFileSystem.h" |
| 34 #include "core/workers/WorkerContext.h" | 34 #include "core/workers/WorkerGlobalScope.h" |
| 35 #include "modules/filesystem/DOMFileSystemBase.h" | 35 #include "modules/filesystem/DOMFileSystemBase.h" |
| 36 #include "modules/filesystem/DOMFileSystemSync.h" | 36 #include "modules/filesystem/DOMFileSystemSync.h" |
| 37 #include "modules/filesystem/DirectoryEntrySync.h" | 37 #include "modules/filesystem/DirectoryEntrySync.h" |
| 38 #include "modules/filesystem/ErrorCallback.h" | 38 #include "modules/filesystem/ErrorCallback.h" |
| 39 #include "modules/filesystem/FileEntrySync.h" | 39 #include "modules/filesystem/FileEntrySync.h" |
| 40 #include "modules/filesystem/FileSystemCallback.h" | 40 #include "modules/filesystem/FileSystemCallback.h" |
| 41 #include "modules/filesystem/FileSystemCallbacks.h" | 41 #include "modules/filesystem/FileSystemCallbacks.h" |
| 42 #include "modules/filesystem/FileSystemType.h" | 42 #include "modules/filesystem/FileSystemType.h" |
| 43 #include "modules/filesystem/LocalFileSystem.h" | 43 #include "modules/filesystem/LocalFileSystem.h" |
| 44 #include "modules/filesystem/SyncCallbackHelper.h" | 44 #include "modules/filesystem/SyncCallbackHelper.h" |
| 45 #include "weborigin/SecurityOrigin.h" | 45 #include "weborigin/SecurityOrigin.h" |
| 46 | 46 |
| 47 namespace WebCore { | 47 namespace WebCore { |
| 48 | 48 |
| 49 void WorkerContextFileSystem::webkitRequestFileSystem(WorkerContext* worker, int
type, long long size, PassRefPtr<FileSystemCallback> successCallback, PassRefPt
r<ErrorCallback> errorCallback) | 49 void WorkerGlobalScopeFileSystem::webkitRequestFileSystem(WorkerGlobalScope* wor
ker, int type, long long size, PassRefPtr<FileSystemCallback> successCallback, P
assRefPtr<ErrorCallback> errorCallback) |
| 50 { | 50 { |
| 51 ScriptExecutionContext* secureContext = worker->scriptExecutionContext(); | 51 ScriptExecutionContext* secureContext = worker->scriptExecutionContext(); |
| 52 if (!secureContext->securityOrigin()->canAccessFileSystem()) { | 52 if (!secureContext->securityOrigin()->canAccessFileSystem()) { |
| 53 DOMFileSystem::scheduleCallback(worker, errorCallback, FileError::create
(FileError::SECURITY_ERR)); | 53 DOMFileSystem::scheduleCallback(worker, errorCallback, FileError::create
(FileError::SECURITY_ERR)); |
| 54 return; | 54 return; |
| 55 } | 55 } |
| 56 | 56 |
| 57 FileSystemType fileSystemType = static_cast<FileSystemType>(type); | 57 FileSystemType fileSystemType = static_cast<FileSystemType>(type); |
| 58 if (!DOMFileSystemBase::isValidType(fileSystemType)) { | 58 if (!DOMFileSystemBase::isValidType(fileSystemType)) { |
| 59 DOMFileSystem::scheduleCallback(worker, errorCallback, FileError::create
(FileError::INVALID_MODIFICATION_ERR)); | 59 DOMFileSystem::scheduleCallback(worker, errorCallback, FileError::create
(FileError::INVALID_MODIFICATION_ERR)); |
| 60 return; | 60 return; |
| 61 } | 61 } |
| 62 | 62 |
| 63 LocalFileSystem::localFileSystem().requestFileSystem(worker, fileSystemType,
size, FileSystemCallbacks::create(successCallback, errorCallback, worker, fileS
ystemType), AsynchronousFileSystem); | 63 LocalFileSystem::localFileSystem().requestFileSystem(worker, fileSystemType,
size, FileSystemCallbacks::create(successCallback, errorCallback, worker, fileS
ystemType), AsynchronousFileSystem); |
| 64 } | 64 } |
| 65 | 65 |
| 66 PassRefPtr<DOMFileSystemSync> WorkerContextFileSystem::webkitRequestFileSystemSy
nc(WorkerContext* worker, int type, long long size, ExceptionCode& ec) | 66 PassRefPtr<DOMFileSystemSync> WorkerGlobalScopeFileSystem::webkitRequestFileSyst
emSync(WorkerGlobalScope* worker, int type, long long size, ExceptionCode& ec) |
| 67 { | 67 { |
| 68 ec = 0; | 68 ec = 0; |
| 69 ScriptExecutionContext* secureContext = worker->scriptExecutionContext(); | 69 ScriptExecutionContext* secureContext = worker->scriptExecutionContext(); |
| 70 if (!secureContext->securityOrigin()->canAccessFileSystem()) { | 70 if (!secureContext->securityOrigin()->canAccessFileSystem()) { |
| 71 ec = FileException::SECURITY_ERR; | 71 ec = FileException::SECURITY_ERR; |
| 72 return 0; | 72 return 0; |
| 73 } | 73 } |
| 74 | 74 |
| 75 FileSystemType fileSystemType = static_cast<FileSystemType>(type); | 75 FileSystemType fileSystemType = static_cast<FileSystemType>(type); |
| 76 if (!DOMFileSystemBase::isValidType(fileSystemType)) { | 76 if (!DOMFileSystemBase::isValidType(fileSystemType)) { |
| 77 ec = FileException::INVALID_MODIFICATION_ERR; | 77 ec = FileException::INVALID_MODIFICATION_ERR; |
| 78 return 0; | 78 return 0; |
| 79 } | 79 } |
| 80 | 80 |
| 81 FileSystemSyncCallbackHelper helper; | 81 FileSystemSyncCallbackHelper helper; |
| 82 LocalFileSystem::localFileSystem().requestFileSystem(worker, fileSystemType,
size, FileSystemCallbacks::create(helper.successCallback(), helper.errorCallbac
k(), worker, fileSystemType), SynchronousFileSystem); | 82 LocalFileSystem::localFileSystem().requestFileSystem(worker, fileSystemType,
size, FileSystemCallbacks::create(helper.successCallback(), helper.errorCallbac
k(), worker, fileSystemType), SynchronousFileSystem); |
| 83 return helper.getResult(ec); | 83 return helper.getResult(ec); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void WorkerContextFileSystem::webkitResolveLocalFileSystemURL(WorkerContext* wor
ker, const String& url, PassRefPtr<EntryCallback> successCallback, PassRefPtr<Er
rorCallback> errorCallback) | 86 void WorkerGlobalScopeFileSystem::webkitResolveLocalFileSystemURL(WorkerGlobalSc
ope* worker, const String& url, PassRefPtr<EntryCallback> successCallback, PassR
efPtr<ErrorCallback> errorCallback) |
| 87 { | 87 { |
| 88 KURL completedURL = worker->completeURL(url); | 88 KURL completedURL = worker->completeURL(url); |
| 89 ScriptExecutionContext* secureContext = worker->scriptExecutionContext(); | 89 ScriptExecutionContext* secureContext = worker->scriptExecutionContext(); |
| 90 if (!secureContext->securityOrigin()->canAccessFileSystem() || !secureContex
t->securityOrigin()->canRequest(completedURL)) { | 90 if (!secureContext->securityOrigin()->canAccessFileSystem() || !secureContex
t->securityOrigin()->canRequest(completedURL)) { |
| 91 DOMFileSystem::scheduleCallback(worker, errorCallback, FileError::create
(FileError::SECURITY_ERR)); | 91 DOMFileSystem::scheduleCallback(worker, errorCallback, FileError::create
(FileError::SECURITY_ERR)); |
| 92 return; | 92 return; |
| 93 } | 93 } |
| 94 | 94 |
| 95 FileSystemType type; | 95 FileSystemType type; |
| 96 String filePath; | 96 String filePath; |
| 97 if (!completedURL.isValid() || !DOMFileSystemBase::crackFileSystemURL(comple
tedURL, type, filePath)) { | 97 if (!completedURL.isValid() || !DOMFileSystemBase::crackFileSystemURL(comple
tedURL, type, filePath)) { |
| 98 DOMFileSystem::scheduleCallback(worker, errorCallback, FileError::create
(FileError::ENCODING_ERR)); | 98 DOMFileSystem::scheduleCallback(worker, errorCallback, FileError::create
(FileError::ENCODING_ERR)); |
| 99 return; | 99 return; |
| 100 } | 100 } |
| 101 | 101 |
| 102 LocalFileSystem::localFileSystem().readFileSystem(worker, type, ResolveURICa
llbacks::create(successCallback, errorCallback, worker, type, filePath)); | 102 LocalFileSystem::localFileSystem().readFileSystem(worker, type, ResolveURICa
llbacks::create(successCallback, errorCallback, worker, type, filePath)); |
| 103 } | 103 } |
| 104 | 104 |
| 105 PassRefPtr<EntrySync> WorkerContextFileSystem::webkitResolveLocalFileSystemSyncU
RL(WorkerContext* worker, const String& url, ExceptionCode& ec) | 105 PassRefPtr<EntrySync> WorkerGlobalScopeFileSystem::webkitResolveLocalFileSystemS
yncURL(WorkerGlobalScope* worker, const String& url, ExceptionCode& ec) |
| 106 { | 106 { |
| 107 ec = 0; | 107 ec = 0; |
| 108 KURL completedURL = worker->completeURL(url); | 108 KURL completedURL = worker->completeURL(url); |
| 109 ScriptExecutionContext* secureContext = worker->scriptExecutionContext(); | 109 ScriptExecutionContext* secureContext = worker->scriptExecutionContext(); |
| 110 if (!secureContext->securityOrigin()->canAccessFileSystem() || !secureContex
t->securityOrigin()->canRequest(completedURL)) { | 110 if (!secureContext->securityOrigin()->canAccessFileSystem() || !secureContex
t->securityOrigin()->canRequest(completedURL)) { |
| 111 ec = FileException::SECURITY_ERR; | 111 ec = FileException::SECURITY_ERR; |
| 112 return 0; | 112 return 0; |
| 113 } | 113 } |
| 114 | 114 |
| 115 FileSystemType type; | 115 FileSystemType type; |
| 116 String filePath; | 116 String filePath; |
| 117 if (!completedURL.isValid() || !DOMFileSystemBase::crackFileSystemURL(comple
tedURL, type, filePath)) { | 117 if (!completedURL.isValid() || !DOMFileSystemBase::crackFileSystemURL(comple
tedURL, type, filePath)) { |
| 118 ec = FileException::ENCODING_ERR; | 118 ec = FileException::ENCODING_ERR; |
| 119 return 0; | 119 return 0; |
| 120 } | 120 } |
| 121 | 121 |
| 122 FileSystemSyncCallbackHelper readFileSystemHelper; | 122 FileSystemSyncCallbackHelper readFileSystemHelper; |
| 123 LocalFileSystem::localFileSystem().readFileSystem(worker, type, FileSystemCa
llbacks::create(readFileSystemHelper.successCallback(), readFileSystemHelper.err
orCallback(), worker, type), SynchronousFileSystem); | 123 LocalFileSystem::localFileSystem().readFileSystem(worker, type, FileSystemCa
llbacks::create(readFileSystemHelper.successCallback(), readFileSystemHelper.err
orCallback(), worker, type), SynchronousFileSystem); |
| 124 RefPtr<DOMFileSystemSync> fileSystem = readFileSystemHelper.getResult(ec); | 124 RefPtr<DOMFileSystemSync> fileSystem = readFileSystemHelper.getResult(ec); |
| 125 if (!fileSystem) | 125 if (!fileSystem) |
| 126 return 0; | 126 return 0; |
| 127 | 127 |
| 128 RefPtr<EntrySync> entry = fileSystem->root()->getDirectory(filePath, Diction
ary(), ec); | 128 RefPtr<EntrySync> entry = fileSystem->root()->getDirectory(filePath, Diction
ary(), ec); |
| 129 if (ec == FileException::TYPE_MISMATCH_ERR) | 129 if (ec == FileException::TYPE_MISMATCH_ERR) |
| 130 return fileSystem->root()->getFile(filePath, Dictionary(), ec); | 130 return fileSystem->root()->getFile(filePath, Dictionary(), ec); |
| 131 | 131 |
| 132 return entry.release(); | 132 return entry.release(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 COMPILE_ASSERT(static_cast<int>(WorkerContextFileSystem::TEMPORARY) == static_ca
st<int>(FileSystemTypeTemporary), enum_mismatch); | 135 COMPILE_ASSERT(static_cast<int>(WorkerGlobalScopeFileSystem::TEMPORARY) == stati
c_cast<int>(FileSystemTypeTemporary), enum_mismatch); |
| 136 COMPILE_ASSERT(static_cast<int>(WorkerContextFileSystem::PERSISTENT) == static_c
ast<int>(FileSystemTypePersistent), enum_mismatch); | 136 COMPILE_ASSERT(static_cast<int>(WorkerGlobalScopeFileSystem::PERSISTENT) == stat
ic_cast<int>(FileSystemTypePersistent), enum_mismatch); |
| 137 | 137 |
| 138 } // namespace WebCore | 138 } // namespace WebCore |
| OLD | NEW |