Commit 1242f8a4 authored by Donn Denman's avatar Donn Denman Committed by Commit Bot

Change our ellipsize in FramebustBlockInfoBar.

When using a layout with ellipsize=start on old versions of Android a
crash can result. This is a speculative fix that changes the way we
ellipsize to "middle" to workaround this crash.

BUG=834959

Change-Id: I0330d9eee82400983e4407bb8a558e322cbf4482
Reviewed-on: https://chromium-review.googlesource.com/1107169
Commit-Queue: Donn Denman <donnd@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Reviewed-by: default avatarAnita Woodruff <awdf@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570121}
parent e53b7dd1
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
android:clickable="false" android:clickable="false"
tools:text="https://" /> tools:text="https://" />
<TextView <org.chromium.chrome.browser.infobar.TextViewEllipsizerSafe
android:id="@+id/url_minus_scheme" android:id="@+id/url_minus_scheme"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
......
...@@ -10,7 +10,6 @@ import android.view.LayoutInflater; ...@@ -10,7 +10,6 @@ import android.view.LayoutInflater;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import org.chromium.base.Log;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.R; import org.chromium.chrome.R;
...@@ -21,8 +20,6 @@ import org.chromium.components.url_formatter.UrlFormatter; ...@@ -21,8 +20,6 @@ import org.chromium.components.url_formatter.UrlFormatter;
* continue the redirection by tapping on a link. * continue the redirection by tapping on a link.
*/ */
public class FramebustBlockInfoBar extends InfoBar { public class FramebustBlockInfoBar extends InfoBar {
/** For Log statements. */
private static final String TAG = "Framebust Infobar";
private final String mBlockedUrl; private final String mBlockedUrl;
...@@ -46,9 +43,6 @@ public class FramebustBlockInfoBar extends InfoBar { ...@@ -46,9 +43,6 @@ public class FramebustBlockInfoBar extends InfoBar {
layout.setMessage(getString(R.string.redirect_blocked_message)); layout.setMessage(getString(R.string.redirect_blocked_message));
InfoBarControlLayout control = layout.addControlLayout(); InfoBarControlLayout control = layout.addControlLayout();
// TODO(crbug.com/834959): remove after bug fixed.
Log.i(TAG, "Mark possible occurance of crbug.com/834959");
ViewGroup ellipsizerView = ViewGroup ellipsizerView =
(ViewGroup) LayoutInflater.from(getContext()) (ViewGroup) LayoutInflater.from(getContext())
.inflate(R.layout.infobar_control_url_ellipsizer, control, false); .inflate(R.layout.infobar_control_url_ellipsizer, control, false);
...@@ -63,7 +57,10 @@ public class FramebustBlockInfoBar extends InfoBar { ...@@ -63,7 +57,10 @@ public class FramebustBlockInfoBar extends InfoBar {
schemeView.setText(scheme); schemeView.setText(scheme);
TextView urlView = ellipsizerView.findViewById(R.id.url_minus_scheme); TextView urlView = ellipsizerView.findViewById(R.id.url_minus_scheme);
urlView.setText(formattedUrl.substring(scheme.length())); String textToEllipsize = formattedUrl.substring(scheme.length());
// 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.
((TextViewEllipsizerSafe) urlView).setTextSafely(textToEllipsize);
ellipsizerView.setOnClickListener(view -> onLinkClicked()); ellipsizerView.setOnClickListener(view -> onLinkClicked());
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.infobar;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.TextView;
/**
* Provides a TextView that provides safety for ellipsize=start on any version of Android.
* TODO(donnd): remove this when older versions of Android are no longer supported.
* See crbug.com/834959.
*/
public class TextViewEllipsizerSafe extends TextView {
// The maximum length of a string that we return when detecting a crash.
// This needs to be small enough to not take a long time in the worst case where we crash again
// and again while shortening the string.
private static final int STRING_MAXIMUM_LENGTH = 2000;
// The minimum length of a string that we return when detecting multiple crashes.
// This needs to be big enough so that we'll always ellipsize on Chrome for Android, e.g. on a
// big tablet in landscape mode.
private static final int STRING_MINIMUM_LENGTH = 1000;
/**
* Constructs a subclass of TextView for use in the URL Infobar UI.
*/
public TextViewEllipsizerSafe(Context context, AttributeSet attrs) {
super(context, attrs);
}
/**
* Safely does #setText when ellipsize=start in at TextView on any version of Android.
* The #setText method is final, so we have to make our own safe variant.
* @param stringToEllipsize The text to set in the TextView, which can use the dangerous form
* of ellipsize=start. See https://crbug.com/834959 for details.
*/
void setTextSafely(String stringToEllipsize) {
assert stringToEllipsize != null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
setText(stringToEllipsize);
return;
}
// First trim the string to some reasonable length limit.
int beginIndex = Math.max(0, stringToEllipsize.length() - STRING_MAXIMUM_LENGTH);
String result = stringToEllipsize.substring(beginIndex);
int measureSpec = android.view.View.MeasureSpec.EXACTLY;
while (result.length() > STRING_MINIMUM_LENGTH) {
try {
// Attempt to set and measure the altered text. In rare cases this may crash.
setText(result);
onMeasure(measureSpec, measureSpec);
return;
} catch (Exception e) {
// Try to prevent a Chrome crash by retrying with a shorter version.
// NOTE: we must trim at the start of the string, as specified by the UI/Security
// spec.
result = result.substring(1);
}
}
}
}
...@@ -22,7 +22,6 @@ import android.view.View; ...@@ -22,7 +22,6 @@ import android.view.View;
import android.widget.RemoteViews; import android.widget.RemoteViews;
import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.Log;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
import org.chromium.chrome.R; import org.chromium.chrome.R;
...@@ -78,9 +77,6 @@ public class CustomNotificationBuilder extends NotificationBuilderBase { ...@@ -78,9 +77,6 @@ public class CustomNotificationBuilder extends NotificationBuilderBase {
*/ */
private static final int BUTTON_ICON_COLOR_MATERIAL = 0xff757575; private static final int BUTTON_ICON_COLOR_MATERIAL = 0xff757575;
/** For Log statements. */
private static final String TAG = "Custom Notification";
private final Context mContext; private final Context mContext;
public CustomNotificationBuilder(Context context) { public CustomNotificationBuilder(Context context) {
...@@ -120,9 +116,6 @@ public class CustomNotificationBuilder extends NotificationBuilderBase { ...@@ -120,9 +116,6 @@ public class CustomNotificationBuilder extends NotificationBuilderBase {
StrictMode.setThreadPolicy(oldPolicy); StrictMode.setThreadPolicy(oldPolicy);
} }
// TODO(crbug.com/834959): remove after bug fixed.
Log.i(TAG, "Mark possible occurrence of crbug.com/834959");
for (RemoteViews view : new RemoteViews[] {compactView, bigView}) { for (RemoteViews view : new RemoteViews[] {compactView, bigView}) {
view.setTextViewText(R.id.time, formattedTime); view.setTextViewText(R.id.time, formattedTime);
view.setTextViewText(R.id.title, mTitle); view.setTextViewText(R.id.title, mTitle);
......
...@@ -638,6 +638,7 @@ chrome_java_sources = [ ...@@ -638,6 +638,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/infobar/ReaderModeInfoBar.java", "java/src/org/chromium/chrome/browser/infobar/ReaderModeInfoBar.java",
"java/src/org/chromium/chrome/browser/infobar/SearchGeolocationDisclosureInfoBar.java", "java/src/org/chromium/chrome/browser/infobar/SearchGeolocationDisclosureInfoBar.java",
"java/src/org/chromium/chrome/browser/infobar/SimpleConfirmInfoBarBuilder.java", "java/src/org/chromium/chrome/browser/infobar/SimpleConfirmInfoBarBuilder.java",
"java/src/org/chromium/chrome/browser/infobar/TextViewEllipsizerSafe.java",
"java/src/org/chromium/chrome/browser/infobar/AdsBlockedInfoBar.java", "java/src/org/chromium/chrome/browser/infobar/AdsBlockedInfoBar.java",
"java/src/org/chromium/chrome/browser/infobar/DownloadProgressInfoBar.java", "java/src/org/chromium/chrome/browser/infobar/DownloadProgressInfoBar.java",
"java/src/org/chromium/chrome/browser/infobar/SubPanelListener.java", "java/src/org/chromium/chrome/browser/infobar/SubPanelListener.java",
......
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