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