Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Side by Side Diff: net/base/directory_listing.cc

Issue 1548503002: net: extract GetDirectoryListingXXX functions into directory_listing.* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: REBASE Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/base/directory_listing.h ('k') | net/base/directory_listing_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « net/base/directory_listing.h ('k') | net/base/directory_listing_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698