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" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 | 25 |
26 namespace { | 26 namespace { |
27 // Placeholder "experiment" flag. Change this to YES to have the toolbar at the | 27 // Placeholder "experiment" flag. Change this to YES to have the toolbar at the |
28 // bottom. | 28 // bottom. |
29 const BOOL kUseBottomToolbar = NO; | 29 const BOOL kUseBottomToolbar = NO; |
30 } // namespace | 30 } // namespace |
31 | 31 |
32 @interface TabCoordinator ()<CRWWebStateObserver, | 32 @interface TabCoordinator ()<CRWWebStateObserver, |
33 UIViewControllerTransitioningDelegate> | 33 UIViewControllerTransitioningDelegate> |
34 @property(nonatomic, strong) TabContainerViewController* viewController; | 34 @property(nonatomic, strong) TabContainerViewController* viewController; |
35 @property(nonatomic, weak) NTPCoordinator* ntpCoordinator; | |
36 @property(nonatomic, weak) WebCoordinator* webCoordinator; | |
35 @end | 37 @end |
36 | 38 |
37 @implementation TabCoordinator { | 39 @implementation TabCoordinator { |
38 std::unique_ptr<web::WebStateObserverBridge> _webStateObserver; | 40 std::unique_ptr<web::WebStateObserverBridge> _webStateObserver; |
39 } | 41 } |
40 | 42 |
41 @synthesize presentationKey = _presentationKey; | 43 @synthesize presentationKey = _presentationKey; |
42 @synthesize viewController = _viewController; | 44 @synthesize viewController = _viewController; |
43 @synthesize webState = _webState; | 45 @synthesize webState = _webState; |
46 @synthesize webCoordinator = _webCoordinator; | |
47 @synthesize ntpCoordinator = _ntpCoordinator; | |
44 | 48 |
45 #pragma mark - BrowserCoordinator | 49 #pragma mark - BrowserCoordinator |
46 | 50 |
47 - (void)start { | 51 - (void)start { |
48 self.viewController = [self newTabContainer]; | 52 self.viewController = [self newTabContainer]; |
49 self.viewController.transitioningDelegate = self; | 53 self.viewController.transitioningDelegate = self; |
50 self.viewController.modalPresentationStyle = UIModalPresentationCustom; | 54 self.viewController.modalPresentationStyle = UIModalPresentationCustom; |
51 _webStateObserver = | 55 _webStateObserver = |
52 base::MakeUnique<web::WebStateObserverBridge>(self.webState, self); | 56 base::MakeUnique<web::WebStateObserverBridge>(self.webState, self); |
53 | 57 |
54 WebCoordinator* webCoordinator = [[WebCoordinator alloc] init]; | 58 WebCoordinator* webCoordinator = [[WebCoordinator alloc] init]; |
55 webCoordinator.webState = self.webState; | 59 webCoordinator.webState = self.webState; |
56 [self addChildCoordinator:webCoordinator]; | 60 [self addChildCoordinator:webCoordinator]; |
57 // Unset the base view controller, so |webCoordinator| doesn't present its | 61 // Unset the base view controller, so |webCoordinator| doesn't present its |
58 // view controller. | 62 // view controller. |
59 webCoordinator.context.baseViewController = nil; | 63 webCoordinator.context.baseViewController = nil; |
60 [webCoordinator start]; | 64 [webCoordinator start]; |
65 self.webCoordinator = webCoordinator; | |
61 | 66 |
62 ToolbarCoordinator* toolbarCoordinator = [[ToolbarCoordinator alloc] init]; | 67 ToolbarCoordinator* toolbarCoordinator = [[ToolbarCoordinator alloc] init]; |
63 toolbarCoordinator.webState = self.webState; | 68 toolbarCoordinator.webState = self.webState; |
64 [self addChildCoordinator:toolbarCoordinator]; | 69 [self addChildCoordinator:toolbarCoordinator]; |
65 // Unset the base view controller, so |toolbarCoordinator| doesn't present | 70 // Unset the base view controller, so |toolbarCoordinator| doesn't present |
66 // its view controller. | 71 // its view controller. |
67 toolbarCoordinator.context.baseViewController = nil; | 72 toolbarCoordinator.context.baseViewController = nil; |
68 [toolbarCoordinator start]; | 73 [toolbarCoordinator start]; |
69 | 74 |
70 TabStripCoordinator* tabStripCoordinator = [[TabStripCoordinator alloc] init]; | 75 TabStripCoordinator* tabStripCoordinator = [[TabStripCoordinator alloc] init]; |
71 [self addChildCoordinator:tabStripCoordinator]; | 76 [self addChildCoordinator:tabStripCoordinator]; |
72 // Unset the base view controller since this is a contained view controller. | 77 // Unset the base view controller since this is a contained view controller. |
73 tabStripCoordinator.context.baseViewController = nil; | 78 tabStripCoordinator.context.baseViewController = nil; |
74 [tabStripCoordinator start]; | 79 [tabStripCoordinator start]; |
75 | 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. | |
lpromero
2017/04/06 13:01:06
Should we then delay starting the webCoordinator t
justincohen
2017/04/06 18:25:11
Perhaps, saving for a followup.
| |
85 if (self.webState->GetLastCommittedURL() == GURL("chrome://newtab/")) { | |
86 self.viewController.contentViewController = | |
87 self.ntpCoordinator.viewController; | |
88 } | |
89 | |
76 [self.context.baseViewController presentViewController:self.viewController | 90 [self.context.baseViewController presentViewController:self.viewController |
77 animated:self.context.animated | 91 animated:self.context.animated |
78 completion:nil]; | 92 completion:nil]; |
93 | |
79 [super start]; | 94 [super start]; |
80 } | 95 } |
81 | 96 |
82 - (void)stop { | 97 - (void)stop { |
83 [super stop]; | 98 [super stop]; |
84 // PLACEHOLDER: Stop child coordinators here for now. We might deal with this | 99 // PLACEHOLDER: Stop child coordinators here for now. We might deal with this |
85 // differently later on. | 100 // differently later on. |
86 for (BrowserCoordinator* child in self.children) { | 101 for (BrowserCoordinator* child in self.children) { |
87 [child stop]; | 102 [child stop]; |
88 } | 103 } |
104 | |
105 [self.viewController setContentViewController:nil]; | |
lpromero
2017/04/06 13:01:06
Use self.viewController.contentViewController = ni
lpromero
2017/04/06 13:01:06
Why this call? Seems like you expect a side effect
justincohen
2017/04/06 18:25:11
Done.
justincohen
2017/04/06 18:25:11
Moved to childCoordinatorWillStop
| |
106 | |
89 [self.viewController.presentingViewController | 107 [self.viewController.presentingViewController |
90 dismissViewControllerAnimated:self.context.animated | 108 dismissViewControllerAnimated:self.context.animated |
91 completion:nil]; | 109 completion:nil]; |
92 _webStateObserver.reset(); | 110 _webStateObserver.reset(); |
93 } | 111 } |
94 | 112 |
95 - (void)childCoordinatorDidStart:(BrowserCoordinator*)coordinator { | 113 - (void)childCoordinatorDidStart:(BrowserCoordinator*)coordinator { |
96 if ([coordinator isKindOfClass:[ToolbarCoordinator class]]) { | 114 if ([coordinator isKindOfClass:[ToolbarCoordinator class]]) { |
97 self.viewController.toolbarViewController = coordinator.viewController; | 115 self.viewController.toolbarViewController = coordinator.viewController; |
98 } else if ([coordinator isKindOfClass:[WebCoordinator class]]) { | 116 } else if ([coordinator isKindOfClass:[WebCoordinator class]]) { |
99 self.viewController.contentViewController = coordinator.viewController; | 117 self.viewController.contentViewController = coordinator.viewController; |
100 } else if ([coordinator isKindOfClass:[TabStripCoordinator class]]) { | 118 } else if ([coordinator isKindOfClass:[TabStripCoordinator class]]) { |
101 self.viewController.tabStripViewController = coordinator.viewController; | 119 self.viewController.tabStripViewController = coordinator.viewController; |
120 } else if ([coordinator isKindOfClass:[NTPCoordinator class]]) { | |
121 self.viewController.contentViewController = coordinator.viewController; | |
102 } | 122 } |
103 } | 123 } |
104 | 124 |
105 - (BOOL)canAddOverlayCoordinator:(BrowserCoordinator*)overlayCoordinator { | 125 - (BOOL)canAddOverlayCoordinator:(BrowserCoordinator*)overlayCoordinator { |
106 // This coordinator will always accept overlay coordinators. | 126 // This coordinator will always accept overlay coordinators. |
107 return YES; | 127 return YES; |
108 } | 128 } |
109 | 129 |
110 #pragma mark - Experiment support | 130 #pragma mark - Experiment support |
111 | 131 |
(...skipping 10 matching lines...) Expand all Loading... | |
122 #pragma mark - CRWWebStateObserver | 142 #pragma mark - CRWWebStateObserver |
123 | 143 |
124 // This will eventually be called in -didFinishNavigation and perhaps as an | 144 // This will eventually be called in -didFinishNavigation and perhaps as an |
125 // optimization in some equivalent to loadURL. | 145 // optimization in some equivalent to loadURL. |
126 - (void)webState:(web::WebState*)webState | 146 - (void)webState:(web::WebState*)webState |
127 didCommitNavigationWithDetails:(const web::LoadCommittedDetails&)details { | 147 didCommitNavigationWithDetails:(const web::LoadCommittedDetails&)details { |
128 if (webState->GetLastCommittedURL() == GURL("chrome://newtab/")) { | 148 if (webState->GetLastCommittedURL() == GURL("chrome://newtab/")) { |
129 NTPCoordinator* ntpCoordinator = [[NTPCoordinator alloc] init]; | 149 NTPCoordinator* ntpCoordinator = [[NTPCoordinator alloc] init]; |
130 [self addChildCoordinator:ntpCoordinator]; | 150 [self addChildCoordinator:ntpCoordinator]; |
131 ntpCoordinator.context.baseViewController = nil; | 151 ntpCoordinator.context.baseViewController = nil; |
152 ntpCoordinator.webState = self.webState; | |
132 [ntpCoordinator start]; | 153 [ntpCoordinator start]; |
133 self.viewController.contentViewController = ntpCoordinator.viewController; | 154 self.ntpCoordinator = ntpCoordinator; |
134 } | 155 } |
135 } | 156 } |
136 | 157 |
158 - (void)webState:(web::WebState*)webState | |
159 didStartProvisionalNavigationForURL:(const GURL&)URL { | |
160 if (self.ntpCoordinator) { | |
161 [self.ntpCoordinator stop]; | |
162 [self removeChildCoordinator:self.ntpCoordinator]; | |
163 self.viewController.contentViewController = | |
164 self.webCoordinator.viewController; | |
165 } | |
166 } | |
167 | |
137 #pragma mark - UIViewControllerTransitioningDelegate | 168 #pragma mark - UIViewControllerTransitioningDelegate |
138 | 169 |
139 - (id<UIViewControllerAnimatedTransitioning>) | 170 - (id<UIViewControllerAnimatedTransitioning>) |
140 animationControllerForPresentedController:(UIViewController*)presented | 171 animationControllerForPresentedController:(UIViewController*)presented |
141 presentingController:(UIViewController*)presenting | 172 presentingController:(UIViewController*)presenting |
142 sourceController:(UIViewController*)source { | 173 sourceController:(UIViewController*)source { |
143 ZoomTransitionAnimator* animator = [[ZoomTransitionAnimator alloc] init]; | 174 ZoomTransitionAnimator* animator = [[ZoomTransitionAnimator alloc] init]; |
144 animator.presenting = YES; | 175 animator.presenting = YES; |
145 animator.presentationKey = self.presentationKey; | 176 animator.presentationKey = self.presentationKey; |
146 [animator selectDelegate:@[ source, presenting ]]; | 177 [animator selectDelegate:@[ source, presenting ]]; |
147 return animator; | 178 return animator; |
148 } | 179 } |
149 | 180 |
150 - (id<UIViewControllerAnimatedTransitioning>) | 181 - (id<UIViewControllerAnimatedTransitioning>) |
151 animationControllerForDismissedController:(UIViewController*)dismissed { | 182 animationControllerForDismissedController:(UIViewController*)dismissed { |
152 ZoomTransitionAnimator* animator = [[ZoomTransitionAnimator alloc] init]; | 183 ZoomTransitionAnimator* animator = [[ZoomTransitionAnimator alloc] init]; |
153 animator.presenting = NO; | 184 animator.presenting = NO; |
154 animator.presentationKey = self.presentationKey; | 185 animator.presentationKey = self.presentationKey; |
155 [animator selectDelegate:@[ dismissed.presentingViewController ]]; | 186 [animator selectDelegate:@[ dismissed.presentingViewController ]]; |
156 return animator; | 187 return animator; |
157 } | 188 } |
158 | 189 |
159 @end | 190 @end |
OLD | NEW |