summaryrefslogtreecommitdiffstats
path: root/webkit/fileapi/isolated_mount_point_provider.cc
blob: 770bbfe9fe1d0f091690653b5046d56ca4948ffa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "webkit/fileapi/isolated_mount_point_provider.h"

#include <string>

#include "base/bind.h"
#include "base/file_path.h"
#include "base/logging.h"
#include "base/message_loop_proxy.h"
#include "base/sequenced_task_runner.h"
#include "webkit/blob/local_file_stream_reader.h"
#include "webkit/fileapi/file_system_callback_dispatcher.h"
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_file_stream_reader.h"
#include "webkit/fileapi/file_system_types.h"
#include "webkit/fileapi/file_system_util.h"
#include "webkit/fileapi/isolated_context.h"
#include "webkit/fileapi/isolated_file_util.h"
#include "webkit/fileapi/local_file_stream_writer.h"
#include "webkit/fileapi/local_file_system_operation.h"
#include "webkit/fileapi/native_file_util.h"

namespace fileapi {

namespace {

IsolatedContext* isolated_context() {
  return IsolatedContext::GetInstance();
}

FilePath GetPathFromURL(const FileSystemURL& url) {
  if (!url.is_valid() || url.type() != kFileSystemTypeIsolated)
    return FilePath();
  std::string fsid;
  FilePath path;
  if (!isolated_context()->CrackIsolatedPath(url.path(), &fsid, NULL, &path))
    return FilePath();
  return path;
}

}  // namespace

IsolatedMountPointProvider::IsolatedMountPointProvider()
    : isolated_file_util_(new IsolatedFileUtil()) {
}

IsolatedMountPointProvider::~IsolatedMountPointProvider() {
}

void IsolatedMountPointProvider::ValidateFileSystemRoot(
    const GURL& origin_url,
    FileSystemType type,
    bool create,
    const ValidateFileSystemCallback& callback) {
  // We never allow opening a new isolated FileSystem via usual OpenFileSystem.
  base::MessageLoopProxy::current()->PostTask(
      FROM_HERE,
      base::Bind(callback, base::PLATFORM_FILE_ERROR_SECURITY));
}

FilePath IsolatedMountPointProvider::GetFileSystemRootPathOnFileThread(
    const GURL& origin_url,
    FileSystemType type,
    const FilePath& virtual_path,
    bool create) {
  if (create || type != kFileSystemTypeIsolated)
    return FilePath();
  std::string fsid;
  FilePath path;
  IsolatedContext::FileInfo root;
  if (!isolated_context()->CrackIsolatedPath(virtual_path, &fsid, &root, &path))
    return FilePath();
  return root.path;
}

bool IsolatedMountPointProvider::IsAccessAllowed(
    const GURL& origin_url, FileSystemType type, const FilePath& virtual_path) {
  if (type != fileapi::kFileSystemTypeIsolated)
    return false;

  std::string filesystem_id;
  FilePath path;
  return isolated_context()->CrackIsolatedPath(
      virtual_path, &filesystem_id, NULL, &path);
}

bool IsolatedMountPointProvider::IsRestrictedFileName(
    const FilePath& filename) const {
  return false;
}

FileSystemFileUtil* IsolatedMountPointProvider::GetFileUtil() {
  return isolated_file_util_.get();
}

FilePath IsolatedMountPointProvider::GetPathForPermissionsCheck(
    const FilePath& virtual_path) const {
  std::string fsid;
  FilePath path;
  if (!isolated_context()->CrackIsolatedPath(virtual_path, &fsid, NULL, &path))
    return FilePath();
  return path;
}

FileSystemOperationInterface*
IsolatedMountPointProvider::CreateFileSystemOperation(
    const FileSystemURL& url,
    FileSystemContext* context) const {
  return new LocalFileSystemOperation(context);
}

webkit_blob::FileStreamReader*
IsolatedMountPointProvider::CreateFileStreamReader(
    const FileSystemURL& url,
    int64 offset,
    FileSystemContext* context) const {
  FilePath path = GetPathFromURL(url);
  return path.empty() ? NULL : new webkit_blob::LocalFileStreamReader(
      context->file_task_runner(), path, offset, base::Time());
}

FileStreamWriter* IsolatedMountPointProvider::CreateFileStreamWriter(
    const FileSystemURL& url,
    int64 offset,
    FileSystemContext* context) const {
  FilePath path = GetPathFromURL(url);
  return path.empty() ? NULL : new LocalFileStreamWriter(path, offset);
}

FileSystemQuotaUtil* IsolatedMountPointProvider::GetQuotaUtil() {
  // No quota support.
  return NULL;
}

}  // namespace fileapi