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