[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 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 | |
[email protected] | c671c8a | 2012-04-05 10:28:39 | [diff] [blame] | 7 | #include <string> |
| 8 | |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 9 | #include "base/bind.h" |
| 10 | #include "base/file_path.h" |
| 11 | #include "base/logging.h" |
| 12 | #include "base/message_loop_proxy.h" |
[email protected] | 2f9f5b49 | 2012-09-12 02:59:06 | [diff] [blame^] | 13 | #include "base/platform_file.h" |
[email protected] | bcbd98d | 2012-05-07 04:10:10 | [diff] [blame] | 14 | #include "base/sequenced_task_runner.h" |
[email protected] | c4ca3b45 | 2012-05-31 03:15:46 | [diff] [blame] | 15 | #include "webkit/blob/local_file_stream_reader.h" |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 16 | #include "webkit/fileapi/file_system_callback_dispatcher.h" |
[email protected] | bcbd98d | 2012-05-07 04:10:10 | [diff] [blame] | 17 | #include "webkit/fileapi/file_system_context.h" |
[email protected] | c4ca3b45 | 2012-05-31 03:15:46 | [diff] [blame] | 18 | #include "webkit/fileapi/file_system_file_stream_reader.h" |
[email protected] | dc57ec8 | 2012-08-07 03:50:10 | [diff] [blame] | 19 | #include "webkit/fileapi/file_system_task_runners.h" |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 20 | #include "webkit/fileapi/file_system_types.h" |
[email protected] | ad117b1 | 2012-04-19 05:40:19 | [diff] [blame] | 21 | #include "webkit/fileapi/file_system_util.h" |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 22 | #include "webkit/fileapi/isolated_context.h" |
| 23 | #include "webkit/fileapi/isolated_file_util.h" |
[email protected] | 7e836a3d | 2012-05-31 05:14:59 | [diff] [blame] | 24 | #include "webkit/fileapi/local_file_stream_writer.h" |
[email protected] | 02a6054 | 2012-07-24 20:05:33 | [diff] [blame] | 25 | #include "webkit/fileapi/local_file_system_operation.h" |
[email protected] | cf4b6d6 | 2012-08-03 07:31:12 | [diff] [blame] | 26 | #include "webkit/fileapi/media/media_file_system_config.h" |
[email protected] | 6ef35d6 | 2012-08-02 02:55:28 | [diff] [blame] | 27 | #include "webkit/fileapi/media/media_path_filter.h" |
| 28 | #include "webkit/fileapi/media/native_media_file_util.h" |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 29 | #include "webkit/fileapi/native_file_util.h" |
| 30 | |
[email protected] | cf4b6d6 | 2012-08-03 07:31:12 | [diff] [blame] | 31 | #if defined(SUPPORT_MEDIA_FILESYSTEM) |
| 32 | #include "webkit/fileapi/media/device_media_file_util.h" |
| 33 | #include "webkit/fileapi/media/media_device_map_service.h" |
| 34 | #endif |
| 35 | |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 36 | namespace fileapi { |
| 37 | |
[email protected] | 7469890 | 2012-06-12 12:16:38 | [diff] [blame] | 38 | namespace { |
| 39 | |
| 40 | IsolatedContext* isolated_context() { |
| 41 | return IsolatedContext::GetInstance(); |
| 42 | } |
| 43 | |
[email protected] | 7469890 | 2012-06-12 12:16:38 | [diff] [blame] | 44 | } // namespace |
| 45 | |
[email protected] | cf4b6d6 | 2012-08-03 07:31:12 | [diff] [blame] | 46 | IsolatedMountPointProvider::IsolatedMountPointProvider( |
| 47 | const FilePath& profile_path) |
| 48 | : profile_path_(profile_path), |
| 49 | media_path_filter_(new MediaPathFilter()), |
[email protected] | 6ef35d6 | 2012-08-02 02:55:28 | [diff] [blame] | 50 | isolated_file_util_(new IsolatedFileUtil()), |
| 51 | dragged_file_util_(new DraggedFileUtil()), |
| 52 | native_media_file_util_(new NativeMediaFileUtil()) { |
[email protected] | cf4b6d6 | 2012-08-03 07:31:12 | [diff] [blame] | 53 | #if defined(SUPPORT_MEDIA_FILESYSTEM) |
[email protected] | 2f9f5b49 | 2012-09-12 02:59:06 | [diff] [blame^] | 54 | // TODO(kmadhusu): Initialize |device_media_file_util_| in |
| 55 | // initialization list. |
[email protected] | cf4b6d6 | 2012-08-03 07:31:12 | [diff] [blame] | 56 | device_media_file_util_.reset(new DeviceMediaFileUtil(profile_path_)); |
| 57 | #endif |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | IsolatedMountPointProvider::~IsolatedMountPointProvider() { |
| 61 | } |
| 62 | |
| 63 | void IsolatedMountPointProvider::ValidateFileSystemRoot( |
| 64 | const GURL& origin_url, |
| 65 | FileSystemType type, |
| 66 | bool create, |
| 67 | const ValidateFileSystemCallback& callback) { |
| 68 | // We never allow opening a new isolated FileSystem via usual OpenFileSystem. |
| 69 | base::MessageLoopProxy::current()->PostTask( |
| 70 | FROM_HERE, |
| 71 | base::Bind(callback, base::PLATFORM_FILE_ERROR_SECURITY)); |
| 72 | } |
| 73 | |
| 74 | FilePath IsolatedMountPointProvider::GetFileSystemRootPathOnFileThread( |
| 75 | const GURL& origin_url, |
| 76 | FileSystemType type, |
| 77 | const FilePath& virtual_path, |
| 78 | bool create) { |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame] | 79 | // This is not supposed to be used. |
| 80 | NOTREACHED(); |
| 81 | return FilePath(); |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 82 | } |
| 83 | |
[email protected] | 5aeeb7c6 | 2012-08-27 11:34:13 | [diff] [blame] | 84 | bool IsolatedMountPointProvider::IsAccessAllowed(const FileSystemURL& url) { |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame] | 85 | return true; |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | bool IsolatedMountPointProvider::IsRestrictedFileName( |
| 89 | const FilePath& filename) const { |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame] | 90 | // TODO(kinuko): We need to check platform-specific restricted file names |
| 91 | // before we actually start allowing file creation in isolated file systems. |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 92 | return false; |
| 93 | } |
| 94 | |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame] | 95 | FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil( |
| 96 | FileSystemType type) { |
[email protected] | 6ef35d6 | 2012-08-02 02:55:28 | [diff] [blame] | 97 | switch (type) { |
[email protected] | 9fb9294a | 2012-08-21 14:55:37 | [diff] [blame] | 98 | case kFileSystemTypeNativeLocal: |
[email protected] | 6ef35d6 | 2012-08-02 02:55:28 | [diff] [blame] | 99 | return isolated_file_util_.get(); |
| 100 | case kFileSystemTypeDragged: |
| 101 | return dragged_file_util_.get(); |
| 102 | case kFileSystemTypeNativeMedia: |
| 103 | return native_media_file_util_.get(); |
[email protected] | 6ef35d6 | 2012-08-02 02:55:28 | [diff] [blame] | 104 | case kFileSystemTypeDeviceMedia: |
[email protected] | cf4b6d6 | 2012-08-03 07:31:12 | [diff] [blame] | 105 | #if defined(SUPPORT_MEDIA_FILESYSTEM) |
| 106 | return device_media_file_util_.get(); |
| 107 | #endif |
| 108 | |
[email protected] | 9fb9294a | 2012-08-21 14:55:37 | [diff] [blame] | 109 | default: |
[email protected] | 6ef35d6 | 2012-08-02 02:55:28 | [diff] [blame] | 110 | NOTREACHED(); |
| 111 | } |
| 112 | return NULL; |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | FilePath IsolatedMountPointProvider::GetPathForPermissionsCheck( |
| 116 | const FilePath& virtual_path) const { |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame] | 117 | // For isolated filesystems we only check per-filesystem permissions. |
[email protected] | 9fb9294a | 2012-08-21 14:55:37 | [diff] [blame] | 118 | return FilePath(); |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 119 | } |
| 120 | |
[email protected] | 8e3bc3e | 2012-08-24 13:12:53 | [diff] [blame] | 121 | FileSystemOperation* IsolatedMountPointProvider::CreateFileSystemOperation( |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 122 | const FileSystemURL& url, |
[email protected] | d23a00cc | 2012-09-11 17:38:13 | [diff] [blame] | 123 | FileSystemContext* context, |
| 124 | base::PlatformFileError* error_code) const { |
[email protected] | 75af1a4 | 2012-07-26 04:06:20 | [diff] [blame] | 125 | scoped_ptr<FileSystemOperationContext> operation_context( |
| 126 | new FileSystemOperationContext(context)); |
[email protected] | 2f9f5b49 | 2012-09-12 02:59:06 | [diff] [blame^] | 127 | if (url.type() == kFileSystemTypeNativeMedia) { |
[email protected] | 6ef35d6 | 2012-08-02 02:55:28 | [diff] [blame] | 128 | operation_context->set_media_path_filter(media_path_filter_.get()); |
[email protected] | dc57ec8 | 2012-08-07 03:50:10 | [diff] [blame] | 129 | operation_context->set_task_runner( |
| 130 | context->task_runners()->media_task_runner()); |
| 131 | } |
[email protected] | cf4b6d6 | 2012-08-03 07:31:12 | [diff] [blame] | 132 | |
| 133 | #if defined(SUPPORT_MEDIA_FILESYSTEM) |
| 134 | if (url.type() == kFileSystemTypeDeviceMedia) { |
[email protected] | 2f9f5b49 | 2012-09-12 02:59:06 | [diff] [blame^] | 135 | MediaDeviceMapService* map_service = MediaDeviceMapService::GetInstance(); |
| 136 | MediaDeviceDelegate* device_delegate = |
| 137 | map_service->GetMediaDeviceDelegate(url.filesystem_id()); |
| 138 | if (!device_delegate) { |
| 139 | if (error_code) |
| 140 | *error_code = base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 141 | return NULL; |
| 142 | } |
| 143 | operation_context->set_media_device_delegate(device_delegate); |
| 144 | operation_context->set_task_runner(device_delegate->media_task_runner()); |
| 145 | operation_context->set_media_path_filter(media_path_filter_.get()); |
[email protected] | cf4b6d6 | 2012-08-03 07:31:12 | [diff] [blame] | 146 | } |
| 147 | #endif |
| 148 | |
[email protected] | 75af1a4 | 2012-07-26 04:06:20 | [diff] [blame] | 149 | return new LocalFileSystemOperation(context, operation_context.Pass()); |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 150 | } |
| 151 | |
[email protected] | c4ca3b45 | 2012-05-31 03:15:46 | [diff] [blame] | 152 | webkit_blob::FileStreamReader* |
| 153 | IsolatedMountPointProvider::CreateFileStreamReader( |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 154 | const FileSystemURL& url, |
[email protected] | ad117b1 | 2012-04-19 05:40:19 | [diff] [blame] | 155 | int64 offset, |
[email protected] | ad117b1 | 2012-04-19 05:40:19 | [diff] [blame] | 156 | FileSystemContext* context) const { |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame] | 157 | return new webkit_blob::LocalFileStreamReader( |
[email protected] | dc57ec8 | 2012-08-07 03:50:10 | [diff] [blame] | 158 | context->task_runners()->file_task_runner(), |
| 159 | url.path(), offset, base::Time()); |
[email protected] | ad117b1 | 2012-04-19 05:40:19 | [diff] [blame] | 160 | } |
| 161 | |
[email protected] | 7e836a3d | 2012-05-31 05:14:59 | [diff] [blame] | 162 | FileStreamWriter* IsolatedMountPointProvider::CreateFileStreamWriter( |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 163 | const FileSystemURL& url, |
[email protected] | 7e84b91 | 2012-05-16 04:42:01 | [diff] [blame] | 164 | int64 offset, |
| 165 | FileSystemContext* context) const { |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame] | 166 | return new LocalFileStreamWriter(url.path(), offset); |
[email protected] | 7e84b91 | 2012-05-16 04:42:01 | [diff] [blame] | 167 | } |
| 168 | |
[email protected] | 6faad82 | 2012-05-11 12:58:29 | [diff] [blame] | 169 | FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() { |
| 170 | // No quota support. |
| 171 | return NULL; |
| 172 | } |
| 173 | |
[email protected] | d5e0855 | 2012-08-02 21:43:40 | [diff] [blame] | 174 | void IsolatedMountPointProvider::DeleteFileSystem( |
| 175 | const GURL& origin_url, |
| 176 | FileSystemType type, |
| 177 | FileSystemContext* context, |
| 178 | const DeleteFileSystemCallback& callback) { |
| 179 | NOTREACHED(); |
| 180 | callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); |
| 181 | } |
| 182 | |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 183 | } // namespace fileapi |