summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/mojo/mojo_handle.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/blink/renderer/core/mojo/mojo_handle.cc')
-rw-r--r--chromium/third_party/blink/renderer/core/mojo/mojo_handle.cc29
1 files changed, 21 insertions, 8 deletions
diff --git a/chromium/third_party/blink/renderer/core/mojo/mojo_handle.cc b/chromium/third_party/blink/renderer/core/mojo/mojo_handle.cc
index b74bf25779e..a2491fcdd63 100644
--- a/chromium/third_party/blink/renderer/core/mojo/mojo_handle.cc
+++ b/chromium/third_party/blink/renderer/core/mojo/mojo_handle.cc
@@ -4,6 +4,9 @@
#include "third_party/blink/renderer/core/mojo/mojo_handle.h"
+#include "base/numerics/safe_math.h"
+#include "mojo/public/c/system/message_pipe.h"
+#include "mojo/public/cpp/bindings/message.h"
#include "mojo/public/cpp/system/message_pipe.h"
#include "third_party/blink/renderer/bindings/core/v8/array_buffer_or_array_buffer_view.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
@@ -50,11 +53,17 @@ MojoWatcher* MojoHandle::watch(ScriptState* script_state,
MojoResult MojoHandle::writeMessage(
ArrayBufferOrArrayBufferView& buffer,
const HeapVector<Member<MojoHandle>>& handles) {
- // mojo::WriteMessageRaw takes ownership of the handles, so release them here.
- Vector<::MojoHandle, kHandleVectorInlineCapacity> raw_handles(handles.size());
- std::transform(
- handles.begin(), handles.end(), raw_handles.begin(),
- [](MojoHandle* handle) { return handle->handle_.release().value(); });
+ Vector<mojo::ScopedHandle, kHandleVectorInlineCapacity> scoped_handles;
+ scoped_handles.ReserveCapacity(handles.size());
+ bool has_invalid_handles = false;
+ for (auto& handle : handles) {
+ if (!handle->handle_.is_valid())
+ has_invalid_handles = true;
+ else
+ scoped_handles.emplace_back(std::move(handle->handle_));
+ }
+ if (has_invalid_handles)
+ return MOJO_RESULT_INVALID_ARGUMENT;
const void* bytes = nullptr;
size_t num_bytes = 0;
@@ -68,9 +77,13 @@ MojoResult MojoHandle::writeMessage(
num_bytes = view->byteLength();
}
- return mojo::WriteMessageRaw(
- mojo::MessagePipeHandle(handle_.get().value()), bytes, num_bytes,
- raw_handles.data(), raw_handles.size(), MOJO_WRITE_MESSAGE_FLAG_NONE);
+ auto message = mojo::Message(
+ base::make_span(static_cast<const uint8_t*>(bytes), num_bytes),
+ base::make_span(scoped_handles));
+ DCHECK(!message.IsNull());
+ return mojo::WriteMessageNew(mojo::MessagePipeHandle(handle_.get().value()),
+ message.TakeMojoMessage(),
+ MOJO_WRITE_MESSAGE_FLAG_NONE);
}
MojoReadMessageResult* MojoHandle::readMessage(