Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: content/browser/fileapi/browser_file_system_helper.cc

Issue 2830743004: Extracting and unittesting PrepareDropDataForChildProcess function. (Closed)
Patch Set: Readding a summary comment to PrepareDropDataForChildProcess as suggested in the CR feedback... (it… Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/sequenced_task_runner.h" 14 #include "base/sequenced_task_runner.h"
15 #include "base/strings/utf_string_conversions.h"
15 #include "base/threading/sequenced_worker_pool.h" 16 #include "base/threading/sequenced_worker_pool.h"
16 #include "content/browser/child_process_security_policy_impl.h" 17 #include "content/browser/child_process_security_policy_impl.h"
17 #include "content/public/browser/browser_context.h" 18 #include "content/public/browser/browser_context.h"
18 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/child_process_security_policy.h"
19 #include "content/public/browser/content_browser_client.h" 21 #include "content/public/browser/content_browser_client.h"
20 #include "content/public/common/content_client.h" 22 #include "content/public/common/content_client.h"
21 #include "content/public/common/content_switches.h" 23 #include "content/public/common/content_switches.h"
24 #include "content/public/common/drop_data.h"
25 #include "content/public/common/url_constants.h"
26 #include "net/base/filename_util.h"
22 #include "storage/browser/fileapi/external_mount_points.h" 27 #include "storage/browser/fileapi/external_mount_points.h"
23 #include "storage/browser/fileapi/file_permission_policy.h" 28 #include "storage/browser/fileapi/file_permission_policy.h"
24 #include "storage/browser/fileapi/file_system_backend.h" 29 #include "storage/browser/fileapi/file_system_backend.h"
25 #include "storage/browser/fileapi/file_system_context.h" 30 #include "storage/browser/fileapi/file_system_context.h"
26 #include "storage/browser/fileapi/file_system_operation_runner.h" 31 #include "storage/browser/fileapi/file_system_operation_runner.h"
27 #include "storage/browser/fileapi/file_system_options.h" 32 #include "storage/browser/fileapi/file_system_options.h"
33 #include "storage/browser/fileapi/file_system_url.h"
34 #include "storage/browser/fileapi/isolated_context.h"
28 #include "storage/browser/quota/quota_manager.h" 35 #include "storage/browser/quota/quota_manager.h"
36 #include "url/gurl.h"
29 #include "url/url_constants.h" 37 #include "url/url_constants.h"
30 38
31 namespace content { 39 namespace content {
32 40
33 namespace { 41 namespace {
34 42
35 using storage::FileSystemOptions; 43 using storage::FileSystemOptions;
36 44
37 FileSystemOptions CreateBrowserFileSystemOptions(bool is_incognito) { 45 FileSystemOptions CreateBrowserFileSystemOptions(bool is_incognito) {
38 FileSystemOptions::ProfileMode profile_mode = 46 FileSystemOptions::ProfileMode profile_mode =
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 133
126 context->operation_runner()->SyncGetPlatformPath(url, platform_path); 134 context->operation_runner()->SyncGetPlatformPath(url, platform_path);
127 135
128 // The path is to be attached to URLLoader so we grant read permission 136 // The path is to be attached to URLLoader so we grant read permission
129 // for the file. (We need to check first because a parent directory may 137 // for the file. (We need to check first because a parent directory may
130 // already have the permissions and we don't need to grant it to the file.) 138 // already have the permissions and we don't need to grant it to the file.)
131 if (!policy->CanReadFile(process_id, *platform_path)) 139 if (!policy->CanReadFile(process_id, *platform_path))
132 policy->GrantReadFile(process_id, *platform_path); 140 policy->GrantReadFile(process_id, *platform_path);
133 } 141 }
134 142
143 void PrepareDropDataForChildProcess(
144 DropData* drop_data,
145 ChildProcessSecurityPolicyImpl* security_policy,
146 int child_id,
147 const storage::FileSystemContext* file_system_context) {
148 #if defined(OS_CHROMEOS)
149 // The externalfile:// scheme is used in Chrome OS to open external files in a
150 // browser tab.
151 if (drop_data->url.SchemeIs(content::kExternalFileScheme))
152 security_policy->GrantRequestURL(child_id, drop_data->url);
153 #endif
154
155 // The filenames vector represents a capability to access the given files.
156 storage::IsolatedContext::FileInfoSet files;
157 for (auto& filename : drop_data->filenames) {
158 // Make sure we have the same display_name as the one we register.
159 if (filename.display_name.empty()) {
160 std::string name;
161 files.AddPath(filename.path, &name);
162 filename.display_name = base::FilePath::FromUTF8Unsafe(name);
163 } else {
164 files.AddPathWithName(filename.path,
165 filename.display_name.AsUTF8Unsafe());
166 }
167 // A dragged file may wind up as the value of an input element, or it
168 // may be used as the target of a navigation instead. We don't know
169 // which will happen at this point, so generously grant both access
170 // and request permissions to the specific file to cover both cases.
171 // We do not give it the permission to request all file:// URLs.
172 security_policy->GrantRequestSpecificFileURL(
173 child_id, net::FilePathToFileURL(filename.path));
174
175 // If the renderer already has permission to read these paths, we don't need
176 // to re-grant them. This prevents problems with DnD for files in the CrOS
177 // file manager--the file manager already had read/write access to those
178 // directories, but dragging a file would cause the read/write access to be
179 // overwritten with read-only access, making them impossible to delete or
180 // rename until the renderer was killed.
181 if (!security_policy->CanReadFile(child_id, filename.path))
182 security_policy->GrantReadFile(child_id, filename.path);
183 }
184
185 storage::IsolatedContext* isolated_context =
186 storage::IsolatedContext::GetInstance();
187 DCHECK(isolated_context);
188
189 if (!files.fileset().empty()) {
190 std::string filesystem_id =
191 isolated_context->RegisterDraggedFileSystem(files);
192 if (!filesystem_id.empty()) {
193 // Grant the permission iff the ID is valid.
194 security_policy->GrantReadFileSystem(child_id, filesystem_id);
195 }
196 drop_data->filesystem_id = base::UTF8ToUTF16(filesystem_id);
197 }
198
199 for (auto& file_system_file : drop_data->file_system_files) {
200 storage::FileSystemURL file_system_url =
201 file_system_context->CrackURL(file_system_file.url);
202
203 std::string register_name;
204 std::string filesystem_id = isolated_context->RegisterFileSystemForPath(
205 file_system_url.type(), file_system_url.filesystem_id(),
206 file_system_url.path(), &register_name);
207
208 if (!filesystem_id.empty()) {
209 // Grant the permission iff the ID is valid.
210 security_policy->GrantReadFileSystem(child_id, filesystem_id);
211 }
212
213 // Note: We are using the origin URL provided by the sender here. It may be
214 // different from the receiver's.
215 file_system_file.url =
216 GURL(storage::GetIsolatedFileSystemRootURIString(
217 file_system_url.origin(), filesystem_id, std::string())
218 .append(register_name));
219 file_system_file.filesystem_id = filesystem_id;
220 }
221 }
222
135 } // namespace content 223 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/fileapi/browser_file_system_helper.h ('k') | content/browser/fileapi/browser_file_system_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698