Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(697)

Unified Diff: third_party/WebKit/Source/core/mojo/MojoHandle.cpp

Issue 2720873002: Implements JS bindings for mojo shared buffer. (Closed)
Patch Set: adds layout tests Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/mojo/MojoHandle.cpp
diff --git a/third_party/WebKit/Source/core/mojo/MojoHandle.cpp b/third_party/WebKit/Source/core/mojo/MojoHandle.cpp
index 0ae42778335411c744034c169d24a21ffa984f91..b16a6aeccd37ceace2dea26b70442c0219be33fe 100644
--- a/third_party/WebKit/Source/core/mojo/MojoHandle.cpp
+++ b/third_party/WebKit/Source/core/mojo/MojoHandle.cpp
@@ -8,6 +8,9 @@
#include "bindings/core/v8/ScriptState.h"
#include "core/dom/DOMArrayBuffer.h"
#include "core/dom/DOMArrayBufferView.h"
+#include "core/mojo/MojoCloneBufferHandleFlags.h"
+#include "core/mojo/MojoCreateSharedBufferResult.h"
+#include "core/mojo/MojoMapBufferResult.h"
#include "core/mojo/MojoReadMessageFlags.h"
#include "core/mojo/MojoReadMessageResult.h"
#include "core/mojo/MojoWatcher.h"
@@ -92,4 +95,38 @@ void MojoHandle::readMessage(const MojoReadMessageFlags& flagsDict,
resultDict.setHandles(handles);
}
+void MojoHandle::mapBuffer(unsigned offset,
+ unsigned numBytes,
+ MojoMapBufferResult& resultDict) {
+ void* data = nullptr;
+ MojoResult result = MojoMapBuffer(m_handle->value(), offset, numBytes, &data,
+ MOJO_MAP_BUFFER_FLAG_NONE);
+ resultDict.setResult(result);
+ if (result == MOJO_RESULT_OK) {
+ WTF::ArrayBufferContents::DataHandle dataHandle(data, [](void* buffer) {
+ MojoResult result = MojoUnmapBuffer(buffer);
+ DCHECK_EQ(result, MOJO_RESULT_OK);
+ });
+ WTF::ArrayBufferContents contents(std::move(dataHandle), numBytes,
+ WTF::ArrayBufferContents::NotShared);
+ resultDict.setBuffer(DOMArrayBuffer::create(contents));
+ }
+}
+
+void MojoHandle::clone(const MojoCloneBufferHandleFlags& flagsDict,
+ MojoCreateSharedBufferResult& resultDict) {
+ MojoDuplicateBufferHandleOptions options = {
+ sizeof(options), MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE};
+ if (flagsDict.readOnly())
+ options.flags |= MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_READ_ONLY;
+
+ mojo::Handle handle;
+ MojoResult result = MojoDuplicateBufferHandle(m_handle->value(), &options,
+ handle.mutable_value());
+ resultDict.setResult(result);
+ if (result == MOJO_RESULT_OK) {
+ resultDict.setHandle(MojoHandle::create(mojo::MakeScopedHandle(handle)));
+ }
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698