Commit 32582f54 authored by Anna Malova's avatar Anna Malova Committed by Commit Bot

Add preprocessing of URL with no scheme.

FramebustBlockInfoBar#createContent crashes in case no scheme is specified in url.

Bug: 854733
Change-Id: I9603f4609dbf9b5882accd8f645f82a86452df27
Reviewed-on: https://chromium-review.googlesource.com/1217423
Commit-Queue: Anna Malova <amalova@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590274}
parent 449ab884
...@@ -50,14 +50,25 @@ public class FramebustBlockInfoBar extends InfoBar { ...@@ -50,14 +50,25 @@ public class FramebustBlockInfoBar extends InfoBar {
// Formatting the URL and requesting to omit the scheme might still include it for some of // Formatting the URL and requesting to omit the scheme might still include it for some of
// them (e.g. file, filesystem). We split the output of the formatting to make sure we don't // them (e.g. file, filesystem). We split the output of the formatting to make sure we don't
// end up duplicating it. // end up duplicating it.
String formattedUrl = UrlFormatter.formatUrlForSecurityDisplay(mBlockedUrl); final String schemeSeparator = "://";
String scheme = Uri.parse(mBlockedUrl).getScheme() + "://"; String scheme = Uri.parse(mBlockedUrl).getScheme();
// In case mBlockedUrl does not specify a scheme, formatUrlForSecurityDisplay returns an
// empty string. Temporarily adding scheme separator allows it to parse the URL correctly.
String urlWithScheme = mBlockedUrl;
if (scheme == null) {
scheme = "";
urlWithScheme = schemeSeparator + mBlockedUrl;
}
String textToEllipsize = UrlFormatter
.formatUrlForSecurityDisplay(urlWithScheme)
.substring(scheme.length() + schemeSeparator.length());
TextView schemeView = ellipsizerView.findViewById(R.id.url_scheme); TextView schemeView = ellipsizerView.findViewById(R.id.url_scheme);
schemeView.setText(scheme); schemeView.setText(scheme);
TextView urlView = ellipsizerView.findViewById(R.id.url_minus_scheme); TextView urlView = ellipsizerView.findViewById(R.id.url_minus_scheme);
String textToEllipsize = formattedUrl.substring(scheme.length());
// Handle adjusting the text to workaround Android crashes when ellipsizing on old versions. // Handle adjusting the text to workaround Android crashes when ellipsizing on old versions.
// TODO(donnd): remove this class when older versions of Android are no longer supported. // TODO(donnd): remove this class when older versions of Android are no longer supported.
((TextViewEllipsizerSafe) urlView).setTextSafely(textToEllipsize); ((TextViewEllipsizerSafe) urlView).setTextSafely(textToEllipsize);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment