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

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: rebased, most Android targets locally built successfully 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
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,
130 false /*omit_scheme*/) + 129 false /*omit_scheme*/) +
Peter Kasting 2016/04/05 02:42:33 Nit: While here, I'd remove the /*omit_scheme*/ on
jungshik at Google 2016/04/05 18:56:19 Done.
131 base::UTF8ToUTF16(url.path()); 130 base::UTF8ToUTF16(url.path());
132 } 131 }
133 return base::ASCIIToUTF16(url::kFileSystemScheme) + colon + 132 return base::ASCIIToUTF16(url::kFileSystemScheme) + colon +
134 FormatUrlForSecurityDisplayInternal(*inner_url, languages, 133 FormatUrlForSecurityDisplayInternal(*inner_url,
135 false /*omit_scheme*/); 134 false /*omit_scheme*/);
136 } 135 }
137 136
138 const GURL origin = url.GetOrigin(); 137 const GURL origin = url.GetOrigin();
139 const std::string& scheme = origin.scheme(); 138 const std::string& scheme = origin.scheme();
140 const std::string& host = origin.host(); 139 const std::string& host = origin.host();
141 140
142 base::string16 result; 141 base::string16 result;
143 if (!omit_scheme || !url.SchemeIsHTTPOrHTTPS()) 142 if (!omit_scheme || !url.SchemeIsHTTPOrHTTPS())
144 result = base::UTF8ToUTF16(scheme) + scheme_separator; 143 result = base::UTF8ToUTF16(scheme) + scheme_separator;
(...skipping 13 matching lines...) Expand all
158 namespace url_formatter { 157 namespace url_formatter {
159 158
160 #if !defined(OS_ANDROID) 159 #if !defined(OS_ANDROID)
161 160
162 // TODO(pkasting): http://crbug.com/77883 This whole function gets 161 // TODO(pkasting): http://crbug.com/77883 This whole function gets
163 // kerning/ligatures/etc. issues potentially wrong by assuming that the width of 162 // 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 163 // a rendered string is always the sum of the widths of its substrings. Also I
165 // suspect it could be made simpler. 164 // suspect it could be made simpler.
166 base::string16 ElideUrl(const GURL& url, 165 base::string16 ElideUrl(const GURL& url,
167 const gfx::FontList& font_list, 166 const gfx::FontList& font_list,
168 float available_pixel_width, 167 float available_pixel_width) {
169 const std::string& languages) {
170 // Get a formatted string and corresponding parsing of the url. 168 // Get a formatted string and corresponding parsing of the url.
171 url::Parsed parsed; 169 url::Parsed parsed;
172 const base::string16 url_string = url_formatter::FormatUrl( 170 const base::string16 url_string = url_formatter::FormatUrl(
173 url, languages, url_formatter::kFormatUrlOmitAll, 171 url, url_formatter::kFormatUrlOmitAll,
174 net::UnescapeRule::SPACES, &parsed, nullptr, nullptr); 172 net::UnescapeRule::SPACES, &parsed, nullptr, nullptr);
175 if (available_pixel_width <= 0) 173 if (available_pixel_width <= 0)
176 return url_string; 174 return url_string;
177 175
178 // If non-standard, return plain eliding. 176 // If non-standard, return plain eliding.
179 if (!url.IsStandard()) 177 if (!url.IsStandard())
180 return gfx::ElideText(url_string, font_list, available_pixel_width, 178 return gfx::ElideText(url_string, font_list, available_pixel_width,
181 gfx::ELIDE_TAIL); 179 gfx::ELIDE_TAIL);
182 180
183 // Now start eliding url_string to fit within available pixel width. 181 // 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; 349 float subdomain_width = available_pixel_width - pixel_width_url_domain;
352 if (subdomain_width <= 0) 350 if (subdomain_width <= 0)
353 return base::string16(gfx::kEllipsisUTF16) + kDot + url_domain; 351 return base::string16(gfx::kEllipsisUTF16) + kDot + url_domain;
354 352
355 return gfx::ElideText(url_host, font_list, available_pixel_width, 353 return gfx::ElideText(url_host, font_list, available_pixel_width,
356 gfx::ELIDE_HEAD); 354 gfx::ELIDE_HEAD);
357 } 355 }
358 356
359 #endif // !defined(OS_ANDROID) 357 #endif // !defined(OS_ANDROID)
360 358
361 base::string16 FormatUrlForSecurityDisplay(const GURL& url, 359 base::string16 FormatUrlForSecurityDisplay(const GURL& url) {
362 const std::string& languages) { 360 return FormatUrlForSecurityDisplayInternal(url, false);
363 return FormatUrlForSecurityDisplayInternal(url, languages, false);
364 } 361 }
365 362
366 base::string16 FormatUrlForSecurityDisplayOmitScheme( 363 base::string16 FormatUrlForSecurityDisplayOmitScheme(const GURL& url) {
367 const GURL& url, 364 return FormatUrlForSecurityDisplayInternal(url, true);
368 const std::string& languages) {
369 return FormatUrlForSecurityDisplayInternal(url, languages, true);
370 } 365 }
371 366
372 } // namespace url_formatter 367 } // namespace url_formatter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698