OLD | NEW |
---|---|
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 unecessary 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 // Remove the scheme. The caller should only specify kFormatUrlOmitScheme | |
78 // after verifying that it is secure to do so. Not part of kFormatUrlOmitAll. | |
79 NET_EXPORT extern const FormatUrlType kFormatUrlOmitScheme; | |
80 | |
81 // Remove the port. The caller should only specify kFormatUrlOmitPort | |
82 // after verifying that it is secure to do so. Not part of kFormatUrlOmitAll. | |
Ryan Sleevi
2014/09/02 19:26:17
This is... vaguely worded.
When is it ever secure
| |
83 NET_EXPORT extern const FormatUrlType kFormatUrlOmitPort; | |
84 | |
77 // Returns the number of explicitly allowed ports; for testing. | 85 // Returns the number of explicitly allowed ports; for testing. |
78 NET_EXPORT_PRIVATE extern size_t GetCountOfExplicitlyAllowedPorts(); | 86 NET_EXPORT_PRIVATE extern size_t GetCountOfExplicitlyAllowedPorts(); |
79 | 87 |
80 // Splits an input of the form <host>[":"<port>] into its consitituent parts. | 88 // 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 | 89 // Saves the result into |*host| and |*port|. If the input did not have |
82 // the optional port, sets |*port| to -1. | 90 // the optional port, sets |*port| to -1. |
83 // Returns true if the parsing was successful, false otherwise. | 91 // Returns true if the parsing was successful, false otherwise. |
84 // The returned host is NOT canonicalized, and may be invalid. If <host> is | 92 // The returned host is NOT canonicalized, and may be invalid. If <host> is |
85 // an IPv6 literal address, the returned host includes the square brackets. | 93 // an IPv6 literal address, the returned host includes the square brackets. |
86 NET_EXPORT bool ParseHostAndPort( | 94 NET_EXPORT bool ParseHostAndPort( |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 NET_EXPORT_PRIVATE bool IsPortAllowedByFtp(int port); | 266 NET_EXPORT_PRIVATE bool IsPortAllowedByFtp(int port); |
259 | 267 |
260 // Check if banned |port| has been overriden by an entry in | 268 // Check if banned |port| has been overriden by an entry in |
261 // |explicitly_allowed_ports_|. | 269 // |explicitly_allowed_ports_|. |
262 NET_EXPORT_PRIVATE bool IsPortAllowedByOverride(int port); | 270 NET_EXPORT_PRIVATE bool IsPortAllowedByOverride(int port); |
263 | 271 |
264 // Set socket to non-blocking mode | 272 // Set socket to non-blocking mode |
265 NET_EXPORT int SetNonBlocking(int fd); | 273 NET_EXPORT int SetNonBlocking(int fd); |
266 | 274 |
267 // Formats the host in |url| and appends it to |output|. The host formatter | 275 // Formats the host in |url| and appends it to |output|. The host formatter |
268 // takes the same accept languages component as ElideURL(). | 276 // takes the same accept languages component as ElideURL(). |
Ryan Sleevi
2014/09/02 19:26:17
So, this is an example of the layering.
ElideURL
| |
269 NET_EXPORT void AppendFormattedHost(const GURL& url, | 277 NET_EXPORT void AppendFormattedHost(const GURL& url, |
270 const std::string& languages, | 278 const std::string& languages, |
271 base::string16* output); | 279 base::string16* output); |
272 | 280 |
273 // Creates a string representation of |url|. The IDN host name may be in Unicode | 281 // Creates a string representation of |url|. The IDN host name may be in Unicode |
274 // if |languages| accepts the Unicode representation. |format_type| is a bitmask | 282 // if |languages| accepts the Unicode representation. |format_type| is a bitmask |
275 // of FormatUrlTypes, see it for details. |unescape_rules| defines how to clean | 283 // of FormatUrlTypes, see it for details. |unescape_rules| defines how to clean |
276 // the URL for human readability. You will generally want |UnescapeRule::SPACES| | 284 // the URL for human readability. You will generally want |UnescapeRule::SPACES| |
277 // for display to the user if you can handle spaces, or |UnescapeRule::NORMAL| | 285 // for display to the user if you can handle spaces, or |UnescapeRule::NORMAL| |
278 // if not. If the path part and the query part seem to be encoded in %-encoded | 286 // if not. If the path part and the query part seem to be encoded in %-encoded |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 | 339 |
332 // This is a convenience function for FormatUrl() with | 340 // This is a convenience function for FormatUrl() with |
333 // format_types = kFormatUrlOmitAll and unescape = SPACES. This is the typical | 341 // format_types = kFormatUrlOmitAll and unescape = SPACES. This is the typical |
334 // set of flags for "URLs to display to the user". You should be cautious about | 342 // set of flags for "URLs to display to the user". You should be cautious about |
335 // using this for URLs which will be parsed or sent to other applications. | 343 // using this for URLs which will be parsed or sent to other applications. |
336 inline base::string16 FormatUrl(const GURL& url, const std::string& languages) { | 344 inline base::string16 FormatUrl(const GURL& url, const std::string& languages) { |
337 return FormatUrl(url, languages, kFormatUrlOmitAll, UnescapeRule::SPACES, | 345 return FormatUrl(url, languages, kFormatUrlOmitAll, UnescapeRule::SPACES, |
338 NULL, NULL, NULL); | 346 NULL, NULL, NULL); |
339 } | 347 } |
340 | 348 |
349 // This is a convenience function for formatting a URL as an origin for display | |
350 // in security UI: infobars, permission strings, etc. Use this instead of | |
Ryan Sleevi
2014/09/02 19:26:17
So, to re-iterate the layering, //net has no idea
felt
2014/09/15 05:42:30
Here are some files that should be refactored to c
felt
2014/09/15 22:47:55
Sleevi: what about putting this on gurl.h?
| |
351 // FormatUrl() for strings in a security UI context. Do not use this for URLs | |
352 // which will be parsed or sent to other applications. | |
353 // - The path is dropped for standard schemes, excepting file and filesystem. | |
354 // - Standard ports are removed for http and https. | |
355 // - By default, the scheme is only displayed for non-secure origins. This can | |
Michael van Ouwerkerk
2014/09/02 13:10:47
Why is https omitted by default? Haven't we been t
| |
356 // be overridden with |always_show_scheme|. | |
357 NET_EXPORT base::string16 FormatOriginForDisplay( | |
358 const GURL& origin, const std::string& languages, bool always_show_scheme); | |
359 | |
341 // Returns whether FormatUrl() would strip a trailing slash from |url|, given a | 360 // Returns whether FormatUrl() would strip a trailing slash from |url|, given a |
342 // format flag including kFormatUrlOmitTrailingSlashOnBareHostname. | 361 // format flag including kFormatUrlOmitTrailingSlashOnBareHostname. |
343 NET_EXPORT bool CanStripTrailingSlash(const GURL& url); | 362 NET_EXPORT bool CanStripTrailingSlash(const GURL& url); |
344 | 363 |
345 // Strip the portions of |url| that aren't core to the network request. | 364 // Strip the portions of |url| that aren't core to the network request. |
346 // - user name / password | 365 // - user name / password |
347 // - reference section | 366 // - reference section |
348 NET_EXPORT_PRIVATE GURL SimplifyUrlForRequest(const GURL& url); | 367 NET_EXPORT_PRIVATE GURL SimplifyUrlForRequest(const GURL& url); |
349 | 368 |
350 NET_EXPORT void SetExplicitlyAllowedPorts(const std::string& allowed_ports); | 369 NET_EXPORT void SetExplicitlyAllowedPorts(const std::string& allowed_ports); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
531 DSCP_CS5 = 40, // Video | 550 DSCP_CS5 = 40, // Video |
532 DSCP_EF = 46, // Voice | 551 DSCP_EF = 46, // Voice |
533 DSCP_CS6 = 48, // Voice | 552 DSCP_CS6 = 48, // Voice |
534 DSCP_CS7 = 56, // Control messages | 553 DSCP_CS7 = 56, // Control messages |
535 DSCP_LAST = DSCP_CS7 | 554 DSCP_LAST = DSCP_CS7 |
536 }; | 555 }; |
537 | 556 |
538 } // namespace net | 557 } // namespace net |
539 | 558 |
540 #endif // NET_BASE_NET_UTIL_H_ | 559 #endif // NET_BASE_NET_UTIL_H_ |
OLD | NEW |