[go: up one dir, main page]

[ios] Checks if delegate is not nil before calling InfobarPresenting

TBR=sczs@chromium.org

(cherry picked from commit 19ea901e4151f5cddf7a3dbce4d5f030aea831be)

Bug: 972634
Change-Id: Ic1925bf36a5b4cdd4a0b769703b802662f1aa30d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1653894
Reviewed-by: Chris Lu <thegreenfrog@chromium.org>
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#668164}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1656208
Reviewed-by: Sergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/branch-heads/3809@{#258}
Cr-Branched-From: d82dec1a818f378c464ba307ddd9c92133eac355-refs/heads/master@{#665002}
diff --git a/ios/chrome/browser/ui/infobars/coordinators/infobar_password_coordinator.mm b/ios/chrome/browser/ui/infobars/coordinators/infobar_password_coordinator.mm
index 1ec93e9..c6af82b 100644
--- a/ios/chrome/browser/ui/infobars/coordinators/infobar_password_coordinator.mm
+++ b/ios/chrome/browser/ui/infobars/coordinators/infobar_password_coordinator.mm
@@ -140,7 +140,10 @@
 }
 
 - (void)infobarBannerWasPresented {
-  self.passwordInfoBarDelegate->InfobarPresenting(YES /*automatic*/);
+  // There's a chance the Delegate was destroyed while the presentation was
+  // taking place e.g. User navigated away. Check if the delegate still exists.
+  if (self.passwordInfoBarDelegate)
+    self.passwordInfoBarDelegate->InfobarPresenting(YES /*automatic*/);
 }
 
 - (void)infobarModalPresentedFromBanner:(BOOL)presentedFromBanner {