Commit fbe3cd79 authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by Commit Bot

Pass the target window in DataOffer/FileHelper.

This allows target specific path/data resolution.

Bug: None

Change-Id: I684e99b09c43838f1b5065a892fa013c9a6be462
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2524823Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Reviewed-by: default avatarNancy Wang <nancylingwang@chromium.org>
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826281}
parent ae1a631c
...@@ -78,7 +78,7 @@ class ChromeFileHelper : public exo::FileHelper { ...@@ -78,7 +78,7 @@ class ChromeFileHelper : public exo::FileHelper {
return kMimeTypeArcUriList; return kMimeTypeArcUriList;
} }
bool GetUrlFromPath(const std::string& app_id, bool GetUrlFromPath(aura::Window* target,
const base::FilePath& path, const base::FilePath& path,
GURL* out) override { GURL* out) override {
return file_manager::util::ConvertPathToArcUrl(path, out); return file_manager::util::ConvertPathToArcUrl(path, out);
...@@ -90,7 +90,7 @@ class ChromeFileHelper : public exo::FileHelper { ...@@ -90,7 +90,7 @@ class ChromeFileHelper : public exo::FileHelper {
return !file_system_urls.empty(); return !file_system_urls.empty();
} }
void GetUrlsFromPickle(const std::string& app_id, void GetUrlsFromPickle(aura::Window* target,
const base::Pickle& pickle, const base::Pickle& pickle,
UrlsFromPickleCallback callback) override { UrlsFromPickleCallback callback) override {
std::vector<storage::FileSystemURL> file_system_urls; std::vector<storage::FileSystemURL> file_system_urls;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "components/exo/data_offer.h" #include "components/exo/data_offer.h"
#include "components/exo/data_source.h" #include "components/exo/data_source.h"
#include "components/exo/seat.h" #include "components/exo/seat.h"
#include "components/exo/shell_surface_util.h"
#include "components/exo/surface.h" #include "components/exo/surface.h"
#include "ui/base/clipboard/clipboard.h" #include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/clipboard_monitor.h" #include "ui/base/clipboard/clipboard_monitor.h"
...@@ -93,7 +94,8 @@ void DataDevice::OnDragEntered(const ui::DropTargetEvent& event) { ...@@ -93,7 +94,8 @@ void DataDevice::OnDragEntered(const ui::DropTargetEvent& event) {
data_offer_ = data_offer_ =
std::make_unique<ScopedDataOffer>(delegate_->OnDataOffer(), this); std::make_unique<ScopedDataOffer>(delegate_->OnDataOffer(), this);
data_offer_->get()->SetDropData(file_helper_, event.data()); data_offer_->get()->SetDropData(file_helper_, surface->window(),
event.data());
data_offer_->get()->SetSourceActions(dnd_actions); data_offer_->get()->SetSourceActions(dnd_actions);
data_offer_->get()->SetActions(base::flat_set<DndAction>(), DndAction::kAsk); data_offer_->get()->SetActions(base::flat_set<DndAction>(), DndAction::kAsk);
delegate_->OnEnter(surface, event.location_f(), *data_offer_->get()); delegate_->OnEnter(surface, event.location_f(), *data_offer_->get());
......
...@@ -66,6 +66,7 @@ void WriteFileDescriptor(base::ScopedFD fd, ...@@ -66,6 +66,7 @@ void WriteFileDescriptor(base::ScopedFD fd,
// Gets a comma-separated list of urls extracted from |data|->file. // Gets a comma-separated list of urls extracted from |data|->file.
bool GetUrlListFromDataFile(FileHelper* file_helper, bool GetUrlListFromDataFile(FileHelper* file_helper,
aura::Window* target,
const ui::OSExchangeData& data, const ui::OSExchangeData& data,
base::string16* url_list_string) { base::string16* url_list_string) {
if (!data.HasFile()) if (!data.HasFile())
...@@ -75,7 +76,7 @@ bool GetUrlListFromDataFile(FileHelper* file_helper, ...@@ -75,7 +76,7 @@ bool GetUrlListFromDataFile(FileHelper* file_helper,
for (const auto& info : files) { for (const auto& info : files) {
GURL url; GURL url;
// TODO(niwa): Need to fill the correct app_id. // TODO(niwa): Need to fill the correct app_id.
if (file_helper->GetUrlFromPath(/* app_id */ "", info.path, &url)) { if (file_helper->GetUrlFromPath(target, info.path, &url)) {
if (!url_list_string->empty()) if (!url_list_string->empty())
*url_list_string += base::UTF8ToUTF16(kUriListSeparator); *url_list_string += base::UTF8ToUTF16(kUriListSeparator);
*url_list_string += base::UTF8ToUTF16(url.spec()); *url_list_string += base::UTF8ToUTF16(url.spec());
...@@ -263,6 +264,7 @@ void DataOffer::SetSourceActions( ...@@ -263,6 +264,7 @@ void DataOffer::SetSourceActions(
} }
void DataOffer::SetDropData(FileHelper* file_helper, void DataOffer::SetDropData(FileHelper* file_helper,
aura::Window* target,
const ui::OSExchangeData& data) { const ui::OSExchangeData& data) {
DCHECK_EQ(0u, data_callbacks_.size()); DCHECK_EQ(0u, data_callbacks_.size());
...@@ -284,7 +286,7 @@ void DataOffer::SetDropData(FileHelper* file_helper, ...@@ -284,7 +286,7 @@ void DataOffer::SetDropData(FileHelper* file_helper,
const std::string uri_list_mime_type = file_helper->GetMimeTypeForUriList(); const std::string uri_list_mime_type = file_helper->GetMimeTypeForUriList();
base::string16 url_list_string; base::string16 url_list_string;
if (GetUrlListFromDataFile(file_helper, data, &url_list_string)) { if (GetUrlListFromDataFile(file_helper, target, data, &url_list_string)) {
data_callbacks_.emplace( data_callbacks_.emplace(
uri_list_mime_type, uri_list_mime_type,
AsyncSend(base::RefCountedString16::TakeString(&url_list_string))); AsyncSend(base::RefCountedString16::TakeString(&url_list_string)));
...@@ -295,10 +297,10 @@ void DataOffer::SetDropData(FileHelper* file_helper, ...@@ -295,10 +297,10 @@ void DataOffer::SetDropData(FileHelper* file_helper,
base::Pickle pickle; base::Pickle pickle;
if (data.GetPickledData(GetClipboardFormatType(), &pickle) && if (data.GetPickledData(GetClipboardFormatType(), &pickle) &&
file_helper->HasUrlsInPickle(pickle)) { file_helper->HasUrlsInPickle(pickle)) {
data_callbacks_.emplace( data_callbacks_.emplace(uri_list_mime_type,
uri_list_mime_type, base::BindOnce(&DataOffer::GetUrlsFromPickle,
base::BindOnce(&DataOffer::GetUrlsFromPickle, weak_ptr_factory_.GetWeakPtr(),
weak_ptr_factory_.GetWeakPtr(), file_helper, pickle)); file_helper, target, pickle));
delegate_->OnOffer(uri_list_mime_type); delegate_->OnOffer(uri_list_mime_type);
return; return;
} }
...@@ -407,11 +409,11 @@ void DataOffer::OnDataReady(const std::string& mime_type, ...@@ -407,11 +409,11 @@ void DataOffer::OnDataReady(const std::string& mime_type,
} }
void DataOffer::GetUrlsFromPickle(FileHelper* file_helper, void DataOffer::GetUrlsFromPickle(FileHelper* file_helper,
aura::Window* target,
const base::Pickle& pickle, const base::Pickle& pickle,
DataOffer::SendDataCallback callback) { DataOffer::SendDataCallback callback) {
// TODO(niwa): Need to fill the correct app_id.
file_helper->GetUrlsFromPickle( file_helper->GetUrlsFromPickle(
/* app_id */ "", pickle, target, pickle,
base::BindOnce(&DataOffer::OnPickledUrlsResolved, base::BindOnce(&DataOffer::OnPickledUrlsResolved,
weak_ptr_factory_.GetWeakPtr(), std::move(callback))); weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
} }
......
...@@ -18,6 +18,10 @@ ...@@ -18,6 +18,10 @@
#include "ui/base/class_property.h" #include "ui/base/class_property.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace aura {
class Window;
}
namespace base { namespace base {
class Pickle; class Pickle;
class RefCountedMemory; class RefCountedMemory;
...@@ -66,12 +70,15 @@ class DataOffer final : public ui::PropertyHandler { ...@@ -66,12 +70,15 @@ class DataOffer final : public ui::PropertyHandler {
// Sets the dropped data from |data| to the DataOffer object. |file_helper| // Sets the dropped data from |data| to the DataOffer object. |file_helper|
// will be used to convert paths to handle mount points which is mounted in // will be used to convert paths to handle mount points which is mounted in
// the mount point namespace of clinet process. // the mount point namespace of clinet process. |target| is the drop target
// While this function immediately calls DataOfferDelegate::OnOffer inside it // window and can be used to apply the target specitic logic to interpret the
// with found mime types, dropped data bytes may be populated asynchronously // data. While this function immediately calls DataOfferDelegate::OnOffer
// after this function call. // inside it with found mime types, dropped data bytes may be populated
// (e.g. Asynchronous lookup is required for resolving file system urls.) // asynchronously after this function call. (e.g. Asynchronous lookup is
void SetDropData(FileHelper* file_helper, const ui::OSExchangeData& data); // required for resolving file system urls.)
void SetDropData(FileHelper* file_helper,
aura::Window* target,
const ui::OSExchangeData& data);
// Sets the clipboard data from |data| to the DataOffer object. // Sets the clipboard data from |data| to the DataOffer object.
void SetClipboardData(FileHelper* file_helper, const ui::Clipboard& data); void SetClipboardData(FileHelper* file_helper, const ui::Clipboard& data);
...@@ -88,6 +95,7 @@ class DataOffer final : public ui::PropertyHandler { ...@@ -88,6 +95,7 @@ class DataOffer final : public ui::PropertyHandler {
base::ScopedFD fd, base::ScopedFD fd,
scoped_refptr<base::RefCountedMemory> data); scoped_refptr<base::RefCountedMemory> data);
void GetUrlsFromPickle(FileHelper* file_helper, void GetUrlsFromPickle(FileHelper* file_helper,
aura::Window* target,
const base::Pickle& pickle, const base::Pickle& pickle,
SendDataCallback callback); SendDataCallback callback);
void OnPickledUrlsResolved(SendDataCallback callback, void OnPickledUrlsResolved(SendDataCallback callback,
......
...@@ -117,7 +117,7 @@ TEST_F(DataOfferTest, SetTextDropData) { ...@@ -117,7 +117,7 @@ TEST_F(DataOfferTest, SetTextDropData) {
EXPECT_EQ(DndAction::kNone, delegate.dnd_action()); EXPECT_EQ(DndAction::kNone, delegate.dnd_action());
TestFileHelper file_helper; TestFileHelper file_helper;
data_offer.SetDropData(&file_helper, data); data_offer.SetDropData(&file_helper, nullptr, data);
data_offer.SetSourceActions(source_actions); data_offer.SetSourceActions(source_actions);
data_offer.SetActions(base::flat_set<DndAction>(), DndAction::kMove); data_offer.SetActions(base::flat_set<DndAction>(), DndAction::kMove);
...@@ -147,7 +147,7 @@ TEST_F(DataOfferTest, SetHTMLDropData) { ...@@ -147,7 +147,7 @@ TEST_F(DataOfferTest, SetHTMLDropData) {
EXPECT_EQ(DndAction::kNone, delegate.dnd_action()); EXPECT_EQ(DndAction::kNone, delegate.dnd_action());
TestFileHelper file_helper; TestFileHelper file_helper;
data_offer.SetDropData(&file_helper, data); data_offer.SetDropData(&file_helper, nullptr, data);
data_offer.SetSourceActions(source_actions); data_offer.SetSourceActions(source_actions);
data_offer.SetActions(base::flat_set<DndAction>(), DndAction::kMove); data_offer.SetActions(base::flat_set<DndAction>(), DndAction::kMove);
...@@ -179,7 +179,7 @@ TEST_F(DataOfferTest, SetFileDropData) { ...@@ -179,7 +179,7 @@ TEST_F(DataOfferTest, SetFileDropData) {
TestFileHelper file_helper; TestFileHelper file_helper;
ui::OSExchangeData data; ui::OSExchangeData data;
data.SetFilename(base::FilePath("/test/downloads/file")); data.SetFilename(base::FilePath("/test/downloads/file"));
data_offer.SetDropData(&file_helper, data); data_offer.SetDropData(&file_helper, nullptr, data);
EXPECT_EQ(1u, delegate.mime_types().size()); EXPECT_EQ(1u, delegate.mime_types().size());
EXPECT_EQ(1u, delegate.mime_types().count("text/uri-list")); EXPECT_EQ(1u, delegate.mime_types().count("text/uri-list"));
...@@ -199,7 +199,7 @@ TEST_F(DataOfferTest, SetPickleDropData) { ...@@ -199,7 +199,7 @@ TEST_F(DataOfferTest, SetPickleDropData) {
pickle.WriteString("id"); // filesystem id pickle.WriteString("id"); // filesystem id
data.SetPickledData( data.SetPickledData(
ui::ClipboardFormatType::GetType("chromium/x-file-system-files"), pickle); ui::ClipboardFormatType::GetType("chromium/x-file-system-files"), pickle);
data_offer.SetDropData(&file_helper, data); data_offer.SetDropData(&file_helper, nullptr, data);
EXPECT_EQ(1u, delegate.mime_types().size()); EXPECT_EQ(1u, delegate.mime_types().size());
EXPECT_EQ(1u, delegate.mime_types().count("text/uri-list")); EXPECT_EQ(1u, delegate.mime_types().count("text/uri-list"));
...@@ -212,7 +212,7 @@ TEST_F(DataOfferTest, ReceiveString) { ...@@ -212,7 +212,7 @@ TEST_F(DataOfferTest, ReceiveString) {
TestFileHelper file_helper; TestFileHelper file_helper;
ui::OSExchangeData data; ui::OSExchangeData data;
data.SetString(base::ASCIIToUTF16("Test data")); data.SetString(base::ASCIIToUTF16("Test data"));
data_offer.SetDropData(&file_helper, data); data_offer.SetDropData(&file_helper, nullptr, data);
base::ScopedFD read_pipe; base::ScopedFD read_pipe;
base::ScopedFD write_pipe; base::ScopedFD write_pipe;
...@@ -247,7 +247,7 @@ TEST_F(DataOfferTest, ReceiveHTML) { ...@@ -247,7 +247,7 @@ TEST_F(DataOfferTest, ReceiveHTML) {
TestFileHelper file_helper; TestFileHelper file_helper;
ui::OSExchangeData data; ui::OSExchangeData data;
data.SetHtml(base::ASCIIToUTF16("Test HTML data"), GURL()); data.SetHtml(base::ASCIIToUTF16("Test HTML data"), GURL());
data_offer.SetDropData(&file_helper, data); data_offer.SetDropData(&file_helper, nullptr, data);
base::ScopedFD read_pipe_16; base::ScopedFD read_pipe_16;
base::ScopedFD write_pipe_16; base::ScopedFD write_pipe_16;
...@@ -273,7 +273,7 @@ TEST_F(DataOfferTest, ReceiveUriList) { ...@@ -273,7 +273,7 @@ TEST_F(DataOfferTest, ReceiveUriList) {
TestFileHelper file_helper; TestFileHelper file_helper;
ui::OSExchangeData data; ui::OSExchangeData data;
data.SetFilename(base::FilePath("/test/downloads/file")); data.SetFilename(base::FilePath("/test/downloads/file"));
data_offer.SetDropData(&file_helper, data); data_offer.SetDropData(&file_helper, nullptr, data);
base::ScopedFD read_pipe; base::ScopedFD read_pipe;
base::ScopedFD write_pipe; base::ScopedFD write_pipe;
...@@ -299,7 +299,7 @@ TEST_F(DataOfferTest, ReceiveUriListFromPickle_ReceiveBeforeUrlIsResolved) { ...@@ -299,7 +299,7 @@ TEST_F(DataOfferTest, ReceiveUriListFromPickle_ReceiveBeforeUrlIsResolved) {
pickle.WriteString("id"); // filesystem id pickle.WriteString("id"); // filesystem id
data.SetPickledData( data.SetPickledData(
ui::ClipboardFormatType::GetType("chromium/x-file-system-files"), pickle); ui::ClipboardFormatType::GetType("chromium/x-file-system-files"), pickle);
data_offer.SetDropData(&file_helper, data); data_offer.SetDropData(&file_helper, nullptr, data);
base::ScopedFD read_pipe1; base::ScopedFD read_pipe1;
base::ScopedFD write_pipe1; base::ScopedFD write_pipe1;
...@@ -347,7 +347,7 @@ TEST_F(DataOfferTest, ...@@ -347,7 +347,7 @@ TEST_F(DataOfferTest,
pickle.WriteString("id"); // filesystem id pickle.WriteString("id"); // filesystem id
data.SetPickledData( data.SetPickledData(
ui::ClipboardFormatType::GetType("chromium/x-file-system-files"), pickle); ui::ClipboardFormatType::GetType("chromium/x-file-system-files"), pickle);
data_offer.SetDropData(&file_helper, data); data_offer.SetDropData(&file_helper, nullptr, data);
base::ScopedFD read_pipe; base::ScopedFD read_pipe;
base::ScopedFD write_pipe; base::ScopedFD write_pipe;
......
...@@ -12,6 +12,10 @@ ...@@ -12,6 +12,10 @@
class GURL; class GURL;
namespace aura {
class Window;
}
namespace base { namespace base {
class FilePath; class FilePath;
class Pickle; class Pickle;
...@@ -27,13 +31,13 @@ class FileHelper { ...@@ -27,13 +31,13 @@ class FileHelper {
// FileHelper. // FileHelper.
virtual std::string GetMimeTypeForUriList() const = 0; virtual std::string GetMimeTypeForUriList() const = 0;
// Converts native file path to URL which can be used by application with // Converts native file path to URL to be consumed by the target window
// |app_id|. We don't expose enter file system to a container directly. // |target|. We don't expose enter file system to a container directly.
// Instead we mount specific directory in the containers' namespace. Thus we // Instead we mount specific directory in the containers' namespace. Thus we
// need to convert native path to file URL which points mount point in // need to convert native path to file URL which points mount point in
// containers. The conversion should be container specific, now we only have // containers. The conversion should be container specific, now we only have
// ARC container though. // ARC container though.
virtual bool GetUrlFromPath(const std::string& app_id, virtual bool GetUrlFromPath(aura::Window* target,
const base::FilePath& path, const base::FilePath& path,
GURL* out) = 0; GURL* out) = 0;
...@@ -45,9 +49,10 @@ class FileHelper { ...@@ -45,9 +49,10 @@ class FileHelper {
base::OnceCallback<void(const std::vector<GURL>& urls)>; base::OnceCallback<void(const std::vector<GURL>& urls)>;
// Takes in |pickle| constructed by the web contents view, reads filesystem // Takes in |pickle| constructed by the web contents view, reads filesystem
// URLs from it and converts the URLs to something that applications can // URLs from it and converts the URLs to something that applications
// understand. e.g. content:// URI for Android apps. // represented by |target| can understand and consume. e.g. content:// URI
virtual void GetUrlsFromPickle(const std::string& app_id, // for Android apps.
virtual void GetUrlsFromPickle(aura::Window* target,
const base::Pickle& pickle, const base::Pickle& pickle,
UrlsFromPickleCallback callback) = 0; UrlsFromPickleCallback callback) = 0;
}; };
......
...@@ -21,7 +21,7 @@ std::string TestFileHelper::GetMimeTypeForUriList() const { ...@@ -21,7 +21,7 @@ std::string TestFileHelper::GetMimeTypeForUriList() const {
return "text/uri-list"; return "text/uri-list";
} }
bool TestFileHelper::GetUrlFromPath(const std::string& app_id, bool TestFileHelper::GetUrlFromPath(aura::Window* target,
const base::FilePath& path, const base::FilePath& path,
GURL* out) { GURL* out) {
*out = GURL("file://" + path.value()); *out = GURL("file://" + path.value());
...@@ -32,7 +32,7 @@ bool TestFileHelper::HasUrlsInPickle(const base::Pickle& pickle) { ...@@ -32,7 +32,7 @@ bool TestFileHelper::HasUrlsInPickle(const base::Pickle& pickle) {
return true; return true;
} }
void TestFileHelper::GetUrlsFromPickle(const std::string& app_id, void TestFileHelper::GetUrlsFromPickle(aura::Window* target,
const base::Pickle& pickle, const base::Pickle& pickle,
UrlsFromPickleCallback callback) { UrlsFromPickleCallback callback) {
urls_callback_ = std::move(callback); urls_callback_ = std::move(callback);
......
...@@ -18,11 +18,11 @@ class TestFileHelper : public FileHelper { ...@@ -18,11 +18,11 @@ class TestFileHelper : public FileHelper {
// FileHelper: // FileHelper:
std::string GetMimeTypeForUriList() const override; std::string GetMimeTypeForUriList() const override;
bool GetUrlFromPath(const std::string& app_id, bool GetUrlFromPath(aura::Window* target,
const base::FilePath& path, const base::FilePath& path,
GURL* out) override; GURL* out) override;
bool HasUrlsInPickle(const base::Pickle& pickle) override; bool HasUrlsInPickle(const base::Pickle& pickle) override;
void GetUrlsFromPickle(const std::string& app_id, void GetUrlsFromPickle(aura::Window* target,
const base::Pickle& pickle, const base::Pickle& pickle,
UrlsFromPickleCallback callback) override; UrlsFromPickleCallback callback) override;
......
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