Commit 1828a132 authored by edchin's avatar edchin Committed by Commit Bot

[ios] Fix crash when tapping done in tab grid

Crash occurs when:
1) hold down done button & close all button
2) release close all
3) release done button (quickly after step 2)

The done button's selector is still called since the interaction began
before the button was disabled.

This CL ensures that the done tap only works if there is a valid
active tab.


Bug: 836563
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I8e98a13a6496c8ed074409d48d61c47c58fcb3d6
Reviewed-on: https://chromium-review.googlesource.com/1114124Reviewed-by: default avataredchin <edchin@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Commit-Queue: edchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570236}
parent 64c540a7
......@@ -241,26 +241,18 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
- (BOOL)isSelectedCellVisible {
if (self.activePage != self.currentPage)
return NO;
switch (self.activePage) {
case TabGridPageIncognitoTabs:
return self.incognitoTabsViewController.selectedCellVisible;
case TabGridPageRegularTabs:
return self.regularTabsViewController.selectedCellVisible;
case TabGridPageRemoteTabs:
return NO;
}
GridViewController* gridViewController =
[self gridViewControllerForPage:self.activePage];
return gridViewController == nil ? NO
: gridViewController.selectedCellVisible;
}
- (GridTransitionLayout*)layoutForTransitionContext:
(id<UIViewControllerContextTransitioning>)context {
switch (self.currentPage) {
case TabGridPageIncognitoTabs:
return [self.incognitoTabsViewController transitionLayout];
case TabGridPageRegularTabs:
return [self.regularTabsViewController transitionLayout];
case TabGridPageRemoteTabs:
return nil;
}
GridViewController* gridViewController =
[self gridViewControllerForPage:self.activePage];
return gridViewController == nil ? nil
: [gridViewController transitionLayout];
}
- (UIView*)proxyContainerForTransitionContext:
......@@ -309,6 +301,19 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
#pragma mark - Private
// Returns the corresponding GridViewController for |page|. Returns |nil| if
// page does not have a corresponding GridViewController.
- (GridViewController*)gridViewControllerForPage:(TabGridPage)page {
switch (page) {
case TabGridPageIncognitoTabs:
return self.incognitoTabsViewController;
case TabGridPageRegularTabs:
return self.regularTabsViewController;
case TabGridPageRemoteTabs:
return nil;
}
}
- (void)setCurrentPage:(TabGridPage)currentPage {
[self setCurrentPage:currentPage animated:NO];
}
......@@ -638,18 +643,13 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
}
- (void)configureDoneButtonBasedOnPage:(TabGridPage)page {
switch (page) {
case TabGridPageIncognitoTabs:
self.doneButton.enabled = !self.incognitoTabsViewController.gridEmpty;
break;
case TabGridPageRegularTabs:
self.doneButton.enabled = !self.regularTabsViewController.gridEmpty;
break;
case TabGridPageRemoteTabs:
NOTREACHED() << "The done button should not be configured based on the "
"contents of the recent tabs page.";
break;
GridViewController* gridViewController =
[self gridViewControllerForPage:page];
if (!gridViewController) {
NOTREACHED() << "The done button should not be configured based on the "
"contents of the recent tabs page.";
}
self.doneButton.enabled = !gridViewController.gridEmpty;
}
- (void)configureCloseAllButtonForCurrentPageAndUndoAvailability {
......@@ -665,17 +665,10 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
return;
}
// Otherwise setup as a Close All button.
switch (self.currentPage) {
case TabGridPageIncognitoTabs:
self.closeAllButton.enabled = !self.incognitoTabsViewController.gridEmpty;
break;
case TabGridPageRegularTabs:
self.closeAllButton.enabled = !self.regularTabsViewController.gridEmpty;
break;
case TabGridPageRemoteTabs:
self.closeAllButton.enabled = NO;
break;
}
GridViewController* gridViewController =
[self gridViewControllerForPage:self.currentPage];
self.closeAllButton.enabled =
gridViewController == nil ? NO : !gridViewController.gridEmpty;
[self.closeAllButton
setTitle:l10n_util::GetNSString(IDS_IOS_TAB_GRID_CLOSE_ALL_BUTTON)
forState:UIControlStateNormal];
......@@ -814,7 +807,12 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
newActivePage = self.activePage;
}
self.activePage = newActivePage;
[self.tabPresentationDelegate showActiveTabInPage:newActivePage];
// Holding the done button down when it is enabled could result in done tap
// being triggered on release after tabs have been closed and the button
// disabled. Ensure that action is only taken on a valid state.
if (![[self gridViewControllerForPage:newActivePage] isGridEmpty]) {
[self.tabPresentationDelegate showActiveTabInPage:newActivePage];
}
}
- (void)closeAllButtonTapped:(id)sender {
......
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