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 fileapi::FileSystemBackend* mount_point_provider = | 115 if (!ChildProcessSecurityPolicyImpl::GetInstance()-> |
108 context->GetFileSystemBackend(url.type()); | 116 HasPermissionsForFileSystemFile(process_id, url, permissions)) { |
109 if (!mount_point_provider) { | 117 *error = base::PLATFORM_FILE_ERROR_SECURITY; |
110 *error = base::PLATFORM_FILE_ERROR_INVALID_URL; | |
111 return false; | 118 return false; |
112 } | 119 } |
113 | 120 |
114 base::FilePath file_path; | 121 *error = base::PLATFORM_FILE_OK; |
115 ChildProcessSecurityPolicyImpl* policy = | 122 return true; |
116 ChildProcessSecurityPolicyImpl::GetInstance(); | |
117 | |
118 if (policy->HasPermissionsForFileSystemFile(process_id, url, permissions)) | |
119 return true; | |
120 | |
121 *error = base::PLATFORM_FILE_ERROR_SECURITY; | |
122 return false; | |
123 } | 123 } |
124 | 124 |
125 void SyncGetPlatformPath(fileapi::FileSystemContext* context, | 125 void SyncGetPlatformPath(fileapi::FileSystemContext* context, |
126 int process_id, | 126 int process_id, |
127 const GURL& path, | 127 const GURL& path, |
128 base::FilePath* platform_path) { | 128 base::FilePath* platform_path) { |
129 DCHECK(context->task_runners()->file_task_runner()-> | 129 DCHECK(context->task_runners()->file_task_runner()-> |
130 RunsTasksOnCurrentThread()); | 130 RunsTasksOnCurrentThread()); |
131 DCHECK(platform_path); | 131 DCHECK(platform_path); |
132 *platform_path = base::FilePath(); | 132 *platform_path = base::FilePath(); |
133 fileapi::FileSystemURL url(context->CrackURL(path)); | 133 fileapi::FileSystemURL url(context->CrackURL(path)); |
134 if (!url.is_valid()) | 134 if (!FileSystemURLIsValid(context, url)) |
135 return; | 135 return; |
136 | 136 |
137 // 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 |
138 // 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 |
139 // path to the file). | 139 // path to the file). |
140 base::PlatformFileError error; | 140 ChildProcessSecurityPolicyImpl* policy = |
141 if (!CheckFileSystemPermissionsForProcess( | 141 ChildProcessSecurityPolicyImpl::GetInstance(); |
142 context, process_id, url, fileapi::kReadFilePermissions, &error)) | 142 if (!policy->CanReadFileSystemFile(process_id, url)) |
143 return; | 143 return; |
144 | 144 |
145 context->operation_runner()->SyncGetPlatformPath(url, platform_path); | 145 context->operation_runner()->SyncGetPlatformPath(url, platform_path); |
146 | 146 |
147 // 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 |
148 // for the file. (We first need to check if it can already be read not to | 148 // for the file. |
149 // overwrite existing permissions) | 149 policy->GrantReadFile(process_id, *platform_path); |
kinuko
2013/07/24 09:25:23
Has situation changed so that we don't need to che
tommycli
2013/07/24 14:38:00
Yes. It used to simply replace the granted permiss
| |
150 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | |
151 process_id, *platform_path)) { | |
152 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile( | |
153 process_id, *platform_path); | |
154 } | |
155 } | 150 } |
156 | 151 |
157 } // namespace content | 152 } // namespace content |
OLD | NEW |