| Index: ios/chrome/browser/ui/ntp/google_landing_mediator.mm
|
| diff --git a/ios/chrome/browser/ui/ntp/google_landing_mediator.mm b/ios/chrome/browser/ui/ntp/google_landing_mediator.mm
|
| index 1014342bbe35d77393c40f821de8ef7d37025e3a..a5a03eabc0491bd4392d20f00a386e3376b58223 100644
|
| --- a/ios/chrome/browser/ui/ntp/google_landing_mediator.mm
|
| +++ b/ios/chrome/browser/ui/ntp/google_landing_mediator.mm
|
| @@ -31,6 +31,8 @@
|
| #import "ios/chrome/browser/ui/ntp/notification_promo_whats_new.h"
|
| #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h"
|
| #import "ios/chrome/browser/ui/url_loader.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"
|
| #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
|
| #include "ios/public/provider/chrome/browser/voice/voice_search_provider.h"
|
|
|
| @@ -79,7 +81,8 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() {
|
|
|
| } // namespace google_landing
|
|
|
| -@interface GoogleLandingMediator ()<MostVisitedSitesObserving> {
|
| +@interface GoogleLandingMediator ()<MostVisitedSitesObserving,
|
| + WebStateListObserving> {
|
| // The ChromeBrowserState associated with this mediator.
|
| ios::ChromeBrowserState* _browserState; // Weak.
|
|
|
| @@ -112,7 +115,9 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() {
|
|
|
| base::WeakNSProtocol<id<WebToolbarDelegate>> _webToolbarDelegate;
|
|
|
| - base::scoped_nsobject<TabModel> _tabModel;
|
| + // Observes the WebStateList so that this mediator can update the UI when the
|
| + // active WebState changes.
|
| + std::unique_ptr<WebStateListObserverBridge> _webStateListObserver;
|
|
|
| // What's new promo.
|
| std::unique_ptr<NotificationPromoWhatsNew> _notification_promo;
|
| @@ -121,6 +126,9 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() {
|
| // Consumer to handle google landing update notifications.
|
| @property(nonatomic) id<GoogleLandingConsumer> consumer;
|
|
|
| +// The WebStateList that is being observed by this mediator.
|
| +@property(nonatomic, assign) WebStateList* webStateList;
|
| +
|
| // Perform initial setup.
|
| - (void)setUp;
|
|
|
| @@ -129,13 +137,14 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() {
|
| @implementation GoogleLandingMediator
|
|
|
| @synthesize consumer = _consumer;
|
| +@synthesize webStateList = _webStateList;
|
|
|
| - (instancetype)initWithConsumer:(id<GoogleLandingConsumer>)consumer
|
| browserState:(ios::ChromeBrowserState*)browserState
|
| loader:(id<UrlLoader>)loader
|
| focuser:(id<OmniboxFocuser>)focuser
|
| webToolbarDelegate:(id<WebToolbarDelegate>)webToolbarDelegate
|
| - tabModel:(TabModel*)tabModel {
|
| + webStateList:(WebStateList*)webStateList {
|
| self = [super init];
|
| if (self) {
|
| _consumer = consumer;
|
| @@ -143,13 +152,18 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() {
|
| _loader = loader;
|
| _focuser.reset(focuser);
|
| _webToolbarDelegate.reset(webToolbarDelegate);
|
| - _tabModel.reset([tabModel retain]);
|
| + _webStateList = webStateList;
|
| +
|
| + _webStateListObserver = base::MakeUnique<WebStateListObserverBridge>(self);
|
| + _webStateList->AddObserver(_webStateListObserver.get());
|
| +
|
| [self setUp];
|
| }
|
| return self;
|
| }
|
|
|
| - (void)dealloc {
|
| + _webStateList->RemoveObserver(_webStateListObserver.get());
|
| [[NSNotificationCenter defaultCenter] removeObserver:self.consumer];
|
| [super dealloc];
|
| }
|
| @@ -161,6 +175,7 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() {
|
| ->IsVoiceSearchEnabled()];
|
| [_consumer
|
| setMaximumMostVisitedSitesShown:[GoogleLandingMediator maxSitesShown]];
|
| + [_consumer setTabCount:self.webStateList->count()];
|
|
|
| // Set up template URL service to listen for default search engine changes.
|
| _templateURLService =
|
| @@ -249,6 +264,20 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() {
|
| }
|
| }
|
|
|
| +#pragma mark - WebStateListObserving
|
| +
|
| +- (void)webStateList:(WebStateList*)webStateList
|
| + didInsertWebState:(web::WebState*)webState
|
| + atIndex:(int)index {
|
| + [self.consumer setTabCount:self.webStateList->count()];
|
| +}
|
| +
|
| +- (void)webStateList:(WebStateList*)webStateList
|
| + didDetachWebState:(web::WebState*)webState
|
| + atIndex:(int)atIndex {
|
| + [self.consumer setTabCount:self.webStateList->count()];
|
| +}
|
| +
|
| #pragma mark - GoogleLandingDataSource
|
|
|
| - (void)addBlacklistedURL:(const GURL&)url {
|
| @@ -292,10 +321,6 @@ void SearchEngineObserver::OnTemplateURLServiceChanged() {
|
| return _webToolbarDelegate;
|
| }
|
|
|
| -- (TabModel*)tabModel {
|
| - return _tabModel;
|
| -}
|
| -
|
| - (void)promoViewed {
|
| DCHECK(_notification_promo);
|
| _notification_promo->HandleViewed();
|
|
|