Chromium Code Reviews| Index: ios/clean/chrome/browser/ui/web_contents/web_coordinator.mm |
| diff --git a/ios/clean/chrome/browser/ui/web_contents/web_coordinator.mm b/ios/clean/chrome/browser/ui/web_contents/web_coordinator.mm |
| index 040b690db59ea01a81da87d36677585de9eddb1c..fbcdb1c7825a4f7725674be510d9303f8aaf351c 100644 |
| --- a/ios/clean/chrome/browser/ui/web_contents/web_coordinator.mm |
| +++ b/ios/clean/chrome/browser/ui/web_contents/web_coordinator.mm |
| @@ -4,12 +4,17 @@ |
| #import "ios/clean/chrome/browser/ui/web_contents/web_coordinator.h" |
| +#include "base/mac/foundation_util.h" |
| #include "base/memory/ptr_util.h" |
| +#import "ios/clean/chrome/browser/ui/commands/context_menu_commands.h" |
| +#import "ios/clean/chrome/browser/ui/context_menu/context_menu_context_impl.h" |
| #import "ios/clean/chrome/browser/ui/context_menu/web_context_menu_coordinator.h" |
| #import "ios/clean/chrome/browser/ui/web_contents/web_contents_mediator.h" |
| #import "ios/clean/chrome/browser/ui/web_contents/web_contents_view_controller.h" |
| #import "ios/shared/chrome/browser/ui/browser_list/browser.h" |
| +#import "ios/shared/chrome/browser/ui/commands/command_dispatcher.h" |
| #import "ios/shared/chrome/browser/ui/coordinators/browser_coordinator+internal.h" |
| +#include "ios/web/public/navigation_manager.h" |
| #include "ios/web/public/web_state/web_state.h" |
| #import "ios/web/public/web_state/web_state_delegate_bridge.h" |
| @@ -17,7 +22,7 @@ |
| #error "This file requires ARC support." |
| #endif |
| -@interface WebCoordinator ()<CRWWebStateDelegate> { |
| +@interface WebCoordinator ()<ContextMenuCommands, CRWWebStateDelegate> { |
| std::unique_ptr<web::WebStateDelegateBridge> _webStateDelegate; |
| } |
| @property(nonatomic, strong) WebContentsViewController* viewController; |
| @@ -63,12 +68,44 @@ - (void)childCoordinatorDidStart:(BrowserCoordinator*)childCoordinator { |
| completion:nil]; |
| } |
| +- (void)childCoordinatorWillStop:(BrowserCoordinator*)childCoordinator { |
| + if ([childCoordinator isKindOfClass:[WebContextMenuCoordinator class]]) { |
| + [self.browser->dispatcher() |
| + stopDispatchingForSelector:@selector(executeContextMenuScript:)]; |
| + [self.browser->dispatcher() |
| + stopDispatchingForSelector:@selector(openContextMenuImage:)]; |
| + } |
| +} |
| + |
| +#pragma mark - ContextMenuCommand |
| + |
| +- (void)executeContextMenuScript:(ContextMenuContext*)context { |
| + ContextMenuContextImpl* contextImpl = |
| + base::mac::ObjCCastStrict<ContextMenuContextImpl>(context); |
| + self.webState->ExecuteJavaScript(contextImpl.script); |
| +} |
| + |
| +- (void)openContextMenuImage:(ContextMenuContext*)context { |
| + ContextMenuContextImpl* contextImpl = |
| + base::mac::ObjCCastStrict<ContextMenuContextImpl>(context); |
| + web::NavigationManager::WebLoadParams loadParams(contextImpl.imageURL); |
| + self.webState->GetNavigationManager()->LoadURLWithParams(loadParams); |
| +} |
| + |
| #pragma mark - CRWWebStateDelegate |
| - (BOOL)webState:(web::WebState*)webState |
| handleContextMenu:(const web::ContextMenuParams&)params { |
| + ContextMenuContextImpl* context = |
| + [[ContextMenuContextImpl alloc] initWithParams:params]; |
| WebContextMenuCoordinator* contextMenu = |
| - [[WebContextMenuCoordinator alloc] init]; |
| + [[WebContextMenuCoordinator alloc] initWithContext:context]; |
| + [self.browser->dispatcher() |
|
edchin
2017/05/27 15:59:03
This would have a more symmetrical design if the -
kkhorimoto
2017/05/27 23:09:04
I didn't really have a good reason, so I followed
|
| + startDispatchingToTarget:self |
| + forSelector:@selector(executeContextMenuScript:)]; |
| + [self.browser->dispatcher() |
| + startDispatchingToTarget:self |
| + forSelector:@selector(openContextMenuImage:)]; |
| [self addChildCoordinator:contextMenu]; |
| [contextMenu start]; |
| return YES; |