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 CHROME_BROWSER_UI_ELIDE_URL_H_ | 7 #ifndef COMPONENTS_SECURE_DISPLAY_ELIDE_URL_H_ |
8 #define CHROME_BROWSER_UI_ELIDE_URL_H_ | 8 #define COMPONENTS_SECURE_DISPLAY_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 "components/secure_display/secure_display_export.h" | |
13 | 14 |
14 class GURL; | 15 class GURL; |
15 | 16 |
16 namespace gfx { | 17 namespace gfx { |
17 class FontList; | 18 class FontList; |
18 } | 19 } |
19 | 20 |
21 namespace secure_display { | |
22 | |
23 // ElideUrl and Elide host require | |
24 // gfx::GetStringWidthF which is not implemented in Android | |
25 #if !defined(OS_ANDROID) | |
20 // 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 |
21 // which composed of parts from subdomain, domain, path, filename and query. | 27 // which composed of parts from subdomain, domain, path, filename and query. |
22 // 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 |
23 // than the |available_pixel_width|. For |available_pixel_width| == 0, a | 29 // than the |available_pixel_width|. For |available_pixel_width| == 0, a |
24 // formatted, but un-elided, string is returned. |languages| is a comma | 30 // formatted, but un-elided, string is returned. |languages| is a comma |
25 // separated list of ISO 639 language codes and is used to determine what | 31 // separated list of ISO 639 language codes and is used to determine what |
26 // characters are understood by a user. It should come from | 32 // characters are understood by a user. It should come from |
27 // |prefs::kAcceptLanguages|. | 33 // |prefs::kAcceptLanguages|. |
28 // | 34 // |
29 // Note: in RTL locales, if the URL returned by this function is going to be | 35 // Note: in RTL locales, if the URL returned by this function is going to be |
30 // displayed in the UI, then it is likely that the string needs to be marked | 36 // displayed in the UI, then it is likely that the string needs to be marked |
31 // as an LTR string (using base::i18n::WrapStringWithLTRFormatting()) so that it | 37 // as an LTR string (using base::i18n::WrapStringWithLTRFormatting()) so that it |
32 // is displayed properly in an RTL context. Please refer to | 38 // is displayed properly in an RTL context. Please refer to |
33 // http://crbug.com/6487 for more information. | 39 // http://crbug.com/6487 for more information. |
34 base::string16 ElideUrl(const GURL& url, | 40 base::string16 SECURE_DISPLAY_EXPORT ElideUrl(const GURL& url, |
35 const gfx::FontList& font_list, | 41 const gfx::FontList& font_list, |
36 float available_pixel_width, | 42 float available_pixel_width, |
37 const std::string& languages); | 43 const std::string& languages); |
38 | 44 |
39 // This function takes a GURL object and elides the host to fit within | 45 // This function takes a GURL object and elides the host to fit within |
40 // the given width. The function will never elide past the TLD+1 point, | 46 // the given width. The function will never elide past the TLD+1 point, |
41 // but after that, will leading-elide the domain name to fit the width. | 47 // but after that, will leading-elide the domain name to fit the width. |
42 // Example: http://sub.domain.com ---> "...domain.com", or "...b.domain.com" | 48 // Example: http://sub.domain.com ---> "...domain.com", or "...b.domain.com" |
43 // depending on the width. | 49 // depending on the width. |
44 base::string16 ElideHost(const GURL& host_url, | 50 base::string16 SECURE_DISPLAY_EXPORT ElideHost(const GURL& host_url, |
45 const gfx::FontList& font_list, | 51 const gfx::FontList& font_list, |
46 float available_pixel_width); | 52 float available_pixel_width); |
53 #endif | |
47 | 54 |
48 // This is a convenience function for formatting a URL in a concise and | 55 // This is a convenience function for formatting a URL in a concise and |
49 // human-friendly way, to help users make security-related decisions (or in | 56 // human-friendly way, to help users make security-related decisions (or in |
50 // other circumstances when people need to distinguish sites, origins, or | 57 // other circumstances when people need to distinguish sites, origins, or |
51 // otherwise-simplified URLs from each other). | 58 // otherwise-simplified URLs from each other). |
52 // | 59 // |
53 // Internationalized domain names (IDN) may be presented in Unicode if | 60 // Internationalized domain names (IDN) may be presented in Unicode if |
54 // |languages| accepts the Unicode representation (see |net::FormatUrl| for more | 61 // |languages| accepts the Unicode representation (see |net::FormatUrl| for more |
55 // details on the algorithm). | 62 // details on the algorithm). |
56 // | 63 // |
57 // - Omits the path for standard schemes, excepting file and filesystem. | 64 // - Omits the path for standard schemes, excepting file and filesystem. |
58 // - Omits the port if it is the default for the scheme. | 65 // - Omits the port if it is the default for the scheme. |
59 // | 66 // |
60 // Do not use this for URLs which will be parsed or sent to other applications. | 67 // Do not use this for URLs which will be parsed or sent to other applications. |
61 base::string16 FormatUrlForSecurityDisplay(const GURL& origin, | 68 base::string16 SECURE_DISPLAY_EXPORT |
62 const std::string& languages); | 69 FormatUrlForSecurityDisplay(const GURL& origin, const std::string& languages); |
63 | 70 |
64 #endif // CHROME_BROWSER_UI_ELIDE_URL_H_ | 71 } // namespace |
noyau (Ping after 24h)
2015/07/22 09:44:00
nit:
// namespace secure_display
| |
72 | |
73 #endif // COMPONENTS_SECURE_DISPLAY_ELIDE_URL_H_ | |
OLD | NEW |