Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Side by Side Diff: components/url_formatter/elide_url.cc

Issue 1841653003: Drop |languages| from {Format,Elide}Url* and IDNToUnicode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typo in elide_url.cc Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/url_formatter/elide_url.h ('k') | components/url_formatter/elide_url_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "components/url_formatter/elide_url.h" 5 #include "components/url_formatter/elide_url.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 *url_subdomain = url_host->substr(0, domain_start_index); 101 *url_subdomain = url_host->substr(0, domain_start_index);
102 if ((*url_subdomain == kWwwPrefix || url_subdomain->empty() || 102 if ((*url_subdomain == kWwwPrefix || url_subdomain->empty() ||
103 url.SchemeIsFile())) { 103 url.SchemeIsFile())) {
104 url_subdomain->clear(); 104 url_subdomain->clear();
105 } 105 }
106 } 106 }
107 107
108 #endif // !defined(OS_ANDROID) 108 #endif // !defined(OS_ANDROID)
109 109
110 base::string16 FormatUrlForSecurityDisplayInternal(const GURL& url, 110 base::string16 FormatUrlForSecurityDisplayInternal(const GURL& url,
111 const std::string& languages,
112 bool omit_scheme) { 111 bool omit_scheme) {
113 if (!url.is_valid() || url.is_empty() || !url.IsStandard()) 112 if (!url.is_valid() || url.is_empty() || !url.IsStandard())
114 return url_formatter::FormatUrl(url, languages); 113 return url_formatter::FormatUrl(url);
115 114
116 const base::string16 colon(base::ASCIIToUTF16(":")); 115 const base::string16 colon(base::ASCIIToUTF16(":"));
117 const base::string16 scheme_separator( 116 const base::string16 scheme_separator(
118 base::ASCIIToUTF16(url::kStandardSchemeSeparator)); 117 base::ASCIIToUTF16(url::kStandardSchemeSeparator));
119 118
120 if (url.SchemeIsFile()) { 119 if (url.SchemeIsFile()) {
121 return base::ASCIIToUTF16(url::kFileScheme) + scheme_separator + 120 return base::ASCIIToUTF16(url::kFileScheme) + scheme_separator +
122 base::UTF8ToUTF16(url.path()); 121 base::UTF8ToUTF16(url.path());
123 } 122 }
124 123
125 if (url.SchemeIsFileSystem()) { 124 if (url.SchemeIsFileSystem()) {
126 const GURL* inner_url = url.inner_url(); 125 const GURL* inner_url = url.inner_url();
127 if (inner_url->SchemeIsFile()) { 126 if (inner_url->SchemeIsFile()) {
128 return base::ASCIIToUTF16(url::kFileSystemScheme) + colon + 127 return base::ASCIIToUTF16(url::kFileSystemScheme) + colon +
129 FormatUrlForSecurityDisplayInternal(*inner_url, languages, 128 FormatUrlForSecurityDisplayInternal(*inner_url, false) +
130 false /*omit_scheme*/) +
131 base::UTF8ToUTF16(url.path()); 129 base::UTF8ToUTF16(url.path());
132 } 130 }
133 return base::ASCIIToUTF16(url::kFileSystemScheme) + colon + 131 return base::ASCIIToUTF16(url::kFileSystemScheme) + colon +
134 FormatUrlForSecurityDisplayInternal(*inner_url, languages, 132 FormatUrlForSecurityDisplayInternal(*inner_url, false);
135 false /*omit_scheme*/);
136 } 133 }
137 134
138 const GURL origin = url.GetOrigin(); 135 const GURL origin = url.GetOrigin();
139 const std::string& scheme = origin.scheme(); 136 const std::string& scheme = origin.scheme();
140 const std::string& host = origin.host(); 137 const std::string& host = origin.host();
141 138
142 base::string16 result; 139 base::string16 result;
143 if (!omit_scheme || !url.SchemeIsHTTPOrHTTPS()) 140 if (!omit_scheme || !url.SchemeIsHTTPOrHTTPS())
144 result = base::UTF8ToUTF16(scheme) + scheme_separator; 141 result = base::UTF8ToUTF16(scheme) + scheme_separator;
145 result += base::UTF8ToUTF16(host); 142 result += base::UTF8ToUTF16(host);
(...skipping 12 matching lines...) Expand all
158 namespace url_formatter { 155 namespace url_formatter {
159 156
160 #if !defined(OS_ANDROID) 157 #if !defined(OS_ANDROID)
161 158
162 // TODO(pkasting): http://crbug.com/77883 This whole function gets 159 // TODO(pkasting): http://crbug.com/77883 This whole function gets
163 // kerning/ligatures/etc. issues potentially wrong by assuming that the width of 160 // kerning/ligatures/etc. issues potentially wrong by assuming that the width of
164 // a rendered string is always the sum of the widths of its substrings. Also I 161 // a rendered string is always the sum of the widths of its substrings. Also I
165 // suspect it could be made simpler. 162 // suspect it could be made simpler.
166 base::string16 ElideUrl(const GURL& url, 163 base::string16 ElideUrl(const GURL& url,
167 const gfx::FontList& font_list, 164 const gfx::FontList& font_list,
168 float available_pixel_width, 165 float available_pixel_width) {
169 const std::string& languages) {
170 // Get a formatted string and corresponding parsing of the url. 166 // Get a formatted string and corresponding parsing of the url.
171 url::Parsed parsed; 167 url::Parsed parsed;
172 const base::string16 url_string = url_formatter::FormatUrl( 168 const base::string16 url_string = url_formatter::FormatUrl(
173 url, languages, url_formatter::kFormatUrlOmitAll, 169 url, url_formatter::kFormatUrlOmitAll,
174 net::UnescapeRule::SPACES, &parsed, nullptr, nullptr); 170 net::UnescapeRule::SPACES, &parsed, nullptr, nullptr);
175 if (available_pixel_width <= 0) 171 if (available_pixel_width <= 0)
176 return url_string; 172 return url_string;
177 173
178 // If non-standard, return plain eliding. 174 // If non-standard, return plain eliding.
179 if (!url.IsStandard()) 175 if (!url.IsStandard())
180 return gfx::ElideText(url_string, font_list, available_pixel_width, 176 return gfx::ElideText(url_string, font_list, available_pixel_width,
181 gfx::ELIDE_TAIL); 177 gfx::ELIDE_TAIL);
182 178
183 // Now start eliding url_string to fit within available pixel width. 179 // Now start eliding url_string to fit within available pixel width.
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 float subdomain_width = available_pixel_width - pixel_width_url_domain; 347 float subdomain_width = available_pixel_width - pixel_width_url_domain;
352 if (subdomain_width <= 0) 348 if (subdomain_width <= 0)
353 return base::string16(gfx::kEllipsisUTF16) + kDot + url_domain; 349 return base::string16(gfx::kEllipsisUTF16) + kDot + url_domain;
354 350
355 return gfx::ElideText(url_host, font_list, available_pixel_width, 351 return gfx::ElideText(url_host, font_list, available_pixel_width,
356 gfx::ELIDE_HEAD); 352 gfx::ELIDE_HEAD);
357 } 353 }
358 354
359 #endif // !defined(OS_ANDROID) 355 #endif // !defined(OS_ANDROID)
360 356
361 base::string16 FormatUrlForSecurityDisplay(const GURL& url, 357 base::string16 FormatUrlForSecurityDisplay(const GURL& url) {
362 const std::string& languages) { 358 return FormatUrlForSecurityDisplayInternal(url, false);
363 return FormatUrlForSecurityDisplayInternal(url, languages, false);
364 } 359 }
365 360
366 base::string16 FormatUrlForSecurityDisplayOmitScheme( 361 base::string16 FormatUrlForSecurityDisplayOmitScheme(const GURL& url) {
367 const GURL& url, 362 return FormatUrlForSecurityDisplayInternal(url, true);
368 const std::string& languages) {
369 return FormatUrlForSecurityDisplayInternal(url, languages, true);
370 } 363 }
371 364
372 } // namespace url_formatter 365 } // namespace url_formatter
OLDNEW
« no previous file with comments | « components/url_formatter/elide_url.h ('k') | components/url_formatter/elide_url_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698