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

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

Issue 1171333003: Move net::FormatUrl and friends outside of //net and into //components (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Compile fixes following rebase Created 5 years, 6 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
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 28 matching lines...) Expand all
39 struct CanonHostInfo; 39 struct CanonHostInfo;
40 struct Parsed; 40 struct Parsed;
41 } 41 }
42 42
43 namespace net { 43 namespace net {
44 44
45 // This is a "forward declaration" to avoid including ip_address_number.h 45 // This is a "forward declaration" to avoid including ip_address_number.h
46 // Keep this in sync. 46 // Keep this in sync.
47 typedef std::vector<unsigned char> IPAddressNumber; 47 typedef std::vector<unsigned char> IPAddressNumber;
48 48
49 // Used by FormatUrl to specify handling of certain parts of the url.
50 typedef uint32_t FormatUrlType;
51 typedef uint32_t FormatUrlTypes;
52
53 #if defined(OS_WIN) 49 #if defined(OS_WIN)
54 // Bluetooth address size. Windows Bluetooth is supported via winsock. 50 // Bluetooth address size. Windows Bluetooth is supported via winsock.
55 static const size_t kBluetoothAddressSize = 6; 51 static const size_t kBluetoothAddressSize = 6;
56 #endif 52 #endif
57 53
58 // Nothing is ommitted.
59 NET_EXPORT extern const FormatUrlType kFormatUrlOmitNothing;
60
61 // If set, any username and password are removed.
62 NET_EXPORT extern const FormatUrlType kFormatUrlOmitUsernamePassword;
63
64 // If the scheme is 'http://', it's removed.
65 NET_EXPORT extern const FormatUrlType kFormatUrlOmitHTTP;
66
67 // Omits the path if it is just a slash and there is no query or ref. This is
68 // meaningful for non-file "standard" URLs.
69 NET_EXPORT extern const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname;
70
71 // Convenience for omitting all unecessary types.
72 NET_EXPORT extern const FormatUrlType kFormatUrlOmitAll;
73
74 // Returns the number of explicitly allowed ports; for testing. 54 // Returns the number of explicitly allowed ports; for testing.
75 NET_EXPORT_PRIVATE extern size_t GetCountOfExplicitlyAllowedPorts(); 55 NET_EXPORT_PRIVATE extern size_t GetCountOfExplicitlyAllowedPorts();
76 56
77 // Splits an input of the form <host>[":"<port>] into its consitituent parts. 57 // Splits an input of the form <host>[":"<port>] into its consitituent parts.
78 // Saves the result into |*host| and |*port|. If the input did not have 58 // Saves the result into |*host| and |*port|. If the input did not have
79 // the optional port, sets |*port| to -1. 59 // the optional port, sets |*port| to -1.
80 // Returns true if the parsing was successful, false otherwise. 60 // Returns true if the parsing was successful, false otherwise.
81 // The returned host is NOT canonicalized, and may be invalid. 61 // The returned host is NOT canonicalized, and may be invalid.
82 // 62 //
83 // IPv6 literals must be specified in a bracketed form, for instance: 63 // IPv6 literals must be specified in a bracketed form, for instance:
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 127
148 // Returns either the host from |url|, or, if the host is empty, the full spec. 128 // Returns either the host from |url|, or, if the host is empty, the full spec.
149 NET_EXPORT std::string GetHostOrSpecFromURL(const GURL& url); 129 NET_EXPORT std::string GetHostOrSpecFromURL(const GURL& url);
150 130
151 // Return the value of the HTTP response header with name 'name'. 'headers' 131 // Return the value of the HTTP response header with name 'name'. 'headers'
152 // should be in the format that URLRequest::GetResponseHeaders() returns. 132 // should be in the format that URLRequest::GetResponseHeaders() returns.
153 // Returns the empty string if the header is not found. 133 // Returns the empty string if the header is not found.
154 NET_EXPORT std::string GetSpecificHeader(const std::string& headers, 134 NET_EXPORT std::string GetSpecificHeader(const std::string& headers,
155 const std::string& name); 135 const std::string& name);
156 136
157 // Converts the given host name to unicode characters. This can be called for
158 // any host name, if the input is not IDN or is invalid in some way, we'll just
159 // return the ASCII source so it is still usable.
160 //
161 // The input should be the canonicalized ASCII host name from GURL. This
162 // function does NOT accept UTF-8!
163 //
164 // |languages| is a comma separated list of ISO 639 language codes. It
165 // is used to determine whether a hostname is 'comprehensible' to a user
166 // who understands languages listed. |host| will be converted to a
167 // human-readable form (Unicode) ONLY when each component of |host| is
168 // regarded as 'comprehensible'. Scipt-mixing is not allowed except that
169 // Latin letters in the ASCII range can be mixed with a limited set of
170 // script-language pairs (currently Han, Kana and Hangul for zh,ja and ko).
171 // When |languages| is empty, even that mixing is not allowed.
172 NET_EXPORT base::string16 IDNToUnicode(const std::string& host,
173 const std::string& languages);
174
175 // Canonicalizes |host| and returns it. Also fills |host_info| with 137 // Canonicalizes |host| and returns it. Also fills |host_info| with
176 // IP address information. |host_info| must not be NULL. 138 // IP address information. |host_info| must not be NULL.
177 NET_EXPORT std::string CanonicalizeHost(const std::string& host, 139 NET_EXPORT std::string CanonicalizeHost(const std::string& host,
178 url::CanonHostInfo* host_info); 140 url::CanonHostInfo* host_info);
179 141
180 // Returns true if |host| is not an IP address and is compliant with a set of 142 // Returns true if |host| is not an IP address and is compliant with a set of
181 // rules based on RFC 1738 and tweaked to be compatible with the real world. 143 // rules based on RFC 1738 and tweaked to be compatible with the real world.
182 // The rules are: 144 // The rules are:
183 // * One or more components separated by '.' 145 // * One or more components separated by '.'
184 // * Each component contains only alphanumeric characters and '-' or '_' 146 // * Each component contains only alphanumeric characters and '-' or '_'
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 // is PORT_OVERIDES_ALLOWED, then ports set as allowed with 194 // is PORT_OVERIDES_ALLOWED, then ports set as allowed with
233 // SetExplicitlyAllowedPorts() or by using ScopedPortException() will be 195 // SetExplicitlyAllowedPorts() or by using ScopedPortException() will be
234 // considered allowed for any scheme. 196 // considered allowed for any scheme.
235 NET_EXPORT bool IsPortAllowedForScheme(int port, 197 NET_EXPORT bool IsPortAllowedForScheme(int port,
236 const std::string& url_scheme, 198 const std::string& url_scheme,
237 PortOverrideMode port_override_mode); 199 PortOverrideMode port_override_mode);
238 200
239 // Set socket to non-blocking mode 201 // Set socket to non-blocking mode
240 NET_EXPORT int SetNonBlocking(int fd); 202 NET_EXPORT int SetNonBlocking(int fd);
241 203
242 // Formats the host in |url| and appends it to |output|. The host formatter
243 // takes the same accept languages component as ElideURL().
244 NET_EXPORT void AppendFormattedHost(const GURL& url,
245 const std::string& languages,
246 base::string16* output);
247
248 // Creates a string representation of |url|. The IDN host name may be in Unicode
249 // if |languages| accepts the Unicode representation. |format_type| is a bitmask
250 // of FormatUrlTypes, see it for details. |unescape_rules| defines how to clean
251 // the URL for human readability. You will generally want |UnescapeRule::SPACES|
252 // for display to the user if you can handle spaces, or |UnescapeRule::NORMAL|
253 // if not. If the path part and the query part seem to be encoded in %-encoded
254 // UTF-8, decodes %-encoding and UTF-8.
255 //
256 // The last three parameters may be NULL.
257 //
258 // |new_parsed| will be set to the parsing parameters of the resultant URL.
259 //
260 // |prefix_end| will be the length before the hostname of the resultant URL.
261 //
262 // |offset[s]_for_adjustment| specifies one or more offsets into the original
263 // URL, representing insertion or selection points between characters: if the
264 // input is "http://foo.com/", offset 0 is before the entire URL, offset 7 is
265 // between the scheme and the host, and offset 15 is after the end of the URL.
266 // Valid input offsets range from 0 to the length of the input URL string. On
267 // exit, each offset will have been modified to reflect any changes made to the
268 // output string. For example, if |url| is "http://a:b@c.com/",
269 // |omit_username_password| is true, and an offset is 12 (pointing between 'c'
270 // and '.'), then on return the output string will be "http://c.com/" and the
271 // offset will be 8. If an offset cannot be successfully adjusted (e.g. because
272 // it points into the middle of a component that was entirely removed or into
273 // the middle of an encoding sequence), it will be set to base::string16::npos.
274 // For consistency, if an input offset points between the scheme and the
275 // username/password, and both are removed, on output this offset will be 0
276 // rather than npos; this means that offsets at the starts and ends of removed
277 // components are always transformed the same way regardless of what other
278 // components are adjacent.
279 NET_EXPORT base::string16 FormatUrl(const GURL& url,
280 const std::string& languages,
281 FormatUrlTypes format_types,
282 UnescapeRule::Type unescape_rules,
283 url::Parsed* new_parsed,
284 size_t* prefix_end,
285 size_t* offset_for_adjustment);
286 NET_EXPORT base::string16 FormatUrlWithOffsets(
287 const GURL& url,
288 const std::string& languages,
289 FormatUrlTypes format_types,
290 UnescapeRule::Type unescape_rules,
291 url::Parsed* new_parsed,
292 size_t* prefix_end,
293 std::vector<size_t>* offsets_for_adjustment);
294 // This function is like those above except it takes |adjustments| rather
295 // than |offset[s]_for_adjustment|. |adjustments| will be set to reflect all
296 // the transformations that happened to |url| to convert it into the returned
297 // value.
298 NET_EXPORT base::string16 FormatUrlWithAdjustments(
299 const GURL& url,
300 const std::string& languages,
301 FormatUrlTypes format_types,
302 UnescapeRule::Type unescape_rules,
303 url::Parsed* new_parsed,
304 size_t* prefix_end,
305 base::OffsetAdjuster::Adjustments* adjustments);
306
307 // This is a convenience function for FormatUrl() with
308 // format_types = kFormatUrlOmitAll and unescape = SPACES. This is the typical
309 // set of flags for "URLs to display to the user". You should be cautious about
310 // using this for URLs which will be parsed or sent to other applications.
311 inline base::string16 FormatUrl(const GURL& url, const std::string& languages) {
312 return FormatUrl(url, languages, kFormatUrlOmitAll, UnescapeRule::SPACES,
313 NULL, NULL, NULL);
314 }
315
316 // Returns whether FormatUrl() would strip a trailing slash from |url|, given a
317 // format flag including kFormatUrlOmitTrailingSlashOnBareHostname.
318 NET_EXPORT bool CanStripTrailingSlash(const GURL& url);
319
320 // Strip the portions of |url| that aren't core to the network request. 204 // Strip the portions of |url| that aren't core to the network request.
321 // - user name / password 205 // - user name / password
322 // - reference section 206 // - reference section
323 NET_EXPORT_PRIVATE GURL SimplifyUrlForRequest(const GURL& url); 207 NET_EXPORT_PRIVATE GURL SimplifyUrlForRequest(const GURL& url);
324 208
325 NET_EXPORT void SetExplicitlyAllowedPorts(const std::string& allowed_ports); 209 NET_EXPORT void SetExplicitlyAllowedPorts(const std::string& allowed_ports);
326 210
327 class NET_EXPORT ScopedPortException { 211 class NET_EXPORT ScopedPortException {
328 public: 212 public:
329 explicit ScopedPortException(int port); 213 explicit ScopedPortException(int port);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 DSCP_CS5 = 40, // Video 296 DSCP_CS5 = 40, // Video
413 DSCP_EF = 46, // Voice 297 DSCP_EF = 46, // Voice
414 DSCP_CS6 = 48, // Voice 298 DSCP_CS6 = 48, // Voice
415 DSCP_CS7 = 56, // Control messages 299 DSCP_CS7 = 56, // Control messages
416 DSCP_LAST = DSCP_CS7 300 DSCP_LAST = DSCP_CS7
417 }; 301 };
418 302
419 } // namespace net 303 } // namespace net
420 304
421 #endif // NET_BASE_NET_UTIL_H_ 305 #endif // NET_BASE_NET_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698