Commit bc2c3c24 authored by Chris Lu's avatar Chris Lu Committed by Commit Bot

[ios] Use BadgeCoordinator and BadgeMediator to manage Infobar badges

Moves delegate for InfobarBadgeTabHelper from LocationBarMediator to
BadgeMediator. LocationBarViewController now implements the BadgeConsumer
protocol to receive signals from BadgeMediator. LocationBarViewController's
implementation of BadgeConsumer looks odd, because it still only supports
one badge. Ultimately a separate view controller owned by BadgeCoordinator will
be the BadgeMediator's consumer.

Bug: 976901
Change-Id: Ifa0eec1796e0436188af25d06e73f0ba3e1eb0da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1690719
Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#677119}
parent b0c5e585
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "ios/chrome/browser/ui/badges/badge_coordinator.h" #import "ios/chrome/browser/ui/badges/badge_coordinator.h"
#import "ios/chrome/browser/ui/badges/badge_mediator.h" #import "ios/chrome/browser/ui/badges/badge_mediator.h"
#import "ios/chrome/browser/ui/infobars/infobar_feature.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
...@@ -20,8 +21,10 @@ ...@@ -20,8 +21,10 @@
@implementation BadgeCoordinator @implementation BadgeCoordinator
- (void)start { - (void)start {
self.mediator = [[BadgeMediator alloc] initWithConsumer:self.viewController if (IsInfobarUIRebootEnabled()) {
webStateList:self.webStateList]; self.mediator = [[BadgeMediator alloc] initWithConsumer:self.viewController
webStateList:self.webStateList];
}
} }
- (void)stop { - (void)stop {
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#import "ios/chrome/browser/infobars/infobar_type.h" #import "ios/chrome/browser/infobars/infobar_type.h"
#import "ios/chrome/browser/ui/badges/badge_consumer.h" #import "ios/chrome/browser/ui/badges/badge_consumer.h"
#import "ios/chrome/browser/ui/badges/badge_item.h" #import "ios/chrome/browser/ui/badges/badge_item.h"
#import "ios/chrome/browser/ui/infobars/infobar_feature.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h" #import "ios/chrome/browser/web_state_list/web_state_list.h"
#import "ios/chrome/browser/web_state_list/web_state_list_observer_bridge.h" #import "ios/chrome/browser/web_state_list/web_state_list_observer_bridge.h"
......
...@@ -44,6 +44,8 @@ source_set("location_bar") { ...@@ -44,6 +44,8 @@ source_set("location_bar") {
"//ios/chrome/browser/search_engines", "//ios/chrome/browser/search_engines",
"//ios/chrome/browser/ssl", "//ios/chrome/browser/ssl",
"//ios/chrome/browser/ui:feature_flags", "//ios/chrome/browser/ui:feature_flags",
"//ios/chrome/browser/ui/badges",
"//ios/chrome/browser/ui/badges:public",
"//ios/chrome/browser/ui/commands", "//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/elements", "//ios/chrome/browser/ui/elements",
"//ios/chrome/browser/ui/fullscreen", "//ios/chrome/browser/ui/fullscreen",
......
...@@ -21,12 +21,14 @@ ...@@ -21,12 +21,14 @@
#include "ios/chrome/browser/infobars/infobar_metrics_recorder.h" #include "ios/chrome/browser/infobars/infobar_metrics_recorder.h"
#import "ios/chrome/browser/ntp/new_tab_page_tab_helper.h" #import "ios/chrome/browser/ntp/new_tab_page_tab_helper.h"
#include "ios/chrome/browser/search_engines/template_url_service_factory.h" #include "ios/chrome/browser/search_engines/template_url_service_factory.h"
#import "ios/chrome/browser/ui/badges/badge_mediator.h"
#include "ios/chrome/browser/ui/commands/browser_commands.h" #include "ios/chrome/browser/ui/commands/browser_commands.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h" #import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/ui/commands/load_query_commands.h" #import "ios/chrome/browser/ui/commands/load_query_commands.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_controller.h" #import "ios/chrome/browser/ui/fullscreen/fullscreen_controller.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_controller_factory.h" #import "ios/chrome/browser/ui/fullscreen/fullscreen_controller_factory.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_ui_updater.h" #import "ios/chrome/browser/ui/fullscreen/fullscreen_ui_updater.h"
#import "ios/chrome/browser/ui/infobars/infobar_feature.h"
#import "ios/chrome/browser/ui/location_bar/location_bar_constants.h" #import "ios/chrome/browser/ui/location_bar/location_bar_constants.h"
#import "ios/chrome/browser/ui/location_bar/location_bar_mediator.h" #import "ios/chrome/browser/ui/location_bar/location_bar_mediator.h"
#import "ios/chrome/browser/ui/location_bar/location_bar_url_loader.h" #import "ios/chrome/browser/ui/location_bar/location_bar_url_loader.h"
...@@ -78,6 +80,8 @@ const int kLocationAuthorizationStatusCount = 5; ...@@ -78,6 +80,8 @@ const int kLocationAuthorizationStatusCount = 5;
@property(nonatomic, assign, getter=isStarted) BOOL started; @property(nonatomic, assign, getter=isStarted) BOOL started;
// Coordinator for the omnibox popup. // Coordinator for the omnibox popup.
@property(nonatomic, strong) OmniboxPopupCoordinator* omniboxPopupCoordinator; @property(nonatomic, strong) OmniboxPopupCoordinator* omniboxPopupCoordinator;
// Mediator for the badges displayed in the LocationBar.
@property(nonatomic, strong) BadgeMediator* badgeMediator;
// Coordinator for the omnibox. // Coordinator for the omnibox.
@property(nonatomic, strong) OmniboxCoordinator* omniboxCoordinator; @property(nonatomic, strong) OmniboxCoordinator* omniboxCoordinator;
@property(nonatomic, strong) LocationBarMediator* mediator; @property(nonatomic, strong) LocationBarMediator* mediator;
...@@ -157,6 +161,13 @@ const int kLocationAuthorizationStatusCount = 5; ...@@ -157,6 +161,13 @@ const int kLocationAuthorizationStatusCount = 5;
self.omniboxPopupCoordinator.webStateList = self.webStateList; self.omniboxPopupCoordinator.webStateList = self.webStateList;
[self.omniboxPopupCoordinator start]; [self.omniboxPopupCoordinator start];
// Create BadgeMediator and set the viewController as its consumer.
if (IsInfobarUIRebootEnabled()) {
self.badgeMediator =
[[BadgeMediator alloc] initWithConsumer:self.viewController
webStateList:self.webStateList];
}
self.mediator = [[LocationBarMediator alloc] self.mediator = [[LocationBarMediator alloc]
initWithLocationBarModel:[self locationBarModel]]; initWithLocationBarModel:[self locationBarModel]];
self.mediator.webStateList = self.webStateList; self.mediator.webStateList = self.webStateList;
...@@ -180,6 +191,7 @@ const int kLocationAuthorizationStatusCount = 5; ...@@ -180,6 +191,7 @@ const int kLocationAuthorizationStatusCount = 5;
// The popup has to be destroyed before the location bar. // The popup has to be destroyed before the location bar.
[self.omniboxPopupCoordinator stop]; [self.omniboxPopupCoordinator stop];
[self.omniboxCoordinator stop]; [self.omniboxCoordinator stop];
[self.badgeMediator disconnect];
_editController.reset(); _editController.reset();
self.viewController = nil; self.viewController = nil;
......
...@@ -8,12 +8,9 @@ ...@@ -8,12 +8,9 @@
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "components/omnibox/browser/location_bar_model.h" #include "components/omnibox/browser/location_bar_model.h"
#include "ios/chrome/browser/chrome_url_constants.h" #include "ios/chrome/browser/chrome_url_constants.h"
#include "ios/chrome/browser/infobars/infobar_badge_tab_helper.h"
#include "ios/chrome/browser/infobars/legacy_infobar_badge_tab_helper_delegate.h"
#import "ios/chrome/browser/search_engines/search_engine_observer_bridge.h" #import "ios/chrome/browser/search_engines/search_engine_observer_bridge.h"
#import "ios/chrome/browser/search_engines/search_engines_util.h" #import "ios/chrome/browser/search_engines/search_engines_util.h"
#include "ios/chrome/browser/ssl/ios_security_state_tab_helper.h" #include "ios/chrome/browser/ssl/ios_security_state_tab_helper.h"
#import "ios/chrome/browser/ui/infobars/infobar_feature.h"
#import "ios/chrome/browser/ui/location_bar/location_bar_consumer.h" #import "ios/chrome/browser/ui/location_bar/location_bar_consumer.h"
#import "ios/chrome/browser/ui/ntp/ntp_util.h" #import "ios/chrome/browser/ui/ntp/ntp_util.h"
#import "ios/chrome/browser/ui/omnibox/omnibox_util.h" #import "ios/chrome/browser/ui/omnibox/omnibox_util.h"
...@@ -34,7 +31,6 @@ ...@@ -34,7 +31,6 @@
#endif #endif
@interface LocationBarMediator () <CRWWebStateObserver, @interface LocationBarMediator () <CRWWebStateObserver,
LegacyInfobarBadgeTabHelperDelegate,
SearchEngineObserving, SearchEngineObserving,
WebStateListObserving> WebStateListObserving>
...@@ -50,7 +46,6 @@ ...@@ -50,7 +46,6 @@
std::unique_ptr<WebStateListObserverBridge> _webStateListObserver; std::unique_ptr<WebStateListObserverBridge> _webStateListObserver;
std::unique_ptr<SearchEngineObserverBridge> _searchEngineObserver; std::unique_ptr<SearchEngineObserverBridge> _searchEngineObserver;
} }
@synthesize badgeState = _badgeState;
- (instancetype)initWithLocationBarModel:(LocationBarModel*)locationBarModel { - (instancetype)initWithLocationBarModel:(LocationBarModel*)locationBarModel {
DCHECK(locationBarModel); DCHECK(locationBarModel);
...@@ -159,18 +154,6 @@ ...@@ -159,18 +154,6 @@
search_engines::SupportsSearchByImage(self.templateURLService); search_engines::SupportsSearchByImage(self.templateURLService);
} }
#pragma mark - InfobarBadgeTabHelper
- (void)displayBadge:(BOOL)display type:(InfobarType)infobarType {
DCHECK(IsInfobarUIRebootEnabled());
[self.consumer displayInfobarBadge:display type:infobarType];
}
- (void)setBadgeState:(InfobarBadgeState)badgeState {
_badgeState = badgeState;
[self.consumer activeInfobarBadge:_badgeState & InfobarBadgeStateAccepted];
}
#pragma mark - Setters #pragma mark - Setters
- (void)setWebState:(web::WebState*)webState { - (void)setWebState:(web::WebState*)webState {
...@@ -183,26 +166,6 @@ ...@@ -183,26 +166,6 @@
if (_webState) { if (_webState) {
_webState->AddObserver(_webStateObserver.get()); _webState->AddObserver(_webStateObserver.get());
if (IsInfobarUIRebootEnabled()) {
InfobarBadgeTabHelper* infobarBadgeTabHelper =
InfobarBadgeTabHelper::FromWebState(_webState);
DCHECK(infobarBadgeTabHelper);
infobarBadgeTabHelper->SetLegacyDelegate(self);
if (self.consumer) {
// Whenever the WebState changes ask the corresponding
// InfobarBadgeTabHelper if a badge should be displayed, and if its
// Active or not.
[self.consumer
displayInfobarBadge:infobarBadgeTabHelper->is_infobar_displaying()
type:infobarBadgeTabHelper->infobar_type()];
if (infobarBadgeTabHelper->is_badge_accepted()) {
self.badgeState |= InfobarBadgeStateAccepted;
} else {
self.badgeState &= ~InfobarBadgeStateAccepted;
}
}
}
if (self.consumer) { if (self.consumer) {
[self notifyConsumerOfChangedLocation]; [self notifyConsumerOfChangedLocation];
[self notifyConsumerOfChangedSecurityIcon]; [self notifyConsumerOfChangedSecurityIcon];
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/badges/badge_consumer.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_ui_element.h" #import "ios/chrome/browser/ui/fullscreen/fullscreen_ui_element.h"
#import "ios/chrome/browser/ui/location_bar/location_bar_consumer.h" #import "ios/chrome/browser/ui/location_bar/location_bar_consumer.h"
#import "ios/chrome/browser/ui/orchestrator/location_bar_animatee.h" #import "ios/chrome/browser/ui/orchestrator/location_bar_animatee.h"
...@@ -35,7 +36,7 @@ ...@@ -35,7 +36,7 @@
// the omnibox textfield is displayed; in the non-editing state, the current // the omnibox textfield is displayed; in the non-editing state, the current
// location is displayed. // location is displayed.
@interface LocationBarViewController @interface LocationBarViewController
: UIViewController<FullscreenUIElement, LocationBarAnimatee> : UIViewController <BadgeConsumer, FullscreenUIElement, LocationBarAnimatee>
// Sets the edit view to use in the editing state. This must be set before the // Sets the edit view to use in the editing state. This must be set before the
// view of this view controller is initialized. This must only be called once. // view of this view controller is initialized. This must only be called once.
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "components/open_from_clipboard/clipboard_recent_content.h" #include "components/open_from_clipboard/clipboard_recent_content.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/infobars/infobar_metrics_recorder.h" #include "ios/chrome/browser/infobars/infobar_metrics_recorder.h"
#import "ios/chrome/browser/ui/badges/badge_item.h"
#import "ios/chrome/browser/ui/commands/activity_service_commands.h" #import "ios/chrome/browser/ui/commands/activity_service_commands.h"
#import "ios/chrome/browser/ui/commands/application_commands.h" #import "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/commands/browser_commands.h" #import "ios/chrome/browser/ui/commands/browser_commands.h"
...@@ -489,6 +490,31 @@ typedef NS_ENUM(int, TrailingButtonState) { ...@@ -489,6 +490,31 @@ typedef NS_ENUM(int, TrailingButtonState) {
[self.locationBarSteadyView.leadingButton setActive:active animated:YES]; [self.locationBarSteadyView.leadingButton setActive:active animated:YES];
} }
#pragma mark - BadgeConsumer
- (void)setupWithBadges:(NSArray*)badges {
self.locationBarSteadyView.leadingButton.hidden = (badges.count == 0);
self.shouldShowLeadingButton = (badges.count > 0);
}
- (void)addBadge:(id<BadgeItem>)badgeItem {
self.locationBarSteadyView.leadingButton.hidden = NO;
self.shouldShowLeadingButton = YES;
self.activeBadge = badgeItem.isAccepted;
[self.locationBarSteadyView.leadingButton setActive:badgeItem.isAccepted
animated:YES];
}
- (void)removeBadge:(id<BadgeItem>)badgeItem {
self.locationBarSteadyView.leadingButton.hidden = YES;
self.shouldShowLeadingButton = NO;
}
- (void)updateBadge:(id<BadgeItem>)badgeItem {
[self.locationBarSteadyView.leadingButton setActive:badgeItem.isAccepted
animated:YES];
}
#pragma mark - UIMenu #pragma mark - UIMenu
- (void)showLongPressMenu:(UILongPressGestureRecognizer*)sender { - (void)showLongPressMenu:(UILongPressGestureRecognizer*)sender {
......
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