Skip to content

Commit

Permalink
Fix Crash where context menu Close action is used on incognito tab
Browse files Browse the repository at this point in the history
The reason for the crash was that the browser state can be destroyed and
created during the life time of the browser. (specifically when there no
incognito tabs).
The fix is to pick the value of browsing status from the existing browser
state when the helper is created.

Bug: 1206655
Change-Id: Iddbe65e78764be3e6d31da5a2f999419f060eab5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2881024
Reviewed-by: edchin <edchin@chromium.org>
Commit-Queue: Mohammad Refaat <mrefaat@chromium.org>
Cr-Commit-Position: refs/heads/master@{#881126}
  • Loading branch information
mrefaat88 authored and Chromium LUCI CQ committed May 10, 2021
1 parent af79f84 commit 21957b6
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
@interface GridContextMenuHelper () <GridContextMenuProvider>

@property(nonatomic, assign) Browser* browser;

@property(nonatomic, weak) id<TabContextMenuDelegate> contextMenuDelegate;
@property(nonatomic, weak) id<GridMenuActionsDataSource> actionsDataSource;

@property(nonatomic, assign) BOOL incognito;
@end

@implementation GridContextMenuHelper
Expand All @@ -41,6 +40,7 @@ - (instancetype)initWithBrowser:(Browser*)browser
_browser = browser;
_contextMenuDelegate = tabContextMenuDelegate;
_actionsDataSource = actionsDataSource;
_incognito = _browser->GetBrowserState()->IsOffTheRecord();
}
return self;
}
Expand Down Expand Up @@ -100,13 +100,11 @@ - (UIContextMenuConfiguration*)contextMenuConfigurationForGridCell:
if ([weakSelf.contextMenuDelegate
respondsToSelector:@selector(closeTabWithIdentifier:
incognito:)]) {
[menuElements
addObject:[actionFactory actionToCloseTabWithBlock:^{
[weakSelf.contextMenuDelegate
closeTabWithIdentifier:gridCell.itemIdentifier
incognito:weakSelf.browser->GetBrowserState()
->IsOffTheRecord()];
}]];
[menuElements addObject:[actionFactory actionToCloseTabWithBlock:^{
[weakSelf.contextMenuDelegate
closeTabWithIdentifier:gridCell.itemIdentifier
incognito:weakSelf.incognito];
}]];
}
return [UIMenu menuWithTitle:@"" children:menuElements];
};
Expand Down

0 comments on commit 21957b6

Please sign in to comment.