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 =
}
- (void)webState:(web::WebState*)webState
contextMenuConfigurationForLinkWithURL:(const GURL&)linkURL
completionHandler:
(void (^)(UIContextMenuConfiguration*))
completionHandler API_AVAILABLE(ios(13.0)) {
contextMenuConfigurationForParams:(const web::ContextMenuParams&)params
completionHandler:
(void (^)(UIContextMenuConfiguration*))completionHandler
API_AVAILABLE(ios(13.0)) {
// Prevent context menu from displaying for a tab which is no longer the
// current one.
if (webState != self.currentWebState) {
......@@ -3606,7 +3606,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
}
// No custom context menu if no valid url is available.
if (!linkURL.is_valid())
if (!params.link_url.is_valid())
return;
DCHECK(self.browserState);
......
......@@ -99,7 +99,7 @@ class WebStateDelegate {
// the context menu.
virtual void ContextMenuConfiguration(
WebState* source,
const GURL& link_url,
const ContextMenuParams& params,
void (^completion_handler)(UIContextMenuConfiguration*))
API_AVAILABLE(ios(13.0));
// Called when iOS13+ context menu is ready to be showed.
......
......@@ -86,10 +86,10 @@
// provide a UIContextMenuConfiguration to |completion_handler| to generate the
// context menu.
- (void)webState:(web::WebState*)webState
contextMenuConfigurationForLinkWithURL:(const GURL&)linkURL
completionHandler:
(void (^)(UIContextMenuConfiguration*))
completionHandler API_AVAILABLE(ios(13.0));
contextMenuConfigurationForParams:(const web::ContextMenuParams&)params
completionHandler:
(void (^)(UIContextMenuConfiguration*))completionHandler
API_AVAILABLE(ios(13.0));
// Called when iOS13+ context menu is ready to be showed.
- (void)webState:(web::WebState*)webState
......@@ -146,7 +146,7 @@ class WebStateDelegateBridge : public web::WebStateDelegate {
UIView* GetWebViewContainer(WebState* source) override;
void ContextMenuConfiguration(
WebState* source,
const GURL& link_url,
const ContextMenuParams& params,
void (^completion_handler)(UIContextMenuConfiguration*))
API_AVAILABLE(ios(13.0)) override;
void ContextMenuDidEnd(WebState* source, const GURL& link_url)
......
......@@ -8,6 +8,7 @@
#include "base/strings/sys_string_conversions.h"
#import "ios/web/navigation/wk_navigation_action_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/web_client.h"
#import "ios/web/web_state/ui/crw_legacy_context_menu_controller.h"
......@@ -199,11 +200,14 @@
completionHandler API_AVAILABLE(ios(13.0)) {
web::WebStateDelegate* delegate = self.webStateImpl->GetDelegate();
if (!delegate) {
completionHandler(nil);
return;
}
delegate->ContextMenuConfiguration(self.webStateImpl,
net::GURLWithNSURL(elementInfo.linkURL),
web::ContextMenuParams params;
params.link_url = net::GURLWithNSURL(elementInfo.linkURL);
delegate->ContextMenuConfiguration(self.webStateImpl, params,
completionHandler);
}
......
......@@ -6,6 +6,7 @@
#include "ios/web/public/test/fakes/test_browser_state.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 "net/base/mac/url_conversions.h"
#import "testing/gtest_mac.h"
......@@ -30,12 +31,12 @@
@implementation FakeCRWWebStateDelegate
- (void)webState:(web::WebState*)webState
contextMenuConfigurationForLinkWithURL:(const GURL&)linkURL
completionHandler:
(void (^)(UIContextMenuConfiguration*))
completionHandler API_AVAILABLE(ios(13.0)) {
contextMenuConfigurationForParams:(const web::ContextMenuParams&)params
completionHandler:
(void (^)(UIContextMenuConfiguration*))completionHandler
API_AVAILABLE(ios(13.0)) {
self.webState = webState;
self.URL = net::NSURLWithGURL(linkURL);
self.URL = net::NSURLWithGURL(params.link_url);
self.contextMenuConfigurationNeeded = YES;
}
......
......@@ -86,9 +86,11 @@ void WebStateDelegate::Detach(WebState* source) {
void WebStateDelegate::ContextMenuConfiguration(
WebState* source,
const GURL& link_url,
const ContextMenuParams& params,
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)
API_AVAILABLE(ios(13.0)) {}
......
......@@ -140,16 +140,17 @@ UIView* WebStateDelegateBridge::GetWebViewContainer(WebState* source) {
void WebStateDelegateBridge::ContextMenuConfiguration(
WebState* source,
const GURL& link_url,
const ContextMenuParams& params,
void (^completion_handler)(UIContextMenuConfiguration*))
API_AVAILABLE(ios(13.0)) {
if ([delegate_
respondsToSelector:@selector
(webState:
contextMenuConfigurationForLinkWithURL:completionHandler:)]) {
if ([delegate_ respondsToSelector:@selector
(webState:
contextMenuConfigurationForParams:completionHandler:)]) {
[delegate_ webState:source
contextMenuConfigurationForLinkWithURL:link_url
completionHandler:completion_handler];
contextMenuConfigurationForParams:params
completionHandler:completion_handler];
} else {
completion_handler(nil);
}
}
......
......@@ -523,16 +523,19 @@ BOOL gChromeLongPressAndForceTouchHandlingEnabled = YES;
}
- (void)webState:(web::WebState*)webState
contextMenuConfigurationForLinkWithURL:(const GURL&)linkURL
completionHandler:
(void (^)(UIContextMenuConfiguration*))
completionHandler API_AVAILABLE(ios(13.0)) {
contextMenuConfigurationForParams:(const web::ContextMenuParams&)params
completionHandler:
(void (^)(UIContextMenuConfiguration*))completionHandler
API_AVAILABLE(ios(13.0)) {
SEL selector = @selector(webView:
contextMenuConfigurationForLinkWithURL:completionHandler:);
if ([_UIDelegate respondsToSelector:selector]) {
[_UIDelegate webView:self
contextMenuConfigurationForLinkWithURL:net::NSURLWithGURL(linkURL)
contextMenuConfigurationForLinkWithURL:net::NSURLWithGURL(
params.link_url)
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