Chromium Code Reviews| Index: components/url_formatter/url_formatter.cc |
| diff --git a/components/url_formatter/url_formatter.cc b/components/url_formatter/url_formatter.cc |
| index 298b1c18ff42bfae9102433a16200dd4a65d642b..51f802840f200eaed6792cddf0ff33896a976843 100644 |
| --- a/components/url_formatter/url_formatter.cc |
| +++ b/components/url_formatter/url_formatter.cc |
| @@ -360,6 +360,7 @@ const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname = 1 << 2; |
| const FormatUrlType kFormatUrlOmitAll = |
| kFormatUrlOmitUsernamePassword | kFormatUrlOmitHTTP | |
| kFormatUrlOmitTrailingSlashOnBareHostname; |
| +const FormatUrlType kFormatUrlExperimentalEllipsizePath = 1 << 3; |
| base::string16 FormatUrl(const GURL& url, |
| FormatUrlTypes format_types, |
| @@ -506,29 +507,50 @@ base::string16 FormatUrlWithAdjustments( |
| } |
| // Path & query. Both get the same general unescape & convert treatment. |
| - if (!(format_types & kFormatUrlOmitTrailingSlashOnBareHostname) || |
| - !CanStripTrailingSlash(url)) { |
| - AppendFormattedComponent(spec, parsed.path, |
| - NonHostComponentTransform(unescape_rules), |
| - &url_string, &new_parsed->path, adjustments); |
| - } else { |
| + if ((format_types & kFormatUrlOmitTrailingSlashOnBareHostname) && |
| + CanStripTrailingSlash(url)) { |
| + // Case when it's just a single trailing slash we can strip. |
| if (parsed.path.len > 0) { |
| adjustments->push_back(base::OffsetAdjuster::Adjustment( |
| parsed.path.begin, parsed.path.len, 0)); |
| } |
| + } else if ((format_types & kFormatUrlExperimentalEllipsizePath) && |
| + url.IsStandard() && !url.SchemeIsFile() && |
| + !url.SchemeIsFileSystem()) { |
| + // Case when we replace the path with an ellipsis. |
| + url_string.push_back('/'); |
| + constexpr base::char16 kEllipsisUTF16[] = {0x2026, 0}; |
| + url_string.append(kEllipsisUTF16); |
|
tommycli
2017/06/28 21:21:40
As a change from PS1, I also added a copy of kElli
|
| + |
| + // Start at begin + 1, since we are preserving the first forward slash. |
| + // Subtract one from the length to account for the first forward slash. |
| + // New length is one to account for the new ellipsis character. |
| + size_t old_length = parsed.path.len - 1; |
| + if (parsed.query.is_valid()) |
| + old_length += parsed.query.len + 1; |
| + if (parsed.ref.is_valid()) |
| + old_length += parsed.ref.len + 1; |
| + adjustments->push_back( |
| + base::OffsetAdjuster::Adjustment(parsed.path.begin + 1, old_length, 1)); |
| + } else { |
| + // Default case. |
| + AppendFormattedComponent(spec, parsed.path, |
| + NonHostComponentTransform(unescape_rules), |
| + &url_string, &new_parsed->path, adjustments); |
| + |
| + if (parsed.query.is_valid()) |
| + url_string.push_back('?'); |
| + AppendFormattedComponent(spec, parsed.query, |
| + NonHostComponentTransform(unescape_rules), |
| + &url_string, &new_parsed->query, adjustments); |
| + |
| + // Ref. This is valid, unescaped UTF-8, so we can just convert. |
| + if (parsed.ref.is_valid()) |
| + url_string.push_back('#'); |
| + AppendFormattedComponent(spec, parsed.ref, |
| + NonHostComponentTransform(net::UnescapeRule::NONE), |
| + &url_string, &new_parsed->ref, adjustments); |
| } |
| - if (parsed.query.is_valid()) |
| - url_string.push_back('?'); |
| - AppendFormattedComponent(spec, parsed.query, |
| - NonHostComponentTransform(unescape_rules), |
| - &url_string, &new_parsed->query, adjustments); |
| - |
| - // Ref. This is valid, unescaped UTF-8, so we can just convert. |
| - if (parsed.ref.is_valid()) |
| - url_string.push_back('#'); |
| - AppendFormattedComponent(spec, parsed.ref, |
| - NonHostComponentTransform(net::UnescapeRule::NONE), |
| - &url_string, &new_parsed->ref, adjustments); |
| // If we need to strip out http do it after the fact. |
| if (omit_http && base::StartsWith(url_string, base::ASCIIToUTF16(kHTTP), |