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

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

Issue 1548503002: net: extract GetDirectoryListingXXX functions into directory_listing.* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/net_util.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
11 #include <string> 11 #include <string>
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 <iphlpapi.h> 17 #include <iphlpapi.h>
18 #include <winsock2.h> 18 #include <winsock2.h>
19 #include <ws2bth.h> 19 #include <ws2bth.h>
20 #pragma comment(lib, "iphlpapi.lib") 20 #pragma comment(lib, "iphlpapi.lib")
21 #elif defined(OS_POSIX) 21 #elif defined(OS_POSIX)
22 #include <fcntl.h> 22 #include <fcntl.h>
23 #include <netdb.h> 23 #include <netdb.h>
24 #include <unistd.h> 24 #include <unistd.h>
25 #endif // defined(OS_POSIX) 25 #endif // defined(OS_POSIX)
26 26
27 #include "base/json/string_escape.h"
28 #include "base/logging.h" 27 #include "base/logging.h"
29 #include "base/strings/string_split.h" 28 #include "base/strings/string_split.h"
30 #include "base/strings/string_util.h" 29 #include "base/strings/string_util.h"
31 #include "base/strings/stringprintf.h" 30 #include "base/strings/stringprintf.h"
32 #include "base/strings/utf_string_conversions.h" 31 #include "base/strings/utf_string_conversions.h"
33 #include "base/sys_byteorder.h" 32 #include "base/sys_byteorder.h"
34 #include "base/values.h" 33 #include "base/values.h"
35 #include "net/base/address_list.h" 34 #include "net/base/address_list.h"
36 #include "net/base/escape.h" 35 #include "net/base/escape.h"
37 #include "net/base/ip_address_number.h" 36 #include "net/base/ip_address_number.h"
38 #include "net/base/net_module.h"
39 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 37 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
40 #include "net/base/url_util.h" 38 #include "net/base/url_util.h"
41 #include "net/grit/net_resources.h"
42 #include "url/gurl.h" 39 #include "url/gurl.h"
43 #include "url/third_party/mozilla/url_parse.h" 40 #include "url/third_party/mozilla/url_parse.h"
44 #include "url/url_canon.h" 41 #include "url/url_canon.h"
45 #include "url/url_canon_ip.h" 42 #include "url/url_canon_ip.h"
46 43
47 #if defined(OS_WIN) 44 #if defined(OS_WIN)
48 #include "net/base/winsock_init.h" 45 #include "net/base/winsock_init.h"
49 #endif 46 #endif
50 47
51 namespace net { 48 namespace net {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 canon_host_output.Complete(); 88 canon_host_output.Complete();
92 DCHECK_EQ(host_info->out_host.len, static_cast<int>(canon_host.length())); 89 DCHECK_EQ(host_info->out_host.len, static_cast<int>(canon_host.length()));
93 } else { 90 } else {
94 // Empty host, or canonicalization failed. We'll return empty. 91 // Empty host, or canonicalization failed. We'll return empty.
95 canon_host.clear(); 92 canon_host.clear();
96 } 93 }
97 94
98 return canon_host; 95 return canon_host;
99 } 96 }
100 97
101 std::string GetDirectoryListingHeader(const base::string16& title) {
102 static const base::StringPiece header(
103 NetModule::GetResource(IDR_DIR_HEADER_HTML));
104 // This can be null in unit tests.
105 DLOG_IF(WARNING, header.empty()) <<
106 "Missing resource: directory listing header";
107
108 std::string result;
109 if (!header.empty())
110 result.assign(header.data(), header.size());
111
112 result.append("<script>start(");
113 base::EscapeJSONString(title, true, &result);
114 result.append(");</script>\n");
115
116 return result;
117 }
118
119 inline bool IsHostCharAlphanumeric(char c) { 98 inline bool IsHostCharAlphanumeric(char c) {
120 // We can just check lowercase because uppercase characters have already been 99 // We can just check lowercase because uppercase characters have already been
121 // normalized. 100 // normalized.
122 return ((c >= 'a') && (c <= 'z')) || ((c >= '0') && (c <= '9')); 101 return ((c >= 'a') && (c <= 'z')) || ((c >= '0') && (c <= '9'));
123 } 102 }
124 103
125 bool IsCanonicalizedHostCompliant(const std::string& host) { 104 bool IsCanonicalizedHostCompliant(const std::string& host) {
126 if (host.empty()) 105 if (host.empty())
127 return false; 106 return false;
128 107
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 // Here it's possible to get away with faster case-sensitive comparisons 491 // Here it's possible to get away with faster case-sensitive comparisons
513 // because the list above is all lowercase, and a GURL's host name will 492 // because the list above is all lowercase, and a GURL's host name will
514 // always be canonicalized to lowercase as well. 493 // always be canonicalized to lowercase as well.
515 if (base::EndsWith(host, suffix, base::CompareCase::SENSITIVE)) 494 if (base::EndsWith(host, suffix, base::CompareCase::SENSITIVE))
516 return true; 495 return true;
517 } 496 }
518 return false; 497 return false;
519 } 498 }
520 499
521 } // namespace net 500 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698