Commit a6ea10e5 authored by Henrique Ferreiro's avatar Henrique Ferreiro Committed by Commit Bot

Make blink.mojom.DragItemFileSystemFile.file_system_id optional

In renderer to browser messages, this field isn't used and, because
WTF::String supports nullability, the value was serialized as null.

In addition, this CL adds and fixes some of the checks done in the
DragData Mojo type mapping.

Bug: 1136901
Change-Id: Ifc9f9343817d2e06d734470573ce3785cbe885d3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2489897
Commit-Queue: Henrique Ferreiro <hferreiro@igalia.com>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821179}
parent 1787bd86
...@@ -8,8 +8,10 @@ ...@@ -8,8 +8,10 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "base/check.h"
#include "base/containers/span.h" #include "base/containers/span.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/optional.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "content/browser/file_system_access/native_file_system_manager_impl.h" #include "content/browser/file_system_access/native_file_system_manager_impl.h"
#include "content/public/common/drop_data.h" #include "content/public/common/drop_data.h"
...@@ -111,14 +113,25 @@ blink::mojom::DragDataPtr DropDataToDragData( ...@@ -111,14 +113,25 @@ blink::mojom::DragDataPtr DropDataToDragData(
items.push_back(blink::mojom::DragItem::NewString(std::move(item))); items.push_back(blink::mojom::DragItem::NewString(std::move(item)));
} }
return blink::mojom::DragData::New(std::move(items), return blink::mojom::DragData::New(
base::UTF16ToUTF8(drop_data.filesystem_id), std::move(items),
drop_data.referrer_policy); // While this shouldn't be a problem in production code, as the
// real file_system_id should never be empty if used in browser to
// renderer messages, some tests use this function to test renderer to
// browser messages, in which case the field is unused and this will hit
// a DCHECK.
drop_data.filesystem_id.empty()
? base::nullopt
: base::Optional<std::string>(
base::UTF16ToUTF8(drop_data.filesystem_id)),
drop_data.referrer_policy);
} }
DropData DragDataToDropData(const blink::mojom::DragData& drag_data) { DropData DragDataToDropData(const blink::mojom::DragData& drag_data) {
DropData result; // This field should be empty when dragging from the renderer.
DCHECK(!drag_data.file_system_id);
DropData result;
for (const blink::mojom::DragItemPtr& item : drag_data.items) { for (const blink::mojom::DragItemPtr& item : drag_data.items) {
switch (item->which()) { switch (item->which()) {
case blink::mojom::DragItemDataView::Tag::STRING: { case blink::mojom::DragItemDataView::Tag::STRING: {
...@@ -168,10 +181,13 @@ DropData DragDataToDropData(const blink::mojom::DragData& drag_data) { ...@@ -168,10 +181,13 @@ DropData DragDataToDropData(const blink::mojom::DragData& drag_data) {
case blink::mojom::DragItemDataView::Tag::FILE_SYSTEM_FILE: { case blink::mojom::DragItemDataView::Tag::FILE_SYSTEM_FILE: {
const blink::mojom::DragItemFileSystemFilePtr& file_system_file_item = const blink::mojom::DragItemFileSystemFilePtr& file_system_file_item =
item->get_file_system_file(); item->get_file_system_file();
// This field should be empty when dragging from the renderer.
DCHECK(!file_system_file_item->file_system_id);
DropData::FileSystemFileInfo info; DropData::FileSystemFileInfo info;
info.url = file_system_file_item->url; info.url = file_system_file_item->url;
info.size = file_system_file_item->size; info.size = file_system_file_item->size;
info.filesystem_id = file_system_file_item->file_system_id; info.filesystem_id = std::string();
result.file_system_files.push_back(std::move(info)); result.file_system_files.push_back(std::move(info));
break; break;
} }
......
...@@ -76,7 +76,7 @@ struct DragItemBinary { ...@@ -76,7 +76,7 @@ struct DragItemBinary {
struct DragItemFileSystemFile { struct DragItemFileSystemFile {
url.mojom.Url url; url.mojom.Url url;
int64 size; int64 size;
string file_system_id; string? file_system_id;
}; };
union DragItem { union DragItem {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "third_party/blink/renderer/platform/mojo/drag_mojom_traits.h" #include "third_party/blink/renderer/platform/mojo/drag_mojom_traits.h"
#include "base/check.h"
#include "base/containers/span.h" #include "base/containers/span.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
...@@ -176,6 +177,7 @@ int64_t StructTraits< ...@@ -176,6 +177,7 @@ int64_t StructTraits<
WTF::String StructTraits<blink::mojom::DragItemFileSystemFileDataView, WTF::String StructTraits<blink::mojom::DragItemFileSystemFileDataView,
blink::WebDragData::Item>:: blink::WebDragData::Item>::
file_system_id(const blink::WebDragData::Item& item) { file_system_id(const blink::WebDragData::Item& item) {
DCHECK(item.file_system_id.IsNull());
return item.file_system_id; return item.file_system_id;
} }
...@@ -185,7 +187,7 @@ StructTraits<blink::mojom::DragItemFileDataView, blink::WebDragData::Item>:: ...@@ -185,7 +187,7 @@ StructTraits<blink::mojom::DragItemFileDataView, blink::WebDragData::Item>::
native_file_system_token(const blink::WebDragData::Item& item) { native_file_system_token(const blink::WebDragData::Item& item) {
// Should never have to send a transfer token information from the renderer // Should never have to send a transfer token information from the renderer
// to the browser. // to the browser.
NOTREACHED(); DCHECK(!item.native_file_system_entry);
return mojo::NullRemote(); return mojo::NullRemote();
} }
......
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