Chromium Code Reviews| 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; | 109 *error = base::PLATFORM_FILE_OK; |
| 101 | 110 |
| 102 if (!url.is_valid()) { | 111 if (!FileSystemURLIsValid(context, url)) { |
| 103 *error = base::PLATFORM_FILE_ERROR_INVALID_URL; | 112 *error = base::PLATFORM_FILE_ERROR_INVALID_URL; |
| 104 return false; | 113 return false; |
| 105 } | 114 } |
| 106 | |
| 107 fileapi::FileSystemBackend* mount_point_provider = | |
| 108 context->GetFileSystemBackend(url.type()); | |
| 109 if (!mount_point_provider) { | |
| 110 *error = base::PLATFORM_FILE_ERROR_INVALID_URL; | |
| 111 return false; | |
| 112 } | |
| 113 | 115 |
| 114 base::FilePath file_path; | 116 base::FilePath file_path; |
| 115 ChildProcessSecurityPolicyImpl* policy = | 117 ChildProcessSecurityPolicyImpl* policy = |
| 116 ChildProcessSecurityPolicyImpl::GetInstance(); | 118 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 117 | 119 |
| 118 if (policy->HasPermissionsForFileSystemFile(process_id, url, permissions)) | 120 if (policy->HasPermissionsForFileSystemFile(process_id, url, permissions)) |
|
Tom Sepez
2013/07/19 18:39:28
nit: I'd prefer inverting this check, setting erro
tommycli
2013/07/23 21:12:35
Done.
| |
| 119 return true; | 121 return true; |
| 120 | 122 |
| 121 *error = base::PLATFORM_FILE_ERROR_SECURITY; | 123 *error = base::PLATFORM_FILE_ERROR_SECURITY; |
| 122 return false; | 124 return false; |
| 123 } | 125 } |
| 124 | 126 |
| 125 void SyncGetPlatformPath(fileapi::FileSystemContext* context, | 127 void SyncGetPlatformPath(fileapi::FileSystemContext* context, |
| 126 int process_id, | 128 int process_id, |
| 127 const GURL& path, | 129 const GURL& path, |
| 128 base::FilePath* platform_path) { | 130 base::FilePath* platform_path) { |
| 129 DCHECK(context->task_runners()->file_task_runner()-> | 131 DCHECK(context->task_runners()->file_task_runner()-> |
| 130 RunsTasksOnCurrentThread()); | 132 RunsTasksOnCurrentThread()); |
| 131 DCHECK(platform_path); | 133 DCHECK(platform_path); |
| 132 *platform_path = base::FilePath(); | 134 *platform_path = base::FilePath(); |
| 133 fileapi::FileSystemURL url(context->CrackURL(path)); | 135 fileapi::FileSystemURL url(context->CrackURL(path)); |
| 134 if (!url.is_valid()) | 136 if (!FileSystemURLIsValid(context, url)) |
| 135 return; | 137 return; |
| 136 | 138 |
| 137 // Make sure if this file is ok to be read (in the current architecture | 139 // Make sure if this file is ok to be read (in the current architecture |
| 138 // which means roughly same as the renderer is allowed to get the platform | 140 // which means roughly same as the renderer is allowed to get the platform |
| 139 // path to the file). | 141 // path to the file). |
| 140 base::PlatformFileError error; | 142 ChildProcessSecurityPolicyImpl* policy = |
| 141 if (!CheckFileSystemPermissionsForProcess( | 143 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 142 context, process_id, url, fileapi::kReadFilePermissions, &error)) | 144 if (!policy->CanReadFileSystemFile(process_id, url)) |
| 143 return; | 145 return; |
| 144 | 146 |
| 145 context->operation_runner()->SyncGetPlatformPath(url, platform_path); | 147 context->operation_runner()->SyncGetPlatformPath(url, platform_path); |
| 146 | 148 |
| 147 // The path is to be attached to URLLoader so we grant read permission | 149 // The path is to be attached to URLLoader so we grant read permission |
| 148 // for the file. (We first need to check if it can already be read not to | 150 // for the file. (We first need to check if it can already be read not to |
| 149 // overwrite existing permissions) | 151 // overwrite existing permissions) |
| 150 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 152 if (!policy->CanReadFile(process_id, *platform_path)) |
|
Tom Sepez
2013/07/19 18:39:28
Is this still the case? Don't the permissions hav
tommycli
2013/07/23 21:12:35
Done. I see no harm in setting it irrespectively.
| |
| 151 process_id, *platform_path)) { | 153 policy->GrantReadFile(process_id, *platform_path); |
| 152 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile( | |
| 153 process_id, *platform_path); | |
| 154 } | |
| 155 } | 154 } |
| 156 | 155 |
| 157 } // namespace content | 156 } // namespace content |
| OLD | NEW |