blob: 92d214fc736b31b014a6d038fdd5bf33d42565a0 [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]6fe69652012-04-02 09:35:0524#include "webkit/fileapi/native_file_util.h"
25
26namespace fileapi {
27
[email protected]74698902012-06-12 12:16:3828namespace {
29
30IsolatedContext* isolated_context() {
31 return IsolatedContext::GetInstance();
32}
33
[email protected]74698902012-06-12 12:16:3834} // namespace
35
[email protected]6fe69652012-04-02 09:35:0536IsolatedMountPointProvider::IsolatedMountPointProvider()
[email protected]d6afd112012-07-25 22:55:0437 : isolated_file_util_(new IsolatedFileUtil()),
38 dragged_file_util_(new DraggedFileUtil()) {
[email protected]6fe69652012-04-02 09:35:0539}
40
41IsolatedMountPointProvider::~IsolatedMountPointProvider() {
42}
43
44void 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
55FilePath IsolatedMountPointProvider::GetFileSystemRootPathOnFileThread(
56 const GURL& origin_url,
57 FileSystemType type,
58 const FilePath& virtual_path,
59 bool create) {
[email protected]d6afd112012-07-25 22:55:0460 // This is not supposed to be used.
61 NOTREACHED();
62 return FilePath();
[email protected]6fe69652012-04-02 09:35:0563}
64
65bool IsolatedMountPointProvider::IsAccessAllowed(
66 const GURL& origin_url, FileSystemType type, const FilePath& virtual_path) {
[email protected]d6afd112012-07-25 22:55:0467 return true;
[email protected]6fe69652012-04-02 09:35:0568}
69
70bool IsolatedMountPointProvider::IsRestrictedFileName(
71 const FilePath& filename) const {
[email protected]d6afd112012-07-25 22:55:0472 // 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]6fe69652012-04-02 09:35:0574 return false;
75}
76
[email protected]d6afd112012-07-25 22:55:0477FileSystemFileUtil* 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]6fe69652012-04-02 09:35:0583}
84
85FilePath IsolatedMountPointProvider::GetPathForPermissionsCheck(
86 const FilePath& virtual_path) const {
[email protected]d6afd112012-07-25 22:55:0487 // For isolated filesystems we only check per-filesystem permissions.
88 NOTREACHED();
89 return virtual_path;
[email protected]6fe69652012-04-02 09:35:0590}
91
92FileSystemOperationInterface*
93IsolatedMountPointProvider::CreateFileSystemOperation(
[email protected]949f25a2012-06-27 01:53:0994 const FileSystemURL& url,
[email protected]6fe69652012-04-02 09:35:0595 FileSystemContext* context) const {
[email protected]02a60542012-07-24 20:05:3396 return new LocalFileSystemOperation(context);
[email protected]6fe69652012-04-02 09:35:0597}
98
[email protected]c4ca3b452012-05-31 03:15:4699webkit_blob::FileStreamReader*
100IsolatedMountPointProvider::CreateFileStreamReader(
[email protected]949f25a2012-06-27 01:53:09101 const FileSystemURL& url,
[email protected]ad117b12012-04-19 05:40:19102 int64 offset,
[email protected]ad117b12012-04-19 05:40:19103 FileSystemContext* context) const {
[email protected]d6afd112012-07-25 22:55:04104 return new webkit_blob::LocalFileStreamReader(
105 context->file_task_runner(), url.path(), offset, base::Time());
[email protected]ad117b12012-04-19 05:40:19106}
107
[email protected]7e836a3d2012-05-31 05:14:59108FileStreamWriter* IsolatedMountPointProvider::CreateFileStreamWriter(
[email protected]949f25a2012-06-27 01:53:09109 const FileSystemURL& url,
[email protected]7e84b912012-05-16 04:42:01110 int64 offset,
111 FileSystemContext* context) const {
[email protected]d6afd112012-07-25 22:55:04112 return new LocalFileStreamWriter(url.path(), offset);
[email protected]7e84b912012-05-16 04:42:01113}
114
[email protected]6faad822012-05-11 12:58:29115FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() {
116 // No quota support.
117 return NULL;
118}
119
[email protected]6fe69652012-04-02 09:35:05120} // namespace fileapi