Commit fc37b89d authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Chromium LUCI CQ

[iOS] Pass ContextMenuParams instead of URL to delegate

This CL changes the ContextMenu callback parameters used by the WebKit
API to use ContextMenuParams instead of just the URL.

This will be necessary to check the new implementation where the
interaction is added to the whole view.

Bug: 1140387
Change-Id: Iabc574d4e0a88d43b4c2e1b7a9c1caeddda3c701
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2582041
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Reviewed-by: default avatarJohn Wu <jzw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835615}
parent 58757fb2
...@@ -3595,10 +3595,10 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -3595,10 +3595,10 @@ NSString* const kBrowserViewControllerSnackbarCategory =
} }
- (void)webState:(web::WebState*)webState - (void)webState:(web::WebState*)webState
contextMenuConfigurationForLinkWithURL:(const GURL&)linkURL contextMenuConfigurationForParams:(const web::ContextMenuParams&)params
completionHandler: completionHandler:
(void (^)(UIContextMenuConfiguration*)) (void (^)(UIContextMenuConfiguration*))completionHandler
completionHandler API_AVAILABLE(ios(13.0)) { API_AVAILABLE(ios(13.0)) {
// Prevent context menu from displaying for a tab which is no longer the // Prevent context menu from displaying for a tab which is no longer the
// current one. // current one.
if (webState != self.currentWebState) { if (webState != self.currentWebState) {
...@@ -3606,7 +3606,7 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -3606,7 +3606,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
} }
// No custom context menu if no valid url is available. // No custom context menu if no valid url is available.
if (!linkURL.is_valid()) if (!params.link_url.is_valid())
return; return;
DCHECK(self.browserState); DCHECK(self.browserState);
......
...@@ -99,7 +99,7 @@ class WebStateDelegate { ...@@ -99,7 +99,7 @@ class WebStateDelegate {
// the context menu. // the context menu.
virtual void ContextMenuConfiguration( virtual void ContextMenuConfiguration(
WebState* source, WebState* source,
const GURL& link_url, const ContextMenuParams& params,
void (^completion_handler)(UIContextMenuConfiguration*)) void (^completion_handler)(UIContextMenuConfiguration*))
API_AVAILABLE(ios(13.0)); API_AVAILABLE(ios(13.0));
// Called when iOS13+ context menu is ready to be showed. // Called when iOS13+ context menu is ready to be showed.
......
...@@ -86,10 +86,10 @@ ...@@ -86,10 +86,10 @@
// provide a UIContextMenuConfiguration to |completion_handler| to generate the // provide a UIContextMenuConfiguration to |completion_handler| to generate the
// context menu. // context menu.
- (void)webState:(web::WebState*)webState - (void)webState:(web::WebState*)webState
contextMenuConfigurationForLinkWithURL:(const GURL&)linkURL contextMenuConfigurationForParams:(const web::ContextMenuParams&)params
completionHandler: completionHandler:
(void (^)(UIContextMenuConfiguration*)) (void (^)(UIContextMenuConfiguration*))completionHandler
completionHandler API_AVAILABLE(ios(13.0)); API_AVAILABLE(ios(13.0));
// Called when iOS13+ context menu is ready to be showed. // Called when iOS13+ context menu is ready to be showed.
- (void)webState:(web::WebState*)webState - (void)webState:(web::WebState*)webState
...@@ -146,7 +146,7 @@ class WebStateDelegateBridge : public web::WebStateDelegate { ...@@ -146,7 +146,7 @@ class WebStateDelegateBridge : public web::WebStateDelegate {
UIView* GetWebViewContainer(WebState* source) override; UIView* GetWebViewContainer(WebState* source) override;
void ContextMenuConfiguration( void ContextMenuConfiguration(
WebState* source, WebState* source,
const GURL& link_url, const ContextMenuParams& params,
void (^completion_handler)(UIContextMenuConfiguration*)) void (^completion_handler)(UIContextMenuConfiguration*))
API_AVAILABLE(ios(13.0)) override; API_AVAILABLE(ios(13.0)) override;
void ContextMenuDidEnd(WebState* source, const GURL& link_url) void ContextMenuDidEnd(WebState* source, const GURL& link_url)
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#import "ios/web/navigation/wk_navigation_action_util.h" #import "ios/web/navigation/wk_navigation_action_util.h"
#import "ios/web/navigation/wk_navigation_util.h" #import "ios/web/navigation/wk_navigation_util.h"
#import "ios/web/public/ui/context_menu_params.h"
#import "ios/web/public/ui/java_script_dialog_type.h" #import "ios/web/public/ui/java_script_dialog_type.h"
#import "ios/web/public/web_client.h" #import "ios/web/public/web_client.h"
#import "ios/web/web_state/ui/crw_legacy_context_menu_controller.h" #import "ios/web/web_state/ui/crw_legacy_context_menu_controller.h"
...@@ -199,11 +200,14 @@ ...@@ -199,11 +200,14 @@
completionHandler API_AVAILABLE(ios(13.0)) { completionHandler API_AVAILABLE(ios(13.0)) {
web::WebStateDelegate* delegate = self.webStateImpl->GetDelegate(); web::WebStateDelegate* delegate = self.webStateImpl->GetDelegate();
if (!delegate) { if (!delegate) {
completionHandler(nil);
return; return;
} }
delegate->ContextMenuConfiguration(self.webStateImpl, web::ContextMenuParams params;
net::GURLWithNSURL(elementInfo.linkURL), params.link_url = net::GURLWithNSURL(elementInfo.linkURL);
delegate->ContextMenuConfiguration(self.webStateImpl, params,
completionHandler); completionHandler);
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "ios/web/public/test/fakes/test_browser_state.h" #include "ios/web/public/test/fakes/test_browser_state.h"
#include "ios/web/public/test/scoped_testing_web_client.h" #include "ios/web/public/test/scoped_testing_web_client.h"
#import "ios/web/public/ui/context_menu_params.h"
#import "ios/web/test/web_test_with_web_controller.h" #import "ios/web/test/web_test_with_web_controller.h"
#import "net/base/mac/url_conversions.h" #import "net/base/mac/url_conversions.h"
#import "testing/gtest_mac.h" #import "testing/gtest_mac.h"
...@@ -30,12 +31,12 @@ ...@@ -30,12 +31,12 @@
@implementation FakeCRWWebStateDelegate @implementation FakeCRWWebStateDelegate
- (void)webState:(web::WebState*)webState - (void)webState:(web::WebState*)webState
contextMenuConfigurationForLinkWithURL:(const GURL&)linkURL contextMenuConfigurationForParams:(const web::ContextMenuParams&)params
completionHandler: completionHandler:
(void (^)(UIContextMenuConfiguration*)) (void (^)(UIContextMenuConfiguration*))completionHandler
completionHandler API_AVAILABLE(ios(13.0)) { API_AVAILABLE(ios(13.0)) {
self.webState = webState; self.webState = webState;
self.URL = net::NSURLWithGURL(linkURL); self.URL = net::NSURLWithGURL(params.link_url);
self.contextMenuConfigurationNeeded = YES; self.contextMenuConfigurationNeeded = YES;
} }
......
...@@ -86,9 +86,11 @@ void WebStateDelegate::Detach(WebState* source) { ...@@ -86,9 +86,11 @@ void WebStateDelegate::Detach(WebState* source) {
void WebStateDelegate::ContextMenuConfiguration( void WebStateDelegate::ContextMenuConfiguration(
WebState* source, WebState* source,
const GURL& link_url, const ContextMenuParams& params,
void (^completion_handler)(UIContextMenuConfiguration*)) void (^completion_handler)(UIContextMenuConfiguration*))
API_AVAILABLE(ios(13.0)) {} API_AVAILABLE(ios(13.0)) {
completion_handler(nil);
}
void WebStateDelegate::ContextMenuDidEnd(WebState* source, const GURL& link_url) void WebStateDelegate::ContextMenuDidEnd(WebState* source, const GURL& link_url)
API_AVAILABLE(ios(13.0)) {} API_AVAILABLE(ios(13.0)) {}
......
...@@ -140,16 +140,17 @@ UIView* WebStateDelegateBridge::GetWebViewContainer(WebState* source) { ...@@ -140,16 +140,17 @@ UIView* WebStateDelegateBridge::GetWebViewContainer(WebState* source) {
void WebStateDelegateBridge::ContextMenuConfiguration( void WebStateDelegateBridge::ContextMenuConfiguration(
WebState* source, WebState* source,
const GURL& link_url, const ContextMenuParams& params,
void (^completion_handler)(UIContextMenuConfiguration*)) void (^completion_handler)(UIContextMenuConfiguration*))
API_AVAILABLE(ios(13.0)) { API_AVAILABLE(ios(13.0)) {
if ([delegate_ if ([delegate_ respondsToSelector:@selector
respondsToSelector:@selector (webState:
(webState: contextMenuConfigurationForParams:completionHandler:)]) {
contextMenuConfigurationForLinkWithURL:completionHandler:)]) {
[delegate_ webState:source [delegate_ webState:source
contextMenuConfigurationForLinkWithURL:link_url contextMenuConfigurationForParams:params
completionHandler:completion_handler]; completionHandler:completion_handler];
} else {
completion_handler(nil);
} }
} }
......
...@@ -523,16 +523,19 @@ BOOL gChromeLongPressAndForceTouchHandlingEnabled = YES; ...@@ -523,16 +523,19 @@ BOOL gChromeLongPressAndForceTouchHandlingEnabled = YES;
} }
- (void)webState:(web::WebState*)webState - (void)webState:(web::WebState*)webState
contextMenuConfigurationForLinkWithURL:(const GURL&)linkURL contextMenuConfigurationForParams:(const web::ContextMenuParams&)params
completionHandler: completionHandler:
(void (^)(UIContextMenuConfiguration*)) (void (^)(UIContextMenuConfiguration*))completionHandler
completionHandler API_AVAILABLE(ios(13.0)) { API_AVAILABLE(ios(13.0)) {
SEL selector = @selector(webView: SEL selector = @selector(webView:
contextMenuConfigurationForLinkWithURL:completionHandler:); contextMenuConfigurationForLinkWithURL:completionHandler:);
if ([_UIDelegate respondsToSelector:selector]) { if ([_UIDelegate respondsToSelector:selector]) {
[_UIDelegate webView:self [_UIDelegate webView:self
contextMenuConfigurationForLinkWithURL:net::NSURLWithGURL(linkURL) contextMenuConfigurationForLinkWithURL:net::NSURLWithGURL(
params.link_url)
completionHandler:completionHandler]; completionHandler:completionHandler];
} else {
completionHandler(nil);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment