OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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> |
12 #endif | 12 #endif |
13 | 13 |
14 #include <string> | 14 #include <string> |
15 | 15 |
16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
17 | 17 |
18 struct addrinfo; | 18 struct addrinfo; |
19 class FilePath; | 19 class FilePath; |
20 class GURL; | 20 class GURL; |
21 | 21 |
22 namespace base { | 22 namespace base { |
23 class Time; | 23 class Time; |
24 } | 24 } |
25 | 25 |
| 26 namespace url_parse { |
| 27 struct Parsed; |
| 28 } |
| 29 |
26 namespace net { | 30 namespace net { |
27 | 31 |
28 // Given the full path to a file name, creates a file: URL. The returned URL | 32 // Given the full path to a file name, creates a file: URL. The returned URL |
29 // may not be valid if the input is malformed. | 33 // may not be valid if the input is malformed. |
30 GURL FilePathToFileURL(const FilePath& path); | 34 GURL FilePathToFileURL(const FilePath& path); |
31 | 35 |
32 // Converts a file: URL back to a filename that can be passed to the OS. The | 36 // Converts a file: URL back to a filename that can be passed to the OS. The |
33 // file URL must be well-formed (GURL::is_valid() must return true); we don't | 37 // file URL must be well-formed (GURL::is_valid() must return true); we don't |
34 // handle degenerate cases here. Returns true on success, false if it isn't a | 38 // handle degenerate cases here. Returns true on success, false if it isn't a |
35 // valid file URL. On failure, *file_path will be empty. | 39 // valid file URL. On failure, *file_path will be empty. |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 bool IsPortAllowedByDefault(int port); | 160 bool IsPortAllowedByDefault(int port); |
157 | 161 |
158 // Checks the given port against a list of ports which are restricted by the | 162 // Checks the given port against a list of ports which are restricted by the |
159 // FTP protocol. Returns true if the port is allowed, false if it is | 163 // FTP protocol. Returns true if the port is allowed, false if it is |
160 // restricted. | 164 // restricted. |
161 bool IsPortAllowedByFtp(int port); | 165 bool IsPortAllowedByFtp(int port); |
162 | 166 |
163 // Set socket to non-blocking mode | 167 // Set socket to non-blocking mode |
164 int SetNonBlocking(int fd); | 168 int SetNonBlocking(int fd); |
165 | 169 |
| 170 // Appends the given part of the original URL to the output string formatted for |
| 171 // the user. The given parsed structure will be updated. The host name formatter |
| 172 // also takes the same accept languages component as ElideURL. |new_parsed| may |
| 173 // be null. |
| 174 void AppendFormattedHost(const GURL& url, const std::wstring& languages, |
| 175 std::wstring* output, url_parse::Parsed* new_parsed); |
| 176 |
| 177 // Creates a string representation of |url|. The IDN host name may |
| 178 // be in Unicode if |languages| accepts the Unicode representation. |
| 179 // If |omit_username_password| is true, the username and the password are |
| 180 // omitted. If |unescape| is true and the path part and the query part seem to |
| 181 // be encoded in %-encoded UTF-8, decodes %-encoding and UTF-8. |
| 182 // |new_parsed| will have parsing parameters of the resultant URL. |prefix_end| |
| 183 // will be the length before the hostname of the resultant URL. |new_parsed| |
| 184 // and |prefix_end| may be NULL. |
| 185 std::wstring FormatUrl(const GURL& url, |
| 186 const std::wstring& languages, |
| 187 bool omit_username_password, |
| 188 bool unescape, |
| 189 url_parse::Parsed* new_parsed, |
| 190 size_t* prefix_end); |
| 191 |
| 192 // Creates a string representation of |url| for display to the user. |
| 193 // This is a shorthand of the above function with omit_username_password=true, |
| 194 // unescape=true, new_parsed=NULL, and prefix_end=NULL. |
| 195 inline std::wstring FormatUrl(const GURL& url, const std::wstring& languages) { |
| 196 return FormatUrl(url, languages, true, true, NULL, NULL); |
| 197 } |
| 198 |
166 } // namespace net | 199 } // namespace net |
167 | 200 |
168 #endif // NET_BASE_NET_UTIL_H__ | 201 #endif // NET_BASE_NET_UTIL_H__ |
OLD | NEW |