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

Side by Side Diff: chrome/browser/ui/elide_url.cc

Issue 1147363005: Create FormatUrlForSecurityDisplay helper function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a test to ensure we show trailing dots in DNS names. Created 5 years, 6 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 | « chrome/browser/ui/elide_url.h ('k') | chrome/browser/ui/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 "chrome/browser/ui/elide_url.h" 5 #include "chrome/browser/ui/elide_url.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_split.h" 8 #include "base/strings/string_split.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "net/base/escape.h" 10 #include "net/base/escape.h"
11 #include "net/base/net_util.h" 11 #include "net/base/net_util.h"
12 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 12 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
13 #include "ui/gfx/text_elider.h" 13 #include "ui/gfx/text_elider.h"
14 #include "ui/gfx/text_utils.h" 14 #include "ui/gfx/text_utils.h"
15 #include "url/gurl.h" 15 #include "url/gurl.h"
16 #include "url/url_constants.h"
16 17
17 using base::UTF8ToUTF16; 18 using base::UTF8ToUTF16;
18 using gfx::ElideText; 19 using gfx::ElideText;
19 using gfx::GetStringWidthF; 20 using gfx::GetStringWidthF;
20 using gfx::kEllipsisUTF16; 21 using gfx::kEllipsisUTF16;
21 using gfx::kForwardSlash; 22 using gfx::kForwardSlash;
22 23
23 namespace { 24 namespace {
24 25
25 const base::char16 kDot = '.'; 26 const base::char16 kDot = '.';
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 295
295 const float pixel_width_url_domain = GetStringWidthF(url_domain, font_list); 296 const float pixel_width_url_domain = GetStringWidthF(url_domain, font_list);
296 float subdomain_width = available_pixel_width - pixel_width_url_domain; 297 float subdomain_width = available_pixel_width - pixel_width_url_domain;
297 if (subdomain_width <= 0) 298 if (subdomain_width <= 0)
298 return base::string16(kEllipsisUTF16) + kDot + url_domain; 299 return base::string16(kEllipsisUTF16) + kDot + url_domain;
299 300
300 const base::string16 elided_subdomain = ElideText( 301 const base::string16 elided_subdomain = ElideText(
301 url_subdomain, font_list, subdomain_width, gfx::ELIDE_HEAD); 302 url_subdomain, font_list, subdomain_width, gfx::ELIDE_HEAD);
302 return elided_subdomain + url_domain; 303 return elided_subdomain + url_domain;
303 } 304 }
305
306 base::string16 FormatOriginForDisplay(const GURL& url,
307 const std::string& languages) {
308 if (!url.is_valid() || url.is_empty() || !url.IsStandard())
309 return net::FormatUrl(url, languages);
310
311 const base::string16 colon(base::ASCIIToUTF16(":"));
312 const base::string16 scheme_separator(
313 (base::ASCIIToUTF16(url::kStandardSchemeSeparator)));
314
315 if (url.SchemeIsFile()) {
316 return (base::ASCIIToUTF16(url::kFileScheme)) + scheme_separator +
Ryan Sleevi 2015/05/29 21:13:51 nit: You don't need the wrapping ()
palmer 2015/05/29 21:51:36 Done.
317 base::UTF8ToUTF16(url.path());
318 }
319
320 if (url.SchemeIsFileSystem()) {
321 const GURL* inner_url = url.inner_url();
322 const GURL& inner_origin = inner_url->GetOrigin();
323 if (inner_origin.SchemeIsFile()) {
324 return base::ASCIIToUTF16(url::kFileSystemScheme) + colon +
325 base::ASCIIToUTF16(url::kFileScheme) + scheme_separator +
326 base::UTF8ToUTF16(inner_url->path()) +
327 base::UTF8ToUTF16(url.path());
Ryan Sleevi 2015/05/29 21:13:50 I'm not sure I fully grokked your reply about this
palmer 2015/05/29 21:51:36 Ahh, yes, thanks. Done.
328 }
329 return base::ASCIIToUTF16(url::kFileSystemScheme) + colon +
330 FormatOriginForDisplay(inner_origin, languages);
331 }
332
333 const GURL origin = url.GetOrigin();
334 const std::string& scheme = origin.scheme();
335 const std::string& host = origin.host();
336
337 base::string16 result = base::UTF8ToUTF16(scheme) + scheme_separator;
Ryan Sleevi 2015/05/29 21:13:51 EXTREME PEDANTRY: This does result in an extra cop
palmer 2015/05/29 21:51:36 Done.
338
339 result += base::UTF8ToUTF16(host);
340
341 const int port = origin.IntPort();
342 const int default_port = url::DefaultPortForScheme(origin.scheme().c_str(),
343 origin.scheme().length());
344 if (port != url::PORT_UNSPECIFIED && port != default_port)
345 result += base::ASCIIToUTF16(":") + base::UTF8ToUTF16(origin.port());
346
347 return result;
348 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/elide_url.h ('k') | chrome/browser/ui/elide_url_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698