Commit 1ca39312 authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

Use BigBuffer for MessagePort message contents

Switches ArrayBuffer and raw encoded message data mojom representations
to use BigBuffer instead of array<uint8>. This avoids large message data
exceeding hard size limitations.

Also introduces BigBufferView as a traits helper to avoid redundant
copies when a deserialized BigBuffer is using inline array storage.

Bug: 829659
Change-Id: I8b62d4bcd7458db1d6aff9e22dcb7c13999f0bf0
Reviewed-on: https://chromium-review.googlesource.com/1004594
Commit-Queue: Ken Rockot <rockot@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550021}
parent 866b53c3
......@@ -921,6 +921,34 @@ public class PostMessageTest {
Assert.assertEquals("12", channelContainer.getMessage());
}
// Make sure very large messages can be sent and received.
@Test
@SmallTest
@Feature({"AndroidWebView", "Android-PostMessage"})
public void testVeryLargeMessage() throws Throwable {
mWebServer.setResponse(IFRAME_URL, ECHO_PAGE, null);
mActivityTestRule.triggerPopup(mAwContents, mContentsClient, mWebServer,
MAIN_PAGE_FOR_POPUP_TEST, POPUP_PAGE_WITH_IFRAME, POPUP_URL, "createPopup()");
mActivityTestRule.connectPendingPopup(mAwContents);
final ChannelContainer channelContainer = new ChannelContainer();
final StringBuilder longMessageBuilder = new StringBuilder();
for (int i = 0; i < 100000; ++i) longMessageBuilder.append(HELLO);
final String longMessage = longMessageBuilder.toString();
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
AppWebMessagePort[] channel = mAwContents.createMessageChannel();
channelContainer.set(channel);
channel[0].setMessageCallback(
(message, sentPorts) -> channelContainer.setMessage(message), null);
mAwContents.postMessageToFrame(null, WEBVIEW_MESSAGE, mWebServer.getBaseUrl(),
new AppWebMessagePort[] {channel[1]});
channel[0].postMessage(longMessage, null);
});
channelContainer.waitForMessage();
Assert.assertEquals(longMessage + JS_MESSAGE, channelContainer.getMessage());
}
// Make sure messages are dispatched on the correct looper.
@Test
@SmallTest
......
......@@ -46,6 +46,7 @@ android_library("content_java") {
"//media/mojo/interfaces:interfaces_java",
"//mojo/android:system_java",
"//mojo/common:common_custom_types_java",
"//mojo/public/java:base_java",
"//mojo/public/java:bindings_java",
"//mojo/public/java:system_java",
"//net/android:net_java",
......
......@@ -24,6 +24,7 @@ import org.chromium.mojo.system.Core;
import org.chromium.mojo.system.MessagePipeHandle;
import org.chromium.mojo.system.Pair;
import org.chromium.mojo.system.impl.CoreImpl;
import org.chromium.mojo_base.BigBufferUtil;
import org.chromium.skia.mojom.Bitmap;
/**
......@@ -128,7 +129,8 @@ public class AppWebMessagePort implements MessagePort {
ports[i] = new AppWebMessagePort(msg.ports[i]);
}
MessagePortMessage portMsg = new MessagePortMessage();
portMsg.encodedMessage = msg.message.encodedMessage;
portMsg.encodedMessage =
BigBufferUtil.getBytesFromBigBuffer(msg.message.encodedMessage);
portMsg.ports = ports;
sendMessage(obtainMessage(MESSAGE_RECEIVED, portMsg));
} catch (DeserializationException e) {
......@@ -248,7 +250,8 @@ public class AppWebMessagePort implements MessagePort {
TransferableMessage msg = new TransferableMessage();
msg.message = new CloneableMessage();
msg.message.encodedMessage = nativeEncodeStringMessage(message);
msg.message.encodedMessage =
BigBufferUtil.createBigBufferFromBytes(nativeEncodeStringMessage(message));
msg.message.blobs = new SerializedBlob[0];
msg.arrayBufferContentsArray = new SerializedArrayBufferContents[0];
msg.imageBitmapContentsArray = new Bitmap[0];
......
......@@ -43,23 +43,7 @@ BigBuffer::BigBuffer() : storage_type_(StorageType::kBytes) {}
BigBuffer::BigBuffer(BigBuffer&& other) = default;
BigBuffer::BigBuffer(base::span<const uint8_t> data) {
if (data.size() > kMaxInlineBytes) {
auto buffer = mojo::SharedBufferHandle::Create(data.size());
if (buffer.is_valid()) {
storage_type_ = StorageType::kSharedMemory;
shared_memory_.emplace(std::move(buffer), data.size());
std::copy(data.begin(), data.end(),
static_cast<uint8_t*>(shared_memory_->buffer_mapping_.get()));
return;
}
}
// Either the data is small enough that we're happy to carry it in an array,
// or shared buffer allocation failed and we fall back on this as a best-
// effort alternative.
storage_type_ = StorageType::kBytes;
bytes_.resize(data.size());
std::copy(data.begin(), data.end(), bytes_.begin());
*this = BigBufferView::ToBigBuffer(BigBufferView(data));
}
BigBuffer::BigBuffer(const std::vector<uint8_t>& data)
......@@ -103,4 +87,69 @@ size_t BigBuffer::size() const {
}
}
BigBufferView::BigBufferView() = default;
BigBufferView::BigBufferView(BigBufferView&& other) = default;
BigBufferView::BigBufferView(base::span<const uint8_t> bytes) {
if (bytes.size() > BigBuffer::kMaxInlineBytes) {
auto buffer = mojo::SharedBufferHandle::Create(bytes.size());
if (buffer.is_valid()) {
storage_type_ = BigBuffer::StorageType::kSharedMemory;
shared_memory_.emplace(std::move(buffer), bytes.size());
std::copy(bytes.begin(), bytes.end(),
static_cast<uint8_t*>(shared_memory_->buffer_mapping_.get()));
return;
}
}
// Either the data is small enough or shared memory allocation failed. Either
// way we fall back to directly referencing the input bytes.
storage_type_ = BigBuffer::StorageType::kBytes;
bytes_ = bytes;
}
BigBufferView::~BigBufferView() = default;
BigBufferView& BigBufferView::operator=(BigBufferView&& other) = default;
void BigBufferView::SetBytes(base::span<const uint8_t> bytes) {
DCHECK(bytes_.empty());
DCHECK(!shared_memory_);
storage_type_ = BigBuffer::StorageType::kBytes;
bytes_ = bytes;
}
void BigBufferView::SetSharedMemory(
internal::BigBufferSharedMemoryRegion shared_memory) {
DCHECK(bytes_.empty());
DCHECK(!shared_memory_);
storage_type_ = BigBuffer::StorageType::kSharedMemory;
shared_memory_ = std::move(shared_memory);
}
base::span<const uint8_t> BigBufferView::data() const {
if (storage_type_ == BigBuffer::StorageType::kBytes) {
return bytes_;
} else {
DCHECK(shared_memory_.has_value());
return base::make_span(static_cast<const uint8_t*>(const_cast<const void*>(
shared_memory_->memory())),
shared_memory_->size());
}
}
// static
BigBuffer BigBufferView::ToBigBuffer(BigBufferView view) {
BigBuffer buffer;
buffer.storage_type_ = view.storage_type_;
if (view.storage_type_ == BigBuffer::StorageType::kBytes) {
std::copy(view.bytes_.begin(), view.bytes_.end(),
std::back_inserter(buffer.bytes_));
} else {
buffer.shared_memory_ = std::move(*view.shared_memory_);
}
return buffer;
}
} // namespace mojo_base
......@@ -18,6 +18,7 @@
namespace mojo_base {
class BigBuffer;
class BigBufferView;
namespace internal {
......@@ -39,6 +40,7 @@ class COMPONENT_EXPORT(MOJO_BASE) BigBufferSharedMemoryRegion {
private:
friend class mojo_base::BigBuffer;
friend class mojo_base::BigBufferView;
size_t size_;
mojo::ScopedSharedBufferHandle buffer_handle_;
......@@ -111,6 +113,8 @@ class COMPONENT_EXPORT(MOJO_BASE) BigBuffer {
}
private:
friend class BigBufferView;
StorageType storage_type_;
std::vector<uint8_t> bytes_;
base::Optional<internal::BigBufferSharedMemoryRegion> shared_memory_;
......@@ -118,6 +122,58 @@ class COMPONENT_EXPORT(MOJO_BASE) BigBuffer {
DISALLOW_COPY_AND_ASSIGN(BigBuffer);
};
// Similar to BigBuffer, but doesn't *necessarily* own the buffer storage.
// Namely, if constructed over a small enough span of memory, it will simply
// retain a reference to that memory. This is generally only safe to use for
// serialization and deserialization.
class COMPONENT_EXPORT(MOJO_BASE) BigBufferView {
public:
BigBufferView();
BigBufferView(BigBufferView&& other);
// Constructs a BigBufferView over |bytes|. If |bytes| is large enough, this
// will allocate shared memory and copy the contents there. Otherwise this
// will retain an unsafe reference to |bytes| and must therefore not outlive
// |bytes|.
explicit BigBufferView(base::span<const uint8_t> bytes);
~BigBufferView();
BigBufferView& operator=(BigBufferView&& other);
base::span<const uint8_t> data() const;
// Explicitly retains a reference to |bytes| as the backing storage for this
// view. Does not copy and therefore |bytes| must remain valid throughout the
// view's lifetime. Used for deserialization.
void SetBytes(base::span<const uint8_t> bytes);
// Explictly adopts |shared_memory| as the backing storage for this view. Used
// for deserialization.
void SetSharedMemory(internal::BigBufferSharedMemoryRegion shared_memory);
// Converts to a BigBuffer which owns the viewed data. May have to copy data.
static BigBuffer ToBigBuffer(BigBufferView view) WARN_UNUSED_RESULT;
BigBuffer::StorageType storage_type() const { return storage_type_; }
base::span<const uint8_t> bytes() const {
DCHECK_EQ(storage_type_, BigBuffer::StorageType::kBytes);
return bytes_;
}
internal::BigBufferSharedMemoryRegion& shared_memory() {
DCHECK_EQ(storage_type_, BigBuffer::StorageType::kSharedMemory);
return shared_memory_.value();
}
private:
BigBuffer::StorageType storage_type_;
base::span<const uint8_t> bytes_;
base::Optional<internal::BigBufferSharedMemoryRegion> shared_memory_;
DISALLOW_COPY_AND_ASSIGN(BigBufferView);
};
} // namespace mojo_base
#endif // MOJO_PUBLIC_CPP_BASE_BIG_BUFFER_H_
......@@ -89,4 +89,58 @@ bool UnionTraits<mojo_base::mojom::BigBufferDataView, mojo_base::BigBuffer>::
return false;
}
// static
mojo_base::mojom::BigBufferDataView::Tag UnionTraits<
mojo_base::mojom::BigBufferDataView,
mojo_base::BigBufferView>::GetTag(const mojo_base::BigBufferView& view) {
switch (view.storage_type()) {
case mojo_base::BigBuffer::StorageType::kBytes:
return mojo_base::mojom::BigBufferDataView::Tag::BYTES;
case mojo_base::BigBuffer::StorageType::kSharedMemory:
return mojo_base::mojom::BigBufferDataView::Tag::SHARED_MEMORY;
}
NOTREACHED();
return mojo_base::mojom::BigBufferDataView::Tag::BYTES;
}
// static
base::span<const uint8_t> UnionTraits<
mojo_base::mojom::BigBufferDataView,
mojo_base::BigBufferView>::bytes(const mojo_base::BigBufferView& view) {
return view.bytes();
}
// static
mojo_base::internal::BigBufferSharedMemoryRegion& UnionTraits<
mojo_base::mojom::BigBufferDataView,
mojo_base::BigBufferView>::shared_memory(mojo_base::BigBufferView& view) {
return view.shared_memory();
}
// static
bool UnionTraits<
mojo_base::mojom::BigBufferDataView,
mojo_base::BigBufferView>::Read(mojo_base::mojom::BigBufferDataView data,
mojo_base::BigBufferView* out) {
switch (data.tag()) {
case mojo_base::mojom::BigBufferDataView::Tag::BYTES: {
mojo::ArrayDataView<uint8_t> bytes_view;
data.GetBytesDataView(&bytes_view);
out->SetBytes(bytes_view);
return true;
}
case mojo_base::mojom::BigBufferDataView::Tag::SHARED_MEMORY: {
mojo_base::internal::BigBufferSharedMemoryRegion shared_memory;
if (!data.ReadSharedMemory(&shared_memory))
return false;
out->SetSharedMemory(std::move(shared_memory));
return true;
}
}
return false;
}
} // namespace mojo
......@@ -9,6 +9,8 @@
#include <vector>
#include "base/component_export.h"
#include "base/containers/span.h"
#include "base/macros.h"
#include "mojo/public/cpp/base/big_buffer.h"
#include "mojo/public/cpp/bindings/union_traits.h"
#include "mojo/public/cpp/system/buffer.h"
......@@ -43,6 +45,20 @@ struct COMPONENT_EXPORT(MOJO_BASE_SHARED_TRAITS)
mojo_base::BigBuffer* out);
};
template <>
struct COMPONENT_EXPORT(MOJO_BASE_SHARED_TRAITS)
UnionTraits<mojo_base::mojom::BigBufferDataView, mojo_base::BigBufferView> {
static mojo_base::mojom::BigBufferDataView::Tag GetTag(
const mojo_base::BigBufferView& view);
static base::span<const uint8_t> bytes(const mojo_base::BigBufferView& view);
static mojo_base::internal::BigBufferSharedMemoryRegion& shared_memory(
mojo_base::BigBufferView& view);
static bool Read(mojo_base::mojom::BigBufferDataView data,
mojo_base::BigBufferView* out);
};
} // namespace mojo
#endif // MOJO_PUBLIC_CPP_BASE_BIG_BUFFER_MOJOM_TRAITS_H_
......@@ -66,3 +66,13 @@ android_library("bindings_java") {
srcjar_deps = [ "../interfaces/bindings:bindings_java_sources" ]
}
android_library("base_java") {
java_files = [ "base/src/org/chromium/mojo_base/BigBufferUtil.java" ]
deps = [
":system_java",
"//mojo/android:system_java",
"//mojo/public/mojom/base:base_java",
]
}
// 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.
package org.chromium.mojo_base;
import org.chromium.mojo.system.Core;
import org.chromium.mojo.system.SharedBufferHandle;
import org.chromium.mojo.system.impl.CoreImpl;
import org.chromium.mojo_base.mojom.BigBuffer;
import org.chromium.mojo_base.mojom.BigBufferSharedMemoryRegion;
import java.nio.ByteBuffer;
/**
* Static helper methods for working with the mojom BigBuffer type.
*/
public final class BigBufferUtil {
public static final int MAX_INLINE_ARRAY_SIZE = 64 * 1024;
// Retrives a copy of the buffer's contents regardless of what type was backing it (i.e. array
// or shared memory).
public static byte[] getBytesFromBigBuffer(BigBuffer buffer) {
if (buffer.which() == BigBuffer.Tag.Bytes) {
return buffer.getBytes();
} else {
BigBufferSharedMemoryRegion region = buffer.getSharedMemory();
ByteBuffer byteBuffer =
region.bufferHandle.map(0, region.size, SharedBufferHandle.MapFlags.NONE);
byte[] bytes = new byte[region.size];
byteBuffer.get(bytes);
return bytes;
}
}
// Creates a new mojom.BigBuffer for IPC from a set of bytes. If the byte array is larger than
// MAX_INLINE_ARRAY_SIZE, shared memory will be used instead of an inline array.
public static BigBuffer createBigBufferFromBytes(byte[] bytes) {
BigBuffer buffer = new BigBuffer();
if (bytes.length <= MAX_INLINE_ARRAY_SIZE) {
buffer.setBytes(bytes);
return buffer;
}
Core core = CoreImpl.getInstance();
BigBufferSharedMemoryRegion region = new BigBufferSharedMemoryRegion();
region.bufferHandle =
core.createSharedBuffer(new SharedBufferHandle.CreateOptions(), bytes.length);
region.size = bytes.length;
ByteBuffer mappedRegion =
region.bufferHandle.map(0, bytes.length, SharedBufferHandle.MapFlags.NONE);
mappedRegion.put(bytes);
buffer.setSharedMemory(region);
return buffer;
}
}
......@@ -110,6 +110,7 @@ _CONFIG = [
# Blink already has a signal for contexts being destroyed, and
# other types of failures should be explicitly signalled.
'mojo::(?!WrapCallback).+',
'mojo_base::BigBuffer.*',
'(?:.+::)?mojom::.+',
"service_manager::BinderRegistry",
# TODO(dcheng): Remove this once Connector isn't needed in Blink
......
......@@ -5,24 +5,27 @@
#include "third_party/blink/common/message_port/cloneable_message_struct_traits.h"
#include "base/containers/span.h"
#include "mojo/public/cpp/base/big_buffer_mojom_traits.h"
namespace mojo {
base::span<const uint8_t> StructTraits<
mojo_base::BigBufferView StructTraits<
blink::mojom::CloneableMessage::DataView,
blink::CloneableMessage>::encoded_message(blink::CloneableMessage& input) {
return input.encoded_message;
return mojo_base::BigBufferView(input.encoded_message);
}
bool StructTraits<blink::mojom::CloneableMessage::DataView,
blink::CloneableMessage>::
Read(blink::mojom::CloneableMessage::DataView data,
blink::CloneableMessage* out) {
if (!data.ReadEncodedMessage(&out->owned_encoded_message) ||
!data.ReadBlobs(&out->blobs)) {
mojo_base::BigBufferView message_view;
if (!data.ReadEncodedMessage(&message_view) || !data.ReadBlobs(&out->blobs)) {
return false;
}
auto message_bytes = message_view.data();
out->owned_encoded_message = {message_bytes.begin(), message_bytes.end()};
out->encoded_message = out->owned_encoded_message;
out->stack_trace_id = data.stack_trace_id();
out->stack_trace_debugger_id_first = data.stack_trace_debugger_id_first();
......
......@@ -5,6 +5,7 @@
#ifndef THIRD_PARTY_WEBKIT_COMMON_MESSAGE_PORT_CLONEABLE_MESSAGE_STRUCT_TRAITS_H_
#define THIRD_PARTY_WEBKIT_COMMON_MESSAGE_PORT_CLONEABLE_MESSAGE_STRUCT_TRAITS_H_
#include "mojo/public/cpp/base/big_buffer.h"
#include "third_party/blink/public/common/message_port/cloneable_message.h"
#include "third_party/blink/public/mojom/message_port/message_port.mojom.h"
......@@ -14,7 +15,7 @@ template <>
struct BLINK_COMMON_EXPORT
StructTraits<blink::mojom::CloneableMessage::DataView,
blink::CloneableMessage> {
static base::span<const uint8_t> encoded_message(
static mojo_base::BigBufferView encoded_message(
blink::CloneableMessage& input);
static std::vector<blink::mojom::SerializedBlobPtr>& blobs(
......
......@@ -26,9 +26,9 @@ struct BLINK_COMMON_EXPORT
return blink::MessagePortChannel::ReleaseHandles(input.ports);
}
static const std::vector<blink::mojom::SerializedArrayBufferContentsPtr>&
static std::vector<blink::mojom::SerializedArrayBufferContentsPtr>
array_buffer_contents_array(blink::TransferableMessage& input) {
return input.array_buffer_contents_array;
return std::move(input.array_buffer_contents_array);
}
static const std::vector<SkBitmap>& image_bitmap_contents_array(
......
......@@ -78,6 +78,7 @@ mojom("mojom_core") {
public_deps = [
":mojom_platform",
"//mojo/public/mojom/base",
"//skia/public/interfaces",
"//url/mojom:url_mojom_gurl",
]
......
......@@ -4,8 +4,10 @@
module blink.mojom;
import "mojo/public/mojom/base/big_buffer.mojom";
// Struct which represents the contents of an ArrayBuffer, e.g.
// WTF::ArrayBufferContents.
struct SerializedArrayBufferContents {
array<uint8> contents;
mojo_base.mojom.BigBuffer contents;
};
......@@ -4,6 +4,7 @@
module blink.mojom;
import "mojo/public/mojom/base/big_buffer.mojom";
import "third_party/blink/public/mojom/array_buffer/array_buffer_contents.mojom";
import "third_party/blink/public/mojom/blob/serialized_blob.mojom";
import "skia/public/interfaces/bitmap.mojom";
......@@ -17,7 +18,7 @@ import "skia/public/interfaces/bitmap.mojom";
// This struct represents the cloneable part of messages that are sent across
// postMessage style APIs. In particular this is used for BroadcastChannel.
struct CloneableMessage {
array<uint8> encoded_message;
mojo_base.mojom.BigBuffer encoded_message;
// Blob handles for any blobs being sent in this message.
array<SerializedBlob> blobs;
// Stack trace captured by sender.
......
......@@ -8,6 +8,7 @@ include_rules = [
"+gpu/config/gpu_feature_info.h",
"-inspector/v8",
"+inspector/v8/public",
"+mojo/public/cpp/base",
"+mojo/public/cpp/bindings",
"+mojo/public/cpp/system",
"+services/metrics/public",
......
......@@ -4,6 +4,7 @@
#include "third_party/blink/renderer/core/messaging/blink_cloneable_message_struct_traits.h"
#include "mojo/public/cpp/base/big_buffer_mojom_traits.h"
#include "third_party/blink/renderer/platform/blob/blob_data.h"
namespace mojo {
......@@ -22,8 +23,10 @@ bool StructTraits<blink::mojom::blink::CloneableMessage::DataView,
blink::BlinkCloneableMessage>::
Read(blink::mojom::blink::CloneableMessage::DataView data,
blink::BlinkCloneableMessage* out) {
mojo::ArrayDataView<uint8_t> message_data;
data.GetEncodedMessageDataView(&message_data);
mojo_base::BigBufferView message_view;
if (!data.ReadEncodedMessage(&message_view))
return false;
auto message_data = message_view.data();
out->message = blink::SerializedScriptValue::Create(
reinterpret_cast<const char*>(message_data.data()), message_data.size());
......
......@@ -5,6 +5,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_MESSAGING_BLINK_CLONEABLE_MESSAGE_STRUCT_TRAITS_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_MESSAGING_BLINK_CLONEABLE_MESSAGE_STRUCT_TRAITS_H_
#include "mojo/public/cpp/base/big_buffer.h"
#include "mojo/public/cpp/bindings/array_traits_wtf_vector.h"
#include "mojo/public/cpp/bindings/string_traits_wtf.h"
#include "third_party/blink/public/mojom/message_port/message_port.mojom-blink.h"
......@@ -18,9 +19,9 @@ namespace mojo {
template <>
struct CORE_EXPORT StructTraits<blink::mojom::blink::CloneableMessage::DataView,
blink::BlinkCloneableMessage> {
static base::span<const uint8_t> encoded_message(
static mojo_base::BigBuffer encoded_message(
blink::BlinkCloneableMessage& input) {
return input.message->GetWireData();
return mojo_base::BigBuffer(input.message->GetWireData());
}
static Vector<scoped_refptr<blink::BlobDataHandle>> blobs(
......
......@@ -2,8 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/imagebitmap/image_bitmap.h"
#include "third_party/blink/renderer/core/messaging/blink_transferable_message_struct_traits.h"
#include "mojo/public/cpp/base/big_buffer_mojom_traits.h"
#include "third_party/blink/renderer/core/imagebitmap/image_bitmap.h"
#include "third_party/skia/include/core/SkBitmap.h"
namespace mojo {
......@@ -105,17 +107,19 @@ bool StructTraits<blink::mojom::blink::SerializedArrayBufferContents::DataView,
WTF::ArrayBufferContents>::
Read(blink::mojom::blink::SerializedArrayBufferContents::DataView data,
WTF::ArrayBufferContents* out) {
mojo::ArrayDataView<uint8_t> mojo_contents;
data.GetContentsDataView(&mojo_contents);
mojo_base::BigBufferView contents_view;
if (!data.ReadContents(&contents_view))
return false;
auto contents_data = contents_view.data();
auto handle = WTF::ArrayBufferContents::CreateDataHandle(
mojo_contents.size(), WTF::ArrayBufferContents::kZeroInitialize);
contents_data.size(), WTF::ArrayBufferContents::kZeroInitialize);
if (!handle)
return false;
WTF::ArrayBufferContents array_buffer_contents(
std::move(handle), WTF::ArrayBufferContents::kNotShared);
memcpy(array_buffer_contents.Data(), mojo_contents.data(),
mojo_contents.size());
memcpy(array_buffer_contents.Data(), contents_data.data(),
contents_data.size());
*out = std::move(array_buffer_contents);
return true;
}
......
......@@ -55,12 +55,12 @@ class CORE_EXPORT
StructTraits<blink::mojom::blink::SerializedArrayBufferContents::DataView,
WTF::ArrayBufferContents> {
public:
static base::span<uint8_t> contents(
static mojo_base::BigBuffer contents(
const WTF::ArrayBufferContents& array_buffer_contents) {
uint8_t* allocation_start =
static_cast<uint8_t*>(array_buffer_contents.Data());
return base::make_span(allocation_start,
array_buffer_contents.DataLength());
return mojo_base::BigBuffer(
base::make_span(allocation_start, array_buffer_contents.DataLength()));
}
static bool Read(blink::mojom::blink::SerializedArrayBufferContents::DataView,
WTF::ArrayBufferContents* out);
......
......@@ -2,22 +2,23 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/messaging/blink_transferable_message_struct_traits.h"
#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
#include "mojo/public/cpp/base/big_buffer_mojom_traits.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/message_port/message_port_channel.h"
#include "third_party/blink/public/mojom/message_port/message_port.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/exception_state.h"
#include "third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.h"
#include "third_party/blink/renderer/bindings/core/v8/serialization/v8_script_value_deserializer.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_array_buffer.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h"
#include "third_party/blink/renderer/core/messaging/blink_transferable_message.h"
#include "third_party/blink/renderer/core/messaging/blink_transferable_message_struct_traits.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h"
#include "third_party/blink/renderer/bindings/core/v8/serialization/v8_script_value_deserializer.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_image_bitmap.h"
#include "third_party/blink/renderer/core/messaging/blink_transferable_message.h"
#include "third_party/blink/renderer/core/messaging/message_port.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h"
#include "third_party/skia/include/core/SkBitmap.h"
namespace blink {
......
......@@ -27,6 +27,8 @@
#include "third_party/blink/renderer/core/messaging/message_port.h"
#include <memory>
#include "mojo/public/cpp/base/big_buffer_mojom_traits.h"
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/renderer/bindings/core/v8/exception_state.h"
......
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