Commit 0b0c1ea5 authored by Chris Lu's avatar Chris Lu Committed by Commit Bot

[ios] Return early if Webstate is not valid in InfobarContainerMediator

If the webstate is nil or if it's not the active webstate, then
it is likely that the BadgeTabHelper is not valid, so return early.

This change also ensures that all InfobarCoordinator blocks
use weakSelf in calls of InfobarContainerMediator

Fixed: 1055908
Change-Id: Ic68ee9950ce928f1143981425cbac934057bbe64
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2075300
Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745061}
parent 387daa9a
......@@ -143,8 +143,8 @@ const CGFloat kBannerOverlapWithOmnibox = 5.0;
weakSelf.infobarBannerState =
InfobarBannerPresentationState::Presented;
[weakSelf.badgeDelegate
infobarBannerWasPresented:self.infobarType
forWebState:self.webState];
infobarBannerWasPresented:weakSelf.infobarType
forWebState:weakSelf.webState];
[weakSelf infobarBannerWasPresented];
if (completion)
completion();
......
......@@ -99,8 +99,12 @@
- (void)infobarWasAccepted:(InfobarType)infobarType
forWebState:(web::WebState*)webState {
DCHECK(webState);
DCHECK_EQ(webState, self.webStateList->GetActiveWebState());
if (!webState || !self.webStateList ||
webState != self.webStateList->GetActiveWebState()) {
// No need to update the badge if the infobar was accepted in a webstate
// that isn't the active WebState.
return;
}
InfobarBadgeTabHelper* infobarBadgeTabHelper =
InfobarBadgeTabHelper::FromWebState(webState);
DCHECK(infobarBadgeTabHelper);
......@@ -109,8 +113,12 @@
- (void)infobarWasReverted:(InfobarType)infobarType
forWebState:(web::WebState*)webState {
DCHECK(webState);
DCHECK_EQ(webState, self.webStateList->GetActiveWebState());
if (!webState || !self.webStateList ||
webState != self.webStateList->GetActiveWebState()) {
// No need to update the badge if the infobar was reverted in a webstate
// that isn't the active WebState.
return;
}
InfobarBadgeTabHelper* infobarBadgeTabHelper =
InfobarBadgeTabHelper::FromWebState(webState);
DCHECK(infobarBadgeTabHelper);
......@@ -119,8 +127,12 @@
- (void)infobarBannerWasPresented:(InfobarType)infobarType
forWebState:(web::WebState*)webState {
DCHECK(webState);
DCHECK_EQ(webState, self.webStateList->GetActiveWebState());
if (!webState || !self.webStateList ||
webState != self.webStateList->GetActiveWebState()) {
// No need to update the badge if the infobar was presented in a webstate
// that isn't the active WebState.
return;
}
InfobarBadgeTabHelper* infobarBadgeTabHelper =
InfobarBadgeTabHelper::FromWebState(webState);
DCHECK(infobarBadgeTabHelper);
......@@ -129,7 +141,9 @@
- (void)infobarBannerWasDismissed:(InfobarType)infobarType
forWebState:(web::WebState*)webState {
DCHECK(webState);
if (!webState) {
return;
}
// If the banner is dismissed because of a change in WebState, |webState| will
// not match the AcitveWebStaate, so don't DCHECK.
InfobarBadgeTabHelper* infobarBadgeTabHelper =
......
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