| Index: ios/clean/chrome/browser/ui/ntp/ntp_coordinator.mm
|
| diff --git a/ios/clean/chrome/browser/ui/ntp/ntp_coordinator.mm b/ios/clean/chrome/browser/ui/ntp/ntp_coordinator.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..c38de0458ccba2bd5e332abb556d74c2445032ad
|
| --- /dev/null
|
| +++ b/ios/clean/chrome/browser/ui/ntp/ntp_coordinator.mm
|
| @@ -0,0 +1,107 @@
|
| +// Copyright 2017 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 "ios/clean/chrome/browser/ui/ntp/ntp_coordinator.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "ios/chrome/browser/ui/ui_util.h"
|
| +#import "ios/clean/chrome/browser/ui/bookmarks/bookmarks_coordinator.h"
|
| +#import "ios/clean/chrome/browser/ui/commands/ntp_commands.h"
|
| +#import "ios/clean/chrome/browser/ui/ntp/ntp_home_coordinator.h"
|
| +#import "ios/clean/chrome/browser/ui/ntp/ntp_mediator.h"
|
| +#import "ios/clean/chrome/browser/ui/ntp/ntp_view_controller.h"
|
| +#import "ios/clean/chrome/browser/ui/recent_tabs/recent_tabs_coordinator.h"
|
| +#import "ios/shared/chrome/browser/coordinator_context/coordinator_context.h"
|
| +#import "ios/shared/chrome/browser/ui/browser_list/browser.h"
|
| +#import "ios/shared/chrome/browser/ui/commands/command_dispatcher.h"
|
| +#import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator+internal.h"
|
| +
|
| +#if !defined(__has_feature) || !__has_feature(objc_arc)
|
| +#error "This file requires ARC support."
|
| +#endif
|
| +
|
| +@interface NTPCoordinator ()<NTPCommands>
|
| +@property(nonatomic, strong) NTPMediator* mediator;
|
| +@property(nonatomic, strong) NTPViewController* viewController;
|
| +@end
|
| +
|
| +@implementation NTPCoordinator
|
| +@synthesize mediator = _mediator;
|
| +@synthesize viewController = _viewController;
|
| +
|
| +- (void)start {
|
| + self.viewController = [[NTPViewController alloc] init];
|
| + self.mediator = [[NTPMediator alloc] initWithConsumer:self.viewController];
|
| +
|
| + CommandDispatcher* dispatcher = self.browser->dispatcher();
|
| + // NTPCommands
|
| + [dispatcher startDispatchingToTarget:self
|
| + forSelector:@selector(showNTPHomePanel)];
|
| + [dispatcher startDispatchingToTarget:self
|
| + forSelector:@selector(showNTPBookmarksPanel)];
|
| + [dispatcher startDispatchingToTarget:self
|
| + forSelector:@selector(showNTPOpenTabsPanel)];
|
| + self.viewController.dispatcher = static_cast<id>(self.browser->dispatcher());
|
| + [super start];
|
| +}
|
| +
|
| +- (void)stop {
|
| + [super stop];
|
| + // PLACEHOLDER: Stop child coordinators here for now. We might deal with this
|
| + // differently later on.
|
| + for (BrowserCoordinator* child in self.children) {
|
| + [child stop];
|
| + }
|
| + [self.browser->dispatcher() stopDispatchingToTarget:self];
|
| +}
|
| +
|
| +- (void)childCoordinatorDidStart:(BrowserCoordinator*)coordinator {
|
| + if ([coordinator isKindOfClass:[NTPHomeCoordinator class]]) {
|
| + [self.viewController addHomePanelViewController:coordinator.viewController];
|
| +
|
| + } else if ([coordinator isKindOfClass:[BookmarksCoordinator class]]) {
|
| + if (IsIPadIdiom()) {
|
| + [self.viewController
|
| + addBookmarksViewController:coordinator.viewController];
|
| + } else {
|
| + [self.context.baseViewController
|
| + presentViewController:coordinator.viewController
|
| + animated:coordinator.context.animated
|
| + completion:nil];
|
| + }
|
| +
|
| + } else if ([coordinator isKindOfClass:[OpenTabsCoordinator class]]) {
|
| + if (IsIPadIdiom()) {
|
| + [self.viewController
|
| + addOpenTabsViewController:coordinator.viewController];
|
| + } else {
|
| + [self.context.baseViewController
|
| + presentViewController:coordinator.viewController
|
| + animated:coordinator.context.animated
|
| + completion:nil];
|
| + }
|
| + }
|
| +}
|
| +
|
| +#pragma mark - NTPCommands
|
| +
|
| +- (void)showNTPHomePanel {
|
| + NTPHomeCoordinator* panelCoordinator = [[NTPHomeCoordinator alloc] init];
|
| + [self addChildCoordinator:panelCoordinator];
|
| + [panelCoordinator start];
|
| +}
|
| +
|
| +- (void)showNTPBookmarksPanel {
|
| + BookmarksCoordinator* panelCoordinator = [[BookmarksCoordinator alloc] init];
|
| + [self addChildCoordinator:panelCoordinator];
|
| + [panelCoordinator start];
|
| +}
|
| +
|
| +- (void)showNTPOpenTabsPanel {
|
| + OpenTabsCoordinator* panelCoordinator = [[OpenTabsCoordinator alloc] init];
|
| + [self addChildCoordinator:panelCoordinator];
|
| + [panelCoordinator start];
|
| +}
|
| +
|
| +@end
|
|
|