Commit e7bb4fe5 authored by edchin's avatar edchin Committed by Commit Bot

[ios] Fix crash in tab switcher

Crash is caused by the previousPanelIndex being out-of-bounds into the
panels array. This CL ensures that previousPanelIndex is kept up-to-date
when any panels are removed so that it is not out-of-bounds.

Bug: 805530
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Id193a85585510c50e9bb92680f0782fee7e34d1a
Reviewed-on: https://chromium-review.googlesource.com/916943Reviewed-by: default avataredchin <edchin@chromium.org>
Reviewed-by: default avatarJérôme Lebel <jlebel@chromium.org>
Commit-Queue: edchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#536745}
parent b8d783fd
...@@ -110,6 +110,17 @@ const CGFloat kNewTabButtonWidth = 48; ...@@ -110,6 +110,17 @@ const CGFloat kNewTabButtonWidth = 48;
DCHECK_EQ([[_panels objectAtIndex:index] superview], _scrollView); DCHECK_EQ([[_panels objectAtIndex:index] superview], _scrollView);
[[_panels objectAtIndex:index] removeFromSuperview]; [[_panels objectAtIndex:index] removeFromSuperview];
[_panels removeObjectAtIndex:index]; [_panels removeObjectAtIndex:index];
if (_previousPanelIndex > -1) {
NSUInteger previousPanelIndexUnsigned =
static_cast<NSUInteger>(_previousPanelIndex);
if (index < previousPanelIndexUnsigned)
_previousPanelIndex--;
else if (index == previousPanelIndexUnsigned) {
[self panelWasHiddenAtIndex:_previousPanelIndex];
_previousPanelIndex = -1;
}
}
if (update) if (update)
[self updateScrollViewContent]; [self updateScrollViewContent];
} }
...@@ -336,7 +347,9 @@ const CGFloat kNewTabButtonWidth = 48; ...@@ -336,7 +347,9 @@ const CGFloat kNewTabButtonWidth = 48;
_previousPanelIndex = panelIndex; _previousPanelIndex = panelIndex;
} }
- (void)panelWasHiddenAtIndex:(NSInteger)index { - (void)panelWasHiddenAtIndex:(NSUInteger)index {
if (index >= [_panels count])
return;
id panel = [_panels objectAtIndex:index]; id panel = [_panels objectAtIndex:index];
if ([panel respondsToSelector:@selector(wasHidden)]) if ([panel respondsToSelector:@selector(wasHidden)])
[panel wasHidden]; [panel wasHidden];
......
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