| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/new_tab_page_controller.h" | 5 #import "ios/chrome/browser/ui/ntp/new_tab_page_controller.h" |
| 6 | 6 |
| 7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
| 8 | 8 |
| 9 #import "base/ios/weak_nsobject.h" | 9 #import "base/ios/weak_nsobject.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/mac/objc_property_releaser.h" | 11 #include "base/mac/objc_property_releaser.h" |
| 12 #include "base/metrics/user_metrics.h" | 12 #include "base/metrics/user_metrics.h" |
| 13 #include "base/metrics/user_metrics_action.h" | 13 #include "base/metrics/user_metrics_action.h" |
| 14 #include "components/prefs/pref_service.h" | 14 #include "components/prefs/pref_service.h" |
| 15 #include "components/search_engines/template_url_service.h" | 15 #include "components/search_engines/template_url_service.h" |
| 16 #include "components/strings/grit/components_strings.h" | 16 #include "components/strings/grit/components_strings.h" |
| 17 #include "components/sync_sessions/synced_session.h" | 17 #include "components/sync_sessions/synced_session.h" |
| 18 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 18 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 19 #include "ios/chrome/browser/pref_names.h" | 19 #include "ios/chrome/browser/pref_names.h" |
| 20 #include "ios/chrome/browser/search_engines/template_url_service_factory.h" | 20 #include "ios/chrome/browser/search_engines/template_url_service_factory.h" |
| 21 #include "ios/chrome/browser/sync/sync_setup_service.h" | 21 #include "ios/chrome/browser/sync/sync_setup_service.h" |
| 22 #include "ios/chrome/browser/sync/sync_setup_service_factory.h" | 22 #include "ios/chrome/browser/sync/sync_setup_service_factory.h" |
| 23 #import "ios/chrome/browser/tabs/tab_model.h" | 23 #import "ios/chrome/browser/tabs/tab_model.h" |
| 24 #import "ios/chrome/browser/ui/bookmarks/bookmark_controller_factory.h" | 24 #import "ios/chrome/browser/ui/bookmarks/bookmark_controller_factory.h" |
| 25 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_tablet_ntp_controller.h" |
| 25 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" | 26 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" |
| 26 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" | 27 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" |
| 27 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" | 28 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" |
| 28 #import "ios/chrome/browser/ui/ntp/google_landing_controller.h" | 29 #import "ios/chrome/browser/ui/ntp/google_landing_controller.h" |
| 29 #import "ios/chrome/browser/ui/ntp/incognito_panel_controller.h" | 30 #import "ios/chrome/browser/ui/ntp/incognito_panel_controller.h" |
| 30 #import "ios/chrome/browser/ui/ntp/new_tab_page_bar_item.h" | 31 #import "ios/chrome/browser/ui/ntp/new_tab_page_bar_item.h" |
| 31 #import "ios/chrome/browser/ui/ntp/new_tab_page_view.h" | 32 #import "ios/chrome/browser/ui/ntp/new_tab_page_view.h" |
| 32 #import "ios/chrome/browser/ui/ntp/recent_tabs/recent_tabs_panel_controller.h" | 33 #import "ios/chrome/browser/ui/ntp/recent_tabs/recent_tabs_panel_controller.h" |
| 33 #import "ios/chrome/browser/ui/rtl_geometry.h" | 34 #import "ios/chrome/browser/ui/rtl_geometry.h" |
| 34 #include "ios/chrome/browser/ui/toolbar/toolbar_model_ios.h" | 35 #include "ios/chrome/browser/ui/toolbar/toolbar_model_ios.h" |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 278 |
| 278 - (void)dealloc { | 279 - (void)dealloc { |
| 279 // Animations can last past the life of the NTP controller, nil out the | 280 // Animations can last past the life of the NTP controller, nil out the |
| 280 // delegate. | 281 // delegate. |
| 281 self.ntpView.scrollView.delegate = nil; | 282 self.ntpView.scrollView.delegate = nil; |
| 282 | 283 |
| 283 // This is not an ideal place to put view controller contaimnent, rather a | 284 // This is not an ideal place to put view controller contaimnent, rather a |
| 284 // //web -wasDismissed method on CRWNativeContent would be more accurate. If | 285 // //web -wasDismissed method on CRWNativeContent would be more accurate. If |
| 285 // CRWNativeContent leaks, this will not be called. | 286 // CRWNativeContent leaks, this will not be called. |
| 286 // TODO(crbug.com/708319): Also call -removeFromParentViewController for | 287 // TODO(crbug.com/708319): Also call -removeFromParentViewController for |
| 287 // bookmarks, open tabs and incognit here. | 288 // open tabs and incognito here. |
| 288 [googleLandingController_ removeFromParentViewController]; | 289 [googleLandingController_ removeFromParentViewController]; |
| 290 [bookmarkController_ removeFromParentViewController]; |
| 289 | 291 |
| 290 [googleLandingController_ setDelegate:nil]; | 292 [googleLandingController_ setDelegate:nil]; |
| 291 [bookmarkController_ setDelegate:nil]; | 293 [bookmarkController_ setDelegate:nil]; |
| 292 [openTabsController_ setDelegate:nil]; | 294 [openTabsController_ setDelegate:nil]; |
| 293 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 295 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 294 [super dealloc]; | 296 [super dealloc]; |
| 295 } | 297 } |
| 296 | 298 |
| 297 #pragma mark - CRWNativeContent | 299 #pragma mark - CRWNativeContent |
| 298 | 300 |
| 299 - (void)willBeDismissed { | 301 - (void)willBeDismissed { |
| 300 // This methods is called by //web immediately before |self|'s view is removed | 302 // This methods is called by //web immediately before |self|'s view is removed |
| 301 // from the view hierarchy, making it an ideal spot to intiate view controller | 303 // from the view hierarchy, making it an ideal spot to intiate view controller |
| 302 // containment methods. | 304 // containment methods. |
| 303 // TODO(crbug.com/708319): Also call -willMoveToParentViewController:nil for | 305 // TODO(crbug.com/708319): Also call -willMoveToParentViewController:nil for |
| 304 // bookmarks, open tabs and incognito here. | 306 // open tabs and incognito here. |
| 305 [googleLandingController_ willMoveToParentViewController:nil]; | 307 [googleLandingController_ willMoveToParentViewController:nil]; |
| 308 [bookmarkController_ willMoveToParentViewController:nil]; |
| 306 } | 309 } |
| 307 | 310 |
| 308 - (void)reload { | 311 - (void)reload { |
| 309 [currentController_ reload]; | 312 [currentController_ reload]; |
| 310 [super reload]; | 313 [super reload]; |
| 311 } | 314 } |
| 312 | 315 |
| 313 - (void)wasShown { | 316 - (void)wasShown { |
| 314 [currentController_ wasShown]; | 317 [currentController_ wasShown]; |
| 315 // Ensure that the NTP has the latest data when it is shown. | 318 // Ensure that the NTP has the latest data when it is shown. |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 // Only load the controllers once. | 508 // Only load the controllers once. |
| 506 if (item.identifier == NewTabPage::kBookmarksPanel) { | 509 if (item.identifier == NewTabPage::kBookmarksPanel) { |
| 507 if (!bookmarkController_) { | 510 if (!bookmarkController_) { |
| 508 base::scoped_nsobject<BookmarkControllerFactory> factory( | 511 base::scoped_nsobject<BookmarkControllerFactory> factory( |
| 509 [[BookmarkControllerFactory alloc] init]); | 512 [[BookmarkControllerFactory alloc] init]); |
| 510 bookmarkController_.reset([[factory | 513 bookmarkController_.reset([[factory |
| 511 bookmarkPanelControllerForBrowserState:browserState_ | 514 bookmarkPanelControllerForBrowserState:browserState_ |
| 512 loader:loader_ | 515 loader:loader_ |
| 513 colorCache:dominantColorCache_] retain]); | 516 colorCache:dominantColorCache_] retain]); |
| 514 } | 517 } |
| 518 panelController = bookmarkController_; |
| 515 view = [bookmarkController_ view]; | 519 view = [bookmarkController_ view]; |
| 516 // TODO(crbug.com/708319): Also set panelController for bookmarks here. | |
| 517 [bookmarkController_ setDelegate:self]; | 520 [bookmarkController_ setDelegate:self]; |
| 518 } else if (item.identifier == NewTabPage::kMostVisitedPanel) { | 521 } else if (item.identifier == NewTabPage::kMostVisitedPanel) { |
| 519 if (!googleLandingController_) { | 522 if (!googleLandingController_) { |
| 520 googleLandingController_.reset([[GoogleLandingController alloc] | 523 googleLandingController_.reset([[GoogleLandingController alloc] |
| 521 initWithLoader:loader_ | 524 initWithLoader:loader_ |
| 522 browserState:browserState_ | 525 browserState:browserState_ |
| 523 focuser:focuser_ | 526 focuser:focuser_ |
| 524 webToolbarDelegate:webToolbarDelegate_ | 527 webToolbarDelegate:webToolbarDelegate_ |
| 525 tabModel:tabModel_]); | 528 tabModel:tabModel_]); |
| 526 } | 529 } |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 | 712 |
| 710 - (void)updateNtpBarShadowForPanelController: | 713 - (void)updateNtpBarShadowForPanelController: |
| 711 (id<NewTabPagePanelProtocol>)ntpPanelController { | 714 (id<NewTabPagePanelProtocol>)ntpPanelController { |
| 712 if (currentController_ != ntpPanelController) | 715 if (currentController_ != ntpPanelController) |
| 713 return; | 716 return; |
| 714 [self.ntpView.tabBar | 717 [self.ntpView.tabBar |
| 715 setShadowAlpha:[ntpPanelController alphaForBottomShadow]]; | 718 setShadowAlpha:[ntpPanelController alphaForBottomShadow]]; |
| 716 } | 719 } |
| 717 | 720 |
| 718 @end | 721 @end |
| OLD | NEW |