OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // This file defines utility functions for eliding URLs. | 5 // This file defines utility functions for eliding URLs. |
6 | 6 |
7 #ifndef COMPONENTS_URL_FORMATTER_ELIDE_URL_H_ | 7 #ifndef COMPONENTS_URL_FORMATTER_ELIDE_URL_H_ |
8 #define COMPONENTS_URL_FORMATTER_ELIDE_URL_H_ | 8 #define COMPONENTS_URL_FORMATTER_ELIDE_URL_H_ |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 | 14 |
15 class GURL; | 15 class GURL; |
16 | 16 |
17 namespace gfx { | 17 namespace gfx { |
18 class FontList; | 18 class FontList; |
19 } | 19 } |
20 | 20 |
21 namespace url_formatter { | 21 namespace url_formatter { |
22 | 22 |
23 // ElideUrl and Elide host require | 23 // ElideUrl and Elide host require |
24 // gfx::GetStringWidthF which is not implemented in Android | 24 // gfx::GetStringWidthF which is not implemented in Android |
25 #if !defined(OS_ANDROID) | 25 #if !defined(OS_ANDROID) |
26 // This function takes a GURL object and elides it. It returns a string | 26 // This function takes a GURL object and elides it. It returns a string |
27 // which composed of parts from subdomain, domain, path, filename and query. | 27 // which composed of parts from subdomain, domain, path, filename and query. |
28 // A "..." is added automatically at the end if the elided string is bigger | 28 // A "..." is added automatically at the end if the elided string is bigger |
29 // than the |available_pixel_width|. For |available_pixel_width| == 0, a | 29 // than the |available_pixel_width|. For |available_pixel_width| == 0, a |
30 // formatted, but un-elided, string is returned. |languages| is a comma | 30 // formatted, but un-elided, string is returned. |
31 // separated list of ISO 639 language codes and is used to determine what | |
32 // characters are understood by a user. It should come from | |
33 // |prefs::kAcceptLanguages|. | |
34 // | 31 // |
35 // Note: in RTL locales, if the URL returned by this function is going to be | 32 // Note: in RTL locales, if the URL returned by this function is going to be |
36 // displayed in the UI, then it is likely that the string needs to be marked | 33 // displayed in the UI, then it is likely that the string needs to be marked |
37 // as an LTR string (using base::i18n::WrapStringWithLTRFormatting()) so that it | 34 // as an LTR string (using base::i18n::WrapStringWithLTRFormatting()) so that it |
38 // is displayed properly in an RTL context. Please refer to | 35 // is displayed properly in an RTL context. Please refer to |
39 // http://crbug.com/6487 for more information. | 36 // http://crbug.com/6487 for more information. |
40 base::string16 ElideUrl(const GURL& url, | 37 base::string16 ElideUrl(const GURL& url, |
41 const gfx::FontList& font_list, | 38 const gfx::FontList& font_list, |
42 float available_pixel_width, | 39 float available_pixel_width); |
43 const std::string& languages); | |
44 | 40 |
45 // This function takes a GURL object and elides the host to fit within | 41 // This function takes a GURL object and elides the host to fit within |
46 // the given width. The function will never elide past the TLD+1 point, | 42 // the given width. The function will never elide past the TLD+1 point, |
47 // but after that, will leading-elide the domain name to fit the width. | 43 // but after that, will leading-elide the domain name to fit the width. |
48 // Example: http://sub.domain.com ---> "...domain.com", or "...b.domain.com" | 44 // Example: http://sub.domain.com ---> "...domain.com", or "...b.domain.com" |
49 // depending on the width. | 45 // depending on the width. |
50 base::string16 ElideHost(const GURL& host_url, | 46 base::string16 ElideHost(const GURL& host_url, |
51 const gfx::FontList& font_list, | 47 const gfx::FontList& font_list, |
52 float available_pixel_width); | 48 float available_pixel_width); |
53 #endif // !defined(OS_ANDROID) | 49 #endif // !defined(OS_ANDROID) |
54 | 50 |
55 // This is a convenience function for formatting a URL in a concise and | 51 // This is a convenience function for formatting a URL in a concise and |
56 // human-friendly way, to help users make security-related decisions (or in | 52 // human-friendly way, to help users make security-related decisions (or in |
57 // other circumstances when people need to distinguish sites, origins, or | 53 // other circumstances when people need to distinguish sites, origins, or |
58 // otherwise-simplified URLs from each other). | 54 // otherwise-simplified URLs from each other). |
59 // | 55 // |
60 // Internationalized domain names (IDN) may be presented in Unicode if | 56 // Internationalized domain names (IDN) may be presented in Unicode if |
61 // |languages| accepts the Unicode representation (see | 57 // they're regarded safe. See |url_formatter::FormatUrl| for more details on |
62 // |url_formatter::FormatUrl| for more details on the algorithm). | 58 // the algorithm). |
63 // | 59 // |
64 // - Omits the path for standard schemes, excepting file and filesystem. | 60 // - Omits the path for standard schemes, excepting file and filesystem. |
65 // - Omits the port if it is the default for the scheme. | 61 // - Omits the port if it is the default for the scheme. |
66 // | 62 // |
67 // Do not use this for URLs which will be parsed or sent to other applications. | 63 // Do not use this for URLs which will be parsed or sent to other applications. |
68 // | 64 // |
69 // Generally, set prefer this function to | 65 // Generally, set prefer this function to |
70 // |FormatUrlForSecurityDisplayOmitScheme| unless there is plenty of indication | 66 // |FormatUrlForSecurityDisplayOmitScheme| unless there is plenty of indication |
71 // as to whether the origin is secure elsewhere in the UX. For example, in | 67 // as to whether the origin is secure elsewhere in the UX. For example, in |
72 // Chrome's Origin Info Bubble, there are icons and strings indicating origin | 68 // Chrome's Origin Info Bubble, there are icons and strings indicating origin |
73 // (non-)security. But in the HTTP Basic Auth prompt (for example), the scheme | 69 // (non-)security. But in the HTTP Basic Auth prompt (for example), the scheme |
74 // may be the only indicator. | 70 // may be the only indicator. |
75 base::string16 FormatUrlForSecurityDisplay(const GURL& origin, | 71 base::string16 FormatUrlForSecurityDisplay(const GURL& origin); |
76 const std::string& languages); | |
77 | 72 |
78 // Just like |FormatUrlForSecurityDisplay|, but also: | 73 // Just like |FormatUrlForSecurityDisplay|, but also: |
79 // | 74 // |
80 // - Omits the scheme if SchemeIsHTTPOrHTTPS(). | 75 // - Omits the scheme if SchemeIsHTTPOrHTTPS(). |
81 base::string16 FormatUrlForSecurityDisplayOmitScheme( | 76 base::string16 FormatUrlForSecurityDisplayOmitScheme(const GURL& origin); |
82 const GURL& origin, | |
83 const std::string& languages); | |
84 | 77 |
85 } // namespace url_formatter | 78 } // namespace url_formatter |
86 | 79 |
87 #endif // COMPONENTS_URL_FORMATTER_ELIDE_URL_H_ | 80 #endif // COMPONENTS_URL_FORMATTER_ELIDE_URL_H_ |
OLD | NEW |