Index: ios/web/web_state/web_view_internal_creation_util.mm |
diff --git a/ios/web/web_state/web_view_internal_creation_util.mm b/ios/web/web_state/web_view_internal_creation_util.mm |
index 2fb8789dea675bbb5615ae1df6615592682af41b..59ff848827db4e88498c12062a89ec4627d06a95 100644 |
--- a/ios/web/web_state/web_view_internal_creation_util.mm |
+++ b/ios/web/web_state/web_view_internal_creation_util.mm |
@@ -4,9 +4,13 @@ |
#import "ios/web/web_state/web_view_internal_creation_util.h" |
+#import <objc/runtime.h> |
+ |
#include "base/logging.h" |
+#import "base/mac/scoped_nsobject.h" |
#include "base/strings/sys_string_conversions.h" |
#import "ios/web/public/web_client.h" |
+#import "ios/web/web_state/ui/crw_context_menu_controller.h" |
#import "ios/web/web_state/ui/wk_web_view_configuration_provider.h" |
namespace web { |
@@ -32,7 +36,8 @@ void VerifyWKWebViewCreationPreConditions( |
WKWebView* BuildWKWebView(CGRect frame, |
WKWebViewConfiguration* configuration, |
BrowserState* browser_state, |
- BOOL use_desktop_user_agent) { |
+ BOOL use_desktop_user_agent, |
+ id<CRWContextMenuDelegate> context_menu_delegate) { |
VerifyWKWebViewCreationPreConditions(browser_state, configuration); |
GetWebClient()->PreWebViewCreation(); |
@@ -53,11 +58,30 @@ WKWebView* BuildWKWebView(CGRect frame, |
// created. |
web_view.allowsLinkPreview = NO; |
+ if (context_menu_delegate) { |
+ base::scoped_nsobject<CRWContextMenuController> context_menu_controller( |
+ [[CRWContextMenuController alloc] |
+ initWithWebView:web_view |
+ injectionEvaluator:nil |
+ delegate:context_menu_delegate]); |
+ objc_setAssociatedObject(web_view, context_menu_controller.get(), |
+ context_menu_controller.get(), |
+ OBJC_ASSOCIATION_RETAIN_NONATOMIC); |
+ } |
+ |
return [web_view autorelease]; |
} |
WKWebView* BuildWKWebView(CGRect frame, |
WKWebViewConfiguration* configuration, |
+ BrowserState* browser_state, |
+ BOOL use_desktop_user_agent) { |
+ return BuildWKWebView(frame, configuration, browser_state, |
+ use_desktop_user_agent, nil); |
+} |
+ |
+WKWebView* BuildWKWebView(CGRect frame, |
+ WKWebViewConfiguration* configuration, |
BrowserState* browser_state) { |
BOOL use_desktop_user_agent = NO; |
return BuildWKWebView(frame, configuration, browser_state, |