| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/clean/chrome/browser/ui/tab/tab_coordinator.h" | 5 #import "ios/clean/chrome/browser/ui/tab/tab_coordinator.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "ios/chrome/browser/chrome_url_constants.h" |
| 11 #import "ios/clean/chrome/browser/ui/animators/zoom_transition_animator.h" | 12 #import "ios/clean/chrome/browser/ui/animators/zoom_transition_animator.h" |
| 12 #import "ios/clean/chrome/browser/ui/ntp/new_tab_page_coordinator.h" | 13 #import "ios/clean/chrome/browser/ui/commands/tab_commands.h" |
| 14 #import "ios/clean/chrome/browser/ui/ntp/ntp_coordinator.h" |
| 13 #import "ios/clean/chrome/browser/ui/tab/tab_container_view_controller.h" | 15 #import "ios/clean/chrome/browser/ui/tab/tab_container_view_controller.h" |
| 14 #import "ios/clean/chrome/browser/ui/tab_strip/tab_strip_coordinator.h" | 16 #import "ios/clean/chrome/browser/ui/tab_strip/tab_strip_coordinator.h" |
| 15 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_coordinator.h" | 17 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_coordinator.h" |
| 16 #import "ios/clean/chrome/browser/ui/web_contents/web_coordinator.h" | 18 #import "ios/clean/chrome/browser/ui/web_contents/web_coordinator.h" |
| 19 #import "ios/shared/chrome/browser/ui/browser_list/browser.h" |
| 20 #import "ios/shared/chrome/browser/ui/commands/command_dispatcher.h" |
| 17 #import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator+internal.
h" | 21 #import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator+internal.
h" |
| 18 #import "ios/web/public/web_state/web_state.h" | 22 #import "ios/web/public/web_state/web_state.h" |
| 19 #import "ios/web/public/web_state/web_state_observer_bridge.h" | 23 #import "ios/web/public/web_state/web_state_observer_bridge.h" |
| 20 | 24 |
| 21 #if !defined(__has_feature) || !__has_feature(objc_arc) | 25 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 22 #error "This file requires ARC support." | 26 #error "This file requires ARC support." |
| 23 #endif | 27 #endif |
| 24 | 28 |
| 25 namespace { | 29 namespace { |
| 26 // Placeholder "experiment" flag. Change this to YES to have the toolbar at the | 30 // Placeholder "experiment" flag. Change this to YES to have the toolbar at the |
| 27 // bottom. | 31 // bottom. |
| 28 const BOOL kUseBottomToolbar = NO; | 32 const BOOL kUseBottomToolbar = NO; |
| 29 } // namespace | 33 } // namespace |
| 30 | 34 |
| 31 @interface TabCoordinator ()<CRWWebStateObserver, | 35 @interface TabCoordinator ()<CRWWebStateObserver, |
| 36 TabCommands, |
| 32 UIViewControllerTransitioningDelegate> | 37 UIViewControllerTransitioningDelegate> |
| 33 @property(nonatomic, strong) TabContainerViewController* viewController; | 38 @property(nonatomic, strong) TabContainerViewController* viewController; |
| 39 @property(nonatomic, weak) NTPCoordinator* ntpCoordinator; |
| 40 @property(nonatomic, weak) WebCoordinator* webCoordinator; |
| 34 @end | 41 @end |
| 35 | 42 |
| 36 @implementation TabCoordinator { | 43 @implementation TabCoordinator { |
| 37 std::unique_ptr<web::WebStateObserverBridge> _webStateObserver; | 44 std::unique_ptr<web::WebStateObserverBridge> _webStateObserver; |
| 38 } | 45 } |
| 39 | 46 |
| 40 @synthesize presentationKey = _presentationKey; | 47 @synthesize presentationKey = _presentationKey; |
| 41 @synthesize viewController = _viewController; | 48 @synthesize viewController = _viewController; |
| 42 @synthesize webState = _webState; | 49 @synthesize webState = _webState; |
| 50 @synthesize webCoordinator = _webCoordinator; |
| 51 @synthesize ntpCoordinator = _ntpCoordinator; |
| 43 | 52 |
| 44 #pragma mark - BrowserCoordinator | 53 #pragma mark - BrowserCoordinator |
| 45 | 54 |
| 46 - (void)start { | 55 - (void)start { |
| 47 self.viewController = [self newTabContainer]; | 56 self.viewController = [self newTabContainer]; |
| 48 self.viewController.transitioningDelegate = self; | 57 self.viewController.transitioningDelegate = self; |
| 49 self.viewController.modalPresentationStyle = UIModalPresentationCustom; | 58 self.viewController.modalPresentationStyle = UIModalPresentationCustom; |
| 50 _webStateObserver = | 59 _webStateObserver = |
| 51 base::MakeUnique<web::WebStateObserverBridge>(self.webState, self); | 60 base::MakeUnique<web::WebStateObserverBridge>(self.webState, self); |
| 52 | 61 |
| 62 CommandDispatcher* dispatcher = self.browser->dispatcher(); |
| 63 // TabCommands |
| 64 [dispatcher startDispatchingToTarget:self forSelector:@selector(loadURL:)]; |
| 65 |
| 53 WebCoordinator* webCoordinator = [[WebCoordinator alloc] init]; | 66 WebCoordinator* webCoordinator = [[WebCoordinator alloc] init]; |
| 54 webCoordinator.webState = self.webState; | 67 webCoordinator.webState = self.webState; |
| 55 [self addChildCoordinator:webCoordinator]; | 68 [self addChildCoordinator:webCoordinator]; |
| 56 [webCoordinator start]; | 69 [webCoordinator start]; |
| 70 self.webCoordinator = webCoordinator; |
| 57 | 71 |
| 58 ToolbarCoordinator* toolbarCoordinator = [[ToolbarCoordinator alloc] init]; | 72 ToolbarCoordinator* toolbarCoordinator = [[ToolbarCoordinator alloc] init]; |
| 59 toolbarCoordinator.webState = self.webState; | 73 toolbarCoordinator.webState = self.webState; |
| 60 [self addChildCoordinator:toolbarCoordinator]; | 74 [self addChildCoordinator:toolbarCoordinator]; |
| 61 [toolbarCoordinator start]; | 75 [toolbarCoordinator start]; |
| 62 | 76 |
| 63 TabStripCoordinator* tabStripCoordinator = [[TabStripCoordinator alloc] init]; | 77 TabStripCoordinator* tabStripCoordinator = [[TabStripCoordinator alloc] init]; |
| 64 [self addChildCoordinator:tabStripCoordinator]; | 78 [self addChildCoordinator:tabStripCoordinator]; |
| 65 [tabStripCoordinator start]; | 79 [tabStripCoordinator start]; |
| 66 | 80 |
| 81 // PLACEHOLDER: Fix the order of events here. The ntpCoordinator was already |
| 82 // created above when |webCoordinator.webState = self.webState;| triggers |
| 83 // a load event, but then the webCoordinator stomps on the |
| 84 // contentViewController when it starts afterwards. |
| 85 if (self.webState->GetLastCommittedURL() == GURL(kChromeUINewTabURL)) { |
| 86 self.viewController.contentViewController = |
| 87 self.ntpCoordinator.viewController; |
| 88 } |
| 89 |
| 67 [super start]; | 90 [super start]; |
| 68 } | 91 } |
| 69 | 92 |
| 70 - (void)stop { | 93 - (void)stop { |
| 71 [super stop]; | 94 [super stop]; |
| 72 // PLACEHOLDER: Stop child coordinators here for now. We might deal with this | 95 // PLACEHOLDER: Stop child coordinators here for now. We might deal with this |
| 73 // differently later on. | 96 // differently later on. |
| 74 for (BrowserCoordinator* child in self.children) { | 97 for (BrowserCoordinator* child in self.children) { |
| 75 [child stop]; | 98 [child stop]; |
| 76 } | 99 } |
| 77 _webStateObserver.reset(); | 100 _webStateObserver.reset(); |
| 101 [self.browser->dispatcher() stopDispatchingToTarget:self]; |
| 78 } | 102 } |
| 79 | 103 |
| 80 - (void)childCoordinatorDidStart:(BrowserCoordinator*)childCoordinator { | 104 - (void)childCoordinatorDidStart:(BrowserCoordinator*)childCoordinator { |
| 81 if ([childCoordinator isKindOfClass:[ToolbarCoordinator class]]) { | 105 if ([childCoordinator isKindOfClass:[ToolbarCoordinator class]]) { |
| 82 self.viewController.toolbarViewController = childCoordinator.viewController; | 106 self.viewController.toolbarViewController = childCoordinator.viewController; |
| 83 } else if ([childCoordinator isKindOfClass:[WebCoordinator class]] || | 107 } else if ([childCoordinator isKindOfClass:[WebCoordinator class]] || |
| 84 [childCoordinator isKindOfClass:[NTPCoordinator class]]) { | 108 [childCoordinator isKindOfClass:[NTPCoordinator class]]) { |
| 85 self.viewController.contentViewController = childCoordinator.viewController; | 109 self.viewController.contentViewController = childCoordinator.viewController; |
| 86 } else if ([childCoordinator isKindOfClass:[TabStripCoordinator class]]) { | 110 } else if ([childCoordinator isKindOfClass:[TabStripCoordinator class]]) { |
| 87 self.viewController.tabStripViewController = | 111 self.viewController.tabStripViewController = |
| 88 childCoordinator.viewController; | 112 childCoordinator.viewController; |
| 89 } | 113 } |
| 90 } | 114 } |
| 91 | 115 |
| 116 - (void)childCoordinatorWillStop:(BrowserCoordinator*)childCoordinator { |
| 117 self.viewController.contentViewController = nil; |
| 118 } |
| 119 |
| 92 - (BOOL)canAddOverlayCoordinator:(BrowserCoordinator*)overlayCoordinator { | 120 - (BOOL)canAddOverlayCoordinator:(BrowserCoordinator*)overlayCoordinator { |
| 93 // This coordinator will always accept overlay coordinators. | 121 // This coordinator will always accept overlay coordinators. |
| 94 return YES; | 122 return YES; |
| 95 } | 123 } |
| 96 | 124 |
| 97 #pragma mark - Experiment support | 125 #pragma mark - Experiment support |
| 98 | 126 |
| 99 // Create and return a new view controller for use as a tab container; | 127 // Create and return a new view controller for use as a tab container; |
| 100 // experimental configurations determine which subclass of | 128 // experimental configurations determine which subclass of |
| 101 // TabContainerViewController to return. | 129 // TabContainerViewController to return. |
| 102 - (TabContainerViewController*)newTabContainer { | 130 - (TabContainerViewController*)newTabContainer { |
| 103 if (kUseBottomToolbar) { | 131 if (kUseBottomToolbar) { |
| 104 return [[BottomToolbarTabViewController alloc] init]; | 132 return [[BottomToolbarTabViewController alloc] init]; |
| 105 } | 133 } |
| 106 return [[TopToolbarTabViewController alloc] init]; | 134 return [[TopToolbarTabViewController alloc] init]; |
| 107 } | 135 } |
| 108 | 136 |
| 109 #pragma mark - CRWWebStateObserver | 137 #pragma mark - CRWWebStateObserver |
| 110 | 138 |
| 111 // This will eventually be called in -didFinishNavigation and perhaps as an | 139 // This will eventually be called in -didFinishNavigation and perhaps as an |
| 112 // optimization in some equivalent to loadURL. | 140 // optimization in some equivalent to loadURL. |
| 113 - (void)webState:(web::WebState*)webState | 141 - (void)webState:(web::WebState*)webState |
| 114 didCommitNavigationWithDetails:(const web::LoadCommittedDetails&)details { | 142 didCommitNavigationWithDetails:(const web::LoadCommittedDetails&)details { |
| 115 if (webState->GetLastCommittedURL() == GURL("chrome://newtab/")) { | 143 if (webState->GetLastCommittedURL() == GURL(kChromeUINewTabURL)) { |
| 116 NTPCoordinator* ntpCoordinator = [[NTPCoordinator alloc] init]; | 144 NTPCoordinator* ntpCoordinator = [[NTPCoordinator alloc] init]; |
| 117 [self addChildCoordinator:ntpCoordinator]; | 145 [self addChildCoordinator:ntpCoordinator]; |
| 118 [ntpCoordinator start]; | 146 [ntpCoordinator start]; |
| 147 self.ntpCoordinator = ntpCoordinator; |
| 119 } | 148 } |
| 120 } | 149 } |
| 121 | 150 |
| 151 - (void)webState:(web::WebState*)webState |
| 152 didStartProvisionalNavigationForURL:(const GURL&)URL { |
| 153 if (self.ntpCoordinator) { |
| 154 [self.ntpCoordinator stop]; |
| 155 [self removeChildCoordinator:self.ntpCoordinator]; |
| 156 self.viewController.contentViewController = |
| 157 self.webCoordinator.viewController; |
| 158 } |
| 159 } |
| 160 |
| 122 #pragma mark - UIViewControllerTransitioningDelegate | 161 #pragma mark - UIViewControllerTransitioningDelegate |
| 123 | 162 |
| 124 - (id<UIViewControllerAnimatedTransitioning>) | 163 - (id<UIViewControllerAnimatedTransitioning>) |
| 125 animationControllerForPresentedController:(UIViewController*)presented | 164 animationControllerForPresentedController:(UIViewController*)presented |
| 126 presentingController:(UIViewController*)presenting | 165 presentingController:(UIViewController*)presenting |
| 127 sourceController:(UIViewController*)source { | 166 sourceController:(UIViewController*)source { |
| 128 ZoomTransitionAnimator* animator = [[ZoomTransitionAnimator alloc] init]; | 167 ZoomTransitionAnimator* animator = [[ZoomTransitionAnimator alloc] init]; |
| 129 animator.presenting = YES; | 168 animator.presenting = YES; |
| 130 animator.presentationKey = self.presentationKey; | 169 animator.presentationKey = self.presentationKey; |
| 131 [animator selectDelegate:@[ source, presenting ]]; | 170 [animator selectDelegate:@[ source, presenting ]]; |
| 132 return animator; | 171 return animator; |
| 133 } | 172 } |
| 134 | 173 |
| 135 - (id<UIViewControllerAnimatedTransitioning>) | 174 - (id<UIViewControllerAnimatedTransitioning>) |
| 136 animationControllerForDismissedController:(UIViewController*)dismissed { | 175 animationControllerForDismissedController:(UIViewController*)dismissed { |
| 137 ZoomTransitionAnimator* animator = [[ZoomTransitionAnimator alloc] init]; | 176 ZoomTransitionAnimator* animator = [[ZoomTransitionAnimator alloc] init]; |
| 138 animator.presenting = NO; | 177 animator.presenting = NO; |
| 139 animator.presentationKey = self.presentationKey; | 178 animator.presentationKey = self.presentationKey; |
| 140 [animator selectDelegate:@[ dismissed.presentingViewController ]]; | 179 [animator selectDelegate:@[ dismissed.presentingViewController ]]; |
| 141 return animator; | 180 return animator; |
| 142 } | 181 } |
| 143 | 182 |
| 183 #pragma mark - TabCommands |
| 184 |
| 185 - (void)loadURL:(web::NavigationManager::WebLoadParams)params { |
| 186 self.webState->GetNavigationManager()->LoadURLWithParams(params); |
| 187 } |
| 188 |
| 144 @end | 189 @end |
| OLD | NEW |