[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] | bcbd98d | 2012-05-07 04:10:10 | [diff] [blame] | 13 | #include "base/sequenced_task_runner.h" |
[email protected] | c4ca3b45 | 2012-05-31 03:15:46 | [diff] [blame] | 14 | #include "webkit/blob/local_file_stream_reader.h" |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 15 | #include "webkit/fileapi/file_system_callback_dispatcher.h" |
[email protected] | bcbd98d | 2012-05-07 04:10:10 | [diff] [blame] | 16 | #include "webkit/fileapi/file_system_context.h" |
[email protected] | c4ca3b45 | 2012-05-31 03:15:46 | [diff] [blame] | 17 | #include "webkit/fileapi/file_system_file_stream_reader.h" |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 18 | #include "webkit/fileapi/file_system_types.h" |
[email protected] | ad117b1 | 2012-04-19 05:40:19 | [diff] [blame] | 19 | #include "webkit/fileapi/file_system_util.h" |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 20 | #include "webkit/fileapi/isolated_context.h" |
| 21 | #include "webkit/fileapi/isolated_file_util.h" |
[email protected] | 7e836a3d | 2012-05-31 05:14:59 | [diff] [blame] | 22 | #include "webkit/fileapi/local_file_stream_writer.h" |
[email protected] | 02a6054 | 2012-07-24 20:05:33 | [diff] [blame] | 23 | #include "webkit/fileapi/local_file_system_operation.h" |
[email protected] | 6ef35d6 | 2012-08-02 02:55:28 | [diff] [blame] | 24 | #include "webkit/fileapi/media/media_path_filter.h" |
| 25 | #include "webkit/fileapi/media/native_media_file_util.h" |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 26 | #include "webkit/fileapi/native_file_util.h" |
| 27 | |
| 28 | namespace fileapi { |
| 29 | |
[email protected] | 7469890 | 2012-06-12 12:16:38 | [diff] [blame] | 30 | namespace { |
| 31 | |
| 32 | IsolatedContext* isolated_context() { |
| 33 | return IsolatedContext::GetInstance(); |
| 34 | } |
| 35 | |
[email protected] | 7469890 | 2012-06-12 12:16:38 | [diff] [blame] | 36 | } // namespace |
| 37 | |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 38 | IsolatedMountPointProvider::IsolatedMountPointProvider() |
[email protected] | 6ef35d6 | 2012-08-02 02:55:28 | [diff] [blame] | 39 | : media_path_filter_(new MediaPathFilter()), |
| 40 | isolated_file_util_(new IsolatedFileUtil()), |
| 41 | dragged_file_util_(new DraggedFileUtil()), |
| 42 | native_media_file_util_(new NativeMediaFileUtil()) { |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | IsolatedMountPointProvider::~IsolatedMountPointProvider() { |
| 46 | } |
| 47 | |
| 48 | void IsolatedMountPointProvider::ValidateFileSystemRoot( |
| 49 | const GURL& origin_url, |
| 50 | FileSystemType type, |
| 51 | bool create, |
| 52 | const ValidateFileSystemCallback& callback) { |
| 53 | // We never allow opening a new isolated FileSystem via usual OpenFileSystem. |
| 54 | base::MessageLoopProxy::current()->PostTask( |
| 55 | FROM_HERE, |
| 56 | base::Bind(callback, base::PLATFORM_FILE_ERROR_SECURITY)); |
| 57 | } |
| 58 | |
| 59 | FilePath IsolatedMountPointProvider::GetFileSystemRootPathOnFileThread( |
| 60 | const GURL& origin_url, |
| 61 | FileSystemType type, |
| 62 | const FilePath& virtual_path, |
| 63 | bool create) { |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame] | 64 | // This is not supposed to be used. |
| 65 | NOTREACHED(); |
| 66 | return FilePath(); |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | bool IsolatedMountPointProvider::IsAccessAllowed( |
| 70 | const GURL& origin_url, FileSystemType type, const FilePath& virtual_path) { |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame] | 71 | return true; |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | bool IsolatedMountPointProvider::IsRestrictedFileName( |
| 75 | const FilePath& filename) const { |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame] | 76 | // TODO(kinuko): We need to check platform-specific restricted file names |
| 77 | // before we actually start allowing file creation in isolated file systems. |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 78 | return false; |
| 79 | } |
| 80 | |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame] | 81 | FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil( |
| 82 | FileSystemType type) { |
[email protected] | 6ef35d6 | 2012-08-02 02:55:28 | [diff] [blame] | 83 | switch (type) { |
| 84 | case kFileSystemTypeIsolated: |
| 85 | return isolated_file_util_.get(); |
| 86 | case kFileSystemTypeDragged: |
| 87 | return dragged_file_util_.get(); |
| 88 | case kFileSystemTypeNativeMedia: |
| 89 | return native_media_file_util_.get(); |
| 90 | |
| 91 | case kFileSystemTypeDeviceMedia: |
| 92 | case kFileSystemTypeTemporary: |
| 93 | case kFileSystemTypePersistent: |
| 94 | case kFileSystemTypeExternal: |
| 95 | case kFileSystemTypeTest: |
| 96 | case kFileSystemTypeUnknown: |
| 97 | NOTREACHED(); |
| 98 | } |
| 99 | return NULL; |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | FilePath IsolatedMountPointProvider::GetPathForPermissionsCheck( |
| 103 | const FilePath& virtual_path) const { |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame] | 104 | // For isolated filesystems we only check per-filesystem permissions. |
| 105 | NOTREACHED(); |
| 106 | return virtual_path; |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | FileSystemOperationInterface* |
| 110 | IsolatedMountPointProvider::CreateFileSystemOperation( |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 111 | const FileSystemURL& url, |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 112 | FileSystemContext* context) const { |
[email protected] | 75af1a4 | 2012-07-26 04:06:20 | [diff] [blame] | 113 | scoped_ptr<FileSystemOperationContext> operation_context( |
| 114 | new FileSystemOperationContext(context)); |
[email protected] | 6ef35d6 | 2012-08-02 02:55:28 | [diff] [blame] | 115 | if (url.type() == kFileSystemTypeNativeMedia || |
| 116 | url.type() == kFileSystemTypeDeviceMedia) |
| 117 | operation_context->set_media_path_filter(media_path_filter_.get()); |
[email protected] | 75af1a4 | 2012-07-26 04:06:20 | [diff] [blame] | 118 | return new LocalFileSystemOperation(context, operation_context.Pass()); |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 119 | } |
| 120 | |
[email protected] | c4ca3b45 | 2012-05-31 03:15:46 | [diff] [blame] | 121 | webkit_blob::FileStreamReader* |
| 122 | IsolatedMountPointProvider::CreateFileStreamReader( |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 123 | const FileSystemURL& url, |
[email protected] | ad117b1 | 2012-04-19 05:40:19 | [diff] [blame] | 124 | int64 offset, |
[email protected] | ad117b1 | 2012-04-19 05:40:19 | [diff] [blame] | 125 | FileSystemContext* context) const { |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame] | 126 | return new webkit_blob::LocalFileStreamReader( |
| 127 | context->file_task_runner(), url.path(), offset, base::Time()); |
[email protected] | ad117b1 | 2012-04-19 05:40:19 | [diff] [blame] | 128 | } |
| 129 | |
[email protected] | 7e836a3d | 2012-05-31 05:14:59 | [diff] [blame] | 130 | FileStreamWriter* IsolatedMountPointProvider::CreateFileStreamWriter( |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 131 | const FileSystemURL& url, |
[email protected] | 7e84b91 | 2012-05-16 04:42:01 | [diff] [blame] | 132 | int64 offset, |
| 133 | FileSystemContext* context) const { |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame] | 134 | return new LocalFileStreamWriter(url.path(), offset); |
[email protected] | 7e84b91 | 2012-05-16 04:42:01 | [diff] [blame] | 135 | } |
| 136 | |
[email protected] | 6faad82 | 2012-05-11 12:58:29 | [diff] [blame] | 137 | FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() { |
| 138 | // No quota support. |
| 139 | return NULL; |
| 140 | } |
| 141 | |
[email protected] | d5e0855 | 2012-08-02 21:43:40 | [diff] [blame^] | 142 | void IsolatedMountPointProvider::DeleteFileSystem( |
| 143 | const GURL& origin_url, |
| 144 | FileSystemType type, |
| 145 | FileSystemContext* context, |
| 146 | const DeleteFileSystemCallback& callback) { |
| 147 | NOTREACHED(); |
| 148 | callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); |
| 149 | } |
| 150 | |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 151 | } // namespace fileapi |