OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/directory_listing.h" |
6 | 6 |
7 #include "base/i18n/time_formatting.h" | 7 #include "base/i18n/time_formatting.h" |
8 #include "base/json/string_escape.h" | 8 #include "base/json/string_escape.h" |
| 9 #include "base/logging.h" |
| 10 #include "base/strings/string_piece.h" |
9 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
11 #include "base/time/time.h" | 13 #include "base/time/time.h" |
12 #include "net/base/escape.h" | 14 #include "net/base/escape.h" |
| 15 #include "net/base/net_module.h" |
| 16 #include "net/grit/net_resources.h" |
13 | 17 |
14 namespace net { | 18 namespace net { |
15 | 19 |
| 20 std::string GetDirectoryListingHeader(const base::string16& title) { |
| 21 static const base::StringPiece header( |
| 22 NetModule::GetResource(IDR_DIR_HEADER_HTML)); |
| 23 // This can be null in unit tests. |
| 24 DLOG_IF(WARNING, header.empty()) |
| 25 << "Missing resource: directory listing header"; |
| 26 |
| 27 std::string result; |
| 28 if (!header.empty()) |
| 29 result.assign(header.data(), header.size()); |
| 30 |
| 31 result.append("<script>start("); |
| 32 base::EscapeJSONString(title, true, &result); |
| 33 result.append(");</script>\n"); |
| 34 |
| 35 return result; |
| 36 } |
| 37 |
16 std::string GetDirectoryListingEntry(const base::string16& name, | 38 std::string GetDirectoryListingEntry(const base::string16& name, |
17 const std::string& raw_bytes, | 39 const std::string& raw_bytes, |
18 bool is_dir, | 40 bool is_dir, |
19 int64_t size, | 41 int64_t size, |
20 base::Time modified) { | 42 base::Time modified) { |
21 std::string result; | 43 std::string result; |
22 result.append("<script>addRow("); | 44 result.append("<script>addRow("); |
23 base::EscapeJSONString(name, true, &result); | 45 base::EscapeJSONString(name, true, &result); |
24 result.append(","); | 46 result.append(","); |
25 if (raw_bytes.empty()) { | 47 if (raw_bytes.empty()) { |
(...skipping 21 matching lines...) Expand all Loading... |
47 if (!modified.is_null()) | 69 if (!modified.is_null()) |
48 modified_str = base::TimeFormatShortDateAndTime(modified); | 70 modified_str = base::TimeFormatShortDateAndTime(modified); |
49 base::EscapeJSONString(modified_str, true, &result); | 71 base::EscapeJSONString(modified_str, true, &result); |
50 | 72 |
51 result.append(");</script>\n"); | 73 result.append(");</script>\n"); |
52 | 74 |
53 return result; | 75 return result; |
54 } | 76 } |
55 | 77 |
56 } // namespace net | 78 } // namespace net |
OLD | NEW |