| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "webkit/fileapi/isolated_mount_point_provider.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "base/files/file_path.h" | |
| 11 #include "base/files/file_util_proxy.h" | |
| 12 #include "base/logging.h" | |
| 13 #include "base/message_loop_proxy.h" | |
| 14 #include "base/platform_file.h" | |
| 15 #include "base/sequenced_task_runner.h" | |
| 16 #include "webkit/blob/local_file_stream_reader.h" | |
| 17 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" | |
| 18 #include "webkit/browser/fileapi/isolated_file_util.h" | |
| 19 #include "webkit/browser/fileapi/native_file_util.h" | |
| 20 #include "webkit/browser/fileapi/transient_file_util.h" | |
| 21 #include "webkit/fileapi/async_file_util_adapter.h" | |
| 22 #include "webkit/fileapi/file_system_context.h" | |
| 23 #include "webkit/fileapi/file_system_file_stream_reader.h" | |
| 24 #include "webkit/fileapi/file_system_operation_context.h" | |
| 25 #include "webkit/fileapi/file_system_task_runners.h" | |
| 26 #include "webkit/fileapi/file_system_types.h" | |
| 27 #include "webkit/fileapi/file_system_util.h" | |
| 28 #include "webkit/fileapi/isolated_context.h" | |
| 29 #include "webkit/fileapi/local_file_stream_writer.h" | |
| 30 #include "webkit/fileapi/local_file_system_operation.h" | |
| 31 | |
| 32 namespace fileapi { | |
| 33 | |
| 34 IsolatedMountPointProvider::IsolatedMountPointProvider() | |
| 35 : isolated_file_util_(new AsyncFileUtilAdapter(new IsolatedFileUtil())), | |
| 36 dragged_file_util_(new AsyncFileUtilAdapter(new DraggedFileUtil())), | |
| 37 transient_file_util_(new AsyncFileUtilAdapter(new TransientFileUtil())) { | |
| 38 } | |
| 39 | |
| 40 IsolatedMountPointProvider::~IsolatedMountPointProvider() { | |
| 41 } | |
| 42 | |
| 43 bool IsolatedMountPointProvider::CanHandleType(FileSystemType type) const { | |
| 44 switch (type) { | |
| 45 case kFileSystemTypeIsolated: | |
| 46 case kFileSystemTypeDragged: | |
| 47 case kFileSystemTypeForTransientFile: | |
| 48 return true; | |
| 49 #if !defined(OS_CHROMEOS) | |
| 50 case kFileSystemTypeNativeLocal: | |
| 51 case kFileSystemTypeNativeForPlatformApp: | |
| 52 return true; | |
| 53 #endif | |
| 54 default: | |
| 55 return false; | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 void IsolatedMountPointProvider::ValidateFileSystemRoot( | |
| 60 const GURL& origin_url, | |
| 61 FileSystemType type, | |
| 62 bool create, | |
| 63 const ValidateFileSystemCallback& callback) { | |
| 64 // We never allow opening a new isolated FileSystem via usual OpenFileSystem. | |
| 65 base::MessageLoopProxy::current()->PostTask( | |
| 66 FROM_HERE, | |
| 67 base::Bind(callback, base::PLATFORM_FILE_ERROR_SECURITY)); | |
| 68 } | |
| 69 | |
| 70 base::FilePath IsolatedMountPointProvider::GetFileSystemRootPathOnFileThread( | |
| 71 const FileSystemURL& url, | |
| 72 bool create) { | |
| 73 // This is not supposed to be used. | |
| 74 NOTREACHED(); | |
| 75 return base::FilePath(); | |
| 76 } | |
| 77 | |
| 78 FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil( | |
| 79 FileSystemType type) { | |
| 80 switch (type) { | |
| 81 case kFileSystemTypeNativeLocal: | |
| 82 return isolated_file_util_->sync_file_util(); | |
| 83 case kFileSystemTypeDragged: | |
| 84 return dragged_file_util_->sync_file_util(); | |
| 85 case kFileSystemTypeForTransientFile: | |
| 86 return transient_file_util_->sync_file_util(); | |
| 87 default: | |
| 88 NOTREACHED(); | |
| 89 } | |
| 90 return NULL; | |
| 91 } | |
| 92 | |
| 93 AsyncFileUtil* IsolatedMountPointProvider::GetAsyncFileUtil( | |
| 94 FileSystemType type) { | |
| 95 switch (type) { | |
| 96 case kFileSystemTypeNativeLocal: | |
| 97 return isolated_file_util_.get(); | |
| 98 case kFileSystemTypeDragged: | |
| 99 return dragged_file_util_.get(); | |
| 100 case kFileSystemTypeForTransientFile: | |
| 101 return transient_file_util_.get(); | |
| 102 default: | |
| 103 NOTREACHED(); | |
| 104 } | |
| 105 return NULL; | |
| 106 } | |
| 107 | |
| 108 CopyOrMoveFileValidatorFactory* | |
| 109 IsolatedMountPointProvider::GetCopyOrMoveFileValidatorFactory( | |
| 110 FileSystemType type, base::PlatformFileError* error_code) { | |
| 111 DCHECK(error_code); | |
| 112 *error_code = base::PLATFORM_FILE_OK; | |
| 113 return NULL; | |
| 114 } | |
| 115 | |
| 116 void IsolatedMountPointProvider::InitializeCopyOrMoveFileValidatorFactory( | |
| 117 FileSystemType type, | |
| 118 scoped_ptr<CopyOrMoveFileValidatorFactory> factory) { | |
| 119 DCHECK(!factory); | |
| 120 } | |
| 121 | |
| 122 FilePermissionPolicy IsolatedMountPointProvider::GetPermissionPolicy( | |
| 123 const FileSystemURL& url, int permissions) const { | |
| 124 if (url.type() == kFileSystemTypeDragged && url.path().empty()) { | |
| 125 // The root directory of the dragged filesystem must be always read-only. | |
| 126 if (permissions & ~fileapi::kReadFilePermissions) | |
| 127 return FILE_PERMISSION_ALWAYS_DENY; | |
| 128 } | |
| 129 // Access to isolated file systems should be checked using per-filesystem | |
| 130 // access permission. | |
| 131 return FILE_PERMISSION_USE_FILESYSTEM_PERMISSION; | |
| 132 } | |
| 133 | |
| 134 FileSystemOperation* IsolatedMountPointProvider::CreateFileSystemOperation( | |
| 135 const FileSystemURL& url, | |
| 136 FileSystemContext* context, | |
| 137 base::PlatformFileError* error_code) const { | |
| 138 return new LocalFileSystemOperation( | |
| 139 context, make_scoped_ptr(new FileSystemOperationContext(context))); | |
| 140 } | |
| 141 | |
| 142 scoped_ptr<webkit_blob::FileStreamReader> | |
| 143 IsolatedMountPointProvider::CreateFileStreamReader( | |
| 144 const FileSystemURL& url, | |
| 145 int64 offset, | |
| 146 const base::Time& expected_modification_time, | |
| 147 FileSystemContext* context) const { | |
| 148 return scoped_ptr<webkit_blob::FileStreamReader>( | |
| 149 new webkit_blob::LocalFileStreamReader( | |
| 150 context->task_runners()->file_task_runner(), | |
| 151 url.path(), offset, expected_modification_time)); | |
| 152 } | |
| 153 | |
| 154 scoped_ptr<FileStreamWriter> IsolatedMountPointProvider::CreateFileStreamWriter( | |
| 155 const FileSystemURL& url, | |
| 156 int64 offset, | |
| 157 FileSystemContext* context) const { | |
| 158 return scoped_ptr<FileStreamWriter>( | |
| 159 new LocalFileStreamWriter(url.path(), offset)); | |
| 160 } | |
| 161 | |
| 162 FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() { | |
| 163 // No quota support. | |
| 164 return NULL; | |
| 165 } | |
| 166 | |
| 167 void IsolatedMountPointProvider::DeleteFileSystem( | |
| 168 const GURL& origin_url, | |
| 169 FileSystemType type, | |
| 170 FileSystemContext* context, | |
| 171 const DeleteFileSystemCallback& callback) { | |
| 172 NOTREACHED(); | |
| 173 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); | |
| 174 } | |
| 175 | |
| 176 } // namespace fileapi | |
| OLD | NEW |