blob: 02bf8ae8cbdb1d799e240893eb8540233f1ea5a6 [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"
13#include "googleurl/src/gurl.h"
[email protected]ad117b12012-04-19 05:40:1914#include "webkit/blob/local_file_reader.h"
[email protected]6fe69652012-04-02 09:35:0515#include "webkit/fileapi/file_system_callback_dispatcher.h"
[email protected]ad117b12012-04-19 05:40:1916#include "webkit/fileapi/file_system_file_reader.h"
[email protected]6fe69652012-04-02 09:35:0517#include "webkit/fileapi/file_system_operation.h"
18#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"
22#include "webkit/fileapi/native_file_util.h"
23
24namespace fileapi {
25
26IsolatedMountPointProvider::IsolatedMountPointProvider()
27 : isolated_file_util_(new IsolatedFileUtil(new NativeFileUtil())) {
28}
29
30IsolatedMountPointProvider::~IsolatedMountPointProvider() {
31}
32
33void IsolatedMountPointProvider::ValidateFileSystemRoot(
34 const GURL& origin_url,
35 FileSystemType type,
36 bool create,
37 const ValidateFileSystemCallback& callback) {
38 // We never allow opening a new isolated FileSystem via usual OpenFileSystem.
39 base::MessageLoopProxy::current()->PostTask(
40 FROM_HERE,
41 base::Bind(callback, base::PLATFORM_FILE_ERROR_SECURITY));
42}
43
44FilePath IsolatedMountPointProvider::GetFileSystemRootPathOnFileThread(
45 const GURL& origin_url,
46 FileSystemType type,
47 const FilePath& virtual_path,
48 bool create) {
49 if (create || type != kFileSystemTypeIsolated)
50 return FilePath();
51 std::string fsid;
52 FilePath root, path;
53 if (!isolated_context()->CrackIsolatedPath(virtual_path, &fsid, &root, &path))
54 return FilePath();
55 return root;
56}
57
58bool IsolatedMountPointProvider::IsAccessAllowed(
59 const GURL& origin_url, FileSystemType type, const FilePath& virtual_path) {
60 if (type != fileapi::kFileSystemTypeIsolated)
61 return false;
62
63 std::string filesystem_id;
64 FilePath root, path;
65 return isolated_context()->CrackIsolatedPath(
66 virtual_path, &filesystem_id, &root, &path);
67}
68
69bool IsolatedMountPointProvider::IsRestrictedFileName(
70 const FilePath& filename) const {
71 return false;
72}
73
74std::vector<FilePath> IsolatedMountPointProvider::GetRootDirectories() const {
75 // We have no pre-defined root directories that need to be given
76 // access permission.
77 return std::vector<FilePath>();
78}
79
80FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil() {
81 return isolated_file_util_.get();
82}
83
84FilePath IsolatedMountPointProvider::GetPathForPermissionsCheck(
85 const FilePath& virtual_path) const {
86 std::string fsid;
87 FilePath root, path;
88 if (!isolated_context()->CrackIsolatedPath(virtual_path, &fsid, &root, &path))
89 return FilePath();
90 return path;
91}
92
93FileSystemOperationInterface*
94IsolatedMountPointProvider::CreateFileSystemOperation(
95 const GURL& origin_url,
96 FileSystemType file_system_type,
97 const FilePath& virtual_path,
98 base::MessageLoopProxy* file_proxy,
99 FileSystemContext* context) const {
100 return new FileSystemOperation(file_proxy, context);
101}
102
[email protected]ad117b12012-04-19 05:40:19103webkit_blob::FileReader* IsolatedMountPointProvider::CreateFileReader(
104 const GURL& url,
105 int64 offset,
106 base::MessageLoopProxy* file_proxy,
107 FileSystemContext* context) const {
108 GURL origin_url;
109 FileSystemType file_system_type = kFileSystemTypeUnknown;
110 FilePath virtual_path;
111 if (!CrackFileSystemURL(url, &origin_url, &file_system_type, &virtual_path))
112 return NULL;
113 std::string fsid;
114 FilePath path;
115 if (!isolated_context()->CrackIsolatedPath(virtual_path, &fsid, NULL, &path))
116 return NULL;
117 if (path.empty())
118 return NULL;
119 return new webkit_blob::LocalFileReader(
120 file_proxy, path, offset, base::Time());
121}
122
[email protected]6fe69652012-04-02 09:35:05123IsolatedContext* IsolatedMountPointProvider::isolated_context() const {
124 return IsolatedContext::GetInstance();
125}
126
127} // namespace fileapi