| 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> |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 // 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 |
| 42 // 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, |
| 43 // 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. |
| 44 // Example: http://sub.domain.com ---> "...domain.com", or "...b.domain.com" | 44 // Example: http://sub.domain.com ---> "...domain.com", or "...b.domain.com" |
| 45 // depending on the width. | 45 // depending on the width. |
| 46 base::string16 ElideHost(const GURL& host_url, | 46 base::string16 ElideHost(const GURL& host_url, |
| 47 const gfx::FontList& font_list, | 47 const gfx::FontList& font_list, |
| 48 float available_pixel_width); | 48 float available_pixel_width); |
| 49 #endif // !defined(OS_ANDROID) | 49 #endif // !defined(OS_ANDROID) |
| 50 | 50 |
| 51 enum class SchemeDisplay { |
| 52 SHOW, |
| 53 OMIT_HTTP_AND_HTTPS, |
| 54 // Omit cryptographic (i.e. https and wss). |
| 55 OMIT_CRYPTOGRAPHIC, |
| 56 }; |
| 57 |
| 51 // This is a convenience function for formatting a URL in a concise and | 58 // This is a convenience function for formatting a URL in a concise and |
| 52 // human-friendly way, to help users make security-related decisions (or in | 59 // human-friendly way, to help users make security-related decisions (or in |
| 53 // other circumstances when people need to distinguish sites, origins, or | 60 // other circumstances when people need to distinguish sites, origins, or |
| 54 // otherwise-simplified URLs from each other). | 61 // otherwise-simplified URLs from each other). |
| 55 // | 62 // |
| 56 // Internationalized domain names (IDN) may be presented in Unicode if | 63 // Internationalized domain names (IDN) may be presented in Unicode if |
| 57 // they're regarded safe. See |url_formatter::FormatUrl| for more details on | 64 // they're regarded safe. See |url_formatter::FormatUrl| for more details on |
| 58 // the algorithm). | 65 // the algorithm). |
| 59 // | 66 // |
| 60 // - Omits the path for standard schemes, excepting file and filesystem. | 67 // - Omits the path for standard schemes, excepting file and filesystem. |
| 61 // - Omits the port if it is the default for the scheme. | 68 // - Omits the port if it is the default for the scheme. |
| 62 // | 69 // |
| 63 // Do not use this for URLs which will be parsed or sent to other applications. | 70 // Do not use this for URLs which will be parsed or sent to other applications. |
| 64 // | 71 // |
| 65 // Generally, set prefer this function to | 72 // Generally, prefer SchemeDisplay::SHOW to omitting the scheme unless there is |
| 66 // |FormatUrlForSecurityDisplayOmitScheme| unless there is plenty of indication | 73 // plenty of indication as to whether the origin is secure elsewhere in the UX. |
| 67 // as to whether the origin is secure elsewhere in the UX. For example, in | 74 // For example, in Chrome's Origin Info Bubble, there are icons and strings |
| 68 // Chrome's Origin Info Bubble, there are icons and strings indicating origin | 75 // indicating origin (non-)security. But in the HTTP Basic Auth prompt (for |
| 69 // (non-)security. But in the HTTP Basic Auth prompt (for example), the scheme | 76 // example), the scheme may be the only indicator. |
| 70 // may be the only indicator. | 77 base::string16 FormatUrlForSecurityDisplay( |
| 71 base::string16 FormatUrlForSecurityDisplay(const GURL& origin); | 78 const GURL& origin, |
| 72 | 79 const SchemeDisplay scheme_display = SchemeDisplay::SHOW); |
| 73 // Just like |FormatUrlForSecurityDisplay|, but also: | |
| 74 // | |
| 75 // - Omits the scheme if SchemeIsHTTPOrHTTPS(). | |
| 76 base::string16 FormatUrlForSecurityDisplayOmitScheme(const GURL& origin); | |
| 77 | 80 |
| 78 } // namespace url_formatter | 81 } // namespace url_formatter |
| 79 | 82 |
| 80 #endif // COMPONENTS_URL_FORMATTER_ELIDE_URL_H_ | 83 #endif // COMPONENTS_URL_FORMATTER_ELIDE_URL_H_ |
| OLD | NEW |