Commit 1bb404d5 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

weblayer: fix crash in InfoBarContainerView.setTranslationY

The crash is happening because setTranslationY is being called
when the InfoBarContainerView's tab is no longer active. This
is problematic as when the tab is not active
getBrowser().getViewController() returns null.

Two fixs:
. make SwipableOverlayView cancel the animation when removed.
. make InfoBarContainerView handle this situation better.

The latter is necessary as setTranslationY() is a public method,
and may be called at any time.

BUG=1121393
TEST=none (at the moment it's a bit hard to trigger this code
     path from tests).

Change-Id: I95cd82f13efc07f81bec3a00b6c7513472bdbaea
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2382680Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803111}
parent 66aa0614
......@@ -171,6 +171,12 @@ public abstract class SwipableOverlayView extends FrameLayout {
if (!isAllowedToAutoHide()) setTranslationY(0.0f);
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
cancelCurrentAnimation();
}
@Override
public void onWindowFocusChanged(boolean hasWindowFocus) {
super.onWindowFocusChanged(hasWindowFocus);
......
......@@ -57,7 +57,7 @@ public class InfoBarContainerView extends SwipableOverlayView {
/** Parent view that contains the InfoBarContainerLayout. */
private ViewGroup mParentView;
private final TabImpl mTab;
private TabImpl mTab;
/** Animation used to snap the container to the nearest state if scroll direction changes. */
private Animator mScrollDirectionChangeAnimation;
......@@ -107,6 +107,7 @@ public class InfoBarContainerView extends SwipableOverlayView {
void destroy() {
removeFromParentView();
mTab = null;
}
// SwipableOverlayView implementation.
......@@ -140,8 +141,9 @@ public class InfoBarContainerView extends SwipableOverlayView {
// View implementation.
@Override
public void setTranslationY(float translationY) {
int contentHeightDelta =
mTab.getBrowser().getViewController().getBottomContentHeightDelta();
int contentHeightDelta = mTab != null
? mTab.getBrowser().getViewController().getBottomContentHeightDelta()
: 0;
// Push the infobar container up by any delta caused by the bottom toolbar while ensuring
// that it does not ascend beyond the top of the bottom toolbar nor descend beyond its own
......@@ -188,6 +190,8 @@ public class InfoBarContainerView extends SwipableOverlayView {
* Adds this class to the parent view {@link #mParentView}.
*/
void addToParentView() {
// If mTab is null, destroy() was called. This should not be added after destroyed.
assert mTab != null;
super.addToParentViewAtIndex(mParentView,
mTab.getBrowser().getViewController().getDesiredInfoBarContainerViewIndex());
}
......
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