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

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

Issue 2862783002: [iOS Clean] Wired up ContextMenuCommands. (Closed)
Patch Set: fix deps 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 side-by-side diff with in-line comments
Download patch
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..6198cab7d5b55770b97724151373fdd9f7165066 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;
@@ -57,18 +62,53 @@ - (void)stop {
}
- (void)childCoordinatorDidStart:(BrowserCoordinator*)childCoordinator {
- DCHECK([childCoordinator isKindOfClass:[WebContextMenuCoordinator class]]);
+ // Register to receive relevant ContextMenuCommands.
+ if ([childCoordinator isKindOfClass:[WebContextMenuCoordinator class]]) {
+ [self.browser->dispatcher()
+ startDispatchingToTarget:self
+ forSelector:@selector(executeContextMenuScript:)];
+ [self.browser->dispatcher()
+ startDispatchingToTarget:self
+ forSelector:@selector(openContextMenuImage:)];
+ }
[self.viewController presentViewController:childCoordinator.viewController
animated:YES
completion:nil];
}
+- (void)childCoordinatorWillStop:(BrowserCoordinator*)childCoordinator {
+ // Unregister ContextMenuCommands once the UI has been dismissed.
+ 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 addChildCoordinator:contextMenu];
[contextMenu start];
return YES;

Powered by Google App Engine
This is Rietveld 408576698