Chromium Code Reviews| Index: net/base/net_util.h |
| diff --git a/net/base/net_util.h b/net/base/net_util.h |
| index 32e2287f9092867b9ab819e459253a3f13979b50..66270bdc4f33e04f97524f369e70b191a9033bf9 100644 |
| --- a/net/base/net_util.h |
| +++ b/net/base/net_util.h |
| @@ -58,7 +58,7 @@ static const size_t kIPv6AddressSize = 16; |
| static const size_t kBluetoothAddressSize = 6; |
| #endif |
| -// Nothing is ommitted. |
| +// Nothing is omitted. |
| NET_EXPORT extern const FormatUrlType kFormatUrlOmitNothing; |
| // If set, any username and password are removed. |
| @@ -71,13 +71,22 @@ NET_EXPORT extern const FormatUrlType kFormatUrlOmitHTTP; |
| // meaningful for non-file "standard" URLs. |
| NET_EXPORT extern const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname; |
| -// Convenience for omitting all unecessary types. |
| +// Convenience for omitting all unnecessary types. |
| NET_EXPORT extern const FormatUrlType kFormatUrlOmitAll; |
| +// Remove the scheme. Callers should only specify this when it is safe to do so |
| +// (e.g. in contexts where the origin is always secure by necessity). Not part |
| +// of |kFormatUrlOmitAll|. |
| +NET_EXPORT extern const FormatUrlType kFormatUrlOmitScheme; |
| + |
| +// Remove the port. The caller should only specify this when the port is the |
| +// default for the scheme. Not part of |kFormatUrlOmitAll|. |
| +NET_EXPORT extern const FormatUrlType kFormatUrlOmitPort; |
| + |
| // Returns the number of explicitly allowed ports; for testing. |
| NET_EXPORT_PRIVATE extern size_t GetCountOfExplicitlyAllowedPorts(); |
| -// Splits an input of the form <host>[":"<port>] into its consitituent parts. |
| +// Splits an input of the form <host>[":"<port>] into its constituent parts. |
| // Saves the result into |*host| and |*port|. If the input did not have |
| // the optional port, sets |*port| to -1. |
| // Returns true if the parsing was successful, false otherwise. |
| @@ -105,13 +114,13 @@ NET_EXPORT std::string GetHostAndPort(const GURL& url); |
| NET_EXPORT_PRIVATE std::string GetHostAndOptionalPort(const GURL& url); |
| // Returns true if |hostname| contains a non-registerable or non-assignable |
| -// domain name (eg: a gTLD that has not been assigned by IANA) or an IP address |
| -// that falls in an IANA-reserved range. |
| +// domain name (e.g.: a gTLD that has not been assigned by IANA) or an IP |
| +// address that falls in an IANA-reserved range. |
| NET_EXPORT bool IsHostnameNonUnique(const std::string& hostname); |
| // Returns true if an IP address hostname is in a range reserved by the IANA. |
| // Works with both IPv4 and IPv6 addresses, and only compares against a given |
| -// protocols's reserved ranges. |
| +// protocol's reserved ranges. |
| NET_EXPORT bool IsIPAddressReserved(const IPAddressNumber& address); |
| // Convenience struct for when you need a |struct sockaddr|. |
| @@ -339,6 +348,21 @@ inline base::string16 FormatUrl(const GURL& url, const std::string& languages) { |
| NULL, NULL, NULL); |
| } |
| +// This is a convenience function for formatting a URL as an origin in a concise |
| +// and human-friendly way. Use this instead of |FormatUrl| when the reader needs |
| +// only to understand the origin (rather than the entire URL). |
| +// |
| +// - Omits the path for standard schemes, excepting file and filesystem. |
| +// - Omits the port if it is the default for the scheme. |
| +// |
| +// Do not use this for URLs which will be parsed or sent to other applications. |
| +// |
| +// Callers should only set |omit_scheme| to true when it is safe to do so (e.g. |
| +// in contexts where the origin is always secure by necessity). |
|
felt
2015/05/13 22:50:14
Should the flag actually be omit_scheme_if_secure
palmer
2015/05/14 18:18:01
I'd like to leave that to the caller to decide, e.
felt
2015/05/14 18:22:13
I'm guessing that callers will be using this becau
|
| +NET_EXPORT base::string16 FormatOriginForDisplay(const GURL& origin, |
| + const std::string& languages, |
| + bool omit_scheme); |
| + |
| // Returns whether FormatUrl() would strip a trailing slash from |url|, given a |
| // format flag including kFormatUrlOmitTrailingSlashOnBareHostname. |
| NET_EXPORT bool CanStripTrailingSlash(const GURL& url); |
| @@ -441,7 +465,7 @@ NET_EXPORT_PRIVATE bool IsLocalhost(const std::string& host); |
| NET_EXPORT_PRIVATE bool IsLocalhostTLD(const std::string& host); |
| -// Returns true if the url's host is a Google server. This should only be used |
| +// Returns true if the URL's host is a Google server. This should only be used |
| // for histograms and shouldn't be used to affect behavior. |
| NET_EXPORT_PRIVATE bool HasGoogleHost(const GURL& url); |