Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2392)

Side by Side Diff: content/child/ftp_directory_listing_response_delegate.cc

Issue 2168003003: Replace ICU encoding detection with CED (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments/add datafiles back Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/i18n/icu_encoding_detection.h" 12 #include "base/i18n/encoding_detection.h"
13 #include "base/i18n/icu_string_conversions.h" 13 #include "base/i18n/icu_string_conversions.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/sys_string_conversions.h" 16 #include "base/strings/sys_string_conversions.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "content/child/weburlresponse_extradata_impl.h" 19 #include "content/child/weburlresponse_extradata_impl.h"
20 #include "net/base/directory_listing.h" 20 #include "net/base/directory_listing.h"
21 #include "net/base/escape.h" 21 #include "net/base/escape.h"
22 #include "net/base/net_errors.h" 22 #include "net/base/net_errors.h"
(...skipping 10 matching lines...) Expand all
33 33
34 base::string16 ConvertPathToUTF16(const std::string& path) { 34 base::string16 ConvertPathToUTF16(const std::string& path) {
35 // Per RFC 2640, FTP servers should use UTF-8 or its proper subset ASCII, 35 // Per RFC 2640, FTP servers should use UTF-8 or its proper subset ASCII,
36 // but many old FTP servers use legacy encodings. Try UTF-8 first. 36 // but many old FTP servers use legacy encodings. Try UTF-8 first.
37 if (base::IsStringUTF8(path)) 37 if (base::IsStringUTF8(path))
38 return base::UTF8ToUTF16(path); 38 return base::UTF8ToUTF16(path);
39 39
40 // Try detecting the encoding. The sample is rather small though, so it may 40 // Try detecting the encoding. The sample is rather small though, so it may
41 // fail. 41 // fail.
42 std::string encoding; 42 std::string encoding;
43 if (base::DetectEncoding(path, &encoding) && !encoding.empty()) { 43 if (base::DetectEncoding(path, &encoding) && encoding != "US-ASCII") {
44 base::string16 path_utf16; 44 base::string16 path_utf16;
45 if (base::CodepageToUTF16(path, encoding.c_str(), 45 if (base::CodepageToUTF16(path, encoding.c_str(),
46 base::OnStringConversionError::SUBSTITUTE, 46 base::OnStringConversionError::SUBSTITUTE,
47 &path_utf16)) { 47 &path_utf16)) {
48 return path_utf16; 48 return path_utf16;
49 } 49 }
50 } 50 }
51 51
52 // Use system native encoding as the last resort. 52 // Use system native encoding as the last resort.
53 return base::WideToUTF16(base::SysNativeMBToWide(path)); 53 return base::WideToUTF16(base::SysNativeMBToWide(path));
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 129
130 void FtpDirectoryListingResponseDelegate::SendDataToClient( 130 void FtpDirectoryListingResponseDelegate::SendDataToClient(
131 const std::string& data) { 131 const std::string& data) {
132 if (client_) { 132 if (client_) {
133 client_->didReceiveData(loader_, data.data(), data.length(), -1, 133 client_->didReceiveData(loader_, data.data(), data.length(), -1,
134 data.length()); 134 data.length());
135 } 135 }
136 } 136 }
137 137
138 } // namespace content 138 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698