OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/fileapi/isolated_mount_point_provider.h" | 5 #include "webkit/fileapi/isolated_mount_point_provider.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "webkit/fileapi/native_file_util.h" | 24 #include "webkit/fileapi/native_file_util.h" |
25 | 25 |
26 namespace fileapi { | 26 namespace fileapi { |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 IsolatedContext* isolated_context() { | 30 IsolatedContext* isolated_context() { |
31 return IsolatedContext::GetInstance(); | 31 return IsolatedContext::GetInstance(); |
32 } | 32 } |
33 | 33 |
34 FilePath GetPathFromURL(const FileSystemURL& url) { | |
35 if (!url.is_valid() || url.type() != kFileSystemTypeIsolated) | |
36 return FilePath(); | |
37 std::string fsid; | |
38 FilePath path; | |
39 if (!isolated_context()->CrackIsolatedPath(url.path(), &fsid, NULL, &path)) | |
40 return FilePath(); | |
41 return path; | |
42 } | |
43 | |
44 } // namespace | 34 } // namespace |
45 | 35 |
46 IsolatedMountPointProvider::IsolatedMountPointProvider() | 36 IsolatedMountPointProvider::IsolatedMountPointProvider() |
47 : isolated_file_util_(new IsolatedFileUtil()) { | 37 : isolated_file_util_(new IsolatedFileUtil()), |
| 38 dragged_file_util_(new DraggedFileUtil()) { |
48 } | 39 } |
49 | 40 |
50 IsolatedMountPointProvider::~IsolatedMountPointProvider() { | 41 IsolatedMountPointProvider::~IsolatedMountPointProvider() { |
51 } | 42 } |
52 | 43 |
53 void IsolatedMountPointProvider::ValidateFileSystemRoot( | 44 void IsolatedMountPointProvider::ValidateFileSystemRoot( |
54 const GURL& origin_url, | 45 const GURL& origin_url, |
55 FileSystemType type, | 46 FileSystemType type, |
56 bool create, | 47 bool create, |
57 const ValidateFileSystemCallback& callback) { | 48 const ValidateFileSystemCallback& callback) { |
58 // We never allow opening a new isolated FileSystem via usual OpenFileSystem. | 49 // We never allow opening a new isolated FileSystem via usual OpenFileSystem. |
59 base::MessageLoopProxy::current()->PostTask( | 50 base::MessageLoopProxy::current()->PostTask( |
60 FROM_HERE, | 51 FROM_HERE, |
61 base::Bind(callback, base::PLATFORM_FILE_ERROR_SECURITY)); | 52 base::Bind(callback, base::PLATFORM_FILE_ERROR_SECURITY)); |
62 } | 53 } |
63 | 54 |
64 FilePath IsolatedMountPointProvider::GetFileSystemRootPathOnFileThread( | 55 FilePath IsolatedMountPointProvider::GetFileSystemRootPathOnFileThread( |
65 const GURL& origin_url, | 56 const GURL& origin_url, |
66 FileSystemType type, | 57 FileSystemType type, |
67 const FilePath& virtual_path, | 58 const FilePath& virtual_path, |
68 bool create) { | 59 bool create) { |
69 if (create || type != kFileSystemTypeIsolated) | 60 // This is not supposed to be used. |
70 return FilePath(); | 61 NOTREACHED(); |
71 std::string fsid; | 62 return FilePath(); |
72 FilePath path; | |
73 IsolatedContext::FileInfo root; | |
74 if (!isolated_context()->CrackIsolatedPath(virtual_path, &fsid, &root, &path)) | |
75 return FilePath(); | |
76 return root.path; | |
77 } | 63 } |
78 | 64 |
79 bool IsolatedMountPointProvider::IsAccessAllowed( | 65 bool IsolatedMountPointProvider::IsAccessAllowed( |
80 const GURL& origin_url, FileSystemType type, const FilePath& virtual_path) { | 66 const GURL& origin_url, FileSystemType type, const FilePath& virtual_path) { |
81 if (type != fileapi::kFileSystemTypeIsolated) | 67 return true; |
82 return false; | |
83 | |
84 std::string filesystem_id; | |
85 FilePath path; | |
86 return isolated_context()->CrackIsolatedPath( | |
87 virtual_path, &filesystem_id, NULL, &path); | |
88 } | 68 } |
89 | 69 |
90 bool IsolatedMountPointProvider::IsRestrictedFileName( | 70 bool IsolatedMountPointProvider::IsRestrictedFileName( |
91 const FilePath& filename) const { | 71 const FilePath& filename) const { |
| 72 // TODO(kinuko): We need to check platform-specific restricted file names |
| 73 // before we actually start allowing file creation in isolated file systems. |
92 return false; | 74 return false; |
93 } | 75 } |
94 | 76 |
95 FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil() { | 77 FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil( |
96 // TODO(kinuko): Return different FileUtil's based on types. | 78 FileSystemType type) { |
97 return isolated_file_util_.get(); | 79 if (type == kFileSystemTypeDragged) |
| 80 return dragged_file_util_.get(); |
| 81 else |
| 82 return isolated_file_util_.get(); |
98 } | 83 } |
99 | 84 |
100 FilePath IsolatedMountPointProvider::GetPathForPermissionsCheck( | 85 FilePath IsolatedMountPointProvider::GetPathForPermissionsCheck( |
101 const FilePath& virtual_path) const { | 86 const FilePath& virtual_path) const { |
102 std::string fsid; | 87 // For isolated filesystems we only check per-filesystem permissions. |
103 FilePath path; | 88 NOTREACHED(); |
104 if (!isolated_context()->CrackIsolatedPath(virtual_path, &fsid, NULL, &path)) | 89 return virtual_path; |
105 return FilePath(); | |
106 return path; | |
107 } | 90 } |
108 | 91 |
109 FileSystemOperationInterface* | 92 FileSystemOperationInterface* |
110 IsolatedMountPointProvider::CreateFileSystemOperation( | 93 IsolatedMountPointProvider::CreateFileSystemOperation( |
111 const FileSystemURL& url, | 94 const FileSystemURL& url, |
112 FileSystemContext* context) const { | 95 FileSystemContext* context) const { |
113 return new LocalFileSystemOperation(context); | 96 return new LocalFileSystemOperation(context); |
114 } | 97 } |
115 | 98 |
116 webkit_blob::FileStreamReader* | 99 webkit_blob::FileStreamReader* |
117 IsolatedMountPointProvider::CreateFileStreamReader( | 100 IsolatedMountPointProvider::CreateFileStreamReader( |
118 const FileSystemURL& url, | 101 const FileSystemURL& url, |
119 int64 offset, | 102 int64 offset, |
120 FileSystemContext* context) const { | 103 FileSystemContext* context) const { |
121 FilePath path = GetPathFromURL(url); | 104 return new webkit_blob::LocalFileStreamReader( |
122 return path.empty() ? NULL : new webkit_blob::LocalFileStreamReader( | 105 context->file_task_runner(), url.path(), offset, base::Time()); |
123 context->file_task_runner(), path, offset, base::Time()); | |
124 } | 106 } |
125 | 107 |
126 FileStreamWriter* IsolatedMountPointProvider::CreateFileStreamWriter( | 108 FileStreamWriter* IsolatedMountPointProvider::CreateFileStreamWriter( |
127 const FileSystemURL& url, | 109 const FileSystemURL& url, |
128 int64 offset, | 110 int64 offset, |
129 FileSystemContext* context) const { | 111 FileSystemContext* context) const { |
130 FilePath path = GetPathFromURL(url); | 112 return new LocalFileStreamWriter(url.path(), offset); |
131 return path.empty() ? NULL : new LocalFileStreamWriter(path, offset); | |
132 } | 113 } |
133 | 114 |
134 FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() { | 115 FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() { |
135 // No quota support. | 116 // No quota support. |
136 return NULL; | 117 return NULL; |
137 } | 118 } |
138 | 119 |
139 } // namespace fileapi | 120 } // namespace fileapi |
OLD | NEW |