Commit 7cef5ae8 authored by Chris Lu's avatar Chris Lu Committed by Commit Bot

[ios] Check if badge should be marked accepted before calling delegate

The translate badge should not be marked as accepted until the translate
has finished, not immediately when the action button in the banner is
tapped. A InfobarCoordinatorImplementation method isInfobarAccepted
will allow specific Infobars to decide whether to call infobarWasAccepted:
when the button is tapped.

Bug: 1014959
Change-Id: I544395077845dd89c9909afe38a11801df5fbf40
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1872759
Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708904}
parent d72f6ed0
...@@ -89,6 +89,10 @@ ...@@ -89,6 +89,10 @@
return YES; return YES;
} }
- (BOOL)isInfobarAccepted {
return NO;
}
- (void)infobarBannerWasPresented { - (void)infobarBannerWasPresented {
// NO-OP. // NO-OP.
} }
......
...@@ -201,8 +201,10 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0; ...@@ -201,8 +201,10 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0;
- (void)bannerInfobarButtonWasPressed:(id)sender { - (void)bannerInfobarButtonWasPressed:(id)sender {
[self performInfobarAction]; [self performInfobarAction];
[self.badgeDelegate infobarWasAccepted:self.infobarType if ([self isInfobarAccepted]) {
forWebState:self.webState]; [self.badgeDelegate infobarWasAccepted:self.infobarType
forWebState:self.webState];
}
[self dismissInfobarBanner:sender animated:YES completion:nil]; [self dismissInfobarBanner:sender animated:YES completion:nil];
} }
...@@ -350,6 +352,11 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0; ...@@ -350,6 +352,11 @@ const CGFloat kiPadBannerOverlapWithOmnibox = 10.0;
return NO; return NO;
} }
- (BOOL)isInfobarAccepted {
NOTREACHED() << "Subclass must implement.";
return NO;
}
- (void)infobarBannerWasPresented { - (void)infobarBannerWasPresented {
NOTREACHED() << "Subclass must implement."; NOTREACHED() << "Subclass must implement.";
} }
......
...@@ -17,6 +17,11 @@ ...@@ -17,6 +17,11 @@
// successfully. If it returns NO no Modal should be presented. // successfully. If it returns NO no Modal should be presented.
- (BOOL)configureModalViewController; - (BOOL)configureModalViewController;
// Returns YES if the Infobar action was completed successfully. Useful for
// Infobar actions that finish asynchronously to delay marking the Infobar as
// accepted.
- (BOOL)isInfobarAccepted;
// Performs any actions related to an Infobar Banner presentation. // Performs any actions related to an Infobar Banner presentation.
- (void)infobarBannerWasPresented; - (void)infobarBannerWasPresented;
......
...@@ -149,6 +149,10 @@ ...@@ -149,6 +149,10 @@
return YES; return YES;
} }
- (BOOL)isInfobarAccepted {
return YES;
}
- (void)infobarBannerWasPresented { - (void)infobarBannerWasPresented {
// There's a chance the Delegate was destroyed while the presentation was // 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. // taking place e.g. User navigated away. Check if the delegate still exists.
......
...@@ -84,6 +84,10 @@ ...@@ -84,6 +84,10 @@
#pragma mark - InfobarCoordinatorImplementation #pragma mark - InfobarCoordinatorImplementation
- (BOOL)isInfobarAccepted {
return YES;
}
- (void)performInfobarAction { - (void)performInfobarAction {
if (self.saveCardInfoBarDelegate->upload()) { if (self.saveCardInfoBarDelegate->upload()) {
// TODO(crbug.com/1014652): Open Modal if CreditCard details will be // TODO(crbug.com/1014652): Open Modal if CreditCard details will be
......
...@@ -32,6 +32,9 @@ ...@@ -32,6 +32,9 @@
// InfobarBannerViewController owned by this Coordinator. // InfobarBannerViewController owned by this Coordinator.
@property(nonatomic, strong) InfobarBannerViewController* bannerViewController; @property(nonatomic, strong) InfobarBannerViewController* bannerViewController;
// The current state of translate.
@property(nonatomic, assign) translate::TranslateStep currentStep;
// Tracks user actions taken throughout Translate lifetime. // Tracks user actions taken throughout Translate lifetime.
@property(nonatomic, assign) UserAction userAction; @property(nonatomic, assign) UserAction userAction;
...@@ -52,6 +55,7 @@ ...@@ -52,6 +55,7 @@
std::make_unique<TranslateInfobarDelegateObserverBridge>( std::make_unique<TranslateInfobarDelegateObserverBridge>(
infoBarDelegate, self); infoBarDelegate, self);
_userAction = UserActionNone; _userAction = UserActionNone;
_currentStep = translate::TranslateStep::TRANSLATE_STEP_BEFORE_TRANSLATE;
} }
return self; return self;
} }
...@@ -61,7 +65,8 @@ ...@@ -61,7 +65,8 @@
- (void)translateInfoBarDelegate:(translate::TranslateInfoBarDelegate*)delegate - (void)translateInfoBarDelegate:(translate::TranslateInfoBarDelegate*)delegate
didChangeTranslateStep:(translate::TranslateStep)step didChangeTranslateStep:(translate::TranslateStep)step
withErrorType:(translate::TranslateErrors::Type)errorType { withErrorType:(translate::TranslateErrors::Type)errorType {
// TODO(crbug.com/1014959): implement // TODO(crbug.com/1014959): Update currentStep and call
// infobarWasAccepted:forWebState: if translate finished.
} }
- (BOOL)translateInfoBarDelegateDidDismissWithoutInteraction: - (BOOL)translateInfoBarDelegateDidDismissWithoutInteraction:
...@@ -100,6 +105,11 @@ ...@@ -100,6 +105,11 @@
#pragma mark - InfobarCoordinatorImplementation #pragma mark - InfobarCoordinatorImplementation
- (BOOL)shouldBadgeBeAccepted {
return self.currentStep ==
translate::TranslateStep::TRANSLATE_STEP_AFTER_TRANSLATE;
}
- (void)performInfobarAction { - (void)performInfobarAction {
self.userAction |= UserActionTranslate; self.userAction |= UserActionTranslate;
......
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