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

[iOS][ContextMenu] Add support for preview provider

This CL adds support for passing PreviewProvider to the WebState
delegate.

Bug: 1140387
Change-Id: I4c4a2665e26875be9d262d884aa96d3cef205af2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2587027
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842156}
parent ff786689
......@@ -3639,6 +3639,8 @@ NSString* const kBrowserViewControllerSnackbarCategory =
- (void)webState:(web::WebState*)webState
contextMenuConfigurationForParams:(const web::ContextMenuParams&)params
previewProvider:
(UIContextMenuContentPreviewProvider)previewProvider
completionHandler:
(void (^)(UIContextMenuConfiguration*))completionHandler
API_AVAILABLE(ios(13.0)) {
......
......@@ -96,10 +96,12 @@ class WebStateDelegate {
// Called when iOS13+ context menu is triggered and now it is required to
// provide a UIContextMenuConfiguration to |completion_handler| to generate
// the context menu.
// the context menu. |previewProvider| is used to show a custom ViewController
// to preview the page.
virtual void ContextMenuConfiguration(
WebState* source,
const ContextMenuParams& params,
UIContextMenuContentPreviewProvider preview_provider,
void (^completion_handler)(UIContextMenuConfiguration*))
API_AVAILABLE(ios(13.0));
// Called when iOS13+ context menu is ready to be showed.
......
......@@ -84,9 +84,12 @@
// Called when iOS13+ context menu is triggered and now it is required to
// provide a UIContextMenuConfiguration to |completion_handler| to generate the
// context menu.
// context menu. |previewProvider| is used to show a custom ViewController to
// preview the page.
- (void)webState:(web::WebState*)webState
contextMenuConfigurationForParams:(const web::ContextMenuParams&)params
previewProvider:
(UIContextMenuContentPreviewProvider)previewProvider
completionHandler:
(void (^)(UIContextMenuConfiguration*))completionHandler
API_AVAILABLE(ios(13.0));
......@@ -147,6 +150,7 @@ class WebStateDelegateBridge : public web::WebStateDelegate {
void ContextMenuConfiguration(
WebState* source,
const ContextMenuParams& params,
UIContextMenuContentPreviewProvider preview_provider,
void (^completion_handler)(UIContextMenuConfiguration*))
API_AVAILABLE(ios(13.0)) override;
void ContextMenuDidEnd(WebState* source, const GURL& link_url)
......
......@@ -146,13 +146,16 @@ const CGFloat kJavaScriptTimeout = 1;
// delegate's methods.
[interaction.view addSubview:self.highlightView];
[interaction.view addSubview:self.dismissView];
self.highlightView.center = location;
self.dismissView.center = location;
self.params.location = [self.webView convertPoint:location
fromView:interaction.view];
__block UIContextMenuConfiguration* configuration;
self.webState->GetDelegate()->ContextMenuConfiguration(
self.webState, self.params, ^(UIContextMenuConfiguration* conf) {
self.webState, self.params, /*preview_provider=*/nil,
^(UIContextMenuConfiguration* conf) {
configuration = conf;
});
......
......@@ -210,8 +210,8 @@
web::ContextMenuParams params;
params.link_url = net::GURLWithNSURL(elementInfo.linkURL);
delegate->ContextMenuConfiguration(self.webStateImpl, params,
completionHandler);
delegate->ContextMenuConfiguration(
self.webStateImpl, params, /*preview_provider=*/nil, completionHandler);
}
#endif // End of >iOS13 deprecated block.
......
......@@ -31,6 +31,8 @@
- (void)webState:(web::WebState*)webState
contextMenuConfigurationForParams:(const web::ContextMenuParams&)params
previewProvider:
(UIContextMenuContentPreviewProvider)previewProvider
completionHandler:
(void (^)(UIContextMenuConfiguration*))completionHandler
API_AVAILABLE(ios(13.0)) {
......
......@@ -87,6 +87,7 @@ void WebStateDelegate::Detach(WebState* source) {
void WebStateDelegate::ContextMenuConfiguration(
WebState* source,
const ContextMenuParams& params,
UIContextMenuContentPreviewProvider preview_provider,
void (^completion_handler)(UIContextMenuConfiguration*))
API_AVAILABLE(ios(13.0)) {
completion_handler(nil);
......
......@@ -141,13 +141,16 @@ UIView* WebStateDelegateBridge::GetWebViewContainer(WebState* source) {
void WebStateDelegateBridge::ContextMenuConfiguration(
WebState* source,
const ContextMenuParams& params,
UIContextMenuContentPreviewProvider preview_provider,
void (^completion_handler)(UIContextMenuConfiguration*))
API_AVAILABLE(ios(13.0)) {
if ([delegate_ respondsToSelector:@selector
(webState:
contextMenuConfigurationForParams:completionHandler:)]) {
contextMenuConfigurationForParams:previewProvider
:completionHandler:)]) {
[delegate_ webState:source
contextMenuConfigurationForParams:params
previewProvider:preview_provider
completionHandler:completion_handler];
} else {
completion_handler(nil);
......
......@@ -524,6 +524,8 @@ BOOL gChromeLongPressAndForceTouchHandlingEnabled = YES;
- (void)webState:(web::WebState*)webState
contextMenuConfigurationForParams:(const web::ContextMenuParams&)params
previewProvider:
(UIContextMenuContentPreviewProvider)previewProvider
completionHandler:
(void (^)(UIContextMenuConfiguration*))completionHandler
API_AVAILABLE(ios(13.0)) {
......
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