Commit 95b18a07 authored by Marijn Kruisselbrink's avatar Marijn Kruisselbrink Committed by Commit Bot

Add typemap from SerializedBlob to blink::BlobDataHandle.

Change-Id: I169564f989c6e17d433ccf31c9b7d50ae2b3cad3
Reviewed-on: https://chromium-review.googlesource.com/889417Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Commit-Queue: Marijn Kruisselbrink <mek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533145}
parent 452ac34e
...@@ -8,16 +8,13 @@ ...@@ -8,16 +8,13 @@
namespace mojo { namespace mojo {
Vector<blink::mojom::blink::SerializedBlobPtr> StructTraits< Vector<scoped_refptr<blink::BlobDataHandle>> StructTraits<
blink::mojom::blink::CloneableMessage::DataView, blink::mojom::blink::CloneableMessage::DataView,
blink::BlinkCloneableMessage>::blobs(blink::BlinkCloneableMessage& input) { blink::BlinkCloneableMessage>::blobs(blink::BlinkCloneableMessage& input) {
Vector<blink::mojom::blink::SerializedBlobPtr> result; Vector<scoped_refptr<blink::BlobDataHandle>> result;
result.ReserveInitialCapacity(input.message->BlobDataHandles().size()); result.ReserveInitialCapacity(input.message->BlobDataHandles().size());
for (const auto& blob : input.message->BlobDataHandles()) { for (const auto& blob : input.message->BlobDataHandles())
result.push_back(blink::mojom::blink::SerializedBlob::New( result.push_back(blob.value);
blob.value->Uuid(), blob.value->GetType(), blob.value->size(),
blob.value->CloneBlobPtr().PassInterface()));
}
return result; return result;
} }
...@@ -30,14 +27,11 @@ bool StructTraits<blink::mojom::blink::CloneableMessage::DataView, ...@@ -30,14 +27,11 @@ bool StructTraits<blink::mojom::blink::CloneableMessage::DataView,
out->message = blink::SerializedScriptValue::Create( out->message = blink::SerializedScriptValue::Create(
reinterpret_cast<const char*>(message_data.data()), message_data.size()); reinterpret_cast<const char*>(message_data.data()), message_data.size());
Vector<blink::mojom::blink::SerializedBlobPtr> blobs; Vector<scoped_refptr<blink::BlobDataHandle>> blobs;
if (!data.ReadBlobs(&blobs)) if (!data.ReadBlobs(&blobs))
return false; return false;
for (auto& blob : blobs) { for (auto& blob : blobs) {
out->message->BlobDataHandles().Set( out->message->BlobDataHandles().Set(blob->Uuid(), blob);
blob->uuid,
blink::BlobDataHandle::Create(blob->uuid, blob->content_type,
blob->size, std::move(blob->blob)));
} }
out->sender_stack_trace_id = v8_inspector::V8StackTraceId( out->sender_stack_trace_id = v8_inspector::V8StackTraceId(
static_cast<uintptr_t>(data.stack_trace_id()), static_cast<uintptr_t>(data.stack_trace_id()),
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "core/messaging/BlinkCloneableMessage.h" #include "core/messaging/BlinkCloneableMessage.h"
#include "mojo/public/cpp/bindings/array_traits_wtf_vector.h" #include "mojo/public/cpp/bindings/array_traits_wtf_vector.h"
#include "mojo/public/cpp/bindings/string_traits_wtf.h" #include "mojo/public/cpp/bindings/string_traits_wtf.h"
#include "platform/blob/SerializedBlobStructTraits.h"
#include "third_party/WebKit/common/message_port/message_port.mojom-blink.h" #include "third_party/WebKit/common/message_port/message_port.mojom-blink.h"
namespace mojo { namespace mojo {
...@@ -21,7 +22,7 @@ struct StructTraits<blink::mojom::blink::CloneableMessage::DataView, ...@@ -21,7 +22,7 @@ struct StructTraits<blink::mojom::blink::CloneableMessage::DataView,
return input.message->GetWireData(); return input.message->GetWireData();
} }
static Vector<blink::mojom::blink::SerializedBlobPtr> blobs( static Vector<scoped_refptr<blink::BlobDataHandle>> blobs(
blink::BlinkCloneableMessage& input); blink::BlinkCloneableMessage& input);
static uint64_t stack_trace_id(blink::BlinkCloneableMessage& input) { static uint64_t stack_trace_id(blink::BlinkCloneableMessage& input) {
......
...@@ -31,6 +31,8 @@ blink_platform_sources("blob") { ...@@ -31,6 +31,8 @@ blink_platform_sources("blob") {
"BlobRegistry.h", "BlobRegistry.h",
"BlobURL.cpp", "BlobURL.cpp",
"BlobURL.h", "BlobURL.h",
"SerializedBlobStructTraits.cpp",
"SerializedBlobStructTraits.h",
] ]
} }
......
dmurph@chromium.org dmurph@chromium.org
mek@chromium.org mek@chromium.org
per-file *StructTraits*.*=set noparent
per-file *StructTraits*.*=file://ipc/SECURITY_OWNERS
per-file *.typemap=set noparent
per-file *.typemap=file://ipc/SECURITY_OWNERS
# TEAM: storage-dev@chromium.org # TEAM: storage-dev@chromium.org
# COMPONENT: Blink>FileAPI # COMPONENT: Blink>FileAPI
# Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
mojom = "//third_party/WebKit/common/blob/serialized_blob.mojom"
public_headers = [ "//third_party/WebKit/Source/platform/blob/BlobData.h" ]
traits_headers =
[ "//third_party/WebKit/Source/platform/blob/SerializedBlobStructTraits.h" ]
deps = [
"//mojo/public/cpp/bindings",
]
type_mappings = [ "blink.mojom.SerializedBlob=scoped_refptr<::blink::BlobDataHandle>[nullable_is_same_type]" ]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "platform/blob/SerializedBlobStructTraits.h"
namespace mojo {
bool StructTraits<blink::mojom::blink::SerializedBlob::DataView,
scoped_refptr<blink::BlobDataHandle>>::
Read(blink::mojom::blink::SerializedBlob::DataView data,
scoped_refptr<blink::BlobDataHandle>* out) {
WTF::String uuid;
WTF::String type;
if (!data.ReadUuid(&uuid) || !data.ReadContentType(&type))
return false;
*out = blink::BlobDataHandle::Create(
uuid, type, data.size(),
data.TakeBlob<blink::mojom::blink::BlobPtrInfo>());
return true;
}
} // namespace mojo
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SerializedBlobStructTraits_h
#define SerializedBlobStructTraits_h
#include "base/memory/ref_counted.h"
#include "mojo/public/cpp/bindings/string_traits_wtf.h"
#include "platform/PlatformExport.h"
#include "platform/blob/BlobData.h"
#include "third_party/WebKit/common/blob/serialized_blob.mojom-blink.h"
namespace mojo {
template <>
struct PLATFORM_EXPORT
StructTraits<blink::mojom::blink::SerializedBlob::DataView,
scoped_refptr<blink::BlobDataHandle>> {
static WTF::String uuid(const scoped_refptr<blink::BlobDataHandle>& input) {
return input->Uuid();
}
static WTF::String content_type(
const scoped_refptr<blink::BlobDataHandle>& input) {
return input->GetType();
}
static uint64_t size(const scoped_refptr<blink::BlobDataHandle>& input) {
return input->size();
}
static blink::mojom::blink::BlobPtr blob(
const scoped_refptr<blink::BlobDataHandle>& input) {
return input->CloneBlobPtr();
}
static bool Read(blink::mojom::blink::SerializedBlob::DataView,
scoped_refptr<blink::BlobDataHandle>* out);
};
} // namespace mojo
#endif // SerializedBlobStructTraits_h
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "mojo/public/cpp/system/platform_handle.h" #include "mojo/public/cpp/system/platform_handle.h"
#include "public/platform/Platform.h" #include "public/platform/Platform.h"
#include "services/service_manager/public/cpp/connector.h" #include "services/service_manager/public/cpp/connector.h"
#include "third_party/WebKit/Source/platform/blob/BlobData.h"
#include "third_party/WebKit/Source/platform/clipboard/ClipboardMimeTypes.h" #include "third_party/WebKit/Source/platform/clipboard/ClipboardMimeTypes.h"
#include "third_party/WebKit/public/platform/WebDragData.h" #include "third_party/WebKit/public/platform/WebDragData.h"
#include "third_party/WebKit/public/platform/WebImage.h" #include "third_party/WebKit/public/platform/WebImage.h"
...@@ -153,12 +154,11 @@ WebBlobInfo WebClipboardImpl::ReadImage(mojom::ClipboardBuffer buffer) { ...@@ -153,12 +154,11 @@ WebBlobInfo WebClipboardImpl::ReadImage(mojom::ClipboardBuffer buffer) {
if (!IsValidBufferType(buffer)) if (!IsValidBufferType(buffer))
return WebBlobInfo(); return WebBlobInfo();
mojom::blink::SerializedBlobPtr blob; scoped_refptr<BlobDataHandle> blob;
clipboard_->ReadImage(buffer, &blob); clipboard_->ReadImage(buffer, &blob);
if (!blob) if (!blob)
return WebBlobInfo(); return WebBlobInfo();
return WebBlobInfo(blob->uuid, blob->content_type, blob->size, return blob;
blob->blob.PassHandle());
} }
WebString WebClipboardImpl::ReadCustomData(mojom::ClipboardBuffer buffer, WebString WebClipboardImpl::ReadCustomData(mojom::ClipboardBuffer buffer,
......
...@@ -7,6 +7,7 @@ typemaps = [ ...@@ -7,6 +7,7 @@ typemaps = [
"//mojo/common/values.typemap", "//mojo/common/values.typemap",
"//third_party/WebKit/Source/core/messaging/BlinkCloneableMessage.typemap", "//third_party/WebKit/Source/core/messaging/BlinkCloneableMessage.typemap",
"//third_party/WebKit/Source/core/messaging/BlinkTransferableMessage.typemap", "//third_party/WebKit/Source/core/messaging/BlinkTransferableMessage.typemap",
"//third_party/WebKit/Source/platform/blob/SerializedBlob.typemap",
"//third_party/WebKit/Source/platform/mojo/BigBuffer.typemap", "//third_party/WebKit/Source/platform/mojo/BigBuffer.typemap",
"//third_party/WebKit/Source/platform/mojo/File.typemap", "//third_party/WebKit/Source/platform/mojo/File.typemap",
"//third_party/WebKit/Source/platform/mojo/Geometry.typemap", "//third_party/WebKit/Source/platform/mojo/Geometry.typemap",
......
...@@ -113,6 +113,7 @@ mojom("mojo_platform_bindings") { ...@@ -113,6 +113,7 @@ mojom("mojo_platform_bindings") {
"blob/blob.mojom", "blob/blob.mojom",
"blob/blob_registry.mojom", "blob/blob_registry.mojom",
"blob/blob_url_store.mojom", "blob/blob_url_store.mojom",
"blob/serialized_blob.mojom",
"clipboard/clipboard.mojom", "clipboard/clipboard.mojom",
"color_chooser/color_chooser.mojom", "color_chooser/color_chooser.mojom",
"feature_policy/feature_policy.mojom", "feature_policy/feature_policy.mojom",
......
...@@ -55,14 +55,3 @@ interface Blob { ...@@ -55,14 +55,3 @@ interface Blob {
// identify the blob. // identify the blob.
GetInternalUUID() => (string uuid); GetInternalUUID() => (string uuid);
}; };
// Struct wrapping a Blob interface pointer.
// TODO(mek): Once https://crbug.com/696107 is implemented all usage of this
// struct can be replaced with a simple Blob interface pointer with handle
// properties for the other attributes.
struct SerializedBlob {
string uuid;
string content_type;
uint64 size;
Blob blob;
};
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module blink.mojom;
import "third_party/WebKit/common/blob/blob.mojom";
// Struct wrapping a Blob interface pointer.
// TODO(mek): Once https://crbug.com/696107 is implemented all usage of this
// struct can be replaced with a simple Blob interface pointer with handle
// properties for the other attributes.
struct SerializedBlob {
string uuid;
string content_type;
uint64 size;
Blob blob;
};
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
module blink.mojom; module blink.mojom;
import "mojo/common/string16.mojom"; import "mojo/common/string16.mojom";
import "third_party/WebKit/common/blob/blob.mojom"; import "third_party/WebKit/common/blob/serialized_blob.mojom";
import "ui/gfx/geometry/mojo/geometry.mojom"; import "ui/gfx/geometry/mojo/geometry.mojom";
import "url/mojo/url.mojom"; import "url/mojo/url.mojom";
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
module blink.mojom; module blink.mojom;
import "third_party/WebKit/common/blob/blob.mojom"; import "third_party/WebKit/common/blob/serialized_blob.mojom";
// A MessagePort is represented as a raw mojo message pipe, as such no interface // A MessagePort is represented as a raw mojo message pipe, as such no interface
// definition exists for it here. Messages on this pipe are serialized versions // definition exists for it here. Messages on this pipe are serialized versions
......
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