| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/base/net_util.h" | |
| 6 | |
| 7 #include "base/i18n/time_formatting.h" | |
| 8 #include "base/json/string_escape.h" | |
| 9 #include "base/strings/string_util.h" | |
| 10 #include "base/strings/utf_string_conversions.h" | |
| 11 #include "base/time/time.h" | |
| 12 #include "net/base/escape.h" | |
| 13 | |
| 14 namespace net { | |
| 15 | |
| 16 std::string GetDirectoryListingEntry(const base::string16& name, | |
| 17 const std::string& raw_bytes, | |
| 18 bool is_dir, | |
| 19 int64_t size, | |
| 20 base::Time modified) { | |
| 21 std::string result; | |
| 22 result.append("<script>addRow("); | |
| 23 base::EscapeJSONString(name, true, &result); | |
| 24 result.append(","); | |
| 25 if (raw_bytes.empty()) { | |
| 26 base::EscapeJSONString(EscapePath(base::UTF16ToUTF8(name)), true, &result); | |
| 27 } else { | |
| 28 base::EscapeJSONString(EscapePath(raw_bytes), true, &result); | |
| 29 } | |
| 30 | |
| 31 if (is_dir) { | |
| 32 result.append(",1,"); | |
| 33 } else { | |
| 34 result.append(",0,"); | |
| 35 } | |
| 36 | |
| 37 // Negative size means unknown or not applicable (e.g. directory). | |
| 38 base::string16 size_string; | |
| 39 if (size >= 0) | |
| 40 size_string = base::FormatBytesUnlocalized(size); | |
| 41 base::EscapeJSONString(size_string, true, &result); | |
| 42 | |
| 43 result.append(","); | |
| 44 | |
| 45 base::string16 modified_str; | |
| 46 // |modified| can be NULL in FTP listings. | |
| 47 if (!modified.is_null()) | |
| 48 modified_str = base::TimeFormatShortDateAndTime(modified); | |
| 49 base::EscapeJSONString(modified_str, true, &result); | |
| 50 | |
| 51 result.append(");</script>\n"); | |
| 52 | |
| 53 return result; | |
| 54 } | |
| 55 | |
| 56 } // namespace net | |
| OLD | NEW |