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 // ====== New Architecture ===== | 5 // ====== New Architecture ===== |
6 // = This code is only used in the new iOS Chrome architecture. = | 6 // = This code is only used in the new iOS Chrome architecture. = |
7 // ============================================================================ | 7 // ============================================================================ |
8 | 8 |
9 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_coordinator.h" | 9 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_coordinator.h" |
10 | 10 |
11 #include "base/strings/sys_string_conversions.h" | |
12 #import "ios/clean/chrome/browser/browser_coordinator+internal.h" | 11 #import "ios/clean/chrome/browser/browser_coordinator+internal.h" |
13 #import "ios/clean/chrome/browser/ui/commands/toolbar_commands.h" | 12 #import "ios/clean/chrome/browser/ui/commands/toolbar_commands.h" |
14 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_view_controller.h" | 13 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_view_controller.h" |
14 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_web_state_mediator.h" | |
15 #import "ios/clean/chrome/browser/ui/tools/tools_coordinator.h" | 15 #import "ios/clean/chrome/browser/ui/tools/tools_coordinator.h" |
16 #import "ios/shared/chrome/browser/coordinator_context/coordinator_context.h" | 16 #import "ios/shared/chrome/browser/coordinator_context/coordinator_context.h" |
17 #include "ios/web/public/web_state/web_state.h" | |
18 | 17 |
19 #if !defined(__has_feature) || !__has_feature(objc_arc) | 18 #if !defined(__has_feature) || !__has_feature(objc_arc) |
20 #error "This file requires ARC support." | 19 #error "This file requires ARC support." |
21 #endif | 20 #endif |
22 | 21 |
23 @interface ToolbarCoordinator ()<ToolbarCommands> | 22 @interface ToolbarCoordinator ()<ToolbarCommands> |
24 @property(nonatomic, weak) ToolsCoordinator* toolsMenuCoordinator; | 23 @property(nonatomic, weak) ToolsCoordinator* toolsMenuCoordinator; |
25 @property(nonatomic, strong) ToolbarViewController* viewController; | 24 @property(nonatomic, strong) ToolbarViewController* viewController; |
25 @property(nonatomic, strong) ToolbarWebStateMediator* mediator; | |
26 @end | 26 @end |
27 | 27 |
28 @implementation ToolbarCoordinator | 28 @implementation ToolbarCoordinator |
29 @synthesize toolsMenuCoordinator = _toolsMenuCoordinator; | 29 @synthesize toolsMenuCoordinator = _toolsMenuCoordinator; |
30 @synthesize viewController = _viewController; | 30 @synthesize viewController = _viewController; |
31 @synthesize webState = _webState; | |
32 @synthesize mediator = _mediator; | |
33 | |
34 - (instancetype)init { | |
35 if ((self = [super init])) { | |
36 _mediator = [[ToolbarWebStateMediator alloc] init]; | |
37 } | |
38 return self; | |
39 } | |
40 | |
41 - (void)setWebState:(web::WebState*)webState { | |
42 _webState = webState; | |
43 self.mediator.webState = self.webState; | |
edchin
2017/02/21 07:56:11
The webState is used only as a pass-through to the
sczs
2017/02/21 17:28:27
It will be used to pass the WebState to the ToolsM
| |
44 } | |
31 | 45 |
32 - (void)start { | 46 - (void)start { |
33 self.viewController = [[ToolbarViewController alloc] init]; | 47 self.viewController = [[ToolbarViewController alloc] init]; |
34 self.viewController.toolbarCommandHandler = self; | 48 self.viewController.toolbarCommandHandler = self; |
49 self.mediator.consumer = self.viewController; | |
35 | 50 |
36 [self.context.baseViewController presentViewController:self.viewController | 51 [self.context.baseViewController presentViewController:self.viewController |
37 animated:self.context.animated | 52 animated:self.context.animated |
38 completion:nil]; | 53 completion:nil]; |
39 } | 54 } |
40 | 55 |
41 #pragma mark - CRWWebStateObserver | |
42 | |
43 - (void)webState:(web::WebState*)webState didLoadPageWithSuccess:(BOOL)success { | |
44 const GURL& pageURL = webState->GetVisibleURL(); | |
45 [self.viewController | |
46 setCurrentPageText:base::SysUTF8ToNSString(pageURL.spec())]; | |
47 } | |
48 | |
49 #pragma mark - ToolbarCommands | 56 #pragma mark - ToolbarCommands |
50 | 57 |
51 - (void)showToolsMenu { | 58 - (void)showToolsMenu { |
52 ToolsCoordinator* toolsCoordinator = [[ToolsCoordinator alloc] init]; | 59 ToolsCoordinator* toolsCoordinator = [[ToolsCoordinator alloc] init]; |
53 toolsCoordinator.toolbarCommandHandler = self; | 60 toolsCoordinator.toolbarCommandHandler = self; |
54 [self addChildCoordinator:toolsCoordinator]; | 61 [self addChildCoordinator:toolsCoordinator]; |
55 [toolsCoordinator start]; | 62 [toolsCoordinator start]; |
56 self.toolsMenuCoordinator = toolsCoordinator; | 63 self.toolsMenuCoordinator = toolsCoordinator; |
57 } | 64 } |
58 | 65 |
59 - (void)closeToolsMenu { | 66 - (void)closeToolsMenu { |
60 [self.toolsMenuCoordinator stop]; | 67 [self.toolsMenuCoordinator stop]; |
61 [self removeChildCoordinator:self.toolsMenuCoordinator]; | 68 [self removeChildCoordinator:self.toolsMenuCoordinator]; |
62 } | 69 } |
63 | 70 |
64 @end | 71 @end |
OLD | NEW |