| 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/url_request_ftp_job.h" | 5 #include "net/url_request/url_request_ftp_job.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "net/base/auth.h" | 10 #include "net/base/auth.h" |
| 11 #include "net/base/host_port_pair.h" | 11 #include "net/base/host_port_pair.h" |
| 12 #include "net/base/load_flags.h" | 12 #include "net/base/load_flags.h" |
| 13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 14 #include "net/base/net_util.h" | 14 #include "net/base/net_util.h" |
| 15 #include "net/ftp/ftp_auth_cache.h" |
| 15 #include "net/ftp/ftp_response_info.h" | 16 #include "net/ftp/ftp_response_info.h" |
| 16 #include "net/ftp/ftp_transaction_factory.h" | 17 #include "net/ftp/ftp_transaction_factory.h" |
| 17 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
| 18 #include "net/http/http_transaction_factory.h" | 19 #include "net/http/http_transaction_factory.h" |
| 19 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
| 20 #include "net/url_request/url_request_context.h" | 21 #include "net/url_request/url_request_context.h" |
| 21 #include "net/url_request/url_request_error_job.h" | 22 #include "net/url_request/url_request_error_job.h" |
| 22 | 23 |
| 23 namespace net { | 24 namespace net { |
| 24 | 25 |
| 25 URLRequestFtpJob::URLRequestFtpJob( | 26 URLRequestFtpJob::URLRequestFtpJob( |
| 26 URLRequest* request, | 27 URLRequest* request, |
| 27 NetworkDelegate* network_delegate, | 28 NetworkDelegate* network_delegate, |
| 28 FtpTransactionFactory* ftp_transaction_factory, | 29 FtpTransactionFactory* ftp_transaction_factory, |
| 29 FtpAuthCache* ftp_auth_cache) | 30 FtpAuthCache* ftp_auth_cache) |
| 30 : URLRequestJob(request, network_delegate), | 31 : URLRequestJob(request, network_delegate), |
| 31 pac_request_(NULL), | 32 pac_request_(NULL), |
| 32 response_info_(NULL), | 33 response_info_(NULL), |
| 33 read_in_progress_(false), | 34 read_in_progress_(false), |
| 34 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 35 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 35 ftp_transaction_factory_(ftp_transaction_factory), | 36 ftp_transaction_factory_(ftp_transaction_factory), |
| 36 ftp_auth_cache_(ftp_auth_cache) { | 37 ftp_auth_cache_(ftp_auth_cache) { |
| 37 DCHECK(ftp_transaction_factory); | 38 DCHECK(ftp_transaction_factory); |
| 38 DCHECK(ftp_auth_cache); | 39 DCHECK(ftp_auth_cache); |
| 39 } | 40 } |
| 40 | 41 |
| 41 // static | |
| 42 URLRequestJob* URLRequestFtpJob::Factory(URLRequest* request, | |
| 43 NetworkDelegate* network_delegate, | |
| 44 const std::string& scheme) { | |
| 45 DCHECK_EQ(scheme, "ftp"); | |
| 46 | |
| 47 int port = request->url().IntPort(); | |
| 48 if (request->url().has_port() && | |
| 49 !IsPortAllowedByFtp(port) && !IsPortAllowedByOverride(port)) { | |
| 50 return new URLRequestErrorJob(request, | |
| 51 network_delegate, | |
| 52 ERR_UNSAFE_PORT); | |
| 53 } | |
| 54 | |
| 55 return new URLRequestFtpJob(request, | |
| 56 network_delegate, | |
| 57 request->context()->ftp_transaction_factory(), | |
| 58 request->context()->ftp_auth_cache()); | |
| 59 } | |
| 60 | |
| 61 bool URLRequestFtpJob::IsSafeRedirect(const GURL& location) { | 42 bool URLRequestFtpJob::IsSafeRedirect(const GURL& location) { |
| 62 // Disallow all redirects. | 43 // Disallow all redirects. |
| 63 return false; | 44 return false; |
| 64 } | 45 } |
| 65 | 46 |
| 66 bool URLRequestFtpJob::GetMimeType(std::string* mime_type) const { | 47 bool URLRequestFtpJob::GetMimeType(std::string* mime_type) const { |
| 67 if (proxy_info_.is_direct()) { | 48 if (proxy_info_.is_direct()) { |
| 68 if (ftp_transaction_->GetResponseInfo()->is_directory_listing) { | 49 if (ftp_transaction_->GetResponseInfo()->is_directory_listing) { |
| 69 *mime_type = "text/vnd.chromium.ftp-dir"; | 50 *mime_type = "text/vnd.chromium.ftp-dir"; |
| 70 return true; | 51 return true; |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 if (rv == ERR_IO_PENDING) { | 361 if (rv == ERR_IO_PENDING) { |
| 381 read_in_progress_ = true; | 362 read_in_progress_ = true; |
| 382 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 363 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 383 } else { | 364 } else { |
| 384 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | 365 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
| 385 } | 366 } |
| 386 return false; | 367 return false; |
| 387 } | 368 } |
| 388 | 369 |
| 389 } // namespace net | 370 } // namespace net |
| OLD | NEW |