Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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/context_menu/web_context_menu_coordinator.h " | 5 #import "ios/clean/chrome/browser/ui/context_menu/web_context_menu_coordinator.h " |
| 6 | 6 |
| 7 #include "base/logging.h" | |
| 8 #import "ios/clean/chrome/browser/ui/commands/context_menu_commands.h" | |
| 9 #import "ios/clean/chrome/browser/ui/context_menu/context_menu_context_impl.h" | |
| 7 #import "ios/clean/chrome/browser/ui/context_menu/context_menu_mediator.h" | 10 #import "ios/clean/chrome/browser/ui/context_menu/context_menu_mediator.h" |
| 8 #import "ios/clean/chrome/browser/ui/context_menu/context_menu_view_controller.h " | 11 #import "ios/clean/chrome/browser/ui/context_menu/context_menu_view_controller.h " |
| 9 #import "ios/shared/chrome/browser/ui/browser_list/browser.h" | 12 #import "ios/shared/chrome/browser/ui/browser_list/browser.h" |
| 10 #import "ios/shared/chrome/browser/ui/commands/command_dispatcher.h" | 13 #import "ios/shared/chrome/browser/ui/commands/command_dispatcher.h" |
| 11 | 14 |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) | 15 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 13 #error "This file requires ARC support." | 16 #error "This file requires ARC support." |
| 14 #endif | 17 #endif |
| 15 | 18 |
| 16 @interface WebContextMenuCoordinator () | 19 @interface WebContextMenuCoordinator ()<ContextMenuCommands> |
| 20 // The menu context. | |
| 21 @property(nonatomic, strong, readonly) ContextMenuContextImpl* context; | |
| 22 // The mediator that handles setting up |viewController|. | |
| 17 @property(nonatomic, strong) ContextMenuMediator* mediator; | 23 @property(nonatomic, strong) ContextMenuMediator* mediator; |
| 24 // The view controller that displayes the context menu UI. | |
| 18 @property(nonatomic, strong) ContextMenuViewController* viewController; | 25 @property(nonatomic, strong) ContextMenuViewController* viewController; |
| 26 | |
| 19 @end | 27 @end |
| 20 | 28 |
| 21 @implementation WebContextMenuCoordinator | 29 @implementation WebContextMenuCoordinator |
| 30 @synthesize context = _context; | |
| 31 @synthesize mediator = _mediator; | |
| 22 @synthesize viewController = _viewController; | 32 @synthesize viewController = _viewController; |
| 23 @synthesize mediator = _mediator; | 33 |
| 34 - (instancetype)initWithContext:(ContextMenuContextImpl*)context { | |
| 35 if ((self = [super init])) { | |
| 36 DCHECK(context); | |
| 37 _context = context; | |
| 38 } | |
| 39 return self; | |
| 40 } | |
| 41 | |
| 42 #pragma mark - BrowserCoordinator | |
| 24 | 43 |
| 25 - (void)start { | 44 - (void)start { |
| 45 id<ContextMenuCommands> contextMenuDispatcher = | |
| 46 static_cast<id<ContextMenuCommands>>(self.browser->dispatcher()); | |
| 26 self.viewController = [[ContextMenuViewController alloc] | 47 self.viewController = [[ContextMenuViewController alloc] |
| 27 initWithDispatcher:static_cast<id>(self.browser->dispatcher())]; | 48 initWithDispatcher:contextMenuDispatcher]; |
| 28 self.mediator = | 49 self.mediator = |
|
edchin
2017/05/25 21:41:53
Since the mediator does its job in its initializer
kkhorimoto
2017/05/26 23:20:09
Doing that gave me an unused variable warning when
edchin
2017/05/27 15:59:03
Interesting question. This is the only mediator th
kkhorimoto
2017/05/27 23:09:03
I'm also working on the javascript dialog coordina
| |
| 29 [[ContextMenuMediator alloc] initWithConsumer:self.viewController]; | 50 [[ContextMenuMediator alloc] initWithConsumer:self.viewController |
| 51 context:self.context]; | |
| 52 [self.browser->dispatcher() | |
| 53 startDispatchingToTarget:self | |
| 54 forSelector:@selector(hideContextMenu:)]; | |
| 30 [super start]; | 55 [super start]; |
| 31 } | 56 } |
| 32 | 57 |
| 58 - (void)stop { | |
| 59 [self.browser->dispatcher() stopDispatchingToTarget:self]; | |
| 60 [super stop]; | |
| 61 } | |
| 62 | |
| 63 #pragma mark - ContextMenuCommands | |
| 64 | |
| 65 - (void)hideContextMenu:(ContextMenuContext*)context { | |
| 66 DCHECK_EQ(self.context, context); | |
| 67 [self stop]; | |
| 68 } | |
| 69 | |
| 33 @end | 70 @end |
| OLD | NEW |