| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/browser/ui/ntp/google_landing_mediator.h" | 5 #import "ios/chrome/browser/ui/ntp/google_landing_mediator.h" |
| 6 | 6 |
| 7 #import "base/ios/weak_nsobject.h" | 7 #import "base/ios/weak_nsobject.h" |
| 8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
| 9 #include "base/metrics/user_metrics.h" | 9 #include "base/metrics/user_metrics.h" |
| 10 #include "base/metrics/user_metrics_action.h" | 10 #include "base/metrics/user_metrics_action.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" | 28 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" |
| 29 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" | 29 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" |
| 30 #import "ios/chrome/browser/ui/ntp/google_landing_consumer.h" | 30 #import "ios/chrome/browser/ui/ntp/google_landing_consumer.h" |
| 31 #import "ios/chrome/browser/ui/ntp/notification_promo_whats_new.h" | 31 #import "ios/chrome/browser/ui/ntp/notification_promo_whats_new.h" |
| 32 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h" | 32 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h" |
| 33 #import "ios/chrome/browser/ui/url_loader.h" | 33 #import "ios/chrome/browser/ui/url_loader.h" |
| 34 #import "ios/chrome/browser/web_state_list/web_state_list.h" | 34 #import "ios/chrome/browser/web_state_list/web_state_list.h" |
| 35 #import "ios/chrome/browser/web_state_list/web_state_list_observer_bridge.h" | 35 #import "ios/chrome/browser/web_state_list/web_state_list_observer_bridge.h" |
| 36 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 36 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
| 37 #include "ios/public/provider/chrome/browser/voice/voice_search_provider.h" | 37 #include "ios/public/provider/chrome/browser/voice/voice_search_provider.h" |
| 38 #include "ios/web/public/web_state/web_state.h" |
| 38 | 39 |
| 39 using base::UserMetricsAction; | 40 using base::UserMetricsAction; |
| 40 | 41 |
| 41 namespace { | 42 namespace { |
| 42 | 43 |
| 43 const NSInteger kMaxNumMostVisitedFavicons = 8; | 44 const NSInteger kMaxNumMostVisitedFavicons = 8; |
| 44 | 45 |
| 45 } // namespace | 46 } // namespace |
| 46 | 47 |
| 47 @interface GoogleLandingMediator (UsedBySearchEngineObserver) | 48 @interface GoogleLandingMediator (UsedBySearchEngineObserver) |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 } | 169 } |
| 169 | 170 |
| 170 - (void)setUp { | 171 - (void)setUp { |
| 171 [_consumer setIsOffTheRecord:_browserState->IsOffTheRecord()]; | 172 [_consumer setIsOffTheRecord:_browserState->IsOffTheRecord()]; |
| 172 [_consumer setVoiceSearchIsEnabled:ios::GetChromeBrowserProvider() | 173 [_consumer setVoiceSearchIsEnabled:ios::GetChromeBrowserProvider() |
| 173 ->GetVoiceSearchProvider() | 174 ->GetVoiceSearchProvider() |
| 174 ->IsVoiceSearchEnabled()]; | 175 ->IsVoiceSearchEnabled()]; |
| 175 [_consumer | 176 [_consumer |
| 176 setMaximumMostVisitedSitesShown:[GoogleLandingMediator maxSitesShown]]; | 177 setMaximumMostVisitedSitesShown:[GoogleLandingMediator maxSitesShown]]; |
| 177 [_consumer setTabCount:self.webStateList->count()]; | 178 [_consumer setTabCount:self.webStateList->count()]; |
| 179 web::WebState* webState = _webStateList->GetActiveWebState(); |
| 180 if (webState) { |
| 181 web::NavigationManager* nav = webState->GetNavigationManager(); |
| 182 [_consumer setCanGoForward:nav->CanGoForward()]; |
| 183 [_consumer setCanGoBack:nav->CanGoBack()]; |
| 184 } |
| 178 | 185 |
| 179 // Set up template URL service to listen for default search engine changes. | 186 // Set up template URL service to listen for default search engine changes. |
| 180 _templateURLService = | 187 _templateURLService = |
| 181 ios::TemplateURLServiceFactory::GetForBrowserState(_browserState); | 188 ios::TemplateURLServiceFactory::GetForBrowserState(_browserState); |
| 182 _observer.reset( | 189 _observer.reset( |
| 183 new google_landing::SearchEngineObserver(self, _templateURLService)); | 190 new google_landing::SearchEngineObserver(self, _templateURLService)); |
| 184 _templateURLService->Load(); | 191 _templateURLService->Load(); |
| 185 _doodleController.reset(ios::GetChromeBrowserProvider()->CreateLogoVendor( | 192 _doodleController.reset(ios::GetChromeBrowserProvider()->CreateLogoVendor( |
| 186 _browserState, _loader)); | 193 _browserState, _loader)); |
| 187 [_consumer setLogoVendor:_doodleController]; | 194 [_consumer setLogoVendor:_doodleController]; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 atIndex:(int)index { | 278 atIndex:(int)index { |
| 272 [self.consumer setTabCount:self.webStateList->count()]; | 279 [self.consumer setTabCount:self.webStateList->count()]; |
| 273 } | 280 } |
| 274 | 281 |
| 275 - (void)webStateList:(WebStateList*)webStateList | 282 - (void)webStateList:(WebStateList*)webStateList |
| 276 didDetachWebState:(web::WebState*)webState | 283 didDetachWebState:(web::WebState*)webState |
| 277 atIndex:(int)atIndex { | 284 atIndex:(int)atIndex { |
| 278 [self.consumer setTabCount:self.webStateList->count()]; | 285 [self.consumer setTabCount:self.webStateList->count()]; |
| 279 } | 286 } |
| 280 | 287 |
| 288 // If the actual webState associated with this mediator were passed in, this |
| 289 // would not be necessary. However, since the active webstate can change when |
| 290 // the new tab page is created (and animated in), listen for changes here and |
| 291 // always display what's active. |
| 292 - (void)webStateList:(WebStateList*)webStateList |
| 293 didChangeActiveWebState:(web::WebState*)newWebState |
| 294 oldWebState:(web::WebState*)oldWebState |
| 295 atIndex:(int)atIndex |
| 296 userAction:(BOOL)userAction { |
| 297 if (newWebState) { |
| 298 web::NavigationManager* nav = newWebState->GetNavigationManager(); |
| 299 [self.consumer setCanGoForward:nav->CanGoForward()]; |
| 300 [self.consumer setCanGoBack:nav->CanGoBack()]; |
| 301 } |
| 302 } |
| 303 |
| 281 #pragma mark - GoogleLandingDataSource | 304 #pragma mark - GoogleLandingDataSource |
| 282 | 305 |
| 283 - (void)addBlacklistedURL:(const GURL&)url { | 306 - (void)addBlacklistedURL:(const GURL&)url { |
| 284 _mostVisitedSites->AddOrRemoveBlacklistedUrl(url, true); | 307 _mostVisitedSites->AddOrRemoveBlacklistedUrl(url, true); |
| 285 } | 308 } |
| 286 | 309 |
| 287 - (void)removeBlacklistedURL:(const GURL&)url { | 310 - (void)removeBlacklistedURL:(const GURL&)url { |
| 288 _mostVisitedSites->AddOrRemoveBlacklistedUrl(url, false); | 311 _mostVisitedSites->AddOrRemoveBlacklistedUrl(url, false); |
| 289 } | 312 } |
| 290 | 313 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 310 } | 333 } |
| 311 | 334 |
| 312 - (LargeIconCache*)largeIconCache { | 335 - (LargeIconCache*)largeIconCache { |
| 313 return IOSChromeLargeIconCacheFactory::GetForBrowserState(_browserState); | 336 return IOSChromeLargeIconCacheFactory::GetForBrowserState(_browserState); |
| 314 } | 337 } |
| 315 | 338 |
| 316 - (favicon::LargeIconService*)largeIconService { | 339 - (favicon::LargeIconService*)largeIconService { |
| 317 return IOSChromeLargeIconServiceFactory::GetForBrowserState(_browserState); | 340 return IOSChromeLargeIconServiceFactory::GetForBrowserState(_browserState); |
| 318 } | 341 } |
| 319 | 342 |
| 320 - (id<WebToolbarDelegate>)toolbarDelegate { | |
| 321 return _webToolbarDelegate; | |
| 322 } | |
| 323 | |
| 324 - (void)promoViewed { | 343 - (void)promoViewed { |
| 325 DCHECK(_notification_promo); | 344 DCHECK(_notification_promo); |
| 326 _notification_promo->HandleViewed(); | 345 _notification_promo->HandleViewed(); |
| 327 [self.consumer setPromoCanShow:_notification_promo->CanShow()]; | 346 [self.consumer setPromoCanShow:_notification_promo->CanShow()]; |
| 328 } | 347 } |
| 329 | 348 |
| 330 - (void)promoTapped { | 349 - (void)promoTapped { |
| 331 DCHECK(_notification_promo); | 350 DCHECK(_notification_promo); |
| 332 _notification_promo->HandleClosed(); | 351 _notification_promo->HandleClosed(); |
| 333 [self.consumer setPromoCanShow:_notification_promo->CanShow()]; | 352 [self.consumer setPromoCanShow:_notification_promo->CanShow()]; |
| 334 | 353 |
| 335 if (_notification_promo->IsURLPromo()) { | 354 if (_notification_promo->IsURLPromo()) { |
| 336 [_loader webPageOrderedOpen:_notification_promo->url() | 355 [_loader webPageOrderedOpen:_notification_promo->url() |
| 337 referrer:web::Referrer() | 356 referrer:web::Referrer() |
| 338 inBackground:NO | 357 inBackground:NO |
| 339 appendTo:kCurrentTab]; | 358 appendTo:kCurrentTab]; |
| 340 return; | 359 return; |
| 341 } | 360 } |
| 342 | 361 |
| 343 if (_notification_promo->IsChromeCommand()) { | 362 if (_notification_promo->IsChromeCommand()) { |
| 344 base::scoped_nsobject<GenericChromeCommand> command( | 363 base::scoped_nsobject<GenericChromeCommand> command( |
| 345 [[GenericChromeCommand alloc] | 364 [[GenericChromeCommand alloc] |
| 346 initWithTag:_notification_promo->command_id()]); | 365 initWithTag:_notification_promo->command_id()]); |
| 347 [self.consumer chromeExecuteCommand:command]; | 366 [self.consumer chromeExecuteCommand:command]; |
| 348 return; | 367 return; |
| 349 } | 368 } |
| 350 NOTREACHED(); | 369 NOTREACHED(); |
| 351 } | 370 } |
| 352 | 371 |
| 372 - (void)prepareToEnterTabSwitcher:(id)sender { |
| 373 [_webToolbarDelegate prepareToEnterTabSwitcher:sender]; |
| 374 } |
| 375 |
| 353 #pragma mark - UrlLoader | 376 #pragma mark - UrlLoader |
| 354 | 377 |
| 355 - (void)loadURL:(const GURL&)url | 378 - (void)loadURL:(const GURL&)url |
| 356 referrer:(const web::Referrer&)referrer | 379 referrer:(const web::Referrer&)referrer |
| 357 transition:(ui::PageTransition)transition | 380 transition:(ui::PageTransition)transition |
| 358 rendererInitiated:(BOOL)rendererInitiated { | 381 rendererInitiated:(BOOL)rendererInitiated { |
| 359 [_loader loadURL:url | 382 [_loader loadURL:url |
| 360 referrer:referrer | 383 referrer:referrer |
| 361 transition:transition | 384 transition:transition |
| 362 rendererInitiated:rendererInitiated]; | 385 rendererInitiated:rendererInitiated]; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 | 431 |
| 409 - (void)onFakeboxBlur { | 432 - (void)onFakeboxBlur { |
| 410 [_focuser onFakeboxBlur]; | 433 [_focuser onFakeboxBlur]; |
| 411 } | 434 } |
| 412 | 435 |
| 413 - (void)onFakeboxAnimationComplete { | 436 - (void)onFakeboxAnimationComplete { |
| 414 [_focuser onFakeboxAnimationComplete]; | 437 [_focuser onFakeboxAnimationComplete]; |
| 415 } | 438 } |
| 416 | 439 |
| 417 @end | 440 @end |
| OLD | NEW |