Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/child/ftp_directory_listing_response_delegate.h" | 5 #include "content/child/ftp_directory_listing_response_delegate.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/i18n/icu_encoding_detection.h" | 9 #include "base/i18n/icu_encoding_detection.h" |
| 10 #include "base/i18n/icu_string_conversions.h" | 10 #include "base/i18n/icu_string_conversions.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 loader_ = NULL; | 75 loader_ = NULL; |
| 76 } | 76 } |
| 77 | 77 |
| 78 void FtpDirectoryListingResponseDelegate::OnReceivedData(const char* data, | 78 void FtpDirectoryListingResponseDelegate::OnReceivedData(const char* data, |
| 79 int data_len) { | 79 int data_len) { |
| 80 buffer_.append(data, data_len); | 80 buffer_.append(data, data_len); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void FtpDirectoryListingResponseDelegate::OnCompletedRequest() { | 83 void FtpDirectoryListingResponseDelegate::OnCompletedRequest() { |
| 84 std::vector<FtpDirectoryListingEntry> entries; | 84 std::vector<FtpDirectoryListingEntry> entries; |
| 85 int rv = net::ParseFtpDirectoryListing(buffer_, base::Time::Now(), &entries); | 85 int rv = -1; |
| 86 #ifdef DISABLE_FTP_SUPPORT | |
| 87 rv = net::ParseFtpDirectoryListing(buffer_, base::Time::Now(), &entries); | |
| 88 #endif | |
| 86 if (rv != net::OK) { | 89 if (rv != net::OK) { |
| 87 SendDataToClient("<script>onListingParsingError();</script>\n"); | 90 SendDataToClient("<script>onListingParsingError();</script>\n"); |
| 88 return; | 91 return; |
| 89 } | 92 } |
| 90 for (size_t i = 0; i < entries.size(); i++) { | 93 for (size_t i = 0; i < entries.size(); i++) { |
| 91 const FtpDirectoryListingEntry& entry = entries[i]; | 94 const FtpDirectoryListingEntry& entry = entries[i]; |
| 92 | 95 |
| 93 // Skip the current and parent directory entries in the listing. Our header | 96 // Skip the current and parent directory entries in the listing. Our header |
| 94 // always includes them. | 97 // always includes them. |
| 95 if (EqualsASCII(entry.name, ".") || EqualsASCII(entry.name, "..")) | 98 if (EqualsASCII(entry.name, ".") || EqualsASCII(entry.name, "..")) |
| 96 continue; | 99 continue; |
| 97 | 100 |
| 98 bool is_directory = (entry.type == FtpDirectoryListingEntry::DIRECTORY); | 101 bool is_directory = (entry.type == FtpDirectoryListingEntry::DIRECTORY); |
| 99 int64 size = entry.size; | 102 int64 size = entry.size; |
| 100 if (entry.type != FtpDirectoryListingEntry::FILE) | 103 if (entry.type != FtpDirectoryListingEntry::FILE) |
| 101 size = 0; | 104 size = 0; |
| 102 SendDataToClient(net::GetDirectoryListingEntry( | 105 SendDataToClient(net::GetDirectoryListingEntry( |
| 103 entry.name, entry.raw_name, is_directory, size, entry.last_modified)); | 106 entry.name, entry.raw_name, is_directory, size, entry.last_modified)); |
| 104 } | 107 } |
| 105 } | 108 } |
| 106 | |
|
lgombos
2014/07/14 15:00:57
You probably should not remove this line.
| |
| 107 void FtpDirectoryListingResponseDelegate::Init(const GURL& response_url) { | 109 void FtpDirectoryListingResponseDelegate::Init(const GURL& response_url) { |
| 108 net::UnescapeRule::Type unescape_rules = net::UnescapeRule::SPACES | | 110 net::UnescapeRule::Type unescape_rules = net::UnescapeRule::SPACES | |
| 109 net::UnescapeRule::URL_SPECIAL_CHARS; | 111 net::UnescapeRule::URL_SPECIAL_CHARS; |
| 110 std::string unescaped_path = net::UnescapeURLComponent(response_url.path(), | 112 std::string unescaped_path = net::UnescapeURLComponent(response_url.path(), |
| 111 unescape_rules); | 113 unescape_rules); |
| 112 SendDataToClient(net::GetDirectoryListingHeader( | 114 SendDataToClient(net::GetDirectoryListingHeader( |
| 113 ConvertPathToUTF16(unescaped_path))); | 115 ConvertPathToUTF16(unescaped_path))); |
| 114 | 116 |
| 115 // If this isn't top level directory (i.e. the path isn't "/",) | 117 // If this isn't top level directory (i.e. the path isn't "/",) |
| 116 // add a link to the parent directory. | 118 // add a link to the parent directory. |
| 117 if (response_url.path().length() > 1) { | 119 if (response_url.path().length() > 1) { |
| 118 SendDataToClient(net::GetDirectoryListingEntry( | 120 SendDataToClient(net::GetDirectoryListingEntry( |
| 119 base::ASCIIToUTF16(".."), std::string(), false, 0, base::Time())); | 121 base::ASCIIToUTF16(".."), std::string(), false, 0, base::Time())); |
| 120 } | 122 } |
| 121 } | 123 } |
| 122 | 124 |
| 123 void FtpDirectoryListingResponseDelegate::SendDataToClient( | 125 void FtpDirectoryListingResponseDelegate::SendDataToClient( |
| 124 const std::string& data) { | 126 const std::string& data) { |
| 125 if (client_) | 127 if (client_) |
| 126 client_->didReceiveData(loader_, data.data(), data.length(), -1); | 128 client_->didReceiveData(loader_, data.data(), data.length(), -1); |
| 127 } | 129 } |
| 128 | 130 |
| 129 } // namespace content | 131 } // namespace content |
| OLD | NEW |