Commit edef980e authored by Aya ElAttar's avatar Aya ElAttar Committed by Chromium LUCI CQ

DLP: Set source of Drag-n-Drop data

- Updated WebContentsView and Exo to
set the sources of the dragged data with
the appropriate DataTransferEndpoint
object.

Bug: 1142406
Change-Id: I15924c0dd96b1bd39436036b3d4d0a78fd4f023f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2563466
Commit-Queue: Aya Elsayed <ayaelattar@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#834288}
parent e4014ae4
...@@ -34,7 +34,9 @@ ...@@ -34,7 +34,9 @@
#include "storage/browser/file_system/file_system_context.h" #include "storage/browser/file_system/file_system_context.h"
#include "storage/browser/file_system/file_system_url.h" #include "storage/browser/file_system/file_system_url.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/base/data_transfer_policy/data_transfer_endpoint.h"
#include "ui/base/dragdrop/file_info/file_info.h" #include "ui/base/dragdrop/file_info/file_info.h"
#include "ui/base/dragdrop/os_exchange_data.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace chromeos { namespace chromeos {
...@@ -245,6 +247,18 @@ ChromeDataExchangeDelegate::ChromeDataExchangeDelegate() = default; ...@@ -245,6 +247,18 @@ ChromeDataExchangeDelegate::ChromeDataExchangeDelegate() = default;
ChromeDataExchangeDelegate::~ChromeDataExchangeDelegate() = default; ChromeDataExchangeDelegate::~ChromeDataExchangeDelegate() = default;
void ChromeDataExchangeDelegate::SetExchangeDataSource(
aura::Window* target,
ui::OSExchangeData* os_exchange_data) {
DCHECK(os_exchange_data);
auto endpoint_type = ui::EndpointType::kGuestOs;
if (ash::window_util::IsArcWindow(target->GetToplevelWindow()))
endpoint_type = ui::EndpointType::kArc;
os_exchange_data->SetSource(
std::make_unique<ui::DataTransferEndpoint>(endpoint_type));
}
std::vector<ui::FileInfo> ChromeDataExchangeDelegate::GetFilenames( std::vector<ui::FileInfo> ChromeDataExchangeDelegate::GetFilenames(
aura::Window* source, aura::Window* source,
const std::vector<uint8_t>& data) const { const std::vector<uint8_t>& data) const {
......
...@@ -18,6 +18,8 @@ class ChromeDataExchangeDelegate : public exo::DataExchangeDelegate { ...@@ -18,6 +18,8 @@ class ChromeDataExchangeDelegate : public exo::DataExchangeDelegate {
~ChromeDataExchangeDelegate() override; ~ChromeDataExchangeDelegate() override;
// DataExchangeDelegate: // DataExchangeDelegate:
void SetExchangeDataSource(aura::Window* target,
ui::OSExchangeData* os_exchange_data) override;
std::vector<ui::FileInfo> GetFilenames( std::vector<ui::FileInfo> GetFilenames(
aura::Window* source, aura::Window* source,
const std::vector<uint8_t>& data) const override; const std::vector<uint8_t>& data) const override;
......
...@@ -29,7 +29,9 @@ ...@@ -29,7 +29,9 @@
#include "ui/aura/test/test_window_delegate.h" #include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/test/test_windows.h" #include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/base/data_transfer_policy/data_transfer_endpoint.h"
#include "ui/base/dragdrop/file_info/file_info.h" #include "ui/base/dragdrop/file_info/file_info.h"
#include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "url/origin.h" #include "url/origin.h"
...@@ -355,4 +357,17 @@ TEST_F(ChromeDataExchangeDelegateTest, HasUrlsInPickle) { ...@@ -355,4 +357,17 @@ TEST_F(ChromeDataExchangeDelegateTest, HasUrlsInPickle) {
EXPECT_EQ(true, data_exchange_delegate.HasUrlsInPickle(valid)); EXPECT_EQ(true, data_exchange_delegate.HasUrlsInPickle(valid));
} }
TEST_F(ChromeDataExchangeDelegateTest, SetExchangeDataSource) {
ChromeDataExchangeDelegate data_exchange_delegate;
ui::OSExchangeData os_exchange_data;
data_exchange_delegate.SetExchangeDataSource(arc_window_, &os_exchange_data);
EXPECT_EQ(ui::EndpointType::kArc, os_exchange_data.GetSource()->type());
data_exchange_delegate.SetExchangeDataSource(crostini_window_,
&os_exchange_data);
EXPECT_EQ(ui::EndpointType::kGuestOs, os_exchange_data.GetSource()->type());
}
} // namespace chromeos } // namespace chromeos
...@@ -22,6 +22,7 @@ class RefCountedMemory; ...@@ -22,6 +22,7 @@ class RefCountedMemory;
namespace ui { namespace ui {
struct FileInfo; struct FileInfo;
class OSExchangeData;
} // namespace ui } // namespace ui
namespace exo { namespace exo {
...@@ -32,6 +33,10 @@ class DataExchangeDelegate { ...@@ -32,6 +33,10 @@ class DataExchangeDelegate {
public: public:
virtual ~DataExchangeDelegate() {} virtual ~DataExchangeDelegate() {}
// Sets the source of `os_exchange_data` according to the `target` window.
virtual void SetExchangeDataSource(aura::Window* target,
ui::OSExchangeData* os_exchange_data) = 0;
// Read filenames from |data| which was provided by source window |source|. // Read filenames from |data| which was provided by source window |source|.
// Translates paths from source to host format. // Translates paths from source to host format.
virtual std::vector<ui::FileInfo> GetFilenames( virtual std::vector<ui::FileInfo> GetFilenames(
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "components/viz/common/frame_sinks/copy_output_request.h" #include "components/viz/common/frame_sinks/copy_output_request.h"
#include "components/viz/common/frame_sinks/copy_output_result.h" #include "components/viz/common/frame_sinks/copy_output_result.h"
#include "ui/aura/client/drag_drop_client.h" #include "ui/aura/client/drag_drop_client.h"
#include "ui/base/data_transfer_policy/data_transfer_endpoint.h"
#include "ui/base/dragdrop/drag_drop_types.h" #include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/dragdrop/file_info/file_info.h" #include "ui/base/dragdrop/file_info/file_info.h"
#include "ui/base/dragdrop/os_exchange_data.h" #include "ui/base/dragdrop/os_exchange_data.h"
...@@ -183,6 +184,9 @@ DragDropOperation::DragDropOperation( ...@@ -183,6 +184,9 @@ DragDropOperation::DragDropOperation(
drag_drop_controller_->AddObserver(this); drag_drop_controller_->AddObserver(this);
data_exchange_delegate->SetExchangeDataSource(origin_->get()->window(),
os_exchange_data_.get());
#if BUILDFLAG(IS_CHROMEOS_ASH) #if BUILDFLAG(IS_CHROMEOS_ASH)
extended_drag_source_ = ExtendedDragSource::Get(); extended_drag_source_ = ExtendedDragSource::Get();
if (extended_drag_source_) { if (extended_drag_source_) {
......
...@@ -23,6 +23,10 @@ TestDataExchangeDelegate::TestDataExchangeDelegate() = default; ...@@ -23,6 +23,10 @@ TestDataExchangeDelegate::TestDataExchangeDelegate() = default;
TestDataExchangeDelegate::~TestDataExchangeDelegate() = default; TestDataExchangeDelegate::~TestDataExchangeDelegate() = default;
void TestDataExchangeDelegate::SetExchangeDataSource(
aura::Window* target,
ui::OSExchangeData* os_exchange_data) {}
std::vector<ui::FileInfo> TestDataExchangeDelegate::GetFilenames( std::vector<ui::FileInfo> TestDataExchangeDelegate::GetFilenames(
aura::Window* source, aura::Window* source,
const std::vector<uint8_t>& data) const { const std::vector<uint8_t>& data) const {
......
...@@ -19,6 +19,8 @@ class TestDataExchangeDelegate : public DataExchangeDelegate { ...@@ -19,6 +19,8 @@ class TestDataExchangeDelegate : public DataExchangeDelegate {
~TestDataExchangeDelegate() override; ~TestDataExchangeDelegate() override;
// DataExchangeDelegate: // DataExchangeDelegate:
void SetExchangeDataSource(aura::Window* target,
ui::OSExchangeData* os_exchange_data) override;
std::vector<ui::FileInfo> GetFilenames( std::vector<ui::FileInfo> GetFilenames(
aura::Window* source, aura::Window* source,
const std::vector<uint8_t>& data) const override; const std::vector<uint8_t>& data) const override;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <memory>
#include <string> #include <string>
#include <utility> #include <utility>
...@@ -1037,6 +1038,8 @@ void WebContentsViewAura::StartDragging( ...@@ -1037,6 +1038,8 @@ void WebContentsViewAura::StartDragging(
auto data(std::make_unique<ui::OSExchangeData>( auto data(std::make_unique<ui::OSExchangeData>(
std::move(provider))); // takes ownership of |provider|. std::move(provider))); // takes ownership of |provider|.
data->SetSource(std::make_unique<ui::DataTransferEndpoint>(
web_contents_->GetFocusedFrame()->GetLastCommittedOrigin()));
if (!image.isNull()) if (!image.isNull())
data->provider().SetDragImage(image, image_offset); data->provider().SetDragImage(image, image_offset);
......
...@@ -103,6 +103,7 @@ class CONTENT_EXPORT WebContentsViewAura ...@@ -103,6 +103,7 @@ class CONTENT_EXPORT WebContentsViewAura
FRIEND_TEST_ALL_PREFIXES(WebContentsViewAuraTest, DragDropOnOopif); FRIEND_TEST_ALL_PREFIXES(WebContentsViewAuraTest, DragDropOnOopif);
FRIEND_TEST_ALL_PREFIXES(WebContentsViewAuraTest, OnPerformDrop_DeepScanOK); FRIEND_TEST_ALL_PREFIXES(WebContentsViewAuraTest, OnPerformDrop_DeepScanOK);
FRIEND_TEST_ALL_PREFIXES(WebContentsViewAuraTest, OnPerformDrop_DeepScanBad); FRIEND_TEST_ALL_PREFIXES(WebContentsViewAuraTest, OnPerformDrop_DeepScanBad);
FRIEND_TEST_ALL_PREFIXES(WebContentsViewAuraTest, StartDragging);
class WindowObserver; class WindowObserver;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_command_line.h" #include "base/test/scoped_command_line.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "build/build_config.h" #include "build/build_config.h"
...@@ -22,9 +23,11 @@ ...@@ -22,9 +23,11 @@
#include "content/public/test/test_renderer_host.h" #include "content/public/test/test_renderer_host.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/drag_drop_client.h"
#include "ui/aura/test/test_windows.h" #include "ui/aura/test/test_windows.h"
#include "ui/aura/test/window_test_api.h" #include "ui/aura/test/window_test_api.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/base/data_transfer_policy/data_transfer_endpoint.h"
#include "ui/base/dragdrop/drag_drop_types.h" #include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/dragdrop/drop_target_event.h" #include "ui/base/dragdrop/drop_target_event.h"
#include "ui/base/dragdrop/os_exchange_data.h" #include "ui/base/dragdrop/os_exchange_data.h"
...@@ -67,6 +70,32 @@ class RunCallbackOnActivation : public WebContentsDelegate { ...@@ -67,6 +70,32 @@ class RunCallbackOnActivation : public WebContentsDelegate {
DISALLOW_COPY_AND_ASSIGN(RunCallbackOnActivation); DISALLOW_COPY_AND_ASSIGN(RunCallbackOnActivation);
}; };
class TestDragDropClient : public aura::client::DragDropClient {
public:
// aura::client::DragDropClient:
int StartDragAndDrop(std::unique_ptr<ui::OSExchangeData> data,
aura::Window* root_window,
aura::Window* source_window,
const gfx::Point& screen_location,
int operation,
ui::mojom::DragEventSource source) override {
drag_in_progress_ = true;
drag_drop_data_ = std::move(data);
return 1;
}
void DragCancel() override { drag_in_progress_ = false; }
bool IsDragDropInProgress() override { return drag_in_progress_; }
void AddObserver(aura::client::DragDropClientObserver* observer) override {}
void RemoveObserver(aura::client::DragDropClientObserver* observer) override {
}
ui::OSExchangeData* GetDragDropData() { return drag_drop_data_.get(); }
private:
bool drag_in_progress_ = false;
std::unique_ptr<ui::OSExchangeData> drag_drop_data_ = nullptr;
};
} // namespace } // namespace
class WebContentsViewAuraTest : public RenderViewHostTestHarness { class WebContentsViewAuraTest : public RenderViewHostTestHarness {
...@@ -562,4 +591,37 @@ TEST_F(WebContentsViewAuraTest, DragDropUrlData) { ...@@ -562,4 +591,37 @@ TEST_F(WebContentsViewAuraTest, DragDropUrlData) {
} }
#endif #endif
} // namespace content #if BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(WebContentsViewAuraTest, StartDragging) {
const char kGmailUrl[] = "http://mail.google.com/";
NavigateAndCommit(GURL(kGmailUrl));
FocusWebContentsOnMainFrame();
TestDragDropClient drag_drop_client;
aura::client::SetDragDropClient(root_window(), &drag_drop_client);
WebContentsViewAura* view = GetView();
// This condition is needed to avoid calling WebContentsViewAura::EndDrag
// which will result NOTREACHED being called in
// `RenderWidgetHostViewBase::TransformPointToCoordSpaceForView`.
view->drag_in_progress_ = true;
DropData drop_data;
drop_data.text.emplace(base::UTF8ToUTF16("Hello World!"));
view->StartDragging(drop_data, blink::DragOperationsMask::kDragOperationNone,
gfx::ImageSkia(), gfx::Vector2d(),
blink::mojom::DragEventSourceInfo(),
RenderWidgetHostImpl::From(rvh()->GetWidget()));
ui::OSExchangeData* exchange_data = drag_drop_client.GetDragDropData();
EXPECT_TRUE(exchange_data);
EXPECT_TRUE(exchange_data->GetSource());
EXPECT_TRUE(exchange_data->GetSource()->IsUrlType());
EXPECT_TRUE(exchange_data->GetSource()->origin()->IsSameOriginWith(
url::Origin::Create(GURL(kGmailUrl))));
}
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
} // namespace content
\ No newline at end of file
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