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

Side by Side Diff: chrome/browser/extensions/api/file_handlers/app_file_handler_util.cc

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 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 | Annotate | Revision Log
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 "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" 5 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file.h" 8 #include "base/files/file.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/child_process_security_policy.h" 11 #include "content/public/browser/child_process_security_policy.h"
12 #include "content/public/browser/render_process_host.h" 12 #include "content/public/browser/render_process_host.h"
13 #include "extensions/browser/extension_prefs.h" 13 #include "extensions/browser/extension_prefs.h"
14 #include "extensions/browser/granted_file_entry.h" 14 #include "extensions/browser/granted_file_entry.h"
15 #include "extensions/common/permissions/permissions_data.h" 15 #include "extensions/common/permissions/permissions_data.h"
16 #include "net/base/mime_util.h" 16 #include "net/base/mime_util.h"
17 #include "webkit/browser/fileapi/isolated_context.h" 17 #include "storage/browser/fileapi/isolated_context.h"
18 #include "webkit/common/fileapi/file_system_mount_option.h" 18 #include "storage/common/fileapi/file_system_mount_option.h"
19 #include "webkit/common/fileapi/file_system_types.h" 19 #include "storage/common/fileapi/file_system_types.h"
20 20
21 #if defined(OS_CHROMEOS) 21 #if defined(OS_CHROMEOS)
22 #include "chrome/browser/chromeos/file_manager/filesystem_api_util.h" 22 #include "chrome/browser/chromeos/file_manager/filesystem_api_util.h"
23 #endif 23 #endif
24 24
25 namespace extensions { 25 namespace extensions {
26 26
27 namespace app_file_handler_util { 27 namespace app_file_handler_util {
28 28
29 const char kInvalidParameters[] = "Invalid parameters"; 29 const char kInvalidParameters[] = "Invalid parameters";
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 FileHandlerCanHandleFileWithExtension(handler, path); 285 FileHandlerCanHandleFileWithExtension(handler, path);
286 } 286 }
287 287
288 GrantedFileEntry CreateFileEntry( 288 GrantedFileEntry CreateFileEntry(
289 Profile* profile, 289 Profile* profile,
290 const Extension* extension, 290 const Extension* extension,
291 int renderer_id, 291 int renderer_id,
292 const base::FilePath& path, 292 const base::FilePath& path,
293 bool is_directory) { 293 bool is_directory) {
294 GrantedFileEntry result; 294 GrantedFileEntry result;
295 fileapi::IsolatedContext* isolated_context = 295 storage::IsolatedContext* isolated_context =
296 fileapi::IsolatedContext::GetInstance(); 296 storage::IsolatedContext::GetInstance();
297 DCHECK(isolated_context); 297 DCHECK(isolated_context);
298 298
299 result.filesystem_id = isolated_context->RegisterFileSystemForPath( 299 result.filesystem_id = isolated_context->RegisterFileSystemForPath(
300 fileapi::kFileSystemTypeNativeForPlatformApp, std::string(), path, 300 storage::kFileSystemTypeNativeForPlatformApp,
301 std::string(),
302 path,
301 &result.registered_name); 303 &result.registered_name);
302 304
303 content::ChildProcessSecurityPolicy* policy = 305 content::ChildProcessSecurityPolicy* policy =
304 content::ChildProcessSecurityPolicy::GetInstance(); 306 content::ChildProcessSecurityPolicy::GetInstance();
305 policy->GrantReadFileSystem(renderer_id, result.filesystem_id); 307 policy->GrantReadFileSystem(renderer_id, result.filesystem_id);
306 if (HasFileSystemWritePermission(extension)) { 308 if (HasFileSystemWritePermission(extension)) {
307 if (is_directory) { 309 if (is_directory) {
308 policy->GrantCreateReadWriteFileSystem(renderer_id, result.filesystem_id); 310 policy->GrantCreateReadWriteFileSystem(renderer_id, result.filesystem_id);
309 } else { 311 } else {
310 policy->GrantWriteFileSystem(renderer_id, result.filesystem_id); 312 policy->GrantWriteFileSystem(renderer_id, result.filesystem_id);
(...skipping 26 matching lines...) Expand all
337 const std::string& filesystem_path, 339 const std::string& filesystem_path,
338 const content::RenderViewHost* render_view_host, 340 const content::RenderViewHost* render_view_host,
339 base::FilePath* file_path, 341 base::FilePath* file_path,
340 std::string* error) { 342 std::string* error) {
341 if (filesystem_path.empty()) { 343 if (filesystem_path.empty()) {
342 *error = kInvalidParameters; 344 *error = kInvalidParameters;
343 return false; 345 return false;
344 } 346 }
345 347
346 std::string filesystem_id; 348 std::string filesystem_id;
347 if (!fileapi::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id)) { 349 if (!storage::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id)) {
348 *error = kInvalidParameters; 350 *error = kInvalidParameters;
349 return false; 351 return false;
350 } 352 }
351 353
352 // Only return the display path if the process has read access to the 354 // Only return the display path if the process has read access to the
353 // filesystem. 355 // filesystem.
354 content::ChildProcessSecurityPolicy* policy = 356 content::ChildProcessSecurityPolicy* policy =
355 content::ChildProcessSecurityPolicy::GetInstance(); 357 content::ChildProcessSecurityPolicy::GetInstance();
356 if (!policy->CanReadFileSystem(render_view_host->GetProcess()->GetID(), 358 if (!policy->CanReadFileSystem(render_view_host->GetProcess()->GetID(),
357 filesystem_id)) { 359 filesystem_id)) {
358 *error = kSecurityError; 360 *error = kSecurityError;
359 return false; 361 return false;
360 } 362 }
361 363
362 fileapi::IsolatedContext* context = fileapi::IsolatedContext::GetInstance(); 364 storage::IsolatedContext* context = storage::IsolatedContext::GetInstance();
363 base::FilePath relative_path = 365 base::FilePath relative_path =
364 base::FilePath::FromUTF8Unsafe(filesystem_path); 366 base::FilePath::FromUTF8Unsafe(filesystem_path);
365 base::FilePath virtual_path = context->CreateVirtualRootPath(filesystem_id) 367 base::FilePath virtual_path = context->CreateVirtualRootPath(filesystem_id)
366 .Append(relative_path); 368 .Append(relative_path);
367 fileapi::FileSystemType type; 369 storage::FileSystemType type;
368 fileapi::FileSystemMountOption mount_option; 370 storage::FileSystemMountOption mount_option;
369 std::string cracked_id; 371 std::string cracked_id;
370 if (!context->CrackVirtualPath( 372 if (!context->CrackVirtualPath(
371 virtual_path, &filesystem_id, &type, &cracked_id, file_path, 373 virtual_path, &filesystem_id, &type, &cracked_id, file_path,
372 &mount_option)) { 374 &mount_option)) {
373 *error = kInvalidParameters; 375 *error = kInvalidParameters;
374 return false; 376 return false;
375 } 377 }
376 378
377 // The file system API is only intended to operate on file entries that 379 // The file system API is only intended to operate on file entries that
378 // correspond to a native file, selected by the user so only allow file 380 // correspond to a native file, selected by the user so only allow file
379 // systems returned by the file system API or from a drag and drop operation. 381 // systems returned by the file system API or from a drag and drop operation.
380 if (type != fileapi::kFileSystemTypeNativeForPlatformApp && 382 if (type != storage::kFileSystemTypeNativeForPlatformApp &&
381 type != fileapi::kFileSystemTypeDragged) { 383 type != storage::kFileSystemTypeDragged) {
382 *error = kInvalidParameters; 384 *error = kInvalidParameters;
383 return false; 385 return false;
384 } 386 }
385 387
386 return true; 388 return true;
387 } 389 }
388 390
389 } // namespace app_file_handler_util 391 } // namespace app_file_handler_util
390 392
391 } // namespace extensions 393 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698