Commit c4e06001 authored by adamta's avatar adamta Committed by Chromium LUCI CQ

[iOS] Creates NewTabPageViewController

Creates a view controller for the NTP, the NewTabPageViewController.
This VC is managed by the NewTabPageCoordinator and contains all the
content that is presented on the regular NTP.

First step of the refactoring effort; more content will be added to it
in later CLs.

Bug: 1114792
Change-Id: I38ce3fc3b386f9d93deed4ca28c9ec879b47a781
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2555662Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Commit-Queue: Adam Trudeau-Arcaro <adamta@google.com>
Cr-Commit-Position: refs/heads/master@{#833889}
parent 1e3a10a2
......@@ -56,6 +56,8 @@ source_set("ntp_internal") {
"incognito_view_controller.mm",
"metrics.h",
"metrics.mm",
"new_tab_page_view_controller.h",
"new_tab_page_view_controller.mm",
"notification_promo_whats_new.h",
"notification_promo_whats_new.mm",
"ntp_tile_saver.h",
......
......@@ -15,6 +15,7 @@
#import "ios/chrome/browser/ui/main/scene_state_browser_agent.h"
#import "ios/chrome/browser/ui/main/scene_state_observer.h"
#import "ios/chrome/browser/ui/ntp/incognito_view_controller.h"
#import "ios/chrome/browser/ui/ntp/new_tab_page_view_controller.h"
#import "ios/chrome/browser/url_loading/url_loading_browser_agent.h"
#import "ios/web/public/navigation/navigation_context.h"
#import "ios/web/public/navigation/navigation_item.h"
......@@ -31,7 +32,10 @@
@property(nonatomic, strong)
ContentSuggestionsCoordinator* contentSuggestionsCoordinator;
// View controller for incognito.
// View controller for the regular NTP.
@property(nonatomic, strong) NewTabPageViewController* ntpViewController;
// View controller for the incognito NTP.
@property(nonatomic, strong) IncognitoViewController* incognitoViewController;
// The timetick of the last time the NTP was displayed.
......@@ -83,6 +87,11 @@
self.panGestureHandler;
[self.contentSuggestionsCoordinator start];
self.ntpViewController = [[NewTabPageViewController alloc]
initWithContentSuggestionsViewController:
self.contentSuggestionsCoordinator.viewController];
base::RecordAction(base::UserMetricsAction("MobileNTPShowMostVisited"));
SceneState* sceneState =
SceneStateBrowserAgent::FromBrowser(self.browser)->GetSceneState();
......@@ -139,7 +148,7 @@
if (self.browser->GetBrowserState()->IsOffTheRecord()) {
return self.incognitoViewController;
} else {
return self.contentSuggestionsCoordinator.viewController;
return self.ntpViewController;
}
}
......
......@@ -16,11 +16,11 @@
#import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/ui/commands/omnibox_commands.h"
#import "ios/chrome/browser/ui/commands/snackbar_commands.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller.h"
#import "ios/chrome/browser/ui/main/scene_state.h"
#import "ios/chrome/browser/ui/main/scene_state_browser_agent.h"
#import "ios/chrome/browser/ui/ntp/incognito_view_controller.h"
#import "ios/chrome/browser/ui/ntp/new_tab_page_controller_delegate.h"
#import "ios/chrome/browser/ui/ntp/new_tab_page_view_controller.h"
#include "ios/chrome/test/ios_chrome_scoped_testing_chrome_browser_state_manager.h"
#import "ios/web/public/test/fakes/test_web_state.h"
#include "ios/web/public/test/web_task_environment.h"
......@@ -101,8 +101,7 @@ TEST_F(NewTabPageCoordinatorTest, StartOnTheRecord) {
forProtocol:@protocol(SnackbarCommands)];
[coordinator_ start];
UIViewController* viewController = [coordinator_ viewController];
EXPECT_TRUE(
[viewController isKindOfClass:[ContentSuggestionsViewController class]]);
EXPECT_TRUE([viewController isKindOfClass:[NewTabPageViewController class]]);
[coordinator_ stop];
}
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_NTP_NEW_TAB_PAGE_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_NTP_NEW_TAB_PAGE_VIEW_CONTROLLER_H_
#import <UIKit/UIKit.h>
// View controller containing all the content presented on a standard,
// non-incognito new tab page.
@interface NewTabPageViewController : UIViewController
// Initializes view controller with content suggestions.
- (instancetype)initWithContentSuggestionsViewController:
(UIViewController*)contentSuggestionsViewController
NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithNibName:(NSString*)name
bundle:(NSBundle*)bundle NS_UNAVAILABLE;
- (instancetype)initWithCoder:(NSCoder*)coder NS_UNAVAILABLE;
@end
#endif // IOS_CHROME_BROWSER_UI_NTP_NEW_TAB_PAGE_VIEW_CONTROLLER_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/ntp/new_tab_page_view_controller.h"
#import "ios/chrome/common/ui/util/constraints_ui_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface NewTabPageViewController ()
// View controller representing the NTP content suggestions.
@property(nonatomic, strong) UIViewController* contentSuggestionsViewController;
@end
@implementation NewTabPageViewController
- (instancetype)initWithContentSuggestionsViewController:
(UIViewController*)contentSuggestionsViewController {
self = [super initWithNibName:nil bundle:nil];
if (self) {
_contentSuggestionsViewController = contentSuggestionsViewController;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self addChildViewController:self.contentSuggestionsViewController];
[self.view addSubview:self.contentSuggestionsViewController.view];
[self.contentSuggestionsViewController didMoveToParentViewController:self];
self.contentSuggestionsViewController.view
.translatesAutoresizingMaskIntoConstraints = NO;
AddSameConstraints(self.contentSuggestionsViewController.view, self.view);
}
@end
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