OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/base/net_util.h" | 5 #include "net/base/net_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <unicode/ucnv.h> | 9 #include <unicode/ucnv.h> |
10 #include <unicode/uidna.h> | 10 #include <unicode/uidna.h> |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include <sys/socket.h> | 25 #include <sys/socket.h> |
26 #include <fcntl.h> | 26 #include <fcntl.h> |
27 #endif | 27 #endif |
28 | 28 |
29 #include "base/basictypes.h" | 29 #include "base/basictypes.h" |
30 #include "base/file_path.h" | 30 #include "base/file_path.h" |
31 #include "base/file_util.h" | 31 #include "base/file_util.h" |
32 #include "base/i18n/file_util_icu.h" | 32 #include "base/i18n/file_util_icu.h" |
33 #include "base/i18n/icu_string_conversions.h" | 33 #include "base/i18n/icu_string_conversions.h" |
34 #include "base/i18n/time_formatting.h" | 34 #include "base/i18n/time_formatting.h" |
| 35 #include "base/json/string_escape.h" |
35 #include "base/lock.h" | 36 #include "base/lock.h" |
36 #include "base/logging.h" | 37 #include "base/logging.h" |
37 #include "base/message_loop.h" | 38 #include "base/message_loop.h" |
38 #include "base/path_service.h" | 39 #include "base/path_service.h" |
39 #include "base/singleton.h" | 40 #include "base/singleton.h" |
40 #include "base/stl_util-inl.h" | 41 #include "base/stl_util-inl.h" |
41 #include "base/string_escape.h" | |
42 #include "base/string_piece.h" | 42 #include "base/string_piece.h" |
43 #include "base/string_tokenizer.h" | 43 #include "base/string_tokenizer.h" |
44 #include "base/string_util.h" | 44 #include "base/string_util.h" |
45 #include "base/sys_string_conversions.h" | 45 #include "base/sys_string_conversions.h" |
46 #include "base/time.h" | 46 #include "base/time.h" |
47 #include "base/utf_string_conversions.h" | 47 #include "base/utf_string_conversions.h" |
48 #include "grit/net_resources.h" | 48 #include "grit/net_resources.h" |
49 #include "googleurl/src/gurl.h" | 49 #include "googleurl/src/gurl.h" |
50 #include "googleurl/src/url_canon.h" | 50 #include "googleurl/src/url_canon.h" |
51 #include "googleurl/src/url_parse.h" | 51 #include "googleurl/src/url_parse.h" |
(...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
926 NetModule::GetResource(IDR_DIR_HEADER_HTML)); | 926 NetModule::GetResource(IDR_DIR_HEADER_HTML)); |
927 // This can be null in unit tests. | 927 // This can be null in unit tests. |
928 DLOG_IF(WARNING, header.empty()) << | 928 DLOG_IF(WARNING, header.empty()) << |
929 "Missing resource: directory listing header"; | 929 "Missing resource: directory listing header"; |
930 | 930 |
931 std::string result; | 931 std::string result; |
932 if (!header.empty()) | 932 if (!header.empty()) |
933 result.assign(header.data(), header.size()); | 933 result.assign(header.data(), header.size()); |
934 | 934 |
935 result.append("<script>start("); | 935 result.append("<script>start("); |
936 string_escape::JsonDoubleQuote(title, true, &result); | 936 base::JsonDoubleQuote(title, true, &result); |
937 result.append(");</script>\n"); | 937 result.append(");</script>\n"); |
938 | 938 |
939 return result; | 939 return result; |
940 } | 940 } |
941 | 941 |
942 inline bool IsHostCharAlpha(char c) { | 942 inline bool IsHostCharAlpha(char c) { |
943 // We can just check lowercase because uppercase characters have already been | 943 // We can just check lowercase because uppercase characters have already been |
944 // normalized. | 944 // normalized. |
945 return (c >= 'a') && (c <= 'z'); | 945 return (c >= 'a') && (c <= 'z'); |
946 } | 946 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 return state == IN_COMPONENT_STARTED_ALPHA; | 987 return state == IN_COMPONENT_STARTED_ALPHA; |
988 } | 988 } |
989 | 989 |
990 std::string GetDirectoryListingEntry(const string16& name, | 990 std::string GetDirectoryListingEntry(const string16& name, |
991 const std::string& raw_bytes, | 991 const std::string& raw_bytes, |
992 bool is_dir, | 992 bool is_dir, |
993 int64 size, | 993 int64 size, |
994 Time modified) { | 994 Time modified) { |
995 std::string result; | 995 std::string result; |
996 result.append("<script>addRow("); | 996 result.append("<script>addRow("); |
997 string_escape::JsonDoubleQuote(name, true, &result); | 997 base::JsonDoubleQuote(name, true, &result); |
998 result.append(","); | 998 result.append(","); |
999 if (raw_bytes.empty()) { | 999 if (raw_bytes.empty()) { |
1000 string_escape::JsonDoubleQuote(EscapePath(UTF16ToUTF8(name)), | 1000 base::JsonDoubleQuote(EscapePath(UTF16ToUTF8(name)), |
1001 true, &result); | 1001 true, &result); |
1002 } else { | 1002 } else { |
1003 string_escape::JsonDoubleQuote(EscapePath(raw_bytes), true, &result); | 1003 base::JsonDoubleQuote(EscapePath(raw_bytes), true, &result); |
1004 } | 1004 } |
1005 if (is_dir) { | 1005 if (is_dir) { |
1006 result.append(",1,"); | 1006 result.append(",1,"); |
1007 } else { | 1007 } else { |
1008 result.append(",0,"); | 1008 result.append(",0,"); |
1009 } | 1009 } |
1010 | 1010 |
1011 string_escape::JsonDoubleQuote( | 1011 base::JsonDoubleQuote( |
1012 WideToUTF16Hack(FormatBytes(size, GetByteDisplayUnits(size), true)), true, | 1012 WideToUTF16Hack(FormatBytes(size, GetByteDisplayUnits(size), true)), true, |
1013 &result); | 1013 &result); |
1014 | 1014 |
1015 result.append(","); | 1015 result.append(","); |
1016 | 1016 |
1017 string16 modified_str; | 1017 string16 modified_str; |
1018 // |modified| can be NULL in FTP listings. | 1018 // |modified| can be NULL in FTP listings. |
1019 if (!modified.is_null()) { | 1019 if (!modified.is_null()) { |
1020 modified_str = WideToUTF16Hack(base::TimeFormatShortDateAndTime(modified)); | 1020 modified_str = WideToUTF16Hack(base::TimeFormatShortDateAndTime(modified)); |
1021 } | 1021 } |
1022 string_escape::JsonDoubleQuote(modified_str, true, &result); | 1022 base::JsonDoubleQuote(modified_str, true, &result); |
1023 | 1023 |
1024 result.append(");</script>\n"); | 1024 result.append(");</script>\n"); |
1025 | 1025 |
1026 return result; | 1026 return result; |
1027 } | 1027 } |
1028 | 1028 |
1029 std::wstring StripWWW(const std::wstring& text) { | 1029 std::wstring StripWWW(const std::wstring& text) { |
1030 const std::wstring www(L"www."); | 1030 const std::wstring www(L"www."); |
1031 return (text.compare(0, www.length(), www) == 0) ? | 1031 return (text.compare(0, www.length(), www) == 0) ? |
1032 text.substr(www.length()) : text; | 1032 text.substr(www.length()) : text; |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1427 if (length > 0) | 1427 if (length > 0) |
1428 ports.insert(StringToInt(WideToASCII( | 1428 ports.insert(StringToInt(WideToASCII( |
1429 allowed_ports.substr(last, length)))); | 1429 allowed_ports.substr(last, length)))); |
1430 last = i + 1; | 1430 last = i + 1; |
1431 } | 1431 } |
1432 } | 1432 } |
1433 explicitly_allowed_ports = ports; | 1433 explicitly_allowed_ports = ports; |
1434 } | 1434 } |
1435 | 1435 |
1436 } // namespace net | 1436 } // namespace net |
OLD | NEW |