| 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 "net/url_request/file_protocol_handler.h" | 5 #include "net/url_request/file_protocol_handler.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/task_runner.h" |
| 8 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 9 #include "net/base/net_util.h" | 10 #include "net/base/net_util.h" |
| 10 #include "net/url_request/url_request.h" | 11 #include "net/url_request/url_request.h" |
| 11 #include "net/url_request/url_request_error_job.h" | 12 #include "net/url_request/url_request_error_job.h" |
| 12 #include "net/url_request/url_request_file_dir_job.h" | 13 #include "net/url_request/url_request_file_dir_job.h" |
| 13 #include "net/url_request/url_request_file_job.h" | 14 #include "net/url_request/url_request_file_job.h" |
| 14 | 15 |
| 15 namespace net { | 16 namespace net { |
| 16 | 17 |
| 17 FileProtocolHandler::FileProtocolHandler() { } | 18 FileProtocolHandler::FileProtocolHandler( |
| 19 const scoped_refptr<base::TaskRunner>& file_task_runner) |
| 20 : file_task_runner_(file_task_runner) {} |
| 21 |
| 22 FileProtocolHandler::~FileProtocolHandler() {} |
| 18 | 23 |
| 19 URLRequestJob* FileProtocolHandler::MaybeCreateJob( | 24 URLRequestJob* FileProtocolHandler::MaybeCreateJob( |
| 20 URLRequest* request, NetworkDelegate* network_delegate) const { | 25 URLRequest* request, NetworkDelegate* network_delegate) const { |
| 21 base::FilePath file_path; | 26 base::FilePath file_path; |
| 22 const bool is_file = FileURLToFilePath(request->url(), &file_path); | 27 const bool is_file = FileURLToFilePath(request->url(), &file_path); |
| 23 | 28 |
| 24 // Check file access permissions. | 29 // Check file access permissions. |
| 25 if (!network_delegate || | 30 if (!network_delegate || |
| 26 !network_delegate->CanAccessFile(*request, file_path)) { | 31 !network_delegate->CanAccessFile(*request, file_path)) { |
| 27 return new URLRequestErrorJob(request, network_delegate, ERR_ACCESS_DENIED); | 32 return new URLRequestErrorJob(request, network_delegate, ERR_ACCESS_DENIED); |
| 28 } | 33 } |
| 29 | 34 |
| 30 // We need to decide whether to create URLRequestFileJob for file access or | 35 // We need to decide whether to create URLRequestFileJob for file access or |
| 31 // URLRequestFileDirJob for directory access. To avoid accessing the | 36 // URLRequestFileDirJob for directory access. To avoid accessing the |
| 32 // filesystem, we only look at the path string here. | 37 // filesystem, we only look at the path string here. |
| 33 // The code in the URLRequestFileJob::Start() method discovers that a path, | 38 // The code in the URLRequestFileJob::Start() method discovers that a path, |
| 34 // which doesn't end with a slash, should really be treated as a directory, | 39 // which doesn't end with a slash, should really be treated as a directory, |
| 35 // and it then redirects to the URLRequestFileDirJob. | 40 // and it then redirects to the URLRequestFileDirJob. |
| 36 if (is_file && | 41 if (is_file && |
| 37 file_path.EndsWithSeparator() && | 42 file_path.EndsWithSeparator() && |
| 38 file_path.IsAbsolute()) { | 43 file_path.IsAbsolute()) { |
| 39 return new URLRequestFileDirJob(request, network_delegate, file_path); | 44 return new URLRequestFileDirJob(request, network_delegate, file_path); |
| 40 } | 45 } |
| 41 | 46 |
| 42 // Use a regular file request job for all non-directories (including invalid | 47 // Use a regular file request job for all non-directories (including invalid |
| 43 // file names). | 48 // file names). |
| 44 return new URLRequestFileJob(request, network_delegate, file_path); | 49 return new URLRequestFileJob(request, network_delegate, file_path, |
| 50 file_task_runner_); |
| 45 } | 51 } |
| 46 | 52 |
| 47 bool FileProtocolHandler::IsSafeRedirectTarget(const GURL& location) const { | 53 bool FileProtocolHandler::IsSafeRedirectTarget(const GURL& location) const { |
| 48 return false; | 54 return false; |
| 49 } | 55 } |
| 50 | 56 |
| 51 } // namespace net | 57 } // namespace net |
| OLD | NEW |