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

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: Change testing strategy, respond to comments. 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 FormatUrlForSecurityDisplay(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 +
317 base::UTF8ToUTF16(url.path());
318 }
319
320 if (url.SchemeIsFileSystem()) {
321 const GURL* inner_url = url.inner_url();
322 if (inner_url->SchemeIsFile()) {
323 return base::ASCIIToUTF16(url::kFileSystemScheme) + colon +
324 FormatUrlForSecurityDisplay(*inner_url, languages) +
325 base::UTF8ToUTF16(url.path());
326 }
327 return base::ASCIIToUTF16(url::kFileSystemScheme) + colon +
328 FormatUrlForSecurityDisplay(*inner_url, languages);
329 }
330
331 const GURL origin = url.GetOrigin();
332 const std::string& scheme = origin.scheme();
333 const std::string& host = origin.host();
334
335 base::string16 result = base::UTF8ToUTF16(scheme);
336 result += scheme_separator;
337 result += base::UTF8ToUTF16(host);
338
339 const int port = origin.IntPort();
340 const int default_port = url::DefaultPortForScheme(origin.scheme().c_str(),
341 origin.scheme().length());
342 if (port != url::PORT_UNSPECIFIED && port != default_port)
343 result += colon + base::UTF8ToUTF16(origin.port());
344
345 return result;
346 }
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