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 // For loading files, we make use of overlapped i/o to ensure that reading from | 5 // For loading files, we make use of overlapped i/o to ensure that reading from |
6 // the filesystem (e.g., a network filesystem) does not block the calling | 6 // the filesystem (e.g., a network filesystem) does not block the calling |
7 // thread. An alternative approach would be to use a background thread or pool | 7 // thread. An alternative approach would be to use a background thread or pool |
8 // of threads, but it seems better to leverage the operating system's ability | 8 // of threads, but it seems better to leverage the operating system's ability |
9 // to do background file reads for us. | 9 // to do background file reads for us. |
10 // | 10 // |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 weak_ptr_factory_(this) {} | 67 weak_ptr_factory_(this) {} |
68 | 68 |
69 void URLRequestFileJob::Start() { | 69 void URLRequestFileJob::Start() { |
70 FileMetaInfo* meta_info = new FileMetaInfo(); | 70 FileMetaInfo* meta_info = new FileMetaInfo(); |
71 file_task_runner_->PostTaskAndReply( | 71 file_task_runner_->PostTaskAndReply( |
72 FROM_HERE, | 72 FROM_HERE, |
73 base::Bind(&URLRequestFileJob::FetchMetaInfo, file_path_, | 73 base::Bind(&URLRequestFileJob::FetchMetaInfo, file_path_, |
74 base::Unretained(meta_info)), | 74 base::Unretained(meta_info)), |
75 base::Bind(&URLRequestFileJob::DidFetchMetaInfo, | 75 base::Bind(&URLRequestFileJob::DidFetchMetaInfo, |
76 weak_ptr_factory_.GetWeakPtr(), | 76 weak_ptr_factory_.GetWeakPtr(), |
77 base::Owned(meta_info))); | 77 base::Owned(meta_info))); |
mmenke
2017/04/18 17:24:46
Again, I assume there's no security/privacy issue
| |
78 } | 78 } |
79 | 79 |
80 void URLRequestFileJob::Kill() { | 80 void URLRequestFileJob::Kill() { |
81 stream_.reset(); | 81 stream_.reset(); |
82 weak_ptr_factory_.InvalidateWeakPtrs(); | 82 weak_ptr_factory_.InvalidateWeakPtrs(); |
83 | 83 |
84 URLRequestJob::Kill(); | 84 URLRequestJob::Kill(); |
85 } | 85 } |
86 | 86 |
87 int URLRequestFileJob::ReadRawData(IOBuffer* dest, int dest_size) { | 87 int URLRequestFileJob::ReadRawData(IOBuffer* dest, int dest_size) { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 } | 189 } |
190 | 190 |
191 std::unique_ptr<SourceStream> URLRequestFileJob::SetUpSourceStream() { | 191 std::unique_ptr<SourceStream> URLRequestFileJob::SetUpSourceStream() { |
192 std::unique_ptr<SourceStream> source = URLRequestJob::SetUpSourceStream(); | 192 std::unique_ptr<SourceStream> source = URLRequestJob::SetUpSourceStream(); |
193 if (!base::LowerCaseEqualsASCII(file_path_.Extension(), ".svgz")) | 193 if (!base::LowerCaseEqualsASCII(file_path_.Extension(), ".svgz")) |
194 return source; | 194 return source; |
195 | 195 |
196 return GzipSourceStream::Create(std::move(source), SourceStream::TYPE_GZIP); | 196 return GzipSourceStream::Create(std::move(source), SourceStream::TYPE_GZIP); |
197 } | 197 } |
198 | 198 |
199 bool URLRequestFileJob::CanAccessFile(const base::FilePath& original_path, | |
200 const base::FilePath& absolute_path) { | |
201 return (!network_delegate() || network_delegate()->CanAccessFile( | |
202 *request(), original_path, absolute_path)); | |
203 } | |
204 | |
199 void URLRequestFileJob::FetchMetaInfo(const base::FilePath& file_path, | 205 void URLRequestFileJob::FetchMetaInfo(const base::FilePath& file_path, |
200 FileMetaInfo* meta_info) { | 206 FileMetaInfo* meta_info) { |
201 base::File::Info file_info; | 207 base::File::Info file_info; |
202 meta_info->file_exists = base::GetFileInfo(file_path, &file_info); | 208 meta_info->file_exists = base::GetFileInfo(file_path, &file_info); |
203 if (meta_info->file_exists) { | 209 if (meta_info->file_exists) { |
204 meta_info->file_size = file_info.size; | 210 meta_info->file_size = file_info.size; |
205 meta_info->is_directory = file_info.is_directory; | 211 meta_info->is_directory = file_info.is_directory; |
206 } | 212 } |
207 // On Windows GetMimeTypeFromFile() goes to the registry. Thus it should be | 213 // On Windows GetMimeTypeFromFile() goes to the registry. Thus it should be |
208 // done in WorkerPool. | 214 // done in WorkerPool. |
209 meta_info->mime_type_result = GetMimeTypeFromFile(file_path, | 215 meta_info->mime_type_result = GetMimeTypeFromFile(file_path, |
210 &meta_info->mime_type); | 216 &meta_info->mime_type); |
217 meta_info->absolute_path = base::MakeAbsoluteFilePath(file_path); | |
211 } | 218 } |
212 | 219 |
213 void URLRequestFileJob::DidFetchMetaInfo(const FileMetaInfo* meta_info) { | 220 void URLRequestFileJob::DidFetchMetaInfo(const FileMetaInfo* meta_info) { |
214 meta_info_ = *meta_info; | 221 meta_info_ = *meta_info; |
215 | 222 |
216 // We use URLRequestFileJob to handle files as well as directories without | 223 // We use URLRequestFileJob to handle files as well as directories without |
217 // trailing slash. | 224 // trailing slash. |
218 // If a directory does not exist, we return ERR_FILE_NOT_FOUND. Otherwise, | 225 // If a directory does not exist, we return ERR_FILE_NOT_FOUND. Otherwise, |
219 // we will append trailing slash and redirect to FileDirJob. | 226 // we will append trailing slash and redirect to FileDirJob. |
220 // A special case is "\" on Windows. We should resolve as invalid. | 227 // A special case is "\" on Windows. We should resolve as invalid. |
221 // However, Windows resolves "\" to "C:\", thus reports it as existent. | 228 // However, Windows resolves "\" to "C:\", thus reports it as existent. |
222 // So what happens is we append it with trailing slash and redirect it to | 229 // So what happens is we append it with trailing slash and redirect it to |
223 // FileDirJob where it is resolved as invalid. | 230 // FileDirJob where it is resolved as invalid. |
224 if (!meta_info_.file_exists) { | 231 if (!meta_info_.file_exists) { |
225 DidOpen(ERR_FILE_NOT_FOUND); | 232 DidOpen(ERR_FILE_NOT_FOUND); |
226 return; | 233 return; |
227 } | 234 } |
228 if (meta_info_.is_directory) { | 235 if (meta_info_.is_directory) { |
229 DidOpen(OK); | 236 DidOpen(OK); |
230 return; | 237 return; |
231 } | 238 } |
232 | 239 |
240 if (CanAccessFile(file_path_, meta_info->absolute_path)) { | |
241 DidOpen(ERR_ACCESS_DENIED); | |
242 return; | |
243 } | |
244 | |
233 int flags = base::File::FLAG_OPEN | | 245 int flags = base::File::FLAG_OPEN | |
234 base::File::FLAG_READ | | 246 base::File::FLAG_READ | |
235 base::File::FLAG_ASYNC; | 247 base::File::FLAG_ASYNC; |
236 int rv = stream_->Open(file_path_, flags, | 248 int rv = stream_->Open(file_path_, flags, |
237 base::Bind(&URLRequestFileJob::DidOpen, | 249 base::Bind(&URLRequestFileJob::DidOpen, |
238 weak_ptr_factory_.GetWeakPtr())); | 250 weak_ptr_factory_.GetWeakPtr())); |
239 if (rv != ERR_IO_PENDING) | 251 if (rv != ERR_IO_PENDING) |
240 DidOpen(rv); | 252 DidOpen(rv); |
241 } | 253 } |
242 | 254 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 DCHECK_GE(remaining_bytes_, 0); | 303 DCHECK_GE(remaining_bytes_, 0); |
292 } | 304 } |
293 | 305 |
294 OnReadComplete(buf.get(), result); | 306 OnReadComplete(buf.get(), result); |
295 buf = NULL; | 307 buf = NULL; |
296 | 308 |
297 ReadRawDataComplete(result); | 309 ReadRawDataComplete(result); |
298 } | 310 } |
299 | 311 |
300 } // namespace net | 312 } // namespace net |
OLD | NEW |