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" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 for (size_t i = 0; i < types.size(); ++i) { | 85 for (size_t i = 0; i < types.size(); ++i) { |
86 ChildProcessSecurityPolicyImpl::GetInstance()-> | 86 ChildProcessSecurityPolicyImpl::GetInstance()-> |
87 RegisterFileSystemPermissionPolicy( | 87 RegisterFileSystemPermissionPolicy( |
88 types[i], | 88 types[i], |
89 fileapi::FileSystemContext::GetPermissionPolicy(types[i])); | 89 fileapi::FileSystemContext::GetPermissionPolicy(types[i])); |
90 } | 90 } |
91 | 91 |
92 return file_system_context; | 92 return file_system_context; |
93 } | 93 } |
94 | 94 |
| 95 bool FileSystemURLIsValid( |
| 96 fileapi::FileSystemContext* context, |
| 97 const fileapi::FileSystemURL& url) { |
| 98 if (!url.is_valid()) |
| 99 return false; |
| 100 |
| 101 return context->GetFileSystemBackend(url.type()) != NULL; |
| 102 } |
| 103 |
95 bool CheckFileSystemPermissionsForProcess( | 104 bool CheckFileSystemPermissionsForProcess( |
96 fileapi::FileSystemContext* context, int process_id, | 105 fileapi::FileSystemContext* context, int process_id, |
97 const fileapi::FileSystemURL& url, int permissions, | 106 const fileapi::FileSystemURL& url, int permissions, |
98 base::PlatformFileError* error) { | 107 base::PlatformFileError* error) { |
99 DCHECK(error); | 108 DCHECK(error); |
100 *error = base::PLATFORM_FILE_OK; | |
101 | 109 |
102 if (!url.is_valid()) { | 110 if (!FileSystemURLIsValid(context, url)) { |
103 *error = base::PLATFORM_FILE_ERROR_INVALID_URL; | 111 *error = base::PLATFORM_FILE_ERROR_INVALID_URL; |
104 return false; | 112 return false; |
105 } | 113 } |
106 | 114 |
107 if (!context->GetFileSystemBackend(url.type())) { | 115 if (!ChildProcessSecurityPolicyImpl::GetInstance()-> |
108 *error = base::PLATFORM_FILE_ERROR_INVALID_URL; | 116 HasPermissionsForFileSystemFile(process_id, url, permissions)) { |
| 117 *error = base::PLATFORM_FILE_ERROR_SECURITY; |
109 return false; | 118 return false; |
110 } | 119 } |
111 | 120 |
112 base::FilePath file_path; | 121 *error = base::PLATFORM_FILE_OK; |
113 ChildProcessSecurityPolicyImpl* policy = | 122 return true; |
114 ChildProcessSecurityPolicyImpl::GetInstance(); | |
115 | |
116 if (policy->HasPermissionsForFileSystemFile(process_id, url, permissions)) | |
117 return true; | |
118 | |
119 *error = base::PLATFORM_FILE_ERROR_SECURITY; | |
120 return false; | |
121 } | 123 } |
122 | 124 |
123 void SyncGetPlatformPath(fileapi::FileSystemContext* context, | 125 void SyncGetPlatformPath(fileapi::FileSystemContext* context, |
124 int process_id, | 126 int process_id, |
125 const GURL& path, | 127 const GURL& path, |
126 base::FilePath* platform_path) { | 128 base::FilePath* platform_path) { |
127 DCHECK(context->task_runners()->file_task_runner()-> | 129 DCHECK(context->task_runners()->file_task_runner()-> |
128 RunsTasksOnCurrentThread()); | 130 RunsTasksOnCurrentThread()); |
129 DCHECK(platform_path); | 131 DCHECK(platform_path); |
130 *platform_path = base::FilePath(); | 132 *platform_path = base::FilePath(); |
131 fileapi::FileSystemURL url(context->CrackURL(path)); | 133 fileapi::FileSystemURL url(context->CrackURL(path)); |
132 if (!url.is_valid()) | 134 if (!FileSystemURLIsValid(context, url)) |
133 return; | 135 return; |
134 | 136 |
135 // Make sure if this file is ok to be read (in the current architecture | 137 // Make sure if this file is ok to be read (in the current architecture |
136 // which means roughly same as the renderer is allowed to get the platform | 138 // which means roughly same as the renderer is allowed to get the platform |
137 // path to the file). | 139 // path to the file). |
138 base::PlatformFileError error; | 140 ChildProcessSecurityPolicyImpl* policy = |
139 if (!CheckFileSystemPermissionsForProcess( | 141 ChildProcessSecurityPolicyImpl::GetInstance(); |
140 context, process_id, url, fileapi::kReadFilePermissions, &error)) | 142 if (!policy->CanReadFileSystemFile(process_id, url)) |
141 return; | 143 return; |
142 | 144 |
143 context->operation_runner()->SyncGetPlatformPath(url, platform_path); | 145 context->operation_runner()->SyncGetPlatformPath(url, platform_path); |
144 | 146 |
145 // The path is to be attached to URLLoader so we grant read permission | 147 // The path is to be attached to URLLoader so we grant read permission |
146 // for the file. (We first need to check if it can already be read not to | 148 // for the file. (We need to check first because a parent directory may |
147 // overwrite existing permissions) | 149 // already have the permissions and we don't need to grant it to the file.) |
148 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 150 if (!policy->CanReadFile(process_id, *platform_path)) |
149 process_id, *platform_path)) { | 151 policy->GrantReadFile(process_id, *platform_path); |
150 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile( | |
151 process_id, *platform_path); | |
152 } | |
153 } | 152 } |
154 | 153 |
155 } // namespace content | 154 } // namespace content |
OLD | NEW |