| 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 "webkit/child/ftp_directory_listing_response_delegate.h" | 5 #include "webkit/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 15 matching lines...) Expand all Loading... |
| 26 using blink::WebURLLoader; | 26 using blink::WebURLLoader; |
| 27 using blink::WebURLLoaderClient; | 27 using blink::WebURLLoaderClient; |
| 28 using blink::WebURLResponse; | 28 using blink::WebURLResponse; |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 base::string16 ConvertPathToUTF16(const std::string& path) { | 32 base::string16 ConvertPathToUTF16(const std::string& path) { |
| 33 // Per RFC 2640, FTP servers should use UTF-8 or its proper subset ASCII, | 33 // Per RFC 2640, FTP servers should use UTF-8 or its proper subset ASCII, |
| 34 // but many old FTP servers use legacy encodings. Try UTF-8 first. | 34 // but many old FTP servers use legacy encodings. Try UTF-8 first. |
| 35 if (IsStringUTF8(path)) | 35 if (IsStringUTF8(path)) |
| 36 return UTF8ToUTF16(path); | 36 return base::UTF8ToUTF16(path); |
| 37 | 37 |
| 38 // Try detecting the encoding. The sample is rather small though, so it may | 38 // Try detecting the encoding. The sample is rather small though, so it may |
| 39 // fail. | 39 // fail. |
| 40 std::string encoding; | 40 std::string encoding; |
| 41 if (base::DetectEncoding(path, &encoding) && !encoding.empty()) { | 41 if (base::DetectEncoding(path, &encoding) && !encoding.empty()) { |
| 42 base::string16 path_utf16; | 42 base::string16 path_utf16; |
| 43 if (base::CodepageToUTF16(path, encoding.c_str(), | 43 if (base::CodepageToUTF16(path, encoding.c_str(), |
| 44 base::OnStringConversionError::SUBSTITUTE, | 44 base::OnStringConversionError::SUBSTITUTE, |
| 45 &path_utf16)) { | 45 &path_utf16)) { |
| 46 return path_utf16; | 46 return path_utf16; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 net::UnescapeRule::URL_SPECIAL_CHARS; | 104 net::UnescapeRule::URL_SPECIAL_CHARS; |
| 105 std::string unescaped_path = net::UnescapeURLComponent(response_url.path(), | 105 std::string unescaped_path = net::UnescapeURLComponent(response_url.path(), |
| 106 unescape_rules); | 106 unescape_rules); |
| 107 SendDataToClient(net::GetDirectoryListingHeader( | 107 SendDataToClient(net::GetDirectoryListingHeader( |
| 108 ConvertPathToUTF16(unescaped_path))); | 108 ConvertPathToUTF16(unescaped_path))); |
| 109 | 109 |
| 110 // If this isn't top level directory (i.e. the path isn't "/",) | 110 // If this isn't top level directory (i.e. the path isn't "/",) |
| 111 // add a link to the parent directory. | 111 // add a link to the parent directory. |
| 112 if (response_url.path().length() > 1) { | 112 if (response_url.path().length() > 1) { |
| 113 SendDataToClient(net::GetDirectoryListingEntry( | 113 SendDataToClient(net::GetDirectoryListingEntry( |
| 114 ASCIIToUTF16(".."), std::string(), false, 0, base::Time())); | 114 base::ASCIIToUTF16(".."), std::string(), false, 0, base::Time())); |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 | 117 |
| 118 void FtpDirectoryListingResponseDelegate::SendDataToClient( | 118 void FtpDirectoryListingResponseDelegate::SendDataToClient( |
| 119 const std::string& data) { | 119 const std::string& data) { |
| 120 client_->didReceiveData(loader_, data.data(), data.length(), -1); | 120 client_->didReceiveData(loader_, data.data(), data.length(), -1); |
| 121 } | 121 } |
| 122 | 122 |
| 123 } // namespace webkit_glue | 123 } // namespace webkit_glue |
| OLD | NEW |