| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/fileapi/sandboxed_file_system_operation.h" | 5 #include "webkit/fileapi/sandboxed_file_system_operation.h" |
| 6 | 6 |
| 7 #include "net/url_request/url_request_context.h" | 7 #include "net/url_request/url_request_context.h" |
| 8 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 8 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
| 9 #include "webkit/fileapi/file_system_path_manager.h" | 9 #include "webkit/fileapi/file_system_path_manager.h" |
| 10 #include "webkit/fileapi/file_system_quota_manager.h" | 10 #include "webkit/fileapi/file_system_quota_manager.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 const base::Time& last_access_time, | 119 const base::Time& last_access_time, |
| 120 const base::Time& last_modified_time) { | 120 const base::Time& last_modified_time) { |
| 121 if (!VerifyFileSystemPathForWrite(path, true /* create */, 0)) | 121 if (!VerifyFileSystemPathForWrite(path, true /* create */, 0)) |
| 122 return; | 122 return; |
| 123 FileSystemOperation::TouchFile(path, last_access_time, last_modified_time); | 123 FileSystemOperation::TouchFile(path, last_access_time, last_modified_time); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void SandboxedFileSystemOperation::DidGetRootPath( | 126 void SandboxedFileSystemOperation::DidGetRootPath( |
| 127 bool success, const FilePath& path, const std::string& name) { | 127 bool success, const FilePath& path, const std::string& name) { |
| 128 DCHECK(success || path.empty()); | 128 DCHECK(success || path.empty()); |
| 129 dispatcher()->DidOpenFileSystem(name, path); | 129 destructive_dispatcher()->DidOpenFileSystem(name, path); |
| 130 } | 130 } |
| 131 | 131 |
| 132 bool SandboxedFileSystemOperation::VerifyFileSystemPathForRead( | 132 bool SandboxedFileSystemOperation::VerifyFileSystemPathForRead( |
| 133 const FilePath& path) { | 133 const FilePath& path) { |
| 134 // We may want do more checks, but for now it just checks if the given | 134 // We may want do more checks, but for now it just checks if the given |
| 135 // |path| is under the valid FileSystem root path for this host context. | 135 // |path| is under the valid FileSystem root path for this host context. |
| 136 if (!file_system_context_->path_manager()->CrackFileSystemPath( | 136 if (!file_system_context_->path_manager()->CrackFileSystemPath( |
| 137 path, NULL, NULL, NULL)) { | 137 path, NULL, NULL, NULL)) { |
| 138 dispatcher()->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 138 destructive_dispatcher()->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 139 return false; | 139 return false; |
| 140 } | 140 } |
| 141 return true; | 141 return true; |
| 142 } | 142 } |
| 143 | 143 |
| 144 bool SandboxedFileSystemOperation::VerifyFileSystemPathForWrite( | 144 bool SandboxedFileSystemOperation::VerifyFileSystemPathForWrite( |
| 145 const FilePath& path, bool create, int64 growth) { | 145 const FilePath& path, bool create, int64 growth) { |
| 146 GURL origin_url; | 146 GURL origin_url; |
| 147 FilePath virtual_path; | 147 FilePath virtual_path; |
| 148 if (!file_system_context_->path_manager()->CrackFileSystemPath( | 148 if (!file_system_context_->path_manager()->CrackFileSystemPath( |
| 149 path, &origin_url, NULL, &virtual_path)) { | 149 path, &origin_url, NULL, &virtual_path)) { |
| 150 dispatcher()->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 150 destructive_dispatcher()->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 151 return false; | 151 return false; |
| 152 } | 152 } |
| 153 // Any write access is disallowed on the root path. | 153 // Any write access is disallowed on the root path. |
| 154 if (virtual_path.value().length() == 0 || | 154 if (virtual_path.value().length() == 0 || |
| 155 virtual_path.DirName().value() == virtual_path.value()) { | 155 virtual_path.DirName().value() == virtual_path.value()) { |
| 156 dispatcher()->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 156 destructive_dispatcher()->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 157 return false; | 157 return false; |
| 158 } | 158 } |
| 159 if (create && file_system_context_->path_manager()->IsRestrictedFileName( | 159 if (create && file_system_context_->path_manager()->IsRestrictedFileName( |
| 160 path.BaseName())) { | 160 path.BaseName())) { |
| 161 dispatcher()->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 161 destructive_dispatcher()->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 162 return false; | 162 return false; |
| 163 } | 163 } |
| 164 // TODO(kinuko): For operations with kUnknownSize we'll eventually | 164 // TODO(kinuko): For operations with kUnknownSize we'll eventually |
| 165 // need to resolve what amount of size it's going to write. | 165 // need to resolve what amount of size it's going to write. |
| 166 if (!file_system_context_->quota_manager()->CheckOriginQuota( | 166 if (!file_system_context_->quota_manager()->CheckOriginQuota( |
| 167 origin_url, growth)) { | 167 origin_url, growth)) { |
| 168 dispatcher()->DidFail(base::PLATFORM_FILE_ERROR_NO_SPACE); | 168 destructive_dispatcher()->DidFail(base::PLATFORM_FILE_ERROR_NO_SPACE); |
| 169 return false; | 169 return false; |
| 170 } | 170 } |
| 171 return true; | 171 return true; |
| 172 } | 172 } |
| 173 | 173 |
| 174 bool SandboxedFileSystemOperation::CheckIfFilePathIsSafe( | 174 bool SandboxedFileSystemOperation::CheckIfFilePathIsSafe( |
| 175 const FilePath& path) { | 175 const FilePath& path) { |
| 176 if (file_system_context_->path_manager()->IsRestrictedFileName( | 176 if (file_system_context_->path_manager()->IsRestrictedFileName( |
| 177 path.BaseName())) { | 177 path.BaseName())) { |
| 178 dispatcher()->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 178 destructive_dispatcher()->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 179 return false; | 179 return false; |
| 180 } | 180 } |
| 181 return true; | 181 return true; |
| 182 } | 182 } |
| 183 | 183 |
| 184 } // namespace fileapi | 184 } // namespace fileapi |
| OLD | NEW |