OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/clean/chrome/browser/ui/ntp/ntp_coordinator.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "ios/chrome/browser/ui/ui_util.h" |
| 9 #import "ios/clean/chrome/browser/ui/bookmarks/bookmarks_coordinator.h" |
| 10 #import "ios/clean/chrome/browser/ui/commands/ntp_commands.h" |
| 11 #import "ios/clean/chrome/browser/ui/ntp/ntp_home_coordinator.h" |
| 12 #import "ios/clean/chrome/browser/ui/ntp/ntp_mediator.h" |
| 13 #import "ios/clean/chrome/browser/ui/ntp/ntp_view_controller.h" |
| 14 #import "ios/clean/chrome/browser/ui/recent_tabs/recent_tabs_coordinator.h" |
| 15 #import "ios/shared/chrome/browser/coordinator_context/coordinator_context.h" |
| 16 #import "ios/shared/chrome/browser/ui/browser_list/browser.h" |
| 17 #import "ios/shared/chrome/browser/ui/commands/command_dispatcher.h" |
| 18 #import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator+internal.
h" |
| 19 |
| 20 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 21 #error "This file requires ARC support." |
| 22 #endif |
| 23 |
| 24 @interface NTPCoordinator ()<NTPCommands> |
| 25 @property(nonatomic, strong) NTPMediator* mediator; |
| 26 @property(nonatomic, strong) NTPViewController* viewController; |
| 27 @end |
| 28 |
| 29 @implementation NTPCoordinator |
| 30 @synthesize mediator = _mediator; |
| 31 @synthesize viewController = _viewController; |
| 32 |
| 33 - (void)start { |
| 34 self.viewController = [[NTPViewController alloc] init]; |
| 35 self.mediator = [[NTPMediator alloc] initWithConsumer:self.viewController]; |
| 36 |
| 37 CommandDispatcher* dispatcher = self.browser->dispatcher(); |
| 38 // NTPCommands |
| 39 [dispatcher startDispatchingToTarget:self |
| 40 forSelector:@selector(showNTPHomePanel)]; |
| 41 [dispatcher startDispatchingToTarget:self |
| 42 forSelector:@selector(showNTPBookmarksPanel)]; |
| 43 [dispatcher startDispatchingToTarget:self |
| 44 forSelector:@selector(showNTPOpenTabsPanel)]; |
| 45 self.viewController.dispatcher = static_cast<id>(self.browser->dispatcher()); |
| 46 [super start]; |
| 47 } |
| 48 |
| 49 - (void)stop { |
| 50 [super stop]; |
| 51 // PLACEHOLDER: Stop child coordinators here for now. We might deal with this |
| 52 // differently later on. |
| 53 for (BrowserCoordinator* child in self.children) { |
| 54 [child stop]; |
| 55 } |
| 56 [self.browser->dispatcher() stopDispatchingToTarget:self]; |
| 57 } |
| 58 |
| 59 - (void)childCoordinatorDidStart:(BrowserCoordinator*)coordinator { |
| 60 if ([coordinator isKindOfClass:[NTPHomeCoordinator class]]) { |
| 61 [self.viewController addHomePanelViewController:coordinator.viewController]; |
| 62 |
| 63 } else if ([coordinator isKindOfClass:[BookmarksCoordinator class]]) { |
| 64 if (IsIPadIdiom()) { |
| 65 [self.viewController |
| 66 addBookmarksViewController:coordinator.viewController]; |
| 67 } else { |
| 68 [self.context.baseViewController |
| 69 presentViewController:coordinator.viewController |
| 70 animated:coordinator.context.animated |
| 71 completion:nil]; |
| 72 } |
| 73 |
| 74 } else if ([coordinator isKindOfClass:[OpenTabsCoordinator class]]) { |
| 75 if (IsIPadIdiom()) { |
| 76 [self.viewController |
| 77 addOpenTabsViewController:coordinator.viewController]; |
| 78 } else { |
| 79 [self.context.baseViewController |
| 80 presentViewController:coordinator.viewController |
| 81 animated:coordinator.context.animated |
| 82 completion:nil]; |
| 83 } |
| 84 } |
| 85 } |
| 86 |
| 87 #pragma mark - NTPCommands |
| 88 |
| 89 - (void)showNTPHomePanel { |
| 90 NTPHomeCoordinator* panelCoordinator = [[NTPHomeCoordinator alloc] init]; |
| 91 [self addChildCoordinator:panelCoordinator]; |
| 92 [panelCoordinator start]; |
| 93 } |
| 94 |
| 95 - (void)showNTPBookmarksPanel { |
| 96 BookmarksCoordinator* panelCoordinator = [[BookmarksCoordinator alloc] init]; |
| 97 [self addChildCoordinator:panelCoordinator]; |
| 98 [panelCoordinator start]; |
| 99 } |
| 100 |
| 101 - (void)showNTPOpenTabsPanel { |
| 102 OpenTabsCoordinator* panelCoordinator = [[OpenTabsCoordinator alloc] init]; |
| 103 [self addChildCoordinator:panelCoordinator]; |
| 104 [panelCoordinator start]; |
| 105 } |
| 106 |
| 107 @end |
OLD | NEW |