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 "content/browser/fileapi/browser_file_system_helper.h" | 5 #include "content/browser/fileapi/browser_file_system_helper.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
| 13 #include "content/browser/child_process_security_policy_impl.h" |
13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
14 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
15 #include "webkit/fileapi/external_mount_points.h" | 16 #include "webkit/fileapi/external_mount_points.h" |
| 17 #include "webkit/fileapi/file_permission_policy.h" |
16 #include "webkit/fileapi/file_system_options.h" | 18 #include "webkit/fileapi/file_system_options.h" |
17 #include "webkit/fileapi/file_system_task_runners.h" | 19 #include "webkit/fileapi/file_system_task_runners.h" |
| 20 #include "webkit/fileapi/local_file_system_operation.h" |
| 21 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
18 #include "webkit/quota/quota_manager.h" | 22 #include "webkit/quota/quota_manager.h" |
19 | 23 |
20 namespace content { | 24 namespace content { |
21 namespace { | 25 namespace { |
22 | 26 |
23 const char kChromeScheme[] = "chrome"; | 27 const char kChromeScheme[] = "chrome"; |
24 const char kExtensionScheme[] = "chrome-extension"; | 28 const char kExtensionScheme[] = "chrome-extension"; |
25 | 29 |
26 using fileapi::FileSystemOptions; | 30 using fileapi::FileSystemOptions; |
27 | 31 |
(...skipping 30 matching lines...) Expand all Loading... |
58 | 62 |
59 return new fileapi::FileSystemContext( | 63 return new fileapi::FileSystemContext( |
60 task_runners.Pass(), | 64 task_runners.Pass(), |
61 external_mount_points, | 65 external_mount_points, |
62 special_storage_policy, | 66 special_storage_policy, |
63 quota_manager_proxy, | 67 quota_manager_proxy, |
64 profile_path, | 68 profile_path, |
65 CreateBrowserFileSystemOptions(is_incognito)); | 69 CreateBrowserFileSystemOptions(is_incognito)); |
66 } | 70 } |
67 | 71 |
| 72 bool CheckFileSystemPermissionsForProcess( |
| 73 fileapi::FileSystemContext* context, int process_id, |
| 74 const fileapi::FileSystemURL& url, int permissions, |
| 75 base::PlatformFileError* error) { |
| 76 DCHECK(error); |
| 77 *error = base::PLATFORM_FILE_OK; |
| 78 |
| 79 if (!url.is_valid()) { |
| 80 *error = base::PLATFORM_FILE_ERROR_INVALID_URL; |
| 81 return false; |
| 82 } |
| 83 |
| 84 fileapi::FileSystemMountPointProvider* mount_point_provider = |
| 85 context->GetMountPointProvider(url.type()); |
| 86 if (!mount_point_provider) { |
| 87 *error = base::PLATFORM_FILE_ERROR_INVALID_URL; |
| 88 return false; |
| 89 } |
| 90 |
| 91 base::FilePath file_path; |
| 92 ChildProcessSecurityPolicyImpl* policy = |
| 93 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 94 |
| 95 switch (mount_point_provider->GetPermissionPolicy(url, permissions)) { |
| 96 case fileapi::FILE_PERMISSION_ALWAYS_DENY: |
| 97 *error = base::PLATFORM_FILE_ERROR_SECURITY; |
| 98 return false; |
| 99 case fileapi::FILE_PERMISSION_ALWAYS_ALLOW: |
| 100 CHECK(mount_point_provider == context->sandbox_provider()); |
| 101 return true; |
| 102 case fileapi::FILE_PERMISSION_USE_FILE_PERMISSION: { |
| 103 const bool success = policy->HasPermissionsForFile( |
| 104 process_id, url.path(), permissions); |
| 105 if (!success) |
| 106 *error = base::PLATFORM_FILE_ERROR_SECURITY; |
| 107 return success; |
| 108 } |
| 109 case fileapi::FILE_PERMISSION_USE_FILESYSTEM_PERMISSION: { |
| 110 const bool success = policy->HasPermissionsForFileSystem( |
| 111 process_id, url.filesystem_id(), permissions); |
| 112 if (!success) |
| 113 *error = base::PLATFORM_FILE_ERROR_SECURITY; |
| 114 return success; |
| 115 } |
| 116 } |
| 117 NOTREACHED(); |
| 118 *error = base::PLATFORM_FILE_ERROR_SECURITY; |
| 119 return false; |
| 120 } |
| 121 |
| 122 void SyncGetPlatformPath(fileapi::FileSystemContext* context, |
| 123 int process_id, |
| 124 const GURL& path, |
| 125 base::FilePath* platform_path) { |
| 126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 127 DCHECK(platform_path); |
| 128 *platform_path = base::FilePath(); |
| 129 fileapi::FileSystemURL url(context->CrackURL(path)); |
| 130 if (!url.is_valid()) |
| 131 return; |
| 132 |
| 133 // Make sure if this file is ok to be read (in the current architecture |
| 134 // which means roughly same as the renderer is allowed to get the platform |
| 135 // path to the file). |
| 136 base::PlatformFileError error; |
| 137 if (!CheckFileSystemPermissionsForProcess( |
| 138 context, process_id, url, fileapi::kReadFilePermissions, &error)) |
| 139 return; |
| 140 |
| 141 // This is called only by pepper plugin as of writing to get the |
| 142 // underlying platform path to upload a file in the sandboxed filesystem |
| 143 // (e.g. TEMPORARY or PERSISTENT). |
| 144 // TODO(kinuko): this hack should go away once appropriate upload-stream |
| 145 // handling based on element types is supported. |
| 146 fileapi::LocalFileSystemOperation* operation = |
| 147 context->CreateFileSystemOperation( |
| 148 url, NULL)->AsLocalFileSystemOperation(); |
| 149 DCHECK(operation); |
| 150 if (!operation) |
| 151 return; |
| 152 |
| 153 operation->SyncGetPlatformPath(url, platform_path); |
| 154 |
| 155 // The path is to be attached to URLLoader so we grant read permission |
| 156 // for the file. (We first need to check if it can already be read not to |
| 157 // overwrite existing permissions) |
| 158 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
| 159 process_id, *platform_path)) { |
| 160 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile( |
| 161 process_id, *platform_path); |
| 162 } |
| 163 } |
| 164 |
68 } // namespace content | 165 } // namespace content |
OLD | NEW |