OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // url_formatter contains routines for formatting URLs in a way that can be | 5 // url_formatter contains routines for formatting URLs in a way that can be |
6 // safely and securely displayed to users. For example, it is responsible | 6 // safely and securely displayed to users. For example, it is responsible |
7 // for determining when to convert an IDN A-Label (e.g. "xn--[something]") | 7 // for determining when to convert an IDN A-Label (e.g. "xn--[something]") |
8 // into the IDN U-Label. | 8 // into the IDN U-Label. |
9 // | 9 // |
10 // Note that this formatting is only intended for display purposes; it would | 10 // Note that this formatting is only intended for display purposes; it would |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // If the scheme is 'http://', it's removed. | 45 // If the scheme is 'http://', it's removed. |
46 extern const FormatUrlType kFormatUrlOmitHTTP; | 46 extern const FormatUrlType kFormatUrlOmitHTTP; |
47 | 47 |
48 // Omits the path if it is just a slash and there is no query or ref. This is | 48 // Omits the path if it is just a slash and there is no query or ref. This is |
49 // meaningful for non-file "standard" URLs. | 49 // meaningful for non-file "standard" URLs. |
50 extern const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname; | 50 extern const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname; |
51 | 51 |
52 // Convenience for omitting all unecessary types. | 52 // Convenience for omitting all unecessary types. |
53 extern const FormatUrlType kFormatUrlOmitAll; | 53 extern const FormatUrlType kFormatUrlOmitAll; |
54 | 54 |
55 // Creates a string representation of |url|. The IDN host name may be in Unicode | 55 // Creates a string representation of |url|. The IDN host name is turned to |
56 // if |languages| accepts the Unicode representation. |format_type| is a bitmask | 56 // Unicode if the Unicode representation is deemed safe. |languages| is not |
| 57 // used any more and will be removed. |format_type| is a bitmask |
57 // of FormatUrlTypes, see it for details. |unescape_rules| defines how to clean | 58 // of FormatUrlTypes, see it for details. |unescape_rules| defines how to clean |
58 // the URL for human readability. You will generally want |UnescapeRule::SPACES| | 59 // the URL for human readability. You will generally want |UnescapeRule::SPACES| |
59 // for display to the user if you can handle spaces, or |UnescapeRule::NORMAL| | 60 // for display to the user if you can handle spaces, or |UnescapeRule::NORMAL| |
60 // if not. If the path part and the query part seem to be encoded in %-encoded | 61 // if not. If the path part and the query part seem to be encoded in %-encoded |
61 // UTF-8, decodes %-encoding and UTF-8. | 62 // UTF-8, decodes %-encoding and UTF-8. |
62 // | 63 // |
63 // The last three parameters may be NULL. | 64 // The last three parameters may be NULL. |
64 // | 65 // |
65 // |new_parsed| will be set to the parsing parameters of the resultant URL. | 66 // |new_parsed| will be set to the parsing parameters of the resultant URL. |
66 // | 67 // |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 inline base::string16 FormatUrl(const GURL& url, const std::string& languages) { | 121 inline base::string16 FormatUrl(const GURL& url, const std::string& languages) { |
121 return FormatUrl(url, languages, kFormatUrlOmitAll, net::UnescapeRule::SPACES, | 122 return FormatUrl(url, languages, kFormatUrlOmitAll, net::UnescapeRule::SPACES, |
122 nullptr, nullptr, nullptr); | 123 nullptr, nullptr, nullptr); |
123 } | 124 } |
124 | 125 |
125 // Returns whether FormatUrl() would strip a trailing slash from |url|, given a | 126 // Returns whether FormatUrl() would strip a trailing slash from |url|, given a |
126 // format flag including kFormatUrlOmitTrailingSlashOnBareHostname. | 127 // format flag including kFormatUrlOmitTrailingSlashOnBareHostname. |
127 bool CanStripTrailingSlash(const GURL& url); | 128 bool CanStripTrailingSlash(const GURL& url); |
128 | 129 |
129 // Formats the host in |url| and appends it to |output|. The host formatter | 130 // Formats the host in |url| and appends it to |output|. The host formatter |
130 // takes the same accept languages component as ElideURL(). | 131 // takes the same accept languages component as ElideURL(), but it does not |
| 132 // affect the result. It'll be removed. |
131 void AppendFormattedHost(const GURL& url, | 133 void AppendFormattedHost(const GURL& url, |
132 const std::string& languages, | 134 const std::string& languages, |
133 base::string16* output); | 135 base::string16* output); |
134 | 136 |
135 // Converts the given host name to unicode characters. This can be called for | 137 // Converts the given host name to unicode characters. This can be called for |
136 // any host name, if the input is not IDN or is invalid in some way, we'll just | 138 // any host name, if the input is not IDN or is invalid in some way, we'll just |
137 // return the ASCII source so it is still usable. | 139 // return the ASCII source so it is still usable. |
138 // | 140 // |
139 // The input should be the canonicalized ASCII host name from GURL. This | 141 // The input should be the canonicalized ASCII host name from GURL. This |
140 // function does NOT accept UTF-8! | 142 // function does NOT accept UTF-8! |
141 // | 143 // |languages| is not used any more and will be removed. |
142 // |languages| is a comma separated list of ISO 639 language codes. It | |
143 // is used to determine whether a hostname is 'comprehensible' to a user | |
144 // who understands languages listed. |host| will be converted to a | |
145 // human-readable form (Unicode) ONLY when each component of |host| is | |
146 // regarded as 'comprehensible'. Scipt-mixing is not allowed except that | |
147 // Latin letters in the ASCII range can be mixed with a limited set of | |
148 // script-language pairs (currently Han, Kana and Hangul for zh,ja and ko). | |
149 // When |languages| is empty, even that mixing is not allowed. | |
150 base::string16 IDNToUnicode(const std::string& host, | 144 base::string16 IDNToUnicode(const std::string& host, |
151 const std::string& languages); | 145 const std::string& languages); |
152 | 146 |
153 } // url_formatter | 147 } // url_formatter |
154 | 148 |
155 #endif // COMPONENTS_URL_FORMATTER_URL_FORMATTER_H_ | 149 #endif // COMPONENTS_URL_FORMATTER_URL_FORMATTER_H_ |
OLD | NEW |