Commit b8c856b0 authored by Dominique Fauteux-Chapleau's avatar Dominique Fauteux-Chapleau Committed by Commit Bot

Hook Deep Scanning drag+drop on MacOS

This change was started in crrev.com/c/1814619 but is a no-op on Mac
without the changes in this CL. This only changes the drag+drop
behavior of users with the appropriate policies enabled and doesn't
affect other users.

Bug: 1046921
Change-Id: I3603ae28a730472e6f88f0281c72720c4a71be03
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2037450Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Dominique Fauteux-Chapleau <domfc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738971}
parent b148fbdd
...@@ -513,7 +513,8 @@ bool WebContentsViewMac::DraggingUpdated(DraggingInfoPtr dragging_info, ...@@ -513,7 +513,8 @@ bool WebContentsViewMac::DraggingUpdated(DraggingInfoPtr dragging_info,
bool WebContentsViewMac::PerformDragOperation(DraggingInfoPtr dragging_info, bool WebContentsViewMac::PerformDragOperation(DraggingInfoPtr dragging_info,
bool* out_result) { bool* out_result) {
*out_result = [drag_dest_ performDragOperation:dragging_info.get()]; *out_result = [drag_dest_ performDragOperation:dragging_info.get()
withWebContentsViewDelegate:delegate_.get()];
return true; return true;
} }
......
...@@ -32,6 +32,26 @@ class DraggingInfo; ...@@ -32,6 +32,26 @@ class DraggingInfo;
} // namespace remote_cocoa } // namespace remote_cocoa
namespace content { namespace content {
class WebContentsViewDelegate;
// A structure used to keep drop context for asynchronously finishing a drop
// operation. This is required because some drop event data can change before
// completeDropAsync is called.
struct DropContext {
DropContext(const content::DropData drop_data,
const gfx::PointF client_pt,
const gfx::PointF screen_pt,
int modifier_flags,
base::WeakPtr<content::RenderWidgetHostImpl> target_rwh);
DropContext(const DropContext& other);
~DropContext();
const content::DropData drop_data;
const gfx::PointF client_pt;
const gfx::PointF screen_pt;
const int modifier_flags;
base::WeakPtr<content::RenderWidgetHostImpl> target_rwh;
};
// Given |data|, which should not be nil, fill it in using the contents of the // Given |data|, which should not be nil, fill it in using the contents of the
// given pasteboard. The types handled by this method should be kept in sync // given pasteboard. The types handled by this method should be kept in sync
...@@ -106,7 +126,11 @@ CONTENT_EXPORT ...@@ -106,7 +126,11 @@ CONTENT_EXPORT
- (void)draggingExited; - (void)draggingExited;
- (NSDragOperation)draggingUpdated: - (NSDragOperation)draggingUpdated:
(const remote_cocoa::mojom::DraggingInfo*)info; (const remote_cocoa::mojom::DraggingInfo*)info;
- (BOOL)performDragOperation:(const remote_cocoa::mojom::DraggingInfo*)info; - (BOOL)performDragOperation:(const remote_cocoa::mojom::DraggingInfo*)info
withWebContentsViewDelegate:
(content::WebContentsViewDelegate*)webContentsViewDelegate;
- (void)completeDropAsync:(BOOL)success
withContext:(const content::DropContext)context;
// Helper to call WebWidgetHostInputEventRouter::GetRenderWidgetHostAtPoint(). // Helper to call WebWidgetHostInputEventRouter::GetRenderWidgetHostAtPoint().
- (content::RenderWidgetHostImpl*) - (content::RenderWidgetHostImpl*)
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "content/browser/web_contents/web_contents_impl.h" #include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/web_contents_ns_view_bridge.mojom.h" #include "content/common/web_contents_ns_view_bridge.mojom.h"
#include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_view_delegate.h"
#include "content/public/browser/web_drag_dest_delegate.h" #include "content/public/browser/web_drag_dest_delegate.h"
#include "content/public/common/child_process_host.h" #include "content/public/common/child_process_host.h"
#include "content/public/common/drop_data.h" #include "content/public/common/drop_data.h"
...@@ -34,6 +35,26 @@ using content::Referrer; ...@@ -34,6 +35,26 @@ using content::Referrer;
using content::WebContentsImpl; using content::WebContentsImpl;
using remote_cocoa::mojom::DraggingInfo; using remote_cocoa::mojom::DraggingInfo;
namespace content {
DropContext::DropContext(
const content::DropData drop_data,
const gfx::PointF client_pt,
const gfx::PointF screen_pt,
int modifier_flags,
base::WeakPtr<content::RenderWidgetHostImpl> target_rwh)
: drop_data(drop_data),
client_pt(client_pt),
screen_pt(screen_pt),
modifier_flags(modifier_flags),
target_rwh(target_rwh) {}
DropContext::DropContext(const DropContext& other) = default;
DropContext::~DropContext() = default;
} // namespace content
namespace { namespace {
int GetModifierFlags() { int GetModifierFlags() {
...@@ -68,6 +89,22 @@ content::GlobalRoutingID GetRenderViewHostID(content::RenderViewHost* rvh) { ...@@ -68,6 +89,22 @@ content::GlobalRoutingID GetRenderViewHostID(content::RenderViewHost* rvh) {
rvh->GetRoutingID()); rvh->GetRoutingID());
} }
void DropCompletionCallback(
WebDragDest* drag_dest,
const content::DropContext context,
content::WebContentsViewDelegate::DropCompletionResult result) {
// This is an async callback. Make sure RWH is still valid.
if (!context.target_rwh ||
![drag_dest isValidDragTarget:context.target_rwh.get()]) {
return;
}
bool success =
result ==
content::WebContentsViewDelegate::DropCompletionResult::kContinue;
[drag_dest completeDropAsync:success withContext:context];
}
} // namespace } // namespace
@implementation WebDragDest @implementation WebDragDest
...@@ -280,7 +317,9 @@ content::GlobalRoutingID GetRenderViewHostID(content::RenderViewHost* rvh) { ...@@ -280,7 +317,9 @@ content::GlobalRoutingID GetRenderViewHostID(content::RenderViewHost* rvh) {
return _currentOperation; return _currentOperation;
} }
- (BOOL)performDragOperation:(const DraggingInfo*)info { - (BOOL)performDragOperation:(const DraggingInfo*)info
withWebContentsViewDelegate:
(content::WebContentsViewDelegate*)webContentsViewDelegate {
gfx::PointF transformedPt; gfx::PointF transformedPt;
content::RenderWidgetHostImpl* targetRWH = content::RenderWidgetHostImpl* targetRWH =
[self GetRenderWidgetHostAtPoint:info->location_in_view [self GetRenderWidgetHostAtPoint:info->location_in_view
...@@ -308,21 +347,46 @@ content::GlobalRoutingID GetRenderViewHostID(content::RenderViewHost* rvh) { ...@@ -308,21 +347,46 @@ content::GlobalRoutingID GetRenderViewHostID(content::RenderViewHost* rvh) {
} }
} }
if (_delegate)
_delegate->OnDrop();
_currentRVH = NULL; _currentRVH = NULL;
_webContents->Focus(); _webContents->Focus();
targetRWH->DragTargetDrop(*_dropDataFiltered, transformedPt,
info->location_in_screen, GetModifierFlags());
if (webContentsViewDelegate) {
content::DropContext context(/*drop_data=*/*_dropDataFiltered,
/*client_pt=*/transformedPt,
/*screen_pt=*/info->location_in_screen,
/*modifier_flags=*/GetModifierFlags(),
/*target_rwh=*/targetRWH->GetWeakPtr());
webContentsViewDelegate->OnPerformDrop(
context.drop_data,
base::BindOnce(&DropCompletionCallback, self, context));
} else {
if (_delegate)
_delegate->OnDrop();
targetRWH->DragTargetDrop(*_dropDataFiltered, transformedPt,
info->location_in_screen, GetModifierFlags());
}
_dropDataUnfiltered.reset(); _dropDataUnfiltered.reset();
_dropDataFiltered.reset(); _dropDataFiltered.reset();
return YES; return YES;
} }
- (void)completeDropAsync:(BOOL)success
withContext:(const content::DropContext)context {
if (success) {
if (_delegate)
_delegate->OnDrop();
context.target_rwh->DragTargetDrop(context.drop_data, context.client_pt,
context.screen_pt,
context.modifier_flags);
} else {
if (_delegate)
_delegate->OnDragLeave();
context.target_rwh->DragTargetDragLeave(gfx::PointF(), gfx::PointF());
}
}
- (content::RenderWidgetHostImpl*) - (content::RenderWidgetHostImpl*)
GetRenderWidgetHostAtPoint:(const gfx::PointF&)viewPoint GetRenderWidgetHostAtPoint:(const gfx::PointF&)viewPoint
transformedPt:(gfx::PointF*)transformedPt { transformedPt:(gfx::PointF*)transformedPt {
......
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