Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: ios/clean/chrome/browser/ui/web_contents/web_coordinator.mm

Issue 2921833002: [iOS Clean] Created OverlayService.
Patch Set: Cancel overlays on queue deallocation Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/web_contents/web_coordinator.h" 5 #import "ios/clean/chrome/browser/ui/web_contents/web_coordinator.h"
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #import "ios/clean/chrome/browser/ui/commands/context_menu_commands.h" 9 #import "ios/clean/chrome/browser/ui/commands/context_menu_commands.h"
10 #import "ios/clean/chrome/browser/ui/commands/overlay_commands.h"
10 #import "ios/clean/chrome/browser/ui/context_menu/context_menu_context_impl.h" 11 #import "ios/clean/chrome/browser/ui/context_menu/context_menu_context_impl.h"
11 #import "ios/clean/chrome/browser/ui/context_menu/web_context_menu_coordinator.h " 12 #import "ios/clean/chrome/browser/ui/context_menu/web_context_menu_coordinator.h "
13 #import "ios/clean/chrome/browser/ui/overlays/overlay_queue.h"
12 #import "ios/clean/chrome/browser/ui/web_contents/web_contents_mediator.h" 14 #import "ios/clean/chrome/browser/ui/web_contents/web_contents_mediator.h"
13 #import "ios/clean/chrome/browser/ui/web_contents/web_contents_view_controller.h " 15 #import "ios/clean/chrome/browser/ui/web_contents/web_contents_view_controller.h "
14 #import "ios/shared/chrome/browser/ui/browser_list/browser.h" 16 #import "ios/shared/chrome/browser/ui/browser_list/browser.h"
15 #import "ios/shared/chrome/browser/ui/commands/command_dispatcher.h" 17 #import "ios/shared/chrome/browser/ui/commands/command_dispatcher.h"
16 #import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator+internal. h" 18 #import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator+internal. h"
17 #include "ios/web/public/navigation_manager.h" 19 #include "ios/web/public/navigation_manager.h"
18 #include "ios/web/public/web_state/web_state.h" 20 #include "ios/web/public/web_state/web_state.h"
19 #import "ios/web/public/web_state/web_state_delegate_bridge.h" 21 #import "ios/web/public/web_state/web_state_delegate_bridge.h"
20 22
21 #if !defined(__has_feature) || !__has_feature(objc_arc) 23 #if !defined(__has_feature) || !__has_feature(objc_arc)
22 #error "This file requires ARC support." 24 #error "This file requires ARC support."
23 #endif 25 #endif
24 26
25 @interface WebCoordinator ()<ContextMenuCommands, CRWWebStateDelegate> { 27 @interface WebCoordinator ()<ContextMenuCommands,
28 CRWWebStateDelegate,
29 OverlayPresentationCommands> {
26 std::unique_ptr<web::WebStateDelegateBridge> _webStateDelegate; 30 std::unique_ptr<web::WebStateDelegateBridge> _webStateDelegate;
27 } 31 }
28 @property(nonatomic, strong) WebContentsViewController* viewController; 32 @property(nonatomic, strong) WebContentsViewController* viewController;
29 @property(nonatomic, strong) WebContentsMediator* mediator; 33 @property(nonatomic, strong) WebContentsMediator* mediator;
34
35 // Lazily creates a WebJavaScriptDialogPresenter and OverlayQueue for the
36 // WebState.
37 - (void)createDialogHelpers;
38
39 // Starts the next overlay in |webState|'s OverlayQueue.
40 - (void)startNextOverlay;
41
30 @end 42 @end
31 43
32 @implementation WebCoordinator 44 @implementation WebCoordinator
33 @synthesize webState = _webState; 45 @synthesize webState = _webState;
34 @synthesize viewController = _viewController; 46 @synthesize viewController = _viewController;
35 @synthesize mediator = _mediator; 47 @synthesize mediator = _mediator;
36 48
37 - (instancetype)init { 49 - (instancetype)init {
38 if ((self = [super init])) { 50 if ((self = [super init])) {
39 _mediator = [[WebContentsMediator alloc] init]; 51 _mediator = [[WebContentsMediator alloc] init];
40 _webStateDelegate = base::MakeUnique<web::WebStateDelegateBridge>(self); 52 _webStateDelegate = base::MakeUnique<web::WebStateDelegateBridge>(self);
41 } 53 }
42 return self; 54 return self;
43 } 55 }
44 56
45 - (void)setWebState:(web::WebState*)webState { 57 - (void)setWebState:(web::WebState*)webState {
46 // PLACEHOLDER: The web state delegate will be set by another object, and 58 // PLACEHOLDER: The web state delegate will be set by another object, and
47 // this coordinator will not need to know the active web state. 59 // this coordinator will not need to know the active web state.
48 _webState = webState; 60 _webState = webState;
49 self.webState->SetDelegate(_webStateDelegate.get()); 61 self.webState->SetDelegate(_webStateDelegate.get());
50 } 62 }
51 63
52 - (void)start { 64 - (void)start {
65 // Create the view controller and start it.
53 self.viewController = [[WebContentsViewController alloc] init]; 66 self.viewController = [[WebContentsViewController alloc] init];
54 self.mediator.consumer = self.viewController; 67 self.mediator.consumer = self.viewController;
55 self.mediator.webStateList = &self.browser->web_state_list(); 68 self.mediator.webStateList = &self.browser->web_state_list();
56 [super start]; 69 [super start];
70 // Register for overlay commands and start the next overlay.
71 [self.browser->dispatcher()
72 startDispatchingToTarget:self
73 forProtocol:@protocol(OverlayPresentationCommands)];
74 [self createDialogHelpers];
75 [self startNextOverlay];
57 } 76 }
58 77
59 - (void)stop { 78 - (void)stop {
79 [self.browser->dispatcher() stopDispatchingToTarget:self];
60 [super stop]; 80 [super stop];
61 [self.mediator disconnect]; 81 [self.mediator disconnect];
62 } 82 }
63 83
64 - (void)childCoordinatorDidStart:(BrowserCoordinator*)childCoordinator { 84 - (void)childCoordinatorDidStart:(BrowserCoordinator*)childCoordinator {
65 // Register to receive relevant ContextMenuCommands. 85 // Register to receive relevant ContextMenuCommands.
66 if ([childCoordinator isKindOfClass:[WebContextMenuCoordinator class]]) { 86 if ([childCoordinator isKindOfClass:[WebContextMenuCoordinator class]]) {
67 [self.browser->dispatcher() 87 [self.browser->dispatcher()
68 startDispatchingToTarget:self 88 startDispatchingToTarget:self
69 forSelector:@selector(executeContextMenuScript:)]; 89 forSelector:@selector(executeContextMenuScript:)];
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 handleContextMenu:(const web::ContextMenuParams&)params { 127 handleContextMenu:(const web::ContextMenuParams&)params {
108 ContextMenuContextImpl* context = 128 ContextMenuContextImpl* context =
109 [[ContextMenuContextImpl alloc] initWithParams:params]; 129 [[ContextMenuContextImpl alloc] initWithParams:params];
110 WebContextMenuCoordinator* contextMenu = 130 WebContextMenuCoordinator* contextMenu =
111 [[WebContextMenuCoordinator alloc] initWithContext:context]; 131 [[WebContextMenuCoordinator alloc] initWithContext:context];
112 [self addChildCoordinator:contextMenu]; 132 [self addChildCoordinator:contextMenu];
113 [contextMenu start]; 133 [contextMenu start];
114 return YES; 134 return YES;
115 } 135 }
116 136
137 #pragma mark - OverlayPresentationCommands
138
139 - (void)startNextOverlayForWebState:(web::WebState*)webState {
140 DCHECK_EQ(self.webState, webState);
141 [self startNextOverlay];
142 }
143
144 #pragma mark -
145
146 - (void)createDialogHelpers {
147 id<OverlaySchedulerCommands> overlayDispatcher =
148 static_cast<id<OverlaySchedulerCommands>>(self.browser->dispatcher());
149 OverlayQueue::CreateForWebState(self.webState, overlayDispatcher);
150 }
151
152 - (void)startNextOverlay {
153 OverlayQueue* queue = OverlayQueue::FromWebState(self.webState);
marq (ping after 24h) 2017/06/14 10:02:32 This might belong in a mediator. (The general id
kkhorimoto 2017/06/15 08:26:29 This is no longer necessary.
154 if (queue->HasQueuedOverlays() && !queue->IsShowingOverlay())
155 queue->StartNextOverlay(self);
156 }
157
117 @end 158 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698