[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] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 24 | #include "webkit/fileapi/native_file_util.h" |
| 25 | |
| 26 | namespace fileapi { |
| 27 | |
[email protected] | 7469890 | 2012-06-12 12:16:38 | [diff] [blame] | 28 | namespace { |
| 29 | |
| 30 | IsolatedContext* isolated_context() { |
| 31 | return IsolatedContext::GetInstance(); |
| 32 | } |
| 33 | |
[email protected] | 7469890 | 2012-06-12 12:16:38 | [diff] [blame] | 34 | } // namespace |
| 35 | |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 36 | IsolatedMountPointProvider::IsolatedMountPointProvider() |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame^] | 37 | : isolated_file_util_(new IsolatedFileUtil()), |
| 38 | dragged_file_util_(new DraggedFileUtil()) { |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | IsolatedMountPointProvider::~IsolatedMountPointProvider() { |
| 42 | } |
| 43 | |
| 44 | void IsolatedMountPointProvider::ValidateFileSystemRoot( |
| 45 | const GURL& origin_url, |
| 46 | FileSystemType type, |
| 47 | bool create, |
| 48 | const ValidateFileSystemCallback& callback) { |
| 49 | // We never allow opening a new isolated FileSystem via usual OpenFileSystem. |
| 50 | base::MessageLoopProxy::current()->PostTask( |
| 51 | FROM_HERE, |
| 52 | base::Bind(callback, base::PLATFORM_FILE_ERROR_SECURITY)); |
| 53 | } |
| 54 | |
| 55 | FilePath IsolatedMountPointProvider::GetFileSystemRootPathOnFileThread( |
| 56 | const GURL& origin_url, |
| 57 | FileSystemType type, |
| 58 | const FilePath& virtual_path, |
| 59 | bool create) { |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame^] | 60 | // This is not supposed to be used. |
| 61 | NOTREACHED(); |
| 62 | return FilePath(); |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | bool IsolatedMountPointProvider::IsAccessAllowed( |
| 66 | const GURL& origin_url, FileSystemType type, const FilePath& virtual_path) { |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame^] | 67 | return true; |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | bool IsolatedMountPointProvider::IsRestrictedFileName( |
| 71 | const FilePath& filename) const { |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame^] | 72 | // TODO(kinuko): We need to check platform-specific restricted file names |
| 73 | // before we actually start allowing file creation in isolated file systems. |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 74 | return false; |
| 75 | } |
| 76 | |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame^] | 77 | FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil( |
| 78 | FileSystemType type) { |
| 79 | if (type == kFileSystemTypeDragged) |
| 80 | return dragged_file_util_.get(); |
| 81 | else |
| 82 | return isolated_file_util_.get(); |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | FilePath IsolatedMountPointProvider::GetPathForPermissionsCheck( |
| 86 | const FilePath& virtual_path) const { |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame^] | 87 | // For isolated filesystems we only check per-filesystem permissions. |
| 88 | NOTREACHED(); |
| 89 | return virtual_path; |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | FileSystemOperationInterface* |
| 93 | IsolatedMountPointProvider::CreateFileSystemOperation( |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 94 | const FileSystemURL& url, |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 95 | FileSystemContext* context) const { |
[email protected] | 02a6054 | 2012-07-24 20:05:33 | [diff] [blame] | 96 | return new LocalFileSystemOperation(context); |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 97 | } |
| 98 | |
[email protected] | c4ca3b45 | 2012-05-31 03:15:46 | [diff] [blame] | 99 | webkit_blob::FileStreamReader* |
| 100 | IsolatedMountPointProvider::CreateFileStreamReader( |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 101 | const FileSystemURL& url, |
[email protected] | ad117b1 | 2012-04-19 05:40:19 | [diff] [blame] | 102 | int64 offset, |
[email protected] | ad117b1 | 2012-04-19 05:40:19 | [diff] [blame] | 103 | FileSystemContext* context) const { |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame^] | 104 | return new webkit_blob::LocalFileStreamReader( |
| 105 | context->file_task_runner(), url.path(), offset, base::Time()); |
[email protected] | ad117b1 | 2012-04-19 05:40:19 | [diff] [blame] | 106 | } |
| 107 | |
[email protected] | 7e836a3d | 2012-05-31 05:14:59 | [diff] [blame] | 108 | FileStreamWriter* IsolatedMountPointProvider::CreateFileStreamWriter( |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 109 | const FileSystemURL& url, |
[email protected] | 7e84b91 | 2012-05-16 04:42:01 | [diff] [blame] | 110 | int64 offset, |
| 111 | FileSystemContext* context) const { |
[email protected] | d6afd11 | 2012-07-25 22:55:04 | [diff] [blame^] | 112 | return new LocalFileStreamWriter(url.path(), offset); |
[email protected] | 7e84b91 | 2012-05-16 04:42:01 | [diff] [blame] | 113 | } |
| 114 | |
[email protected] | 6faad82 | 2012-05-11 12:58:29 | [diff] [blame] | 115 | FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() { |
| 116 | // No quota support. |
| 117 | return NULL; |
| 118 | } |
| 119 | |
[email protected] | 6fe6965 | 2012-04-02 09:35:05 | [diff] [blame] | 120 | } // namespace fileapi |