| 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/glue/ftp_directory_listing_response_delegate.h" | 5 #include "webkit/glue/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 11 matching lines...) Expand all Loading... |
| 22 #include "webkit/glue/weburlresponse_extradata_impl.h" | 22 #include "webkit/glue/weburlresponse_extradata_impl.h" |
| 23 | 23 |
| 24 using net::FtpDirectoryListingEntry; | 24 using net::FtpDirectoryListingEntry; |
| 25 | 25 |
| 26 using WebKit::WebURLLoader; | 26 using WebKit::WebURLLoader; |
| 27 using WebKit::WebURLLoaderClient; | 27 using WebKit::WebURLLoaderClient; |
| 28 using WebKit::WebURLResponse; | 28 using WebKit::WebURLResponse; |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 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 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 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; |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 | 49 |
| 50 // Use system native encoding as the last resort. | 50 // Use system native encoding as the last resort. |
| 51 return WideToUTF16Hack(base::SysNativeMBToWide(path)); | 51 return WideToUTF16Hack(base::SysNativeMBToWide(path)); |
| 52 } | 52 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 ASCIIToUTF16(".."), std::string(), false, 0, base::Time())); | 114 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 |