Skip to content

Commit

Permalink
[Mac] Fix for AutofillPopupViewBridge Crash
Browse files Browse the repository at this point in the history
Unsubscribe the WebTextfieldTouchBarController from
the notification center when it's deallocated or the
window it's observing is closed.

Bug: 747713
Change-Id: I9d3543775fadc9fda31f6de83c1b962218ce0a30
Reviewed-on: https://chromium-review.googlesource.com/583929
Commit-Queue: Sarah Chan <spqchan@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#489119}
  • Loading branch information
spqchan authored and Commit Bot committed Jul 24, 2017
1 parent 4669827 commit 33fe231
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@interface WebTextfieldTouchBarController : NSObject<NSTouchBarDelegate> {
TabContentsController* owner_; // weak.
AutofillPopupViewCocoa* popupView_; // weak.
NSWindow* window_; // weak.
}

// Designated initializer.
Expand Down
15 changes: 14 additions & 1 deletion chrome/browser/ui/cocoa/web_textfield_touch_bar_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,22 @@ - (instancetype)initWithTabContentsController:(TabContentsController*)owner {
return self;
}

- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}

- (void)showCreditCardAutofillForPopupView:(AutofillPopupViewCocoa*)popupView {
DCHECK(popupView);
DCHECK([popupView window]);

window_ = [popupView window];

NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center addObserver:self
selector:@selector(popupWindowWillClose:)
name:NSWindowWillCloseNotification
object:[popupView window]];
object:window_];
popupView_ = popupView;

if ([owner_ respondsToSelector:@selector(setTouchBar:)])
Expand All @@ -39,6 +47,11 @@ - (void)popupWindowWillClose:(NSNotification*)notif {

if ([owner_ respondsToSelector:@selector(setTouchBar:)])
[owner_ performSelector:@selector(setTouchBar:) withObject:nil];

[[NSNotificationCenter defaultCenter]
removeObserver:self
name:NSWindowWillCloseNotification
object:window_];
}

- (NSTouchBar*)makeTouchBar {
Expand Down

0 comments on commit 33fe231

Please sign in to comment.