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

Unified Diff: ios/web_view/internal/cwv_web_view.mm

Issue 2723433004: Add CWVUIDelegate with method to customize context menu. (Closed)
Patch Set: Created 3 years, 10 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/web_view/internal/cwv_web_view.mm
diff --git a/ios/web_view/internal/cwv_web_view.mm b/ios/web_view/internal/cwv_web_view.mm
index 648cbfac4bbbb7392c8e367f9ef817c752444b88..7fae1af3709731157acd9fb478854416cebc2639 100644
--- a/ios/web_view/internal/cwv_web_view.mm
+++ b/ios/web_view/internal/cwv_web_view.mm
@@ -12,6 +12,7 @@
#include "base/strings/sys_string_conversions.h"
#import "ios/web/public/navigation_manager.h"
#include "ios/web/public/referrer.h"
+#import "ios/web/public/web_state/context_menu_params.h"
#import "ios/web/public/web_state/js/crw_js_injection_receiver.h"
#import "ios/web/public/web_state/ui/crw_web_delegate.h"
#import "ios/web/public/web_state/web_state.h"
@@ -20,6 +21,8 @@
#import "ios/web_view/internal/cwv_website_data_store_internal.h"
#import "ios/web_view/internal/translate/web_view_translate_client.h"
#include "ios/web_view/internal/web_view_browser_state.h"
+#import "ios/web_view/public/cwv_html_element.h"
+#import "ios/web_view/public/cwv_ui_delegate.h"
#import "ios/web_view/public/cwv_web_view_configuration.h"
#import "ios/web_view/public/cwv_web_view_delegate.h"
#import "ios/web_view/public/cwv_website_data_store.h"
@@ -45,6 +48,7 @@
@synthesize delegate = _delegate;
@synthesize loadProgress = _loadProgress;
+@synthesize UIDelegate = _UIDelegate;
- (instancetype)initWithFrame:(CGRect)frame
configuration:(CWVWebViewConfiguration*)configuration {
@@ -185,4 +189,25 @@
[self notifyDidUpdateWithChanges:CRIWVWebViewUpdateTypeProgress];
}
+- (BOOL)webState:(web::WebState*)webState
+ handleContextMenu:(const web::ContextMenuParams&)params {
+ if ([_UIDelegate respondsToSelector:@selector
Eugene But (OOO till 7-30) 2017/02/27 16:34:06 Optional nit: do you want to reverse the condition
michaeldo 2017/02/27 19:02:05 I agree, I like that better.
+ (webView:runContextMenuWithTitle:forHTMLElement:inView
Eugene But (OOO till 7-30) 2017/02/27 16:34:06 Optional nit: Do you want to create a local variab
michaeldo 2017/02/27 19:02:05 Done.
+ :userGestureLocation:)]) {
+ NSURL* hyperlink = net::NSURLWithGURL(params.link_url);
+ NSURL* mediaSource = net::NSURLWithGURL(params.src_url);
+ CWVHTMLElement* htmlElement =
Eugene But (OOO till 7-30) 2017/02/27 16:34:06 s/htmlElement/HTMLElement
michaeldo 2017/02/27 19:02:06 Done.
+ [[CWVHTMLElement alloc] initWithHyperlink:hyperlink
+ mediaSource:mediaSource
+ text:params.link_text];
+ [_UIDelegate webView:self
+ runContextMenuWithTitle:params.menu_title
+ forHTMLElement:htmlElement
+ inView:params.view
+ userGestureLocation:params.location];
+ return YES;
+ }
+ return NO;
+}
+
@end

Powered by Google App Engine
This is Rietveld 408576698