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