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) { ...@@ -241,26 +241,18 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
- (BOOL)isSelectedCellVisible { - (BOOL)isSelectedCellVisible {
if (self.activePage != self.currentPage) if (self.activePage != self.currentPage)
return NO; return NO;
switch (self.activePage) { GridViewController* gridViewController =
case TabGridPageIncognitoTabs: [self gridViewControllerForPage:self.activePage];
return self.incognitoTabsViewController.selectedCellVisible; return gridViewController == nil ? NO
case TabGridPageRegularTabs: : gridViewController.selectedCellVisible;
return self.regularTabsViewController.selectedCellVisible;
case TabGridPageRemoteTabs:
return NO;
}
} }
- (GridTransitionLayout*)layoutForTransitionContext: - (GridTransitionLayout*)layoutForTransitionContext:
(id<UIViewControllerContextTransitioning>)context { (id<UIViewControllerContextTransitioning>)context {
switch (self.currentPage) { GridViewController* gridViewController =
case TabGridPageIncognitoTabs: [self gridViewControllerForPage:self.activePage];
return [self.incognitoTabsViewController transitionLayout]; return gridViewController == nil ? nil
case TabGridPageRegularTabs: : [gridViewController transitionLayout];
return [self.regularTabsViewController transitionLayout];
case TabGridPageRemoteTabs:
return nil;
}
} }
- (UIView*)proxyContainerForTransitionContext: - (UIView*)proxyContainerForTransitionContext:
...@@ -309,6 +301,19 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) { ...@@ -309,6 +301,19 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
#pragma mark - Private #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 { - (void)setCurrentPage:(TabGridPage)currentPage {
[self setCurrentPage:currentPage animated:NO]; [self setCurrentPage:currentPage animated:NO];
} }
...@@ -638,18 +643,13 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) { ...@@ -638,18 +643,13 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
} }
- (void)configureDoneButtonBasedOnPage:(TabGridPage)page { - (void)configureDoneButtonBasedOnPage:(TabGridPage)page {
switch (page) { GridViewController* gridViewController =
case TabGridPageIncognitoTabs: [self gridViewControllerForPage:page];
self.doneButton.enabled = !self.incognitoTabsViewController.gridEmpty; if (!gridViewController) {
break; NOTREACHED() << "The done button should not be configured based on the "
case TabGridPageRegularTabs: "contents of the recent tabs page.";
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;
} }
self.doneButton.enabled = !gridViewController.gridEmpty;
} }
- (void)configureCloseAllButtonForCurrentPageAndUndoAvailability { - (void)configureCloseAllButtonForCurrentPageAndUndoAvailability {
...@@ -665,17 +665,10 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) { ...@@ -665,17 +665,10 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
return; return;
} }
// Otherwise setup as a Close All button. // Otherwise setup as a Close All button.
switch (self.currentPage) { GridViewController* gridViewController =
case TabGridPageIncognitoTabs: [self gridViewControllerForPage:self.currentPage];
self.closeAllButton.enabled = !self.incognitoTabsViewController.gridEmpty; self.closeAllButton.enabled =
break; gridViewController == nil ? NO : !gridViewController.gridEmpty;
case TabGridPageRegularTabs:
self.closeAllButton.enabled = !self.regularTabsViewController.gridEmpty;
break;
case TabGridPageRemoteTabs:
self.closeAllButton.enabled = NO;
break;
}
[self.closeAllButton [self.closeAllButton
setTitle:l10n_util::GetNSString(IDS_IOS_TAB_GRID_CLOSE_ALL_BUTTON) setTitle:l10n_util::GetNSString(IDS_IOS_TAB_GRID_CLOSE_ALL_BUTTON)
forState:UIControlStateNormal]; forState:UIControlStateNormal];
...@@ -814,7 +807,12 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) { ...@@ -814,7 +807,12 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
newActivePage = self.activePage; newActivePage = self.activePage;
} }
self.activePage = newActivePage; 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 { - (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