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

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

Issue 1131813004: Revert of Create net::FormatOriginForDisplay helper function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 | « base/strings/utf_string_conversions.h ('k') | net/base/net_util_icu.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 (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 #ifndef NET_BASE_NET_UTIL_H_ 5 #ifndef NET_BASE_NET_UTIL_H_
6 #define NET_BASE_NET_UTIL_H_ 6 #define NET_BASE_NET_UTIL_H_
7 7
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 9
10 #if defined(OS_WIN) 10 #if defined(OS_WIN)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 typedef std::vector<unsigned char> IPAddressNumber; 51 typedef std::vector<unsigned char> IPAddressNumber;
52 typedef std::vector<IPAddressNumber> IPAddressList; 52 typedef std::vector<IPAddressNumber> IPAddressList;
53 53
54 static const size_t kIPv4AddressSize = 4; 54 static const size_t kIPv4AddressSize = 4;
55 static const size_t kIPv6AddressSize = 16; 55 static const size_t kIPv6AddressSize = 16;
56 #if defined(OS_WIN) 56 #if defined(OS_WIN)
57 // Bluetooth address size. Windows Bluetooth is supported via winsock. 57 // Bluetooth address size. Windows Bluetooth is supported via winsock.
58 static const size_t kBluetoothAddressSize = 6; 58 static const size_t kBluetoothAddressSize = 6;
59 #endif 59 #endif
60 60
61 // Nothing is omitted. 61 // Nothing is ommitted.
62 NET_EXPORT extern const FormatUrlType kFormatUrlOmitNothing; 62 NET_EXPORT extern const FormatUrlType kFormatUrlOmitNothing;
63 63
64 // If set, any username and password are removed. 64 // If set, any username and password are removed.
65 NET_EXPORT extern const FormatUrlType kFormatUrlOmitUsernamePassword; 65 NET_EXPORT extern const FormatUrlType kFormatUrlOmitUsernamePassword;
66 66
67 // If the scheme is 'http://', it's removed. 67 // If the scheme is 'http://', it's removed.
68 NET_EXPORT extern const FormatUrlType kFormatUrlOmitHTTP; 68 NET_EXPORT extern const FormatUrlType kFormatUrlOmitHTTP;
69 69
70 // Omits the path if it is just a slash and there is no query or ref. This is 70 // Omits the path if it is just a slash and there is no query or ref. This is
71 // meaningful for non-file "standard" URLs. 71 // meaningful for non-file "standard" URLs.
72 NET_EXPORT extern const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname; 72 NET_EXPORT extern const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname;
73 73
74 // Convenience for omitting all unnecessary types. 74 // Convenience for omitting all unecessary types.
75 NET_EXPORT extern const FormatUrlType kFormatUrlOmitAll; 75 NET_EXPORT extern const FormatUrlType kFormatUrlOmitAll;
76 76
77 // Returns the number of explicitly allowed ports; for testing. 77 // Returns the number of explicitly allowed ports; for testing.
78 NET_EXPORT_PRIVATE extern size_t GetCountOfExplicitlyAllowedPorts(); 78 NET_EXPORT_PRIVATE extern size_t GetCountOfExplicitlyAllowedPorts();
79 79
80 // Splits an input of the form <host>[":"<port>] into its constituent parts. 80 // Splits an input of the form <host>[":"<port>] into its consitituent parts.
81 // Saves the result into |*host| and |*port|. If the input did not have 81 // Saves the result into |*host| and |*port|. If the input did not have
82 // the optional port, sets |*port| to -1. 82 // the optional port, sets |*port| to -1.
83 // Returns true if the parsing was successful, false otherwise. 83 // Returns true if the parsing was successful, false otherwise.
84 // The returned host is NOT canonicalized, and may be invalid. 84 // The returned host is NOT canonicalized, and may be invalid.
85 // 85 //
86 // IPv6 literals must be specified in a bracketed form, for instance: 86 // IPv6 literals must be specified in a bracketed form, for instance:
87 // [::1]:90 and [::1] 87 // [::1]:90 and [::1]
88 // 88 //
89 // The resultant |*host| in both cases will be "::1" (not bracketed). 89 // The resultant |*host| in both cases will be "::1" (not bracketed).
90 NET_EXPORT bool ParseHostAndPort( 90 NET_EXPORT bool ParseHostAndPort(
91 std::string::const_iterator host_and_port_begin, 91 std::string::const_iterator host_and_port_begin,
92 std::string::const_iterator host_and_port_end, 92 std::string::const_iterator host_and_port_end,
93 std::string* host, 93 std::string* host,
94 int* port); 94 int* port);
95 NET_EXPORT bool ParseHostAndPort( 95 NET_EXPORT bool ParseHostAndPort(
96 const std::string& host_and_port, 96 const std::string& host_and_port,
97 std::string* host, 97 std::string* host,
98 int* port); 98 int* port);
99 99
100 // Returns a host:port string for the given URL. 100 // Returns a host:port string for the given URL.
101 NET_EXPORT std::string GetHostAndPort(const GURL& url); 101 NET_EXPORT std::string GetHostAndPort(const GURL& url);
102 102
103 // Returns a host[:port] string for the given URL, where the port is omitted 103 // Returns a host[:port] string for the given URL, where the port is omitted
104 // if it is the default for the URL's scheme. 104 // if it is the default for the URL's scheme.
105 NET_EXPORT_PRIVATE std::string GetHostAndOptionalPort(const GURL& url); 105 NET_EXPORT_PRIVATE std::string GetHostAndOptionalPort(const GURL& url);
106 106
107 // Returns true if |hostname| contains a non-registerable or non-assignable 107 // Returns true if |hostname| contains a non-registerable or non-assignable
108 // domain name (e.g.: a gTLD that has not been assigned by IANA) or an IP 108 // domain name (eg: a gTLD that has not been assigned by IANA) or an IP address
109 // address that falls in an IANA-reserved range. 109 // that falls in an IANA-reserved range.
110 NET_EXPORT bool IsHostnameNonUnique(const std::string& hostname); 110 NET_EXPORT bool IsHostnameNonUnique(const std::string& hostname);
111 111
112 // Returns true if an IP address hostname is in a range reserved by the IANA. 112 // Returns true if an IP address hostname is in a range reserved by the IANA.
113 // Works with both IPv4 and IPv6 addresses, and only compares against a given 113 // Works with both IPv4 and IPv6 addresses, and only compares against a given
114 // protocol's reserved ranges. 114 // protocols's reserved ranges.
115 NET_EXPORT bool IsIPAddressReserved(const IPAddressNumber& address); 115 NET_EXPORT bool IsIPAddressReserved(const IPAddressNumber& address);
116 116
117 // Convenience struct for when you need a |struct sockaddr|. 117 // Convenience struct for when you need a |struct sockaddr|.
118 struct SockaddrStorage { 118 struct SockaddrStorage {
119 SockaddrStorage() : addr_len(sizeof(addr_storage)), 119 SockaddrStorage() : addr_len(sizeof(addr_storage)),
120 addr(reinterpret_cast<struct sockaddr*>(&addr_storage)) {} 120 addr(reinterpret_cast<struct sockaddr*>(&addr_storage)) {}
121 SockaddrStorage(const SockaddrStorage& other); 121 SockaddrStorage(const SockaddrStorage& other);
122 void operator=(const SockaddrStorage& other); 122 void operator=(const SockaddrStorage& other);
123 123
124 struct sockaddr_storage addr_storage; 124 struct sockaddr_storage addr_storage;
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 332
333 // This is a convenience function for FormatUrl() with 333 // This is a convenience function for FormatUrl() with
334 // format_types = kFormatUrlOmitAll and unescape = SPACES. This is the typical 334 // format_types = kFormatUrlOmitAll and unescape = SPACES. This is the typical
335 // set of flags for "URLs to display to the user". You should be cautious about 335 // set of flags for "URLs to display to the user". You should be cautious about
336 // using this for URLs which will be parsed or sent to other applications. 336 // using this for URLs which will be parsed or sent to other applications.
337 inline base::string16 FormatUrl(const GURL& url, const std::string& languages) { 337 inline base::string16 FormatUrl(const GURL& url, const std::string& languages) {
338 return FormatUrl(url, languages, kFormatUrlOmitAll, UnescapeRule::SPACES, 338 return FormatUrl(url, languages, kFormatUrlOmitAll, UnescapeRule::SPACES,
339 NULL, NULL, NULL); 339 NULL, NULL, NULL);
340 } 340 }
341 341
342 // This is a convenience function for formatting a URL as an origin in a concise
343 // and human-friendly way. Use this instead of |FormatUrl| when the reader needs
344 // only to understand the origin (rather than the entire URL).
345 //
346 // - Omits the path for standard schemes, excepting file and filesystem.
347 // - Omits the port if it is the default for the scheme.
348 //
349 // Do not use this for URLs which will be parsed or sent to other applications.
350 //
351 // Callers should only set |omit_scheme| to true when it is safe to do so: in
352 // contexts where the origin is known to be secure or is always secure by
353 // necessity. As examples:
354 //
355 // display = FormatOriginForDisplay(url, ..., url.SchemeIsCryptographic());
356 //
357 // display = FormatOriginForDisplay(url, ..., IsOriginSecure(url));
358 NET_EXPORT base::string16 FormatOriginForDisplay(const GURL& origin,
359 const std::string& languages,
360 bool omit_scheme);
361
362 // Returns whether FormatUrl() would strip a trailing slash from |url|, given a 342 // Returns whether FormatUrl() would strip a trailing slash from |url|, given a
363 // format flag including kFormatUrlOmitTrailingSlashOnBareHostname. 343 // format flag including kFormatUrlOmitTrailingSlashOnBareHostname.
364 NET_EXPORT bool CanStripTrailingSlash(const GURL& url); 344 NET_EXPORT bool CanStripTrailingSlash(const GURL& url);
365 345
366 // Strip the portions of |url| that aren't core to the network request. 346 // Strip the portions of |url| that aren't core to the network request.
367 // - user name / password 347 // - user name / password
368 // - reference section 348 // - reference section
369 NET_EXPORT_PRIVATE GURL SimplifyUrlForRequest(const GURL& url); 349 NET_EXPORT_PRIVATE GURL SimplifyUrlForRequest(const GURL& url);
370 350
371 NET_EXPORT void SetExplicitlyAllowedPorts(const std::string& allowed_ports); 351 NET_EXPORT void SetExplicitlyAllowedPorts(const std::string& allowed_ports);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 // Returns true if |host| is one of the names (e.g. "localhost") or IP 434 // Returns true if |host| is one of the names (e.g. "localhost") or IP
455 // addresses (IPv4 127.0.0.0/8 or IPv6 ::1) that indicate a loopback. 435 // addresses (IPv4 127.0.0.0/8 or IPv6 ::1) that indicate a loopback.
456 // 436 //
457 // Note that this function does not check for IP addresses other than 437 // Note that this function does not check for IP addresses other than
458 // the above, although other IP addresses may point to the local 438 // the above, although other IP addresses may point to the local
459 // machine. 439 // machine.
460 NET_EXPORT_PRIVATE bool IsLocalhost(const std::string& host); 440 NET_EXPORT_PRIVATE bool IsLocalhost(const std::string& host);
461 441
462 NET_EXPORT_PRIVATE bool IsLocalhostTLD(const std::string& host); 442 NET_EXPORT_PRIVATE bool IsLocalhostTLD(const std::string& host);
463 443
464 // Returns true if the URL's host is a Google server. This should only be used 444 // Returns true if the url's host is a Google server. This should only be used
465 // for histograms and shouldn't be used to affect behavior. 445 // for histograms and shouldn't be used to affect behavior.
466 NET_EXPORT_PRIVATE bool HasGoogleHost(const GURL& url); 446 NET_EXPORT_PRIVATE bool HasGoogleHost(const GURL& url);
467 447
468 // A subset of IP address attributes which are actionable by the 448 // A subset of IP address attributes which are actionable by the
469 // application layer. Currently unimplemented for all hosts; 449 // application layer. Currently unimplemented for all hosts;
470 // IP_ADDRESS_ATTRIBUTE_NONE is always returned. 450 // IP_ADDRESS_ATTRIBUTE_NONE is always returned.
471 enum IPAddressAttributes { 451 enum IPAddressAttributes {
472 IP_ADDRESS_ATTRIBUTE_NONE = 0, 452 IP_ADDRESS_ATTRIBUTE_NONE = 0,
473 453
474 // A temporary address is dynamic by nature and will not contain MAC 454 // A temporary address is dynamic by nature and will not contain MAC
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 DSCP_CS5 = 40, // Video 582 DSCP_CS5 = 40, // Video
603 DSCP_EF = 46, // Voice 583 DSCP_EF = 46, // Voice
604 DSCP_CS6 = 48, // Voice 584 DSCP_CS6 = 48, // Voice
605 DSCP_CS7 = 56, // Control messages 585 DSCP_CS7 = 56, // Control messages
606 DSCP_LAST = DSCP_CS7 586 DSCP_LAST = DSCP_CS7
607 }; 587 };
608 588
609 } // namespace net 589 } // namespace net
610 590
611 #endif // NET_BASE_NET_UTIL_H_ 591 #endif // NET_BASE_NET_UTIL_H_
OLDNEW
« no previous file with comments | « base/strings/utf_string_conversions.h ('k') | net/base/net_util_icu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698