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