| 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" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
| 13 #include "base/threading/sequenced_worker_pool.h" | 13 #include "base/threading/sequenced_worker_pool.h" |
| 14 #include "content/browser/child_process_security_policy_impl.h" | 14 #include "content/browser/child_process_security_policy_impl.h" |
| 15 #include "content/public/browser/browser_context.h" | 15 #include "content/public/browser/browser_context.h" |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/content_browser_client.h" | 17 #include "content/public/browser/content_browser_client.h" |
| 18 #include "content/public/common/content_client.h" | 18 #include "content/public/common/content_client.h" |
| 19 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
| 20 #include "url/url_constants.h" | 20 #include "url/url_constants.h" |
| 21 #include "webkit/browser/fileapi/external_mount_points.h" | 21 #include "storage/browser/fileapi/external_mount_points.h" |
| 22 #include "webkit/browser/fileapi/file_permission_policy.h" | 22 #include "storage/browser/fileapi/file_permission_policy.h" |
| 23 #include "webkit/browser/fileapi/file_system_backend.h" | 23 #include "storage/browser/fileapi/file_system_backend.h" |
| 24 #include "webkit/browser/fileapi/file_system_context.h" | 24 #include "storage/browser/fileapi/file_system_context.h" |
| 25 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 25 #include "storage/browser/fileapi/file_system_operation_runner.h" |
| 26 #include "webkit/browser/fileapi/file_system_options.h" | 26 #include "storage/browser/fileapi/file_system_options.h" |
| 27 #include "webkit/browser/quota/quota_manager.h" | 27 #include "storage/browser/quota/quota_manager.h" |
| 28 | 28 |
| 29 namespace content { | 29 namespace content { |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 using fileapi::FileSystemOptions; | 33 using storage::FileSystemOptions; |
| 34 | 34 |
| 35 FileSystemOptions CreateBrowserFileSystemOptions(bool is_incognito) { | 35 FileSystemOptions CreateBrowserFileSystemOptions(bool is_incognito) { |
| 36 FileSystemOptions::ProfileMode profile_mode = | 36 FileSystemOptions::ProfileMode profile_mode = |
| 37 is_incognito ? FileSystemOptions::PROFILE_MODE_INCOGNITO | 37 is_incognito ? FileSystemOptions::PROFILE_MODE_INCOGNITO |
| 38 : FileSystemOptions::PROFILE_MODE_NORMAL; | 38 : FileSystemOptions::PROFILE_MODE_NORMAL; |
| 39 std::vector<std::string> additional_allowed_schemes; | 39 std::vector<std::string> additional_allowed_schemes; |
| 40 GetContentClient()->browser()->GetAdditionalAllowedSchemesForFileSystem( | 40 GetContentClient()->browser()->GetAdditionalAllowedSchemesForFileSystem( |
| 41 &additional_allowed_schemes); | 41 &additional_allowed_schemes); |
| 42 if (CommandLine::ForCurrentProcess()->HasSwitch( | 42 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 43 switches::kAllowFileAccessFromFiles)) { | 43 switches::kAllowFileAccessFromFiles)) { |
| 44 additional_allowed_schemes.push_back(url::kFileScheme); | 44 additional_allowed_schemes.push_back(url::kFileScheme); |
| 45 } | 45 } |
| 46 return FileSystemOptions(profile_mode, additional_allowed_schemes, NULL); | 46 return FileSystemOptions(profile_mode, additional_allowed_schemes, NULL); |
| 47 } | 47 } |
| 48 | 48 |
| 49 } // namespace | 49 } // namespace |
| 50 | 50 |
| 51 scoped_refptr<fileapi::FileSystemContext> CreateFileSystemContext( | 51 scoped_refptr<storage::FileSystemContext> CreateFileSystemContext( |
| 52 BrowserContext* browser_context, | 52 BrowserContext* browser_context, |
| 53 const base::FilePath& profile_path, | 53 const base::FilePath& profile_path, |
| 54 bool is_incognito, | 54 bool is_incognito, |
| 55 quota::QuotaManagerProxy* quota_manager_proxy) { | 55 quota::QuotaManagerProxy* quota_manager_proxy) { |
| 56 | |
| 57 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); | 56 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); |
| 58 scoped_refptr<base::SequencedTaskRunner> file_task_runner = | 57 scoped_refptr<base::SequencedTaskRunner> file_task_runner = |
| 59 pool->GetSequencedTaskRunnerWithShutdownBehavior( | 58 pool->GetSequencedTaskRunnerWithShutdownBehavior( |
| 60 pool->GetNamedSequenceToken("FileAPI"), | 59 pool->GetNamedSequenceToken("FileAPI"), |
| 61 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 60 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 62 | 61 |
| 63 // Setting up additional filesystem backends. | 62 // Setting up additional filesystem backends. |
| 64 ScopedVector<fileapi::FileSystemBackend> additional_backends; | 63 ScopedVector<storage::FileSystemBackend> additional_backends; |
| 65 GetContentClient()->browser()->GetAdditionalFileSystemBackends( | 64 GetContentClient()->browser()->GetAdditionalFileSystemBackends( |
| 66 browser_context, | 65 browser_context, |
| 67 profile_path, | 66 profile_path, |
| 68 &additional_backends); | 67 &additional_backends); |
| 69 | 68 |
| 70 // Set up the auto mount handlers for url requests. | 69 // Set up the auto mount handlers for url requests. |
| 71 std::vector<fileapi::URLRequestAutoMountHandler> | 70 std::vector<storage::URLRequestAutoMountHandler> |
| 72 url_request_auto_mount_handlers; | 71 url_request_auto_mount_handlers; |
| 73 GetContentClient()->browser()->GetURLRequestAutoMountHandlers( | 72 GetContentClient()->browser()->GetURLRequestAutoMountHandlers( |
| 74 &url_request_auto_mount_handlers); | 73 &url_request_auto_mount_handlers); |
| 75 | 74 |
| 76 scoped_refptr<fileapi::FileSystemContext> file_system_context = | 75 scoped_refptr<storage::FileSystemContext> file_system_context = |
| 77 new fileapi::FileSystemContext( | 76 new storage::FileSystemContext( |
| 78 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get(), | 77 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get(), |
| 79 file_task_runner.get(), | 78 file_task_runner.get(), |
| 80 BrowserContext::GetMountPoints(browser_context), | 79 BrowserContext::GetMountPoints(browser_context), |
| 81 browser_context->GetSpecialStoragePolicy(), | 80 browser_context->GetSpecialStoragePolicy(), |
| 82 quota_manager_proxy, | 81 quota_manager_proxy, |
| 83 additional_backends.Pass(), | 82 additional_backends.Pass(), |
| 84 url_request_auto_mount_handlers, | 83 url_request_auto_mount_handlers, |
| 85 profile_path, | 84 profile_path, |
| 86 CreateBrowserFileSystemOptions(is_incognito)); | 85 CreateBrowserFileSystemOptions(is_incognito)); |
| 87 | 86 |
| 88 std::vector<fileapi::FileSystemType> types; | 87 std::vector<storage::FileSystemType> types; |
| 89 file_system_context->GetFileSystemTypes(&types); | 88 file_system_context->GetFileSystemTypes(&types); |
| 90 for (size_t i = 0; i < types.size(); ++i) { | 89 for (size_t i = 0; i < types.size(); ++i) { |
| 91 ChildProcessSecurityPolicyImpl::GetInstance()-> | 90 ChildProcessSecurityPolicyImpl::GetInstance() |
| 92 RegisterFileSystemPermissionPolicy( | 91 ->RegisterFileSystemPermissionPolicy( |
| 93 types[i], | 92 types[i], |
| 94 fileapi::FileSystemContext::GetPermissionPolicy(types[i])); | 93 storage::FileSystemContext::GetPermissionPolicy(types[i])); |
| 95 } | 94 } |
| 96 | 95 |
| 97 return file_system_context; | 96 return file_system_context; |
| 98 } | 97 } |
| 99 | 98 |
| 100 bool FileSystemURLIsValid( | 99 bool FileSystemURLIsValid(storage::FileSystemContext* context, |
| 101 fileapi::FileSystemContext* context, | 100 const storage::FileSystemURL& url) { |
| 102 const fileapi::FileSystemURL& url) { | |
| 103 if (!url.is_valid()) | 101 if (!url.is_valid()) |
| 104 return false; | 102 return false; |
| 105 | 103 |
| 106 return context->GetFileSystemBackend(url.type()) != NULL; | 104 return context->GetFileSystemBackend(url.type()) != NULL; |
| 107 } | 105 } |
| 108 | 106 |
| 109 void SyncGetPlatformPath(fileapi::FileSystemContext* context, | 107 void SyncGetPlatformPath(storage::FileSystemContext* context, |
| 110 int process_id, | 108 int process_id, |
| 111 const GURL& path, | 109 const GURL& path, |
| 112 base::FilePath* platform_path) { | 110 base::FilePath* platform_path) { |
| 113 DCHECK(context->default_file_task_runner()-> | 111 DCHECK(context->default_file_task_runner()-> |
| 114 RunsTasksOnCurrentThread()); | 112 RunsTasksOnCurrentThread()); |
| 115 DCHECK(platform_path); | 113 DCHECK(platform_path); |
| 116 *platform_path = base::FilePath(); | 114 *platform_path = base::FilePath(); |
| 117 fileapi::FileSystemURL url(context->CrackURL(path)); | 115 storage::FileSystemURL url(context->CrackURL(path)); |
| 118 if (!FileSystemURLIsValid(context, url)) | 116 if (!FileSystemURLIsValid(context, url)) |
| 119 return; | 117 return; |
| 120 | 118 |
| 121 // Make sure if this file is ok to be read (in the current architecture | 119 // Make sure if this file is ok to be read (in the current architecture |
| 122 // which means roughly same as the renderer is allowed to get the platform | 120 // which means roughly same as the renderer is allowed to get the platform |
| 123 // path to the file). | 121 // path to the file). |
| 124 ChildProcessSecurityPolicyImpl* policy = | 122 ChildProcessSecurityPolicyImpl* policy = |
| 125 ChildProcessSecurityPolicyImpl::GetInstance(); | 123 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 126 if (!policy->CanReadFileSystemFile(process_id, url)) | 124 if (!policy->CanReadFileSystemFile(process_id, url)) |
| 127 return; | 125 return; |
| 128 | 126 |
| 129 context->operation_runner()->SyncGetPlatformPath(url, platform_path); | 127 context->operation_runner()->SyncGetPlatformPath(url, platform_path); |
| 130 | 128 |
| 131 // The path is to be attached to URLLoader so we grant read permission | 129 // The path is to be attached to URLLoader so we grant read permission |
| 132 // for the file. (We need to check first because a parent directory may | 130 // for the file. (We need to check first because a parent directory may |
| 133 // already have the permissions and we don't need to grant it to the file.) | 131 // already have the permissions and we don't need to grant it to the file.) |
| 134 if (!policy->CanReadFile(process_id, *platform_path)) | 132 if (!policy->CanReadFile(process_id, *platform_path)) |
| 135 policy->GrantReadFile(process_id, *platform_path); | 133 policy->GrantReadFile(process_id, *platform_path); |
| 136 } | 134 } |
| 137 | 135 |
| 138 } // namespace content | 136 } // namespace content |
| OLD | NEW |