Commit 2928283f authored by Aya ElAttar's avatar Aya ElAttar Committed by Commit Bot

DLP: Add source for drag-and-drop data

- Added source for drag-and-drop data the
same as clipboard data to be able to apply
the rules of data leak prevention policy.

Bug: 1139886
Change-Id: I321c9ab7527cb1b16561973b1e57420e5a4b9e36
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2489634Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarDarwin Huang <huangdarwin@chromium.org>
Commit-Queue: Aya Elsayed <ayaelattar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822163}
parent 464d5145
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/pickle.h" #include "base/pickle.h"
#include "ui/base/clipboard/clipboard_format_type.h" #include "ui/base/clipboard/clipboard_format_type.h"
#include "ui/base/data_transfer_policy/data_transfer_endpoint.h"
#include "ui/base/dragdrop/os_exchange_data_provider_factory.h" #include "ui/base/dragdrop/os_exchange_data_provider_factory.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -160,4 +161,13 @@ bool OSExchangeData::GetHtml(base::string16* html, GURL* base_url) const { ...@@ -160,4 +161,13 @@ bool OSExchangeData::GetHtml(base::string16* html, GURL* base_url) const {
} }
#endif #endif
void OSExchangeData::SetSource(
std::unique_ptr<DataTransferEndpoint> data_source) {
provider_->SetSource(std::move(data_source));
}
DataTransferEndpoint* OSExchangeData::GetSource() const {
return provider_->GetSource();
}
} // namespace ui } // namespace ui
...@@ -32,6 +32,7 @@ class Pickle; ...@@ -32,6 +32,7 @@ class Pickle;
namespace ui { namespace ui {
class ClipboardFormatType; class ClipboardFormatType;
class DataTransferEndpoint;
struct FileInfo; struct FileInfo;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
...@@ -186,6 +187,12 @@ class COMPONENT_EXPORT(UI_BASE) OSExchangeData { ...@@ -186,6 +187,12 @@ class COMPONENT_EXPORT(UI_BASE) OSExchangeData {
bool HasHtml() const; bool HasHtml() const;
#endif #endif
// Adds a DataTransferEndpoint to represent the source of the data.
// TODO(crbug.com/1142406): Update all drag-and-drop references to set the
// source of the data.
void SetSource(std::unique_ptr<DataTransferEndpoint> data_source);
DataTransferEndpoint* GetSource() const;
private: private:
// Provides the actual data. // Provides the actual data.
std::unique_ptr<OSExchangeDataProvider> provider_; std::unique_ptr<OSExchangeDataProvider> provider_;
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
namespace ui { namespace ui {
class DataTransferEndpoint;
// Controls whether or not filenames should be converted to file: URLs when // Controls whether or not filenames should be converted to file: URLs when
// getting a URL. // getting a URL.
enum class FilenameToURLPolicy { enum class FilenameToURLPolicy {
...@@ -105,6 +107,10 @@ class COMPONENT_EXPORT(UI_BASE_DATA_EXCHANGE) OSExchangeDataProvider { ...@@ -105,6 +107,10 @@ class COMPONENT_EXPORT(UI_BASE_DATA_EXCHANGE) OSExchangeDataProvider {
virtual gfx::ImageSkia GetDragImage() const = 0; virtual gfx::ImageSkia GetDragImage() const = 0;
virtual gfx::Vector2d GetDragImageOffset() const = 0; virtual gfx::Vector2d GetDragImageOffset() const = 0;
#endif #endif
// These functions are only implemented on Chrome OS currently.
virtual void SetSource(std::unique_ptr<DataTransferEndpoint> data_source) = 0;
virtual DataTransferEndpoint* GetSource() const = 0;
}; };
} // namespace ui } // namespace ui
......
...@@ -76,6 +76,9 @@ class COMPONENT_EXPORT(UI_BASE) OSExchangeDataProviderMac ...@@ -76,6 +76,9 @@ class COMPONENT_EXPORT(UI_BASE) OSExchangeDataProviderMac
// OSExchangeData. // OSExchangeData.
static NSArray* SupportedPasteboardTypes(); static NSArray* SupportedPasteboardTypes();
void SetSource(std::unique_ptr<DataTransferEndpoint> data_source) override;
DataTransferEndpoint* GetSource() const override;
protected: protected:
OSExchangeDataProviderMac(); OSExchangeDataProviderMac();
OSExchangeDataProviderMac(const OSExchangeDataProviderMac&); OSExchangeDataProviderMac(const OSExchangeDataProviderMac&);
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "ui/base/clipboard/clipboard_format_type.h" #include "ui/base/clipboard/clipboard_format_type.h"
#import "ui/base/clipboard/clipboard_util_mac.h" #import "ui/base/clipboard/clipboard_util_mac.h"
#include "ui/base/clipboard/custom_data_helper.h" #include "ui/base/clipboard/custom_data_helper.h"
#include "ui/base/data_transfer_policy/data_transfer_policy_controller.h"
#import "ui/base/dragdrop/cocoa_dnd_util.h" #import "ui/base/dragdrop/cocoa_dnd_util.h"
#include "ui/base/dragdrop/file_info/file_info.h" #include "ui/base/dragdrop/file_info/file_info.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -337,4 +338,11 @@ NSArray* OSExchangeDataProviderMac::SupportedPasteboardTypes() { ...@@ -337,4 +338,11 @@ NSArray* OSExchangeDataProviderMac::SupportedPasteboardTypes() {
]; ];
} }
void OSExchangeDataProviderMac::SetSource(
std::unique_ptr<DataTransferEndpoint> data_source) {}
DataTransferEndpoint* OSExchangeDataProviderMac::GetSource() const {
return nullptr;
}
} // namespace ui } // namespace ui
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "net/base/filename_util.h" #include "net/base/filename_util.h"
#include "ui/base/clipboard/clipboard_format_type.h" #include "ui/base/clipboard/clipboard_format_type.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/base/dragdrop/os_exchange_data.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -238,4 +239,13 @@ bool OSExchangeDataProviderNonBacked::GetPlainTextURL(GURL* url) const { ...@@ -238,4 +239,13 @@ bool OSExchangeDataProviderNonBacked::GetPlainTextURL(GURL* url) const {
return true; return true;
} }
void OSExchangeDataProviderNonBacked::SetSource(
std::unique_ptr<DataTransferEndpoint> data_source) {
source_ = std::move(data_source);
}
DataTransferEndpoint* OSExchangeDataProviderNonBacked::GetSource() const {
return source_.get();
}
} // namespace ui } // namespace ui
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_NON_BACKED_H_ #define UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_NON_BACKED_H_
#include <map> #include <map>
#include <memory>
#include "base/component_export.h" #include "base/component_export.h"
#include "base/pickle.h" #include "base/pickle.h"
...@@ -72,6 +73,9 @@ class COMPONENT_EXPORT(UI_BASE) OSExchangeDataProviderNonBacked ...@@ -72,6 +73,9 @@ class COMPONENT_EXPORT(UI_BASE) OSExchangeDataProviderNonBacked
gfx::ImageSkia GetDragImage() const override; gfx::ImageSkia GetDragImage() const override;
gfx::Vector2d GetDragImageOffset() const override; gfx::Vector2d GetDragImageOffset() const override;
void SetSource(std::unique_ptr<DataTransferEndpoint> data_source) override;
DataTransferEndpoint* GetSource() const override;
private: private:
// Returns true if |formats_| contains a file format and the file name can be // Returns true if |formats_| contains a file format and the file name can be
// parsed as a URL. // parsed as a URL.
...@@ -107,6 +111,9 @@ class COMPONENT_EXPORT(UI_BASE) OSExchangeDataProviderNonBacked ...@@ -107,6 +111,9 @@ class COMPONENT_EXPORT(UI_BASE) OSExchangeDataProviderNonBacked
GURL base_url_; GURL base_url_;
bool originated_from_renderer_ = false; bool originated_from_renderer_ = false;
// Data source.
std::unique_ptr<DataTransferEndpoint> source_;
}; };
} // namespace ui } // namespace ui
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/clipboard/clipboard_format_type.h" #include "ui/base/clipboard/clipboard_format_type.h"
#include "ui/base/clipboard/clipboard_util_win.h" #include "ui/base/clipboard/clipboard_util_win.h"
#include "ui/base/data_transfer_policy/data_transfer_policy_controller.h"
#include "ui/base/dragdrop/file_info/file_info.h" #include "ui/base/dragdrop/file_info/file_info.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/l10n_util_win.h" #include "ui/base/l10n/l10n_util_win.h"
...@@ -754,6 +755,13 @@ gfx::Vector2d OSExchangeDataProviderWin::GetDragImageOffset() const { ...@@ -754,6 +755,13 @@ gfx::Vector2d OSExchangeDataProviderWin::GetDragImageOffset() const {
return gfx::Vector2d(); return gfx::Vector2d();
} }
void OSExchangeDataProviderWin::SetSource(
std::unique_ptr<DataTransferEndpoint> data_source) {}
DataTransferEndpoint* OSExchangeDataProviderWin::GetSource() const {
return nullptr;
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// DataObjectImpl, IDataObject implementation: // DataObjectImpl, IDataObject implementation:
......
...@@ -191,6 +191,9 @@ class COMPONENT_EXPORT(UI_BASE) OSExchangeDataProviderWin ...@@ -191,6 +191,9 @@ class COMPONENT_EXPORT(UI_BASE) OSExchangeDataProviderWin
gfx::ImageSkia GetDragImage() const override; gfx::ImageSkia GetDragImage() const override;
gfx::Vector2d GetDragImageOffset() const override; gfx::Vector2d GetDragImageOffset() const override;
void SetSource(std::unique_ptr<DataTransferEndpoint> data_source) override;
DataTransferEndpoint* GetSource() const override;
private: private:
void SetVirtualFileContentAtIndexForTesting(base::span<const uint8_t> data, void SetVirtualFileContentAtIndexForTesting(base::span<const uint8_t> data,
DWORD tymed, DWORD tymed,
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/check.h" #include "base/check.h"
#include "ui/base/clipboard/clipboard_constants.h" #include "ui/base/clipboard/clipboard_constants.h"
#include "ui/base/data_transfer_policy/data_transfer_policy_controller.h"
#include "ui/base/x/selection_utils.h" #include "ui/base/x/selection_utils.h"
#include "ui/events/platform/platform_event_source.h" #include "ui/events/platform/platform_event_source.h"
#include "ui/gfx/x/x11_atom_cache.h" #include "ui/gfx/x/x11_atom_cache.h"
...@@ -46,4 +47,11 @@ bool OSExchangeDataProviderX11::DispatchXEvent(x11::Event* xev) { ...@@ -46,4 +47,11 @@ bool OSExchangeDataProviderX11::DispatchXEvent(x11::Event* xev) {
return false; return false;
} }
void OSExchangeDataProviderX11::SetSource(
std::unique_ptr<DataTransferEndpoint> data_source) {}
DataTransferEndpoint* OSExchangeDataProviderX11::GetSource() const {
return nullptr;
}
} // namespace ui } // namespace ui
...@@ -38,6 +38,9 @@ class COMPONENT_EXPORT(UI_BASE) OSExchangeDataProviderX11 ...@@ -38,6 +38,9 @@ class COMPONENT_EXPORT(UI_BASE) OSExchangeDataProviderX11
// XEventDispatcher: // XEventDispatcher:
bool DispatchXEvent(x11::Event* xev) override; bool DispatchXEvent(x11::Event* xev) override;
void SetSource(std::unique_ptr<DataTransferEndpoint> data_source) override;
DataTransferEndpoint* GetSource() const override;
private: private:
friend class OSExchangeDataProviderX11Test; friend class OSExchangeDataProviderX11Test;
}; };
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "net/base/filename_util.h" #include "net/base/filename_util.h"
#include "ui/base/clipboard/clipboard_constants.h" #include "ui/base/clipboard/clipboard_constants.h"
#include "ui/base/clipboard/clipboard_format_type.h" #include "ui/base/clipboard/clipboard_format_type.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/x/selection_utils.h" #include "ui/base/x/selection_utils.h"
#include "ui/base/x/x11_util.h" #include "ui/base/x/x11_util.h"
...@@ -475,4 +476,11 @@ void XOSExchangeDataProvider::InsertData( ...@@ -475,4 +476,11 @@ void XOSExchangeDataProvider::InsertData(
format_map_.Insert(format, data); format_map_.Insert(format, data);
} }
void XOSExchangeDataProvider::SetSource(
std::unique_ptr<DataTransferEndpoint> data_source) {}
DataTransferEndpoint* XOSExchangeDataProvider::GetSource() const {
return nullptr;
}
} // namespace ui } // namespace ui
...@@ -92,6 +92,9 @@ class COMPONENT_EXPORT(UI_BASE_X) XOSExchangeDataProvider ...@@ -92,6 +92,9 @@ class COMPONENT_EXPORT(UI_BASE_X) XOSExchangeDataProvider
gfx::ImageSkia GetDragImage() const override; gfx::ImageSkia GetDragImage() const override;
gfx::Vector2d GetDragImageOffset() const override; gfx::Vector2d GetDragImageOffset() const override;
void SetSource(std::unique_ptr<DataTransferEndpoint> data_source) override;
DataTransferEndpoint* GetSource() const override;
protected: protected:
friend class OSExchangeDataProviderX11Test; friend class OSExchangeDataProviderX11Test;
using PickleData = std::map<ClipboardFormatType, base::Pickle>; using PickleData = std::map<ClipboardFormatType, base::Pickle>;
......
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