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