OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifdef OS_WIN | 10 #ifdef OS_WIN |
11 #include <windows.h> | 11 #include <windows.h> |
(...skipping 17 matching lines...) Expand all Loading... |
29 namespace url_canon { | 29 namespace url_canon { |
30 struct CanonHostInfo; | 30 struct CanonHostInfo; |
31 } | 31 } |
32 | 32 |
33 namespace url_parse { | 33 namespace url_parse { |
34 struct Parsed; | 34 struct Parsed; |
35 } | 35 } |
36 | 36 |
37 namespace net { | 37 namespace net { |
38 | 38 |
| 39 // Used by FormatUrl to specify handling of certain parts of the url. |
| 40 typedef uint32 FormatUrlType; |
| 41 typedef uint32 FormatUrlTypes; |
| 42 |
| 43 // Nothing is ommitted. |
| 44 extern const FormatUrlType kFormatUrlOmitNothing; |
| 45 |
| 46 // If set, any username and password are removed. |
| 47 extern const FormatUrlType kFormatUrlOmitUsernamePassword; |
| 48 |
| 49 // If the scheme is 'http://', it's removed. |
| 50 extern const FormatUrlType kFormatUrlOmitHTTP; |
| 51 |
| 52 // Convenience for omitting all unecessary types. |
| 53 extern const FormatUrlType kFormatUrlOmitAll; |
| 54 |
39 // Holds a list of ports that should be accepted despite bans. | 55 // Holds a list of ports that should be accepted despite bans. |
40 extern std::set<int> explicitly_allowed_ports; | 56 extern std::set<int> explicitly_allowed_ports; |
41 | 57 |
42 // Given the full path to a file name, creates a file: URL. The returned URL | 58 // Given the full path to a file name, creates a file: URL. The returned URL |
43 // may not be valid if the input is malformed. | 59 // may not be valid if the input is malformed. |
44 GURL FilePathToFileURL(const FilePath& path); | 60 GURL FilePathToFileURL(const FilePath& path); |
45 | 61 |
46 // Converts a file: URL back to a filename that can be passed to the OS. The | 62 // Converts a file: URL back to a filename that can be passed to the OS. The |
47 // file URL must be well-formed (GURL::is_valid() must return true); we don't | 63 // file URL must be well-formed (GURL::is_valid() must return true); we don't |
48 // handle degenerate cases here. Returns true on success, false if it isn't a | 64 // handle degenerate cases here. Returns true on success, false if it isn't a |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 // the user. The given parsed structure will be updated. The host name formatter | 254 // the user. The given parsed structure will be updated. The host name formatter |
239 // also takes the same accept languages component as ElideURL. |new_parsed| may | 255 // also takes the same accept languages component as ElideURL. |new_parsed| may |
240 // be null. | 256 // be null. |
241 void AppendFormattedHost(const GURL& url, | 257 void AppendFormattedHost(const GURL& url, |
242 const std::wstring& languages, | 258 const std::wstring& languages, |
243 std::wstring* output, | 259 std::wstring* output, |
244 url_parse::Parsed* new_parsed, | 260 url_parse::Parsed* new_parsed, |
245 size_t* offset_for_adjustment); | 261 size_t* offset_for_adjustment); |
246 | 262 |
247 // Creates a string representation of |url|. The IDN host name may be in Unicode | 263 // Creates a string representation of |url|. The IDN host name may be in Unicode |
248 // if |languages| accepts the Unicode representation. If | 264 // if |languages| accepts the Unicode representation. |format_type| is a bitmask |
249 // |omit_username_password| is true, any username and password are removed. | 265 // of FormatUrlTypes, see it for details. |unescape_rules| defines how to clean |
250 // |unescape_rules| defines how to clean the URL for human readability. | 266 // the URL for human readability. You will generally want |UnescapeRule::SPACES| |
251 // You will generally want |UnescapeRule::SPACES| for display to the user if you | 267 // for display to the user if you can handle spaces, or |UnescapeRule::NORMAL| |
252 // can handle spaces, or |UnescapeRule::NORMAL| if not. If the path part and the | 268 // if not. If the path part and the query part seem to be encoded in %-encoded |
253 // query part seem to be encoded in %-encoded UTF-8, decodes %-encoding and | 269 // UTF-8, decodes %-encoding and UTF-8. |
254 // UTF-8. | |
255 // | 270 // |
256 // The last three parameters may be NULL. | 271 // The last three parameters may be NULL. |
257 // |new_parsed| will be set to the parsing parameters of the resultant URL. | 272 // |new_parsed| will be set to the parsing parameters of the resultant URL. |
258 // |prefix_end| will be the length before the hostname of the resultant URL. | 273 // |prefix_end| will be the length before the hostname of the resultant URL. |
259 // |offset_for_adjustment| is an offset into the original |url|'s spec(), which | 274 // |offset_for_adjustment| is an offset into the original |url|'s spec(), which |
260 // will be modified to reflect changes this function makes to the output string; | 275 // will be modified to reflect changes this function makes to the output string; |
261 // for example, if |url| is "http://a:b@c.com/", |omit_username_password| is | 276 // for example, if |url| is "http://a:b@c.com/", |omit_username_password| is |
262 // true, and |offset_for_adjustment| is 12 (the offset of '.'), then on return | 277 // true, and |offset_for_adjustment| is 12 (the offset of '.'), then on return |
263 // the output string will be "http://c.com/" and |offset_for_adjustment| will be | 278 // the output string will be "http://c.com/" and |offset_for_adjustment| will be |
264 // 8. If the offset cannot be successfully adjusted (e.g. because it points | 279 // 8. If the offset cannot be successfully adjusted (e.g. because it points |
265 // into the middle of a component that was entirely removed, past the end of the | 280 // into the middle of a component that was entirely removed, past the end of the |
266 // string, or into the middle of an encoding sequence), it will be set to | 281 // string, or into the middle of an encoding sequence), it will be set to |
267 // std::wstring::npos. | 282 // std::wstring::npos. |
268 std::wstring FormatUrl(const GURL& url, | 283 std::wstring FormatUrl(const GURL& url, |
269 const std::wstring& languages, | 284 const std::wstring& languages, |
270 bool omit_username_password, | 285 FormatUrlTypes format_types, |
271 UnescapeRule::Type unescape_rules, | 286 UnescapeRule::Type unescape_rules, |
272 url_parse::Parsed* new_parsed, | 287 url_parse::Parsed* new_parsed, |
273 size_t* prefix_end, | 288 size_t* prefix_end, |
274 size_t* offset_for_adjustment); | 289 size_t* offset_for_adjustment); |
275 | 290 |
276 // Creates a string representation of |url| for display to the user. | 291 // This is a convenience for FormatUrl with |
277 // This is a shorthand of the above function with omit_username_password=true, | 292 // format_types=kFormatUrlOmitUsernamePassword and unescape=SPACES. |
278 // unescape=SPACES, new_parsed=NULL, and prefix_end=NULL. | |
279 inline std::wstring FormatUrl(const GURL& url, const std::wstring& languages) { | 293 inline std::wstring FormatUrl(const GURL& url, const std::wstring& languages) { |
280 return FormatUrl(url, languages, true, UnescapeRule::SPACES, NULL, NULL, | 294 return FormatUrl(url, languages, kFormatUrlOmitUsernamePassword, |
281 NULL); | 295 UnescapeRule::SPACES, NULL, NULL, NULL); |
282 } | 296 } |
283 | 297 |
284 // Strip the portions of |url| that aren't core to the network request. | 298 // Strip the portions of |url| that aren't core to the network request. |
285 // - user name / password | 299 // - user name / password |
286 // - reference section | 300 // - reference section |
287 GURL SimplifyUrlForRequest(const GURL& url); | 301 GURL SimplifyUrlForRequest(const GURL& url); |
288 | 302 |
289 void SetExplicitlyAllowedPorts(const std::wstring& allowed_ports); | 303 void SetExplicitlyAllowedPorts(const std::wstring& allowed_ports); |
290 | 304 |
291 // Perform a simplistic test to see if IPv6 is supported by trying to create an | 305 // Perform a simplistic test to see if IPv6 is supported by trying to create an |
292 // IPv6 socket. | 306 // IPv6 socket. |
293 // TODO(jar): Make test more in-depth as needed. | 307 // TODO(jar): Make test more in-depth as needed. |
294 bool IPv6Supported(); | 308 bool IPv6Supported(); |
295 | 309 |
296 } // namespace net | 310 } // namespace net |
297 | 311 |
298 #endif // NET_BASE_NET_UTIL_H_ | 312 #endif // NET_BASE_NET_UTIL_H_ |
OLD | NEW |