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

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

Issue 1959933002: Add FormatOriginForSecurityDisplay which takes a const url::Origin& origin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address brettw@'s comments Created 4 years, 7 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_number_conversions.h"
11 #include "base/strings/string_piece.h"
10 #include "base/strings/string_split.h" 12 #include "base/strings/string_split.h"
11 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
12 #include "build/build_config.h" 14 #include "build/build_config.h"
13 #include "components/url_formatter/url_formatter.h" 15 #include "components/url_formatter/url_formatter.h"
14 #include "net/base/escape.h" 16 #include "net/base/escape.h"
15 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 17 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
16 #include "url/gurl.h" 18 #include "url/gurl.h"
19 #include "url/origin.h"
17 #include "url/url_constants.h" 20 #include "url/url_constants.h"
18 21
19 #if !defined(OS_ANDROID) 22 #if !defined(OS_ANDROID)
20 #include "ui/gfx/text_elider.h" // nogncheck 23 #include "ui/gfx/text_elider.h" // nogncheck
21 #include "ui/gfx/text_utils.h" // nogncheck 24 #include "ui/gfx/text_utils.h" // nogncheck
22 #endif 25 #endif
23 26
24 namespace { 27 namespace {
25 28
26 #if !defined(OS_ANDROID) 29 #if !defined(OS_ANDROID)
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 base::string16 kWwwPrefix = base::UTF8ToUTF16("www."); 104 base::string16 kWwwPrefix = base::UTF8ToUTF16("www.");
102 if (domain_start_index != base::string16::npos) 105 if (domain_start_index != base::string16::npos)
103 *url_subdomain = url_host->substr(0, domain_start_index); 106 *url_subdomain = url_host->substr(0, domain_start_index);
104 if ((*url_subdomain == kWwwPrefix || url_subdomain->empty() || 107 if ((*url_subdomain == kWwwPrefix || url_subdomain->empty() ||
105 url.SchemeIsFile())) { 108 url.SchemeIsFile())) {
106 url_subdomain->clear(); 109 url_subdomain->clear();
107 } 110 }
108 } 111 }
109 #endif // !defined(OS_ANDROID) 112 #endif // !defined(OS_ANDROID)
110 113
111 bool ShouldShowScheme(const GURL& url, 114 bool ShouldShowScheme(base::StringPiece scheme,
112 const url_formatter::SchemeDisplay scheme_display) { 115 const url_formatter::SchemeDisplay scheme_display) {
113 switch (scheme_display) { 116 switch (scheme_display) {
114 case url_formatter::SchemeDisplay::SHOW: 117 case url_formatter::SchemeDisplay::SHOW:
115 return true; 118 return true;
116 119
117 case url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS: 120 case url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS:
118 return !url.SchemeIs(url::kHttpsScheme) && 121 return scheme != url::kHttpsScheme && scheme != url::kHttpScheme;
119 !url.SchemeIs(url::kHttpScheme);
120 122
121 case url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC: 123 case url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC:
122 return !url.SchemeIsCryptographic(); 124 return scheme != url::kHttpsScheme && scheme != url::kWssScheme;
123 } 125 }
124 126
125 return true; 127 return true;
126 } 128 }
127 129
128 } // namespace 130 } // namespace
129 131
130 namespace url_formatter { 132 namespace url_formatter {
131 133
132 #if !defined(OS_ANDROID) 134 #if !defined(OS_ANDROID)
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 if (inner_url->SchemeIsFile()) { 350 if (inner_url->SchemeIsFile()) {
349 return base::ASCIIToUTF16(url::kFileSystemScheme) + colon + 351 return base::ASCIIToUTF16(url::kFileSystemScheme) + colon +
350 FormatUrlForSecurityDisplay(*inner_url) + 352 FormatUrlForSecurityDisplay(*inner_url) +
351 base::UTF8ToUTF16(url.path()); 353 base::UTF8ToUTF16(url.path());
352 } 354 }
353 return base::ASCIIToUTF16(url::kFileSystemScheme) + colon + 355 return base::ASCIIToUTF16(url::kFileSystemScheme) + colon +
354 FormatUrlForSecurityDisplay(*inner_url); 356 FormatUrlForSecurityDisplay(*inner_url);
355 } 357 }
356 358
357 const GURL origin = url.GetOrigin(); 359 const GURL origin = url.GetOrigin();
358 const std::string& scheme = origin.scheme(); 360 base::StringPiece scheme = origin.scheme_piece();
359 const std::string& host = origin.host(); 361 base::StringPiece host = origin.host_piece();
360 362
361 base::string16 result; 363 base::string16 result;
362 if (ShouldShowScheme(url, scheme_display)) 364 if (ShouldShowScheme(scheme, scheme_display))
363 result = base::UTF8ToUTF16(scheme) + scheme_separator; 365 result = base::UTF8ToUTF16(scheme) + scheme_separator;
364 result += base::UTF8ToUTF16(host); 366 result += base::UTF8ToUTF16(host);
365 367
366 const int port = origin.IntPort(); 368 const int port = origin.IntPort();
367 const int default_port = url::DefaultPortForScheme( 369 const int default_port = url::DefaultPortForScheme(
368 scheme.c_str(), static_cast<int>(scheme.length())); 370 scheme.data(), static_cast<int>(scheme.length()));
369 if (port != url::PORT_UNSPECIFIED && port != default_port) 371 if (port != url::PORT_UNSPECIFIED && port != default_port)
370 result += colon + base::UTF8ToUTF16(origin.port()); 372 result += colon + base::UTF8ToUTF16(origin.port_piece());
371 373
372 return result; 374 return result;
373 } 375 }
376
377 base::string16 FormatOriginForSecurityDisplay(
378 const url::Origin& origin,
379 const SchemeDisplay scheme_display) {
380 base::StringPiece scheme = origin.scheme();
381 base::StringPiece host = origin.host();
382 if (scheme.empty() && host.empty())
383 return base::string16();
384
385 const base::string16 colon(base::ASCIIToUTF16(":"));
386 const base::string16 scheme_separator(
387 base::ASCIIToUTF16(url::kStandardSchemeSeparator));
388
389 base::string16 result;
390 if (ShouldShowScheme(scheme, scheme_display))
391 result = base::UTF8ToUTF16(scheme) + scheme_separator;
392 result += base::UTF8ToUTF16(host);
393
394 int port = static_cast<int>(origin.port());
395 const int default_port = url::DefaultPortForScheme(
396 scheme.data(), static_cast<int>(scheme.length()));
397 if (port != 0 && port != default_port)
398 result += colon + base::UintToString16(origin.port());
399
400 return result;
401 }
374 402
375 } // namespace url_formatter 403 } // 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