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 = ...@@ -3639,6 +3639,8 @@ NSString* const kBrowserViewControllerSnackbarCategory =
- (void)webState:(web::WebState*)webState - (void)webState:(web::WebState*)webState
contextMenuConfigurationForParams:(const web::ContextMenuParams&)params contextMenuConfigurationForParams:(const web::ContextMenuParams&)params
previewProvider:
(UIContextMenuContentPreviewProvider)previewProvider
completionHandler: completionHandler:
(void (^)(UIContextMenuConfiguration*))completionHandler (void (^)(UIContextMenuConfiguration*))completionHandler
API_AVAILABLE(ios(13.0)) { API_AVAILABLE(ios(13.0)) {
......
...@@ -96,10 +96,12 @@ class WebStateDelegate { ...@@ -96,10 +96,12 @@ class WebStateDelegate {
// Called when iOS13+ context menu is triggered and now it is required to // Called when iOS13+ context menu is triggered and now it is required to
// provide a UIContextMenuConfiguration to |completion_handler| to generate // 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( virtual void ContextMenuConfiguration(
WebState* source, WebState* source,
const ContextMenuParams& params, const ContextMenuParams& params,
UIContextMenuContentPreviewProvider preview_provider,
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.
......
...@@ -84,9 +84,12 @@ ...@@ -84,9 +84,12 @@
// Called when iOS13+ context menu is triggered and now it is required to // Called when iOS13+ context menu is triggered and now it is required to
// provide a UIContextMenuConfiguration to |completion_handler| to generate the // 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 - (void)webState:(web::WebState*)webState
contextMenuConfigurationForParams:(const web::ContextMenuParams&)params contextMenuConfigurationForParams:(const web::ContextMenuParams&)params
previewProvider:
(UIContextMenuContentPreviewProvider)previewProvider
completionHandler: completionHandler:
(void (^)(UIContextMenuConfiguration*))completionHandler (void (^)(UIContextMenuConfiguration*))completionHandler
API_AVAILABLE(ios(13.0)); API_AVAILABLE(ios(13.0));
...@@ -147,6 +150,7 @@ class WebStateDelegateBridge : public web::WebStateDelegate { ...@@ -147,6 +150,7 @@ class WebStateDelegateBridge : public web::WebStateDelegate {
void ContextMenuConfiguration( void ContextMenuConfiguration(
WebState* source, WebState* source,
const ContextMenuParams& params, const ContextMenuParams& params,
UIContextMenuContentPreviewProvider preview_provider,
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)
......
...@@ -146,13 +146,16 @@ const CGFloat kJavaScriptTimeout = 1; ...@@ -146,13 +146,16 @@ const CGFloat kJavaScriptTimeout = 1;
// delegate's methods. // delegate's methods.
[interaction.view addSubview:self.highlightView]; [interaction.view addSubview:self.highlightView];
[interaction.view addSubview:self.dismissView]; [interaction.view addSubview:self.dismissView];
self.highlightView.center = location;
self.dismissView.center = location;
self.params.location = [self.webView convertPoint:location self.params.location = [self.webView convertPoint:location
fromView:interaction.view]; fromView:interaction.view];
__block UIContextMenuConfiguration* configuration; __block UIContextMenuConfiguration* configuration;
self.webState->GetDelegate()->ContextMenuConfiguration( self.webState->GetDelegate()->ContextMenuConfiguration(
self.webState, self.params, ^(UIContextMenuConfiguration* conf) { self.webState, self.params, /*preview_provider=*/nil,
^(UIContextMenuConfiguration* conf) {
configuration = conf; configuration = conf;
}); });
......
...@@ -210,8 +210,8 @@ ...@@ -210,8 +210,8 @@
web::ContextMenuParams params; web::ContextMenuParams params;
params.link_url = net::GURLWithNSURL(elementInfo.linkURL); params.link_url = net::GURLWithNSURL(elementInfo.linkURL);
delegate->ContextMenuConfiguration(self.webStateImpl, params, delegate->ContextMenuConfiguration(
completionHandler); self.webStateImpl, params, /*preview_provider=*/nil, completionHandler);
} }
#endif // End of >iOS13 deprecated block. #endif // End of >iOS13 deprecated block.
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
- (void)webState:(web::WebState*)webState - (void)webState:(web::WebState*)webState
contextMenuConfigurationForParams:(const web::ContextMenuParams&)params contextMenuConfigurationForParams:(const web::ContextMenuParams&)params
previewProvider:
(UIContextMenuContentPreviewProvider)previewProvider
completionHandler: completionHandler:
(void (^)(UIContextMenuConfiguration*))completionHandler (void (^)(UIContextMenuConfiguration*))completionHandler
API_AVAILABLE(ios(13.0)) { API_AVAILABLE(ios(13.0)) {
......
...@@ -87,6 +87,7 @@ void WebStateDelegate::Detach(WebState* source) { ...@@ -87,6 +87,7 @@ void WebStateDelegate::Detach(WebState* source) {
void WebStateDelegate::ContextMenuConfiguration( void WebStateDelegate::ContextMenuConfiguration(
WebState* source, WebState* source,
const ContextMenuParams& params, const ContextMenuParams& params,
UIContextMenuContentPreviewProvider preview_provider,
void (^completion_handler)(UIContextMenuConfiguration*)) void (^completion_handler)(UIContextMenuConfiguration*))
API_AVAILABLE(ios(13.0)) { API_AVAILABLE(ios(13.0)) {
completion_handler(nil); completion_handler(nil);
......
...@@ -141,13 +141,16 @@ UIView* WebStateDelegateBridge::GetWebViewContainer(WebState* source) { ...@@ -141,13 +141,16 @@ UIView* WebStateDelegateBridge::GetWebViewContainer(WebState* source) {
void WebStateDelegateBridge::ContextMenuConfiguration( void WebStateDelegateBridge::ContextMenuConfiguration(
WebState* source, WebState* source,
const ContextMenuParams& params, const ContextMenuParams& params,
UIContextMenuContentPreviewProvider preview_provider,
void (^completion_handler)(UIContextMenuConfiguration*)) void (^completion_handler)(UIContextMenuConfiguration*))
API_AVAILABLE(ios(13.0)) { API_AVAILABLE(ios(13.0)) {
if ([delegate_ respondsToSelector:@selector if ([delegate_ respondsToSelector:@selector
(webState: (webState:
contextMenuConfigurationForParams:completionHandler:)]) { contextMenuConfigurationForParams:previewProvider
:completionHandler:)]) {
[delegate_ webState:source [delegate_ webState:source
contextMenuConfigurationForParams:params contextMenuConfigurationForParams:params
previewProvider:preview_provider
completionHandler:completion_handler]; completionHandler:completion_handler];
} else { } else {
completion_handler(nil); completion_handler(nil);
......
...@@ -524,6 +524,8 @@ BOOL gChromeLongPressAndForceTouchHandlingEnabled = YES; ...@@ -524,6 +524,8 @@ BOOL gChromeLongPressAndForceTouchHandlingEnabled = YES;
- (void)webState:(web::WebState*)webState - (void)webState:(web::WebState*)webState
contextMenuConfigurationForParams:(const web::ContextMenuParams&)params contextMenuConfigurationForParams:(const web::ContextMenuParams&)params
previewProvider:
(UIContextMenuContentPreviewProvider)previewProvider
completionHandler: completionHandler:
(void (^)(UIContextMenuConfiguration*))completionHandler (void (^)(UIContextMenuConfiguration*))completionHandler
API_AVAILABLE(ios(13.0)) { 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