| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <unicode/ucnv.h> | 6 #include <unicode/ucnv.h> |
| 7 #include <unicode/uidna.h> | 7 #include <unicode/uidna.h> |
| 8 #include <unicode/ulocdata.h> | 8 #include <unicode/ulocdata.h> |
| 9 #include <unicode/uniset.h> | 9 #include <unicode/uniset.h> |
| 10 #include <unicode/uscript.h> | 10 #include <unicode/uscript.h> |
| (...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 } | 817 } |
| 818 | 818 |
| 819 std::string GetDirectoryListingHeader(const std::string& title) { | 819 std::string GetDirectoryListingHeader(const std::string& title) { |
| 820 static const StringPiece header(NetModule::GetResource(IDR_DIR_HEADER_HTML)); | 820 static const StringPiece header(NetModule::GetResource(IDR_DIR_HEADER_HTML)); |
| 821 if (header.empty()) { | 821 if (header.empty()) { |
| 822 NOTREACHED() << "expected resource not found"; | 822 NOTREACHED() << "expected resource not found"; |
| 823 } | 823 } |
| 824 std::string result(header.data(), header.size()); | 824 std::string result(header.data(), header.size()); |
| 825 | 825 |
| 826 result.append("<script>start("); | 826 result.append("<script>start("); |
| 827 string_escape::JavascriptDoubleQuote(title, true, &result); | 827 string_escape::JsonDoubleQuote(title, true, &result); |
| 828 result.append(");</script>\n"); | 828 result.append(");</script>\n"); |
| 829 | 829 |
| 830 return result; | 830 return result; |
| 831 } | 831 } |
| 832 | 832 |
| 833 std::string GetDirectoryListingEntry(const std::string& name, | 833 std::string GetDirectoryListingEntry(const std::string& name, |
| 834 bool is_dir, | 834 bool is_dir, |
| 835 int64 size, | 835 int64 size, |
| 836 const Time& modified) { | 836 const Time& modified) { |
| 837 std::string result; | 837 std::string result; |
| 838 result.append("<script>addRow("); | 838 result.append("<script>addRow("); |
| 839 string_escape::JavascriptDoubleQuote(name, true, &result); | 839 string_escape::JsonDoubleQuote(name, true, &result); |
| 840 result.append(","); | 840 result.append(","); |
| 841 string_escape::JavascriptDoubleQuote( | 841 string_escape::JsonDoubleQuote(EscapePath(name), true, &result); |
| 842 EscapePath(name), true, &result); | |
| 843 if (is_dir) { | 842 if (is_dir) { |
| 844 result.append(",1,"); | 843 result.append(",1,"); |
| 845 } else { | 844 } else { |
| 846 result.append(",0,"); | 845 result.append(",0,"); |
| 847 } | 846 } |
| 848 | 847 |
| 849 string_escape::JavascriptDoubleQuote( | 848 string_escape::JsonDoubleQuote( |
| 850 WideToUTF16Hack(FormatBytes(size, GetByteDisplayUnits(size), true)), true, | 849 WideToUTF16Hack(FormatBytes(size, GetByteDisplayUnits(size), true)), true, |
| 851 &result); | 850 &result); |
| 852 | 851 |
| 853 result.append(","); | 852 result.append(","); |
| 854 | 853 |
| 855 string16 modified_str; | 854 string16 modified_str; |
| 856 // |modified| can be NULL in FTP listings. | 855 // |modified| can be NULL in FTP listings. |
| 857 if (!modified.is_null()) { | 856 if (!modified.is_null()) { |
| 858 modified_str = WideToUTF16Hack(base::TimeFormatShortDateAndTime(modified)); | 857 modified_str = WideToUTF16Hack(base::TimeFormatShortDateAndTime(modified)); |
| 859 } | 858 } |
| 860 string_escape::JavascriptDoubleQuote(modified_str, true, &result); | 859 string_escape::JsonDoubleQuote(modified_str, true, &result); |
| 861 | 860 |
| 862 result.append(");</script>\n"); | 861 result.append(");</script>\n"); |
| 863 | 862 |
| 864 return result; | 863 return result; |
| 865 } | 864 } |
| 866 | 865 |
| 867 std::wstring StripWWW(const std::wstring& text) { | 866 std::wstring StripWWW(const std::wstring& text) { |
| 868 const std::wstring www(L"www."); | 867 const std::wstring www(L"www."); |
| 869 return (text.compare(0, www.length(), www) == 0) ? | 868 return (text.compare(0, www.length(), www) == 0) ? |
| 870 text.substr(www.length()) : text; | 869 text.substr(www.length()) : text; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1025 char buffer[256]; | 1024 char buffer[256]; |
| 1026 int result = gethostname(buffer, sizeof(buffer)); | 1025 int result = gethostname(buffer, sizeof(buffer)); |
| 1027 if (result != 0) { | 1026 if (result != 0) { |
| 1028 DLOG(INFO) << "gethostname() failed with " << result; | 1027 DLOG(INFO) << "gethostname() failed with " << result; |
| 1029 buffer[0] = '\0'; | 1028 buffer[0] = '\0'; |
| 1030 } | 1029 } |
| 1031 return std::string(buffer); | 1030 return std::string(buffer); |
| 1032 } | 1031 } |
| 1033 | 1032 |
| 1034 } // namespace net | 1033 } // namespace net |
| OLD | NEW |