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

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

Issue 2862783002: [iOS Clean] Wired up ContextMenuCommands. (Closed)
Patch Set: cleanup Created 3 years, 7 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/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #import "ios/clean/chrome/browser/ui/commands/context_menu_commands.h"
10 #import "ios/clean/chrome/browser/ui/context_menu/context_menu_context_impl.h"
8 #import "ios/clean/chrome/browser/ui/context_menu/web_context_menu_coordinator.h " 11 #import "ios/clean/chrome/browser/ui/context_menu/web_context_menu_coordinator.h "
9 #import "ios/clean/chrome/browser/ui/web_contents/web_contents_mediator.h" 12 #import "ios/clean/chrome/browser/ui/web_contents/web_contents_mediator.h"
10 #import "ios/clean/chrome/browser/ui/web_contents/web_contents_view_controller.h " 13 #import "ios/clean/chrome/browser/ui/web_contents/web_contents_view_controller.h "
11 #import "ios/shared/chrome/browser/ui/browser_list/browser.h" 14 #import "ios/shared/chrome/browser/ui/browser_list/browser.h"
15 #import "ios/shared/chrome/browser/ui/commands/command_dispatcher.h"
12 #import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator+internal. h" 16 #import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator+internal. h"
17 #include "ios/web/public/navigation_manager.h"
13 #include "ios/web/public/web_state/web_state.h" 18 #include "ios/web/public/web_state/web_state.h"
14 #import "ios/web/public/web_state/web_state_delegate_bridge.h" 19 #import "ios/web/public/web_state/web_state_delegate_bridge.h"
15 20
16 #if !defined(__has_feature) || !__has_feature(objc_arc) 21 #if !defined(__has_feature) || !__has_feature(objc_arc)
17 #error "This file requires ARC support." 22 #error "This file requires ARC support."
18 #endif 23 #endif
19 24
20 @interface WebCoordinator ()<CRWWebStateDelegate> { 25 @interface WebCoordinator ()<ContextMenuCommands, CRWWebStateDelegate> {
21 std::unique_ptr<web::WebStateDelegateBridge> _webStateDelegate; 26 std::unique_ptr<web::WebStateDelegateBridge> _webStateDelegate;
22 } 27 }
23 @property(nonatomic, strong) WebContentsViewController* viewController; 28 @property(nonatomic, strong) WebContentsViewController* viewController;
24 @property(nonatomic, strong) WebContentsMediator* mediator; 29 @property(nonatomic, strong) WebContentsMediator* mediator;
25 @end 30 @end
26 31
27 @implementation WebCoordinator 32 @implementation WebCoordinator
28 @synthesize webState = _webState; 33 @synthesize webState = _webState;
29 @synthesize viewController = _viewController; 34 @synthesize viewController = _viewController;
30 @synthesize mediator = _mediator; 35 @synthesize mediator = _mediator;
(...skipping 25 matching lines...) Expand all
56 [self.mediator disconnect]; 61 [self.mediator disconnect];
57 } 62 }
58 63
59 - (void)childCoordinatorDidStart:(BrowserCoordinator*)childCoordinator { 64 - (void)childCoordinatorDidStart:(BrowserCoordinator*)childCoordinator {
60 DCHECK([childCoordinator isKindOfClass:[WebContextMenuCoordinator class]]); 65 DCHECK([childCoordinator isKindOfClass:[WebContextMenuCoordinator class]]);
61 [self.viewController presentViewController:childCoordinator.viewController 66 [self.viewController presentViewController:childCoordinator.viewController
62 animated:YES 67 animated:YES
63 completion:nil]; 68 completion:nil];
64 } 69 }
65 70
71 - (void)childCoordinatorWillStop:(BrowserCoordinator*)childCoordinator {
72 if ([childCoordinator isKindOfClass:[WebContextMenuCoordinator class]]) {
73 [self.browser->dispatcher()
74 stopDispatchingForSelector:@selector(executeContextMenuScript:)];
75 [self.browser->dispatcher()
76 stopDispatchingForSelector:@selector(openContextMenuImage:)];
77 }
78 }
79
80 #pragma mark - ContextMenuCommand
81
82 - (void)executeContextMenuScript:(ContextMenuContext*)context {
83 ContextMenuContextImpl* contextImpl =
84 base::mac::ObjCCastStrict<ContextMenuContextImpl>(context);
85 self.webState->ExecuteJavaScript(contextImpl.script);
86 }
87
88 - (void)openContextMenuImage:(ContextMenuContext*)context {
89 ContextMenuContextImpl* contextImpl =
90 base::mac::ObjCCastStrict<ContextMenuContextImpl>(context);
91 web::NavigationManager::WebLoadParams loadParams(contextImpl.imageURL);
92 self.webState->GetNavigationManager()->LoadURLWithParams(loadParams);
93 }
94
66 #pragma mark - CRWWebStateDelegate 95 #pragma mark - CRWWebStateDelegate
67 96
68 - (BOOL)webState:(web::WebState*)webState 97 - (BOOL)webState:(web::WebState*)webState
69 handleContextMenu:(const web::ContextMenuParams&)params { 98 handleContextMenu:(const web::ContextMenuParams&)params {
99 ContextMenuContextImpl* context =
100 [[ContextMenuContextImpl alloc] initWithParams:params];
70 WebContextMenuCoordinator* contextMenu = 101 WebContextMenuCoordinator* contextMenu =
71 [[WebContextMenuCoordinator alloc] init]; 102 [[WebContextMenuCoordinator alloc] initWithContext:context];
103 [self.browser->dispatcher()
104 startDispatchingToTarget:self
105 forSelector:@selector(executeContextMenuScript:)];
106 [self.browser->dispatcher()
107 startDispatchingToTarget:self
108 forSelector:@selector(openContextMenuImage:)];
72 [self addChildCoordinator:contextMenu]; 109 [self addChildCoordinator:contextMenu];
73 [contextMenu start]; 110 [contextMenu start];
74 return YES; 111 return YES;
75 } 112 }
76 113
77 @end 114 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698