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