[email protected] | b9cf48b7 | 2012-07-11 15:45:59 | [diff] [blame] | 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/ftp_protocol_handler.h" |
| 6 | |
Hans Wennborg | 0924470b | 2020-04-27 21:08:05 | [diff] [blame^] | 7 | #include "base/check_op.h" |
mmenke | cd4c753 | 2016-10-19 18:36:05 | [diff] [blame] | 8 | #include "base/memory/ptr_util.h" |
[email protected] | e841d062 | 2012-07-30 04:16:38 | [diff] [blame] | 9 | #include "net/base/net_errors.h" |
eroman | 9ab6484 | 2015-07-21 05:07:52 | [diff] [blame] | 10 | #include "net/base/port_util.h" |
[email protected] | e0f35c9 | 2013-05-08 16:04:34 | [diff] [blame] | 11 | #include "net/ftp/ftp_auth_cache.h" |
mmenke | cd4c753 | 2016-10-19 18:36:05 | [diff] [blame] | 12 | #include "net/ftp/ftp_network_layer.h" |
[email protected] | e841d062 | 2012-07-30 04:16:38 | [diff] [blame] | 13 | #include "net/url_request/url_request.h" |
| 14 | #include "net/url_request/url_request_error_job.h" |
[email protected] | b9cf48b7 | 2012-07-11 15:45:59 | [diff] [blame] | 15 | #include "net/url_request/url_request_ftp_job.h" |
[email protected] | f89276a7 | 2013-07-12 06:41:54 | [diff] [blame] | 16 | #include "url/gurl.h" |
[email protected] | b9cf48b7 | 2012-07-11 15:45:59 | [diff] [blame] | 17 | |
| 18 | namespace net { |
| 19 | |
mmenke | cd4c753 | 2016-10-19 18:36:05 | [diff] [blame] | 20 | std::unique_ptr<FtpProtocolHandler> FtpProtocolHandler::Create( |
Emily Stark | 0122798 | 2019-06-06 18:45:56 | [diff] [blame] | 21 | HostResolver* host_resolver, |
| 22 | FtpAuthCache* auth_cache) { |
| 23 | DCHECK(auth_cache); |
mmenke | cd4c753 | 2016-10-19 18:36:05 | [diff] [blame] | 24 | return base::WrapUnique(new FtpProtocolHandler( |
Emily Stark | 0122798 | 2019-06-06 18:45:56 | [diff] [blame] | 25 | base::WrapUnique(new FtpNetworkLayer(host_resolver)), auth_cache)); |
mmenke | cd4c753 | 2016-10-19 18:36:05 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | std::unique_ptr<FtpProtocolHandler> FtpProtocolHandler::CreateForTesting( |
Emily Stark | 0122798 | 2019-06-06 18:45:56 | [diff] [blame] | 29 | std::unique_ptr<FtpTransactionFactory> ftp_transaction_factory, |
| 30 | FtpAuthCache* auth_cache) { |
mmenke | cd4c753 | 2016-10-19 18:36:05 | [diff] [blame] | 31 | return base::WrapUnique( |
Emily Stark | 0122798 | 2019-06-06 18:45:56 | [diff] [blame] | 32 | new FtpProtocolHandler(std::move(ftp_transaction_factory), auth_cache)); |
[email protected] | e0f35c9 | 2013-05-08 16:04:34 | [diff] [blame] | 33 | } |
| 34 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 35 | FtpProtocolHandler::~FtpProtocolHandler() = default; |
[email protected] | b9cf48b7 | 2012-07-11 15:45:59 | [diff] [blame] | 36 | |
| 37 | URLRequestJob* FtpProtocolHandler::MaybeCreateJob( |
[email protected] | 9f17046 | 2012-08-24 01:06:58 | [diff] [blame] | 38 | URLRequest* request, NetworkDelegate* network_delegate) const { |
mmenke | 4815484 | 2015-06-08 18:50:44 | [diff] [blame] | 39 | DCHECK_EQ("ftp", request->url().scheme()); |
| 40 | |
| 41 | if (!IsPortAllowedForScheme(request->url().EffectiveIntPort(), |
Daniel Cheng | e10c0ea | 2019-04-05 17:19:38 | [diff] [blame] | 42 | request->url().scheme_piece())) { |
[email protected] | 9f17046 | 2012-08-24 01:06:58 | [diff] [blame] | 43 | return new URLRequestErrorJob(request, network_delegate, ERR_UNSAFE_PORT); |
[email protected] | e841d062 | 2012-07-30 04:16:38 | [diff] [blame] | 44 | } |
| 45 | |
mmenke | cd4c753 | 2016-10-19 18:36:05 | [diff] [blame] | 46 | return new URLRequestFtpJob(request, network_delegate, |
Emily Stark | 0122798 | 2019-06-06 18:45:56 | [diff] [blame] | 47 | ftp_transaction_factory_.get(), ftp_auth_cache_); |
[email protected] | b9cf48b7 | 2012-07-11 15:45:59 | [diff] [blame] | 48 | } |
| 49 | |
mmenke | cd4c753 | 2016-10-19 18:36:05 | [diff] [blame] | 50 | FtpProtocolHandler::FtpProtocolHandler( |
Emily Stark | 0122798 | 2019-06-06 18:45:56 | [diff] [blame] | 51 | std::unique_ptr<FtpTransactionFactory> ftp_transaction_factory, |
| 52 | FtpAuthCache* auth_cache) |
mmenke | cd4c753 | 2016-10-19 18:36:05 | [diff] [blame] | 53 | : ftp_transaction_factory_(std::move(ftp_transaction_factory)), |
Emily Stark | 0122798 | 2019-06-06 18:45:56 | [diff] [blame] | 54 | ftp_auth_cache_(auth_cache) { |
mmenke | cd4c753 | 2016-10-19 18:36:05 | [diff] [blame] | 55 | DCHECK(ftp_transaction_factory_); |
| 56 | } |
| 57 | |
[email protected] | b9cf48b7 | 2012-07-11 15:45:59 | [diff] [blame] | 58 | } // namespace net |