blob: bca05fa9742f93e0be7b880b2749ec10f21979cf [file] [log] [blame]
[email protected]6fe69652012-04-02 09:35:051// 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]c671c8a2012-04-05 10:28:397#include <string>
8
[email protected]6fe69652012-04-02 09:35:059#include "base/bind.h"
10#include "base/file_path.h"
11#include "base/logging.h"
12#include "base/message_loop_proxy.h"
[email protected]bcbd98d2012-05-07 04:10:1013#include "base/sequenced_task_runner.h"
[email protected]c4ca3b452012-05-31 03:15:4614#include "webkit/blob/local_file_stream_reader.h"
[email protected]6fe69652012-04-02 09:35:0515#include "webkit/fileapi/file_system_callback_dispatcher.h"
[email protected]bcbd98d2012-05-07 04:10:1016#include "webkit/fileapi/file_system_context.h"
[email protected]c4ca3b452012-05-31 03:15:4617#include "webkit/fileapi/file_system_file_stream_reader.h"
[email protected]6fe69652012-04-02 09:35:0518#include "webkit/fileapi/file_system_types.h"
[email protected]ad117b12012-04-19 05:40:1919#include "webkit/fileapi/file_system_util.h"
[email protected]6fe69652012-04-02 09:35:0520#include "webkit/fileapi/isolated_context.h"
21#include "webkit/fileapi/isolated_file_util.h"
[email protected]7e836a3d2012-05-31 05:14:5922#include "webkit/fileapi/local_file_stream_writer.h"
[email protected]02a60542012-07-24 20:05:3323#include "webkit/fileapi/local_file_system_operation.h"
[email protected]6ef35d62012-08-02 02:55:2824#include "webkit/fileapi/media/media_path_filter.h"
25#include "webkit/fileapi/media/native_media_file_util.h"
[email protected]6fe69652012-04-02 09:35:0526#include "webkit/fileapi/native_file_util.h"
27
28namespace fileapi {
29
[email protected]74698902012-06-12 12:16:3830namespace {
31
32IsolatedContext* isolated_context() {
33 return IsolatedContext::GetInstance();
34}
35
[email protected]74698902012-06-12 12:16:3836} // namespace
37
[email protected]6fe69652012-04-02 09:35:0538IsolatedMountPointProvider::IsolatedMountPointProvider()
[email protected]6ef35d62012-08-02 02:55:2839 : 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]6fe69652012-04-02 09:35:0543}
44
45IsolatedMountPointProvider::~IsolatedMountPointProvider() {
46}
47
48void 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
59FilePath IsolatedMountPointProvider::GetFileSystemRootPathOnFileThread(
60 const GURL& origin_url,
61 FileSystemType type,
62 const FilePath& virtual_path,
63 bool create) {
[email protected]d6afd112012-07-25 22:55:0464 // This is not supposed to be used.
65 NOTREACHED();
66 return FilePath();
[email protected]6fe69652012-04-02 09:35:0567}
68
69bool IsolatedMountPointProvider::IsAccessAllowed(
70 const GURL& origin_url, FileSystemType type, const FilePath& virtual_path) {
[email protected]d6afd112012-07-25 22:55:0471 return true;
[email protected]6fe69652012-04-02 09:35:0572}
73
74bool IsolatedMountPointProvider::IsRestrictedFileName(
75 const FilePath& filename) const {
[email protected]d6afd112012-07-25 22:55:0476 // 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]6fe69652012-04-02 09:35:0578 return false;
79}
80
[email protected]d6afd112012-07-25 22:55:0481FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil(
82 FileSystemType type) {
[email protected]6ef35d62012-08-02 02:55:2883 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]6fe69652012-04-02 09:35:05100}
101
102FilePath IsolatedMountPointProvider::GetPathForPermissionsCheck(
103 const FilePath& virtual_path) const {
[email protected]d6afd112012-07-25 22:55:04104 // For isolated filesystems we only check per-filesystem permissions.
105 NOTREACHED();
106 return virtual_path;
[email protected]6fe69652012-04-02 09:35:05107}
108
109FileSystemOperationInterface*
110IsolatedMountPointProvider::CreateFileSystemOperation(
[email protected]949f25a2012-06-27 01:53:09111 const FileSystemURL& url,
[email protected]6fe69652012-04-02 09:35:05112 FileSystemContext* context) const {
[email protected]75af1a42012-07-26 04:06:20113 scoped_ptr<FileSystemOperationContext> operation_context(
114 new FileSystemOperationContext(context));
[email protected]6ef35d62012-08-02 02:55:28115 if (url.type() == kFileSystemTypeNativeMedia ||
116 url.type() == kFileSystemTypeDeviceMedia)
117 operation_context->set_media_path_filter(media_path_filter_.get());
[email protected]75af1a42012-07-26 04:06:20118 return new LocalFileSystemOperation(context, operation_context.Pass());
[email protected]6fe69652012-04-02 09:35:05119}
120
[email protected]c4ca3b452012-05-31 03:15:46121webkit_blob::FileStreamReader*
122IsolatedMountPointProvider::CreateFileStreamReader(
[email protected]949f25a2012-06-27 01:53:09123 const FileSystemURL& url,
[email protected]ad117b12012-04-19 05:40:19124 int64 offset,
[email protected]ad117b12012-04-19 05:40:19125 FileSystemContext* context) const {
[email protected]d6afd112012-07-25 22:55:04126 return new webkit_blob::LocalFileStreamReader(
127 context->file_task_runner(), url.path(), offset, base::Time());
[email protected]ad117b12012-04-19 05:40:19128}
129
[email protected]7e836a3d2012-05-31 05:14:59130FileStreamWriter* IsolatedMountPointProvider::CreateFileStreamWriter(
[email protected]949f25a2012-06-27 01:53:09131 const FileSystemURL& url,
[email protected]7e84b912012-05-16 04:42:01132 int64 offset,
133 FileSystemContext* context) const {
[email protected]d6afd112012-07-25 22:55:04134 return new LocalFileStreamWriter(url.path(), offset);
[email protected]7e84b912012-05-16 04:42:01135}
136
[email protected]6faad822012-05-11 12:58:29137FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() {
138 // No quota support.
139 return NULL;
140}
141
[email protected]d5e08552012-08-02 21:43:40142void 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]6fe69652012-04-02 09:35:05151} // namespace fileapi