Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" | |
| 10 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 13 #include "components/url_formatter/url_formatter.h" | 14 #include "components/url_formatter/url_formatter.h" |
| 14 #include "net/base/escape.h" | 15 #include "net/base/escape.h" |
| 15 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 16 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 16 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 18 #include "url/origin.h" | |
| 17 #include "url/url_constants.h" | 19 #include "url/url_constants.h" |
| 18 | 20 |
| 19 #if !defined(OS_ANDROID) | 21 #if !defined(OS_ANDROID) |
| 20 #include "ui/gfx/text_elider.h" // nogncheck | 22 #include "ui/gfx/text_elider.h" // nogncheck |
| 21 #include "ui/gfx/text_utils.h" // nogncheck | 23 #include "ui/gfx/text_utils.h" // nogncheck |
| 22 #endif | 24 #endif |
| 23 | 25 |
| 24 namespace { | 26 namespace { |
| 25 | 27 |
| 26 #if !defined(OS_ANDROID) | 28 #if !defined(OS_ANDROID) |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 return !url.SchemeIs(url::kHttpsScheme) && | 120 return !url.SchemeIs(url::kHttpsScheme) && |
| 119 !url.SchemeIs(url::kHttpScheme); | 121 !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 !url.SchemeIsCryptographic(); |
| 123 } | 125 } |
| 124 | 126 |
| 125 return true; | 127 return true; |
| 126 } | 128 } |
| 127 | 129 |
| 130 bool ShouldShowScheme(const url::Origin& origin, | |
|
palmer
2016/05/09 19:40:48
Rather than (essentially) duplicate this code, how
juncai
2016/05/10 02:16:57
Done.
| |
| 131 const url_formatter::SchemeDisplay scheme_display) { | |
| 132 const std::string& scheme = origin.scheme(); | |
| 133 | |
| 134 switch (scheme_display) { | |
| 135 case url_formatter::SchemeDisplay::SHOW: | |
| 136 return true; | |
| 137 | |
| 138 case url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS: | |
| 139 return scheme != url::kHttpsScheme && scheme != url::kHttpScheme; | |
| 140 | |
| 141 case url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC: | |
| 142 return scheme != url::kHttpsScheme && scheme != url::kWssScheme; | |
| 143 } | |
| 144 | |
| 145 return true; | |
| 146 } | |
| 147 | |
| 128 } // namespace | 148 } // namespace |
| 129 | 149 |
| 130 namespace url_formatter { | 150 namespace url_formatter { |
| 131 | 151 |
| 132 #if !defined(OS_ANDROID) | 152 #if !defined(OS_ANDROID) |
| 133 | 153 |
| 134 // TODO(pkasting): http://crbug.com/77883 This whole function gets | 154 // TODO(pkasting): http://crbug.com/77883 This whole function gets |
| 135 // kerning/ligatures/etc. issues potentially wrong by assuming that the width of | 155 // kerning/ligatures/etc. issues potentially wrong by assuming that the width of |
| 136 // a rendered string is always the sum of the widths of its substrings. Also I | 156 // a rendered string is always the sum of the widths of its substrings. Also I |
| 137 // suspect it could be made simpler. | 157 // suspect it could be made simpler. |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 | 385 |
| 366 const int port = origin.IntPort(); | 386 const int port = origin.IntPort(); |
| 367 const int default_port = url::DefaultPortForScheme( | 387 const int default_port = url::DefaultPortForScheme( |
| 368 scheme.c_str(), static_cast<int>(scheme.length())); | 388 scheme.c_str(), static_cast<int>(scheme.length())); |
| 369 if (port != url::PORT_UNSPECIFIED && port != default_port) | 389 if (port != url::PORT_UNSPECIFIED && port != default_port) |
| 370 result += colon + base::UTF8ToUTF16(origin.port()); | 390 result += colon + base::UTF8ToUTF16(origin.port()); |
| 371 | 391 |
| 372 return result; | 392 return result; |
| 373 } | 393 } |
| 374 | 394 |
| 395 base::string16 FormatUrlForSecurityDisplay(const url::Origin& origin, | |
| 396 const SchemeDisplay scheme_display) { | |
| 397 const base::string16 colon(base::ASCIIToUTF16(":")); | |
| 398 const base::string16 scheme_separator( | |
| 399 base::ASCIIToUTF16(url::kStandardSchemeSeparator)); | |
| 400 | |
| 401 const std::string& scheme = origin.scheme(); | |
| 402 const std::string& host = origin.host(); | |
| 403 | |
| 404 base::string16 result; | |
| 405 if (ShouldShowScheme(origin, scheme_display)) | |
| 406 result = base::UTF8ToUTF16(scheme) + scheme_separator; | |
| 407 result += base::UTF8ToUTF16(host); | |
| 408 | |
| 409 uint16_t port = origin.port(); | |
| 410 const int default_port = url::DefaultPortForScheme( | |
| 411 scheme.c_str(), static_cast<int>(scheme.length())); | |
| 412 if (port != default_port) | |
| 413 result += colon + base::UintToString16(origin.port()); | |
| 414 | |
| 415 return result; | |
| 416 } | |
| 417 | |
| 375 } // namespace url_formatter | 418 } // namespace url_formatter |
| OLD | NEW |