Commit 48b2a985 authored by Chris Lu's avatar Chris Lu Committed by Commit Bot

[ios] Add infobarWasReverted:forWebState: to InfobarBadgeUIDelegate

This addition is needed now that Translate can revert its Infobar action
(e.g. show original source language).

Bug: 1014959
Change-Id: I0d9e5537a77c08c6cefb453cb2e5e24c4adeece0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1897906
Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712749}
parent 3190b705
......@@ -34,6 +34,9 @@ class InfobarBadgeTabHelper
// Updates Infobar badge for the case where Infobar of |infobar_type| was
// accepted.
void UpdateBadgeForInfobarAccepted(InfobarType infobar_type);
// Updates Infobar badge for the case where Infobar action of |infobar_type|
// was reverted. This will negate the accepted state of the badge.
void UpdateBadgeForInfobarReverted(InfobarType infobar_type);
// Updates Infobar badge for the case where an Infobar banner of
// |infobar_type| was presented.
void UpdateBadgeForInfobarBannerPresented(InfobarType infobar_type);
......
......@@ -38,6 +38,12 @@ void InfobarBadgeTabHelper::UpdateBadgeForInfobarAccepted(
[delegate_ updateInfobarBadge:infobar_badge_models_[infobar_type]];
}
void InfobarBadgeTabHelper::UpdateBadgeForInfobarReverted(
InfobarType infobar_type) {
infobar_badge_models_[infobar_type].badgeState &= ~BadgeStateAccepted;
[delegate_ updateInfobarBadge:infobar_badge_models_[infobar_type]];
}
void InfobarBadgeTabHelper::UpdateBadgeForInfobarBannerPresented(
InfobarType infobar_type) {
infobar_badge_models_[infobar_type].badgeState |= BadgeStatePresented;
......
......@@ -76,6 +76,11 @@
forWebState:(web::WebState*)webState {
self.infobarBadgeTabHelper->UpdateBadgeForInfobarAccepted(infobarType);
}
- (void)infobarWasReverted:(InfobarType)infobarType
forWebState:(web::WebState*)webState {
self.infobarBadgeTabHelper->UpdateBadgeForInfobarReverted(infobarType);
}
@end
// Fake Infobar Container.
......@@ -241,6 +246,11 @@ TEST_F(InfobarBadgeTabHelperTest, TestInfobarBadgeState) {
infobar_badge_tab_delegate_.badgeState & BadgeStateAccepted);
EXPECT_EQ(BadgeStateRead,
infobar_badge_tab_delegate_.badgeState & BadgeStateRead);
tab_helper()->UpdateBadgeForInfobarReverted(
InfobarType::kInfobarTypePasswordSave);
EXPECT_NE(BadgeStateAccepted,
infobar_badge_tab_delegate_.badgeState & BadgeStateAccepted);
}
// Test the badge state after doesn't change after adding an Infobar with no
......
......@@ -22,6 +22,12 @@ enum class InfobarType;
- (void)infobarWasAccepted:(InfobarType)infobarType
forWebState:(web::WebState*)webState;
// Called whenever the revert action button of an Infobar of type |infobarType|
// in |webState| was tapped (e.g. the Translate "Show Original" action). It is
// triggered by the banner button. |webState| cannot be nil.
- (void)infobarWasReverted:(InfobarType)infobarType
forWebState:(web::WebState*)webState;
// Called whenever an InfobarBanner of type |infobarType| in |webState| was
// presented. |webState| cannot be nil.
- (void)infobarBannerWasPresented:(InfobarType)infobarType
......
......@@ -107,6 +107,16 @@
infobarBadgeTabHelper->UpdateBadgeForInfobarAccepted(infobarType);
}
- (void)infobarWasReverted:(InfobarType)infobarType
forWebState:(web::WebState*)webState {
DCHECK(webState);
DCHECK_EQ(webState, self.webStateList->GetActiveWebState());
InfobarBadgeTabHelper* infobarBadgeTabHelper =
InfobarBadgeTabHelper::FromWebState(webState);
DCHECK(infobarBadgeTabHelper);
infobarBadgeTabHelper->UpdateBadgeForInfobarReverted(infobarType);
}
- (void)infobarBannerWasPresented:(InfobarType)infobarType
forWebState:(web::WebState*)webState {
DCHECK(webState);
......
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