| 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> |
| 11 #include <unicode/uset.h> | 11 #include <unicode/uset.h> |
| 12 | 12 |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 | 14 |
| 15 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
| 16 #include <windows.h> | 16 #include <windows.h> |
| 17 #include <winsock2.h> | 17 #include <winsock2.h> |
| 18 #elif defined(OS_POSIX) | 18 #elif defined(OS_POSIX) |
| 19 #include <sys/socket.h> | 19 #include <sys/socket.h> |
| 20 #include <fcntl.h> | 20 #include <fcntl.h> |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
| 24 | 24 |
| 25 #include "base/basictypes.h" | 25 #include "base/basictypes.h" |
| 26 #include "base/file_path.h" |
| 26 #include "base/file_util.h" | 27 #include "base/file_util.h" |
| 27 #include "base/logging.h" | 28 #include "base/logging.h" |
| 28 #include "base/path_service.h" | 29 #include "base/path_service.h" |
| 29 #include "base/scoped_ptr.h" | 30 #include "base/scoped_ptr.h" |
| 30 #include "base/string_escape.h" | 31 #include "base/string_escape.h" |
| 31 #include "base/string_piece.h" | 32 #include "base/string_piece.h" |
| 32 #include "base/string_tokenizer.h" | 33 #include "base/string_tokenizer.h" |
| 33 #include "base/string_util.h" | 34 #include "base/string_util.h" |
| 34 #include "base/sys_string_conversions.h" | 35 #include "base/sys_string_conversions.h" |
| 35 #include "base/time.h" | 36 #include "base/time.h" |
| (...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 return canon_host.substr(canon_host_component.begin, | 792 return canon_host.substr(canon_host_component.begin, |
| 792 canon_host_component.len); | 793 canon_host_component.len); |
| 793 } | 794 } |
| 794 | 795 |
| 795 std::string CanonicalizeHost(const std::wstring& host, bool* is_ip_address) { | 796 std::string CanonicalizeHost(const std::wstring& host, bool* is_ip_address) { |
| 796 std::string converted_host; | 797 std::string converted_host; |
| 797 WideToUTF8(host.c_str(), host.length(), &converted_host); | 798 WideToUTF8(host.c_str(), host.length(), &converted_host); |
| 798 return CanonicalizeHost(converted_host, is_ip_address); | 799 return CanonicalizeHost(converted_host, is_ip_address); |
| 799 } | 800 } |
| 800 | 801 |
| 801 #ifdef OS_WIN | |
| 802 std::string GetDirectoryListingHeader(const std::string& title) { | 802 std::string GetDirectoryListingHeader(const std::string& title) { |
| 803 #if defined(OS_WIN) |
| 803 std::string result = NetModule::GetResource(IDR_DIR_HEADER_HTML); | 804 std::string result = NetModule::GetResource(IDR_DIR_HEADER_HTML); |
| 804 if (result.empty()) { | 805 if (result.empty()) { |
| 805 NOTREACHED() << "expected resource not found"; | 806 NOTREACHED() << "expected resource not found"; |
| 806 } | 807 } |
| 808 #elif defined(OS_POSIX) |
| 809 // TODO(estade): Temporary hack. Remove these platform #ifdefs when we |
| 810 // have implemented resources for non-Windows platforms. |
| 811 LOG(INFO) << "FIXME: hacked resource loading"; |
| 812 FilePath path; |
| 813 PathService::Get(base::DIR_EXE, &path); |
| 814 path = path.Append("../../net/base/dir_header.html"); |
| 815 std::string result; |
| 816 file_util::ReadFileToString(path.ToWStringHack(), &result); |
| 817 #endif |
| 807 | 818 |
| 808 result.append("<script>start("); | 819 result.append("<script>start("); |
| 809 string_escape::JavascriptDoubleQuote(title, true, &result); | 820 string_escape::JavascriptDoubleQuote(title, true, &result); |
| 810 result.append(");</script>\n"); | 821 result.append(");</script>\n"); |
| 811 | 822 |
| 812 return result; | 823 return result; |
| 813 } | 824 } |
| 814 | 825 |
| 815 std::string GetDirectoryListingEntry(const std::string& name, | 826 std::string GetDirectoryListingEntry(const std::string& name, |
| 816 DWORD attrib, | 827 bool is_dir, |
| 817 int64 size, | 828 int64 size, |
| 818 const FILETIME* modified) { | 829 const Time& modified) { |
| 819 std::string result; | 830 std::string result; |
| 820 result.append("<script>addRow("); | 831 result.append("<script>addRow("); |
| 821 string_escape::JavascriptDoubleQuote(name, true, &result); | 832 string_escape::JavascriptDoubleQuote(name, true, &result); |
| 822 result.append(","); | 833 result.append(","); |
| 823 string_escape::JavascriptDoubleQuote( | 834 string_escape::JavascriptDoubleQuote( |
| 824 EscapePath(name), true, &result); | 835 EscapePath(name), true, &result); |
| 825 if (attrib & FILE_ATTRIBUTE_DIRECTORY) { | 836 if (is_dir) { |
| 826 result.append(",1,"); | 837 result.append(",1,"); |
| 827 } else { | 838 } else { |
| 828 result.append(",0,"); | 839 result.append(",0,"); |
| 829 } | 840 } |
| 830 | 841 |
| 831 string_escape::JavascriptDoubleQuote( | 842 string_escape::JavascriptDoubleQuote( |
| 832 FormatBytes(size, GetByteDisplayUnits(size), true), true, &result); | 843 FormatBytes(size, GetByteDisplayUnits(size), true), true, &result); |
| 833 | 844 |
| 834 result.append(","); | 845 result.append(","); |
| 835 | 846 |
| 836 std::wstring modified_str; | 847 std::wstring modified_str; |
| 837 // |modified| can be NULL in FTP listings. | 848 // |modified| can be NULL in FTP listings. |
| 838 if (modified) { | 849 if (!modified.is_null()) { |
| 839 Time time(Time::FromFileTime(*modified)); | 850 modified_str = base::TimeFormatShortDateAndTime(modified); |
| 840 modified_str = base::TimeFormatShortDateAndTime(time); | |
| 841 } | 851 } |
| 842 string_escape::JavascriptDoubleQuote(modified_str, true, &result); | 852 string_escape::JavascriptDoubleQuote(modified_str, true, &result); |
| 843 | 853 |
| 844 result.append(");</script>\n"); | 854 result.append(");</script>\n"); |
| 845 | 855 |
| 846 return result; | 856 return result; |
| 847 } | 857 } |
| 848 #endif | |
| 849 | 858 |
| 850 std::wstring StripWWW(const std::wstring& text) { | 859 std::wstring StripWWW(const std::wstring& text) { |
| 851 const std::wstring www(L"www."); | 860 const std::wstring www(L"www."); |
| 852 return (text.compare(0, www.length(), www) == 0) ? | 861 return (text.compare(0, www.length(), www) == 0) ? |
| 853 text.substr(www.length()) : text; | 862 text.substr(www.length()) : text; |
| 854 } | 863 } |
| 855 | 864 |
| 856 std::wstring GetSuggestedFilename(const GURL& url, | 865 std::wstring GetSuggestedFilename(const GURL& url, |
| 857 const std::string& content_disposition, | 866 const std::string& content_disposition, |
| 858 const std::wstring& default_name) { | 867 const std::wstring& default_name) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 927 return ioctlsocket(fd, FIONBIO, &no_block); | 936 return ioctlsocket(fd, FIONBIO, &no_block); |
| 928 #elif defined(OS_POSIX) | 937 #elif defined(OS_POSIX) |
| 929 int flags = fcntl(fd, F_GETFL, 0); | 938 int flags = fcntl(fd, F_GETFL, 0); |
| 930 if (-1 == flags) | 939 if (-1 == flags) |
| 931 flags = 0; | 940 flags = 0; |
| 932 return fcntl(fd, F_SETFL, flags | O_NONBLOCK); | 941 return fcntl(fd, F_SETFL, flags | O_NONBLOCK); |
| 933 #endif | 942 #endif |
| 934 } | 943 } |
| 935 | 944 |
| 936 } // namespace net | 945 } // namespace net |
| OLD | NEW |